File: datatype.c

package info (click to toggle)
libminc 2.4.07-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,288 kB
  • sloc: ansic: 57,268; cpp: 3,654; sh: 100; makefile: 23; ruby: 18
file content (117 lines) | stat: -rw-r--r-- 2,863 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/** \file datatype.c
 * \brief MINC 2.0 data type/space functions
 ************************************************************************/

#include <stdlib.h>
#include <hdf5.h>
#include "minc2.h"
#include "minc2_private.h"

/** Return the data class of a volume (See miclass_t).
 */
int miget_data_class ( mihandle_t volume, miclass_t *volume_class )
{
  *volume_class = volume->volume_class;
  return ( MI_NOERROR );
}

/** Return the data type of a volume (See mitype_t).
 */
int miget_data_type ( mihandle_t volume, mitype_t *data_type )
{
  *data_type = volume->volume_type;
  return ( MI_NOERROR );
}

/** Return the byte size of the voxel datatype
 */
int miget_data_type_size ( mihandle_t volume, misize_t *voxel_size )
{
  hid_t grp_id;
  hid_t dset_id;
  hid_t type_id;
  hid_t file_id = volume->hdf_id;

  grp_id = midescend_path ( file_id, MI_FULLIMAGE_PATH );

  if ( grp_id < 0 ) {
    return ( MI_ERROR );
  }

  dset_id = H5Dopen1 ( grp_id, "image" );

  if ( dset_id < 0 ) {
    return ( MI_ERROR );
  }

  type_id = H5Dget_type ( dset_id );

  if ( type_id < 0 ) {
    return ( MI_ERROR );
  }

  *voxel_size = H5Tget_size ( type_id );

  H5Tclose ( type_id );
  H5Dclose ( dset_id );
  H5Gclose ( grp_id );

  return ( MI_NOERROR );
}

/** Return the minc space type, name should be freed after use
 */
int miget_space_name ( mihandle_t volume, char **name )
{
  size_t length = 0;
  int result = MI_ERROR;
  int i;
  /* This is the order of the search for candidates for the space type.
     The reason for this is complication is to permit support for older-style
     MINC files which associate the spacetype with individual dimensions.
  */
  static const char *path_list[] = {
    MI_ROOT_PATH "/" MI_INFO_NAME,
    MI_ROOT_PATH "/dimensions/xspace",
    MI_ROOT_PATH "/dimensions/yspace",
    MI_ROOT_PATH "/dimensions/zspace",
    NULL
  };

  /* Search for the spacetype attribute in all available paths.
   */
  for ( i = 0; path_list[i] != 0; i++ ) {
    result = miget_attr_length ( volume, path_list[i], "spacetype",
                                 &length );

    if ( result == MI_NOERROR ) {
      break;
    }
  }

  if ( result != MI_NOERROR ) {
    /* Nothing found, so use the default.
     */
    length = strlen ( MI_NATIVE );
    *name = malloc ( length + 1 );
    strcpy ( *name, MI_NATIVE );
  } else {
    *name = malloc ( length + 1 );
    result = miget_attr_values ( volume, MI_TYPE_STRING, path_list[i],
                                 "spacetype", length+1, *name );
  }

  return ( result );
}

/**
 * Set minc space type
 */
int miset_space_name ( mihandle_t volume, const char *name )
{
  return miset_attr_values ( volume, MI_TYPE_STRING, MI_ROOT_PATH "/" MI_INFO_NAME,
                             "spacetype", strlen ( name ), name );

}

/* kate: indent-mode cstyle; indent-width 2; replace-tabs on; */