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 record.c
* \brief MINC 2.0 Record Functions
* \author Bert Vincent
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /*HAVE_CONFIG_H*/
#include <hdf5.h>
#include "minc2.h"
#include "minc2_private.h"
/** This method gets the name of the record dimension
* TODO: set record name??
*/
int miget_record_name(mihandle_t volume,
char **name)
{
return (MI_NOERROR);
}
/** This method gets the length (i.e., number of fields in the case of
* uniform records and number of bytes for non_uniform ones) of the
* record.
*/
int miget_record_length(mihandle_t volume,
int *length)
{
if (volume == NULL || length == NULL) {
return (MI_ERROR);
}
if (volume->volume_class == MI_CLASS_UNIFORM_RECORD ||
volume->volume_class == MI_CLASS_NON_UNIFORM_RECORD) {
*length = H5Tget_nmembers(volume->ftype_id);
return (MI_NOERROR);
}
return (MI_ERROR);
}
/** This method returns the field name for the given field index. Memory
* for returned string is allocated on the heap and should be released using
* mifree_name().
*/
int miget_record_field_name(mihandle_t volume,
int index,
char **name)
{
if (volume == NULL || name == NULL) {
return (MI_ERROR);
}
/* Get the field name. The H5Tget_member_name() function allocates
* the memory for the string using malloc(), so we can return the
* pointer directly without any further manipulations.
*/
*name = H5Tget_member_name(volume->ftype_id, index);
if (*name == NULL) {
return (MI_ERROR);
}
return (MI_NOERROR);
}
/** This method sets a field name for the volume record. The volume
* must be of class "MI_CLASS_UNIFORM_RECORD". The size of record
* type will be increased if necessary to accommodate the new field.
*/
int miset_record_field_name(mihandle_t volume,
int index,
const char *name)
{
hid_t mtype_id;
hid_t ftype_id;
size_t offset;
if (volume == NULL || name == NULL) {
return (MI_ERROR);
}
if (volume->volume_class != MI_CLASS_UNIFORM_RECORD &&
volume->volume_class != MI_CLASS_NON_UNIFORM_RECORD) {
return (MI_ERROR);
}
/* Get the type of the record's fields. This is recorded as the
* type of the volume.
*/
ftype_id = mitype_to_hdftype(volume->volume_type, FALSE);
mtype_id = mitype_to_hdftype(volume->volume_type, TRUE);
/* Calculate the offset of the new member.
*/
offset = index * H5Tget_size(ftype_id);
/* If the offset plus the size of the member is larger than the
* current size of the structure, increase the size of the structure.
*/
if (offset + H5Tget_size(ftype_id) > H5Tget_size(volume->ftype_id)) {
H5Tset_size(volume->ftype_id, offset + H5Tget_size(ftype_id));
}
if (offset + H5Tget_size(mtype_id) > H5Tget_size(volume->mtype_id)) {
H5Tset_size(volume->mtype_id, offset + H5Tget_size(mtype_id));
}
/* Actually define the field within the structure.
*/
H5Tinsert(volume->ftype_id, name, offset, ftype_id);
H5Tinsert(volume->mtype_id, name, offset, mtype_id);
/* Delete the HDF5 type object returned by mitype_to_hdftype().
*/
H5Tclose(ftype_id);
H5Tclose(mtype_id);
return (MI_NOERROR);
}
/* kate: indent-mode cstyle; indent-width 2; replace-tabs on; */
|