int_f nh5ltget_attribute_info_c(hid_t_f *loc_id, int_f *namelen, _fcd name, int_f *attrnamelen, _fcd attrname, hsize_t_f *dims, int_f *type_class, size_t_f *type_size) { int ret_value = -1; herr_t ret; hid_t c_loc_id; char *c_name; char *c_attrname; int c_namelen; int c_attrnamelen; H5T_class_t c_classtype; size_t c_type_size; hsize_t c_dims[32]; int i; int c_rank; /* * Convert FORTRAN name to C name */ c_namelen = (int)*namelen; c_name = (char *)HD5f2cstring(name, c_namelen); if (c_name == NULL) return ret_value; c_attrnamelen = (int)*attrnamelen; c_attrname = (char *)HD5f2cstring(attrname, c_attrnamelen); if (c_attrname == NULL) return ret_value; /* * Call H5LTget_attribute_info function. */ c_loc_id = (hid_t)*loc_id; ret = H5LTget_attribute_info(c_loc_id,c_name,c_attrname,c_dims,&c_classtype,&c_type_size); if (ret < 0) return ret_value; *type_class = c_classtype; *type_size = (size_t_f)c_type_size; /* * Transpose dimension arrays because of C-FORTRAN storage order */ ret = H5LTget_attribute_ndims(c_loc_id,c_name,c_attrname,&c_rank); if (ret < 0) return ret_value; for (i = 0; i < c_rank ; i++) { dims[i] = (hsize_t_f) c_dims[c_rank - i - 1]; } ret_value = 0; return ret_value; }
int_f nh5ltget_attribute_ndims_c(hid_t_f *loc_id, int_f *namelen, _fcd dsetname, int_f *attrnamelen, _fcd attrname, int_f *rank) { int ret_value = -1; herr_t ret; hid_t c_loc_id; char *c_name = NULL; char *c_attrname = NULL; int c_namelen; int c_attrnamelen; int c_rank; /* * Convert FORTRAN name to C name */ c_namelen =(int) *namelen; c_name = (char *)HD5f2cstring(dsetname, c_namelen); if (c_name == NULL) goto done; c_attrnamelen = (int)*attrnamelen; c_attrname = (char *)HD5f2cstring(attrname, c_attrnamelen); if (c_attrname == NULL) goto done; /* * Call H5LTset_attribute_ndims function. */ c_loc_id = (hid_t)*loc_id; ret = H5LTget_attribute_ndims(c_loc_id,c_name,c_attrname,&c_rank); if (ret < 0) goto done; *rank = (int_f)c_rank; ret_value = 0; done: if(c_name!=NULL) free(c_name); if(c_attrname!=NULL) free(c_attrname); return ret_value; }
static herr_t make_attributes( hid_t loc_id, const char* obj_name ) { int rank_out; hsize_t *dims_out = 0; H5T_class_t type_class; size_t type_size; int i; char attr_str_in[] = {"My attribute"}; char attr_str_out[20]; char attr_char_in[5] = {1,2,3,4,5}; char attr_char_out[5]; short attr_short_in[5] = {1,2,3,4,5}; short attr_short_out[5]; int attr_int_in[5] = {1,2,3,4,5}; int attr_int_out[5]; long attr_long_in[5] = {1,2,3,4,5}; long attr_long_out[5]; float attr_float_in[5] = {1,2,3,4,5}; float attr_float_out[5]; double attr_double_in[5] = {1,2,3,4,5}; double attr_double_out[5]; unsigned char attr_uchar_in[5] = {1,2,3,4,5}; unsigned char attr_uchar_out[5]; unsigned short attr_ushort_in[5] = {1,2,3,4,5}; unsigned short attr_ushort_out[5]; unsigned int attr_uint_in[5] = {1,2,3,4,5}; unsigned int attr_uint_out[5]; unsigned long attr_ulong_in[5] = {1,2,3,4,5}; unsigned long attr_ulong_out[5]; /*------------------------------------------------------------------------- * H5LTset_attribute_string test *------------------------------------------------------------------------- */ TESTING("H5LTset_attribute_string"); /* Set the attribute */ if ( H5LTset_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_in ) < 0 ) return -1; PASSED(); /*------------------------------------------------------------------------- * H5LTset_attribute_string test *------------------------------------------------------------------------- */ TESTING("H5LTget_attribute_string"); /* Get the attribute */ if ( H5LTget_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_out ) < 0 ) return -1; if ( strcmp( attr_str_in, attr_str_out ) != 0 ) { return -1; } PASSED(); /*------------------------------------------------------------------------- * H5LTset_attribute_char test *------------------------------------------------------------------------- */ TESTING("H5LTset_attribute_char"); /* Set the attribute */ if ( H5LTset_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_in, (size_t)5 ) < 0 ) return -1; PASSED(); /*------------------------------------------------------------------------- * H5LTget_attribute_char test *------------------------------------------------------------------------- */ TESTING("H5LTget_attribute_char"); /* Get the attribute */ if ( H5LTget_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_char_in[i] != attr_char_out[i] ) { return -1; } } /* Get the attribute */ if ( H5LTget_attribute( loc_id, obj_name, ATTR2_NAME, H5T_NATIVE_CHAR, attr_char_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_char_in[i] != attr_char_out[i] ) { return -1; } } PASSED(); /*------------------------------------------------------------------------- * H5LTset_attribute_short test *------------------------------------------------------------------------- */ TESTING("H5LTset_attribute_short"); /* Set the attribute */ if ( H5LTset_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_in, (size_t)5 ) < 0 ) return -1; PASSED(); /*------------------------------------------------------------------------- * H5LTget_attribute_short test *------------------------------------------------------------------------- */ TESTING("H5LTget_attribute_short"); /* Get the attribute */ if ( H5LTget_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_short_in[i] != attr_short_out[i] ) { return -1; } } /* Get the attribute */ if ( H5LTget_attribute( loc_id, obj_name, ATTR3_NAME, H5T_NATIVE_SHORT, attr_short_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_short_in[i] != attr_short_out[i] ) { return -1; } } PASSED(); /*------------------------------------------------------------------------- * H5LTset_attribute_int test *------------------------------------------------------------------------- */ TESTING("H5LTset_attribute_int"); /* Set the attribute */ if ( H5LTset_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_in, (size_t)5 ) < 0 ) return -1; PASSED(); /*------------------------------------------------------------------------- * H5LTget_attribute_int test *------------------------------------------------------------------------- */ TESTING("H5LTget_attribute_int"); /* Get the attribute */ if ( H5LTget_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_int_in[i] != attr_int_out[i] ) { return -1; } } /* Get the attribute */ if ( H5LTget_attribute( loc_id, obj_name, ATTR4_NAME, H5T_NATIVE_INT, attr_int_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_int_in[i] != attr_int_out[i] ) { return -1; } } PASSED(); /*------------------------------------------------------------------------- * H5LTset_attribute_long test *------------------------------------------------------------------------- */ TESTING("H5LTset_attribute_long"); /* Set the attribute */ if ( H5LTset_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_in, (size_t)5 ) < 0 ) return -1; PASSED(); /*------------------------------------------------------------------------- * H5LTget_attribute_long test *------------------------------------------------------------------------- */ TESTING("H5LTget_attribute_long"); /* Get the attribute */ if ( H5LTget_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_long_in[i] != attr_long_out[i] ) { return -1; } } /* Get the attribute */ if ( H5LTget_attribute( loc_id, obj_name, ATTR5_NAME, H5T_NATIVE_LONG, attr_long_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_long_in[i] != attr_long_out[i] ) { return -1; } } PASSED(); /*------------------------------------------------------------------------- * H5LTset_attribute_uchar test *------------------------------------------------------------------------- */ TESTING("H5LTset_attribute_uchar"); /* Set the attribute */ if ( H5LTset_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_in, (size_t)5 ) < 0 ) return -1; PASSED(); /*------------------------------------------------------------------------- * H5LTget_attribute_uchar test *------------------------------------------------------------------------- */ TESTING("H5LTget_attribute_uchar"); /* Get the attribute */ if ( H5LTget_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_uchar_in[i] != attr_uchar_out[i] ) { return -1; } } /* Get the attribute */ if ( H5LTget_attribute( loc_id, obj_name, ATTR6_NAME, H5T_NATIVE_UCHAR, attr_uchar_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_uchar_in[i] != attr_uchar_out[i] ) { return -1; } } PASSED(); /*------------------------------------------------------------------------- * H5LTset_attribute_ushort test *------------------------------------------------------------------------- */ TESTING("H5LTset_attribute_ushort"); /* Set the attribute */ if ( H5LTset_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_in, (size_t)5 ) < 0 ) return -1; PASSED(); /*------------------------------------------------------------------------- * H5LTget_attribute_ushort test *------------------------------------------------------------------------- */ TESTING("H5LTget_attribute_ushort"); /* Get the attribute */ if ( H5LTget_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_ushort_in[i] != attr_ushort_out[i] ) { return -1; } } /* Get the attribute */ if ( H5LTget_attribute( loc_id, obj_name, ATTR7_NAME, H5T_NATIVE_USHORT, attr_ushort_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_ushort_in[i] != attr_ushort_out[i] ) { return -1; } } PASSED(); /*------------------------------------------------------------------------- * H5LTset_attribute_int test *------------------------------------------------------------------------- */ TESTING("H5LTset_attribute_uint"); /* Set the attribute */ if ( H5LTset_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_in, (size_t)5 ) < 0 ) return -1; PASSED(); /*------------------------------------------------------------------------- * H5LTget_attribute_int test *------------------------------------------------------------------------- */ TESTING("H5LTget_attribute_uint"); /* Get the attribute */ if ( H5LTget_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_uint_in[i] != attr_uint_out[i] ) { return -1; } } /* Get the attribute */ if ( H5LTget_attribute( loc_id, obj_name, ATTR8_NAME, H5T_NATIVE_UINT, attr_uint_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_uint_in[i] != attr_uint_out[i] ) { return -1; } } PASSED(); /*------------------------------------------------------------------------- * H5LTset_attribute_ulong test *------------------------------------------------------------------------- */ TESTING("H5LTset_attribute_ulong"); /* Set the attribute */ if ( H5LTset_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_in, (size_t)5 ) < 0 ) return -1; PASSED(); /*------------------------------------------------------------------------- * H5LTget_attribute_long test *------------------------------------------------------------------------- */ TESTING("H5LTget_attribute_ulong"); /* Get the attribute */ if ( H5LTget_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_ulong_in[i] != attr_ulong_out[i] ) { return -1; } } /* Get the attribute */ if ( H5LTget_attribute( loc_id, obj_name, ATTR9_NAME, H5T_NATIVE_ULONG, attr_ulong_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_ulong_in[i] != attr_ulong_out[i] ) { return -1; } } PASSED(); /*------------------------------------------------------------------------- * H5LTset_attribute_float test *------------------------------------------------------------------------- */ TESTING("H5LTset_attribute_float"); /* Set the attribute */ if ( H5LTset_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_in, (size_t)5 ) < 0 ) return -1; PASSED(); /*------------------------------------------------------------------------- * H5LTget_attribute_float test *------------------------------------------------------------------------- */ TESTING("H5LTget_attribute_float"); /* Get the attribute */ if ( H5LTget_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_float_in[i] != attr_float_out[i] ) { return -1; } } /* Get the attribute */ if ( H5LTget_attribute( loc_id, obj_name, ATTR10_NAME, H5T_NATIVE_FLOAT, attr_float_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_float_in[i] != attr_float_out[i] ) { return -1; } } PASSED(); /*------------------------------------------------------------------------- * H5LTset_attribute_double test *------------------------------------------------------------------------- */ TESTING("H5LTset_attribute_double"); /* Set the attribute */ if ( H5LTset_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_in, (size_t)5 ) < 0 ) return -1; PASSED(); /*------------------------------------------------------------------------- * H5LTget_attribute_double test *------------------------------------------------------------------------- */ TESTING("H5LTget_attribute_double"); /* Get the attribute */ if ( H5LTget_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_double_in[i] != attr_double_out[i] ) { return -1; } } /* Get the attribute */ if ( H5LTget_attribute( loc_id, obj_name, ATTR11_NAME, H5T_NATIVE_DOUBLE, attr_double_out ) < 0 ) return -1; for (i = 0; i < 5; i++) { if ( attr_double_in[i] != attr_double_out[i] ) { return -1; } } PASSED(); /*------------------------------------------------------------------------- * H5LTget_attribute_ndims test *------------------------------------------------------------------------- */ TESTING("H5LTget_attribute_ndims"); if ( H5LTget_attribute_ndims( loc_id, obj_name, ATTR2_NAME, &rank_out ) < 0 ) return -1; if ( rank_out != 1 ) { return -1; } PASSED(); /*------------------------------------------------------------------------- * H5LTget_attribute_info test *------------------------------------------------------------------------- */ TESTING("H5LTget_attribute_info"); dims_out = (hsize_t*) malloc( sizeof(hsize_t) * rank_out ); if ( H5LTget_attribute_info( loc_id, obj_name, ATTR2_NAME, dims_out, &type_class, &type_size) < 0 ) return -1; for (i = 0; i < rank_out; i++) { if ( dims_out[i] != 5 ) { return -1; } } if ( type_class != H5T_INTEGER ) { return -1; } if ( dims_out ) free( dims_out ); PASSED(); return 0; }
void rdiff(const char *name, hid_t f1, hid_t f2) { hid_t g1 = H5Gopen(f1, name, H5P_DEFAULT); hid_t g2 = H5Gopen(f2, name, H5P_DEFAULT); if (g1 >= 0 && g2 >= 0) { int n1 = H5Aget_num_attrs(g1); for (int i = 0; i < n1; i++) { char aname[MAXNAME]; hid_t a1 = H5Aopen_idx(g1, i); assert(H5Aget_name(a1, MAXNAME, aname) < MAXNAME); H5Aclose(a1); if (!H5LTfind_attribute(g2, aname)) { printf("Only in %s[%s%s]\n", file1, name, aname); continue; } int d1, d2; H5LTget_attribute_ndims(f1, name, aname, &d1); H5LTget_attribute_ndims(f2, name, aname, &d2); assert(d1 <= 1 && d2 <= 1); hsize_t dims1, dims2; H5T_class_t t1, t2; size_t ts1, ts2; H5LTget_attribute_info(f1, name, aname, &dims1, &t1, &ts1); H5LTget_attribute_info(f2, name, aname, &dims2, &t2, &ts2); assert(t1 == t2); assert(t1 == H5T_INTEGER || t1 == H5T_FLOAT || t1 == H5T_STRING); if (t1 == H5T_INTEGER) { assert(d1==0 || (dims1 == 1 && dims2 == 1)); assert(ts1 == 4 && ts2 == 4); int v1, v2; H5LTget_attribute_int(f1, name, aname, &v1); H5LTget_attribute_int(f2, name, aname, &v2); if (v1 != v2) { printf("%s[%s%s]=%d %s[%s%s]=%d\n", file1, name, aname, v1, file2, name, aname, v2); } } if (t1 == H5T_FLOAT) { assert(d1==0 || (dims1 == 1 && dims2 == 1)); assert(ts1 == 4 && ts2 == 4); float v1, v2; H5LTget_attribute_float(f1, name, aname, &v1); H5LTget_attribute_float(f2, name, aname, &v2); if (v1 != v2) { printf("%s[%s%s]=%g %s[%s%s]=%g\n", file1, name, aname, v1, file2, name, aname, v2); } } if (t1 == H5T_STRING) { assert(ts1 < 256 && ts2 < 256); char buf1[256]; char buf2[256]; H5LTget_attribute_string(f1, name, aname, buf1); H5LTget_attribute_string(f2, name, aname, buf2); if (strcmp(buf1, buf2)) { printf("%s[%s%s]=%s %s[%s%s]=%s\n", file1, name, aname, buf1, file2, name, aname, buf2); } } } int n2 = H5Aget_num_attrs(g2); for (int i = 0; i < n2; i++) { char aname[MAXNAME]; hid_t a2 = H5Aopen_idx(g2, i); assert(H5Aget_name(a2, MAXNAME, aname) < MAXNAME); H5Aclose(a2); if (!H5LTfind_attribute(g1, aname)) { printf("Only in %s[%s%s]\n", file2, name, aname); continue; } } hsize_t nobj; H5Gget_num_objs(g1, &nobj); for (int i = 0; i < nobj; i++) { char oname[MAXNAME]; assert(H5Gget_objname_by_idx(g1, i, oname, MAXNAME) < MAXNAME); int otype = H5Gget_objtype_by_idx(g1, i); assert(otype == H5G_DATASET); if (!H5LTfind_dataset(g2, oname)) { printf("Only in %s[%s%s]\n", file1, name, oname); continue; } hsize_t dims1[2], dims2[2]; H5T_class_t t1, t2; size_t ts1, ts2; H5LTget_dataset_info(g1, oname, dims1, &t1, &ts1); H5LTget_dataset_info(g2, oname, dims2, &t2, &ts2); if (dims1[0] != dims2[0] || dims1[1] != dims2[1]) { printf("%s[%s%s](%d,%d) != %s[%s%s](%d,%d)\n", file1, name, oname, dims1[1], dims1[0], file2, name, oname, dims2[1], dims2[0]); continue; } float *data1 = malloc(dims1[0]*dims1[1]*sizeof(float)); float *data2 = malloc(dims1[0]*dims1[1]*sizeof(float)); H5LTread_dataset_float(g1, oname, data1); H5LTread_dataset_float(g2, oname, data2); float maxdiff = 0; for (int i = dims1[0]*dims1[1]-1; i >= 0; i--) { float d = data1[i] - data2[i]; if (d < 0) d = -d; if (d > maxdiff) maxdiff = d; } printf("max |%s[%s%s] - %s[%s%s]| = %g\n", file1, name, oname, file2, name, oname, maxdiff); free(data1); free(data2); } H5Gget_num_objs(g2, &nobj); for (int i = 0; i < nobj; i++) { char oname[MAXNAME]; assert(H5Gget_objname_by_idx(g2, i, oname, MAXNAME) < MAXNAME); int otype = H5Gget_objtype_by_idx(g2, i); assert(otype == H5G_DATASET); if (!H5LTfind_dataset(g1, oname)) { printf("Only in %s[%s%s]\n", file2, name, oname); continue; } } H5Gclose(g1); H5Gclose(g2); } else if (g1 >= 0) { printf("Only in %s:%s\n", file1, name); H5Gclose(g1); } else if (g2 >= 0) { printf("Only in %s:%s\n", file2, name); H5Gclose(g2); } else { printf("Group %s does not exist in either file.\n", name); } }
/*********************************************************************** NAME: ias_ancillary_read PURPOSE: Calls routines to read ancillary and ephemeris data RETURNS: Integer status code of SUCCESS or ERROR NOTES: Calling routine is responsible for ensuring a valid filename ************************************************************************/ int ias_ancillary_read ( const char *ancillary_filename, /* I: Name of data file */ IAS_ANC_ATTITUDE_DATA **attitude_data, /* I/O: Pointer to attitude data */ IAS_ANC_EPHEMERIS_DATA **ephemeris_data /* I/O: Pointer to ephemeris data */ ) { hid_t hdf_file_id = -1; /* HDF5 file handle */ herr_t hdf_error_status = -1; /* HDF5 error status code; negative values indicate an error */ int file_format_version = 0; /* File format version */ int rank = 0; /* Number of dimensions for the format version attribute */ H5T_class_t type_class; /* Type class identifier */ size_t type_size = 0; /* Size of datatype in bytes */ hsize_t version_dims = 0; /* Format version array dimension */ IAS_ANC_ATTITUDE_DATA *attitude_read = NULL; /* working attitude data buffer */ IAS_ANC_EPHEMERIS_DATA *ephemeris_read = NULL; /* working ephemeris data buffer */ /* Initialize the pointers so caller has something to check against */ *attitude_data = NULL; *ephemeris_data = NULL; /* Make sure the ancillary file is "valid" */ if (!ias_ancillary_is_ancillary_file(ancillary_filename)) { IAS_LOG_ERROR("Ancillary file %s not valid", ancillary_filename); return ERROR; } /* Open the file for reading. */ hdf_file_id = H5Fopen(ancillary_filename, H5F_ACC_RDONLY, H5P_DEFAULT); if (hdf_file_id < 0) { IAS_LOG_ERROR("Opening ancillary data file %s", ancillary_filename); return ERROR; } /* Verify the file format version attribute has a dimension of 1 */ hdf_error_status = H5LTget_attribute_ndims(hdf_file_id, "/", FILE_FORMAT_VERSION_ATTRIBUTE_NAME, &rank); if (hdf_error_status < 0) { IAS_LOG_ERROR("Retrieving file format version attribute dimensions " "in ancillary file %s", ancillary_filename); return ERROR; } if (rank != 1) /* Should only be 1D array */ { IAS_LOG_ERROR("Invalid rank %d detected for file format version " "attribute in ancillary file %s, should be 1", rank, ancillary_filename); return ERROR; } /* The file format version attribute should be a scalar of integer data type*/ hdf_error_status = H5LTget_attribute_info(hdf_file_id, "/", FILE_FORMAT_VERSION_ATTRIBUTE_NAME, &version_dims, &type_class, &type_size); if ((hdf_error_status < 0) || (version_dims != 1) || (type_class != H5T_INTEGER) || (type_size != sizeof(int))) { IAS_LOG_ERROR("Invalid file format version attribute information " "in ancillary file %s", ancillary_filename); return ERROR; } /* Read the file format version information */ hdf_error_status = H5LTget_attribute_int(hdf_file_id, "/", FILE_FORMAT_VERSION_ATTRIBUTE_NAME, &file_format_version); if (hdf_error_status < 0) { IAS_LOG_ERROR("Reading file format version attribute in ancillary " "file %s", ancillary_filename); H5Fclose(hdf_file_id); return ERROR; } /* Read the attitude data from the file. */ attitude_read = read_attitude_data(hdf_file_id, file_format_version); if (attitude_read == NULL) { IAS_LOG_ERROR("Reading attitude data from ancillary data file %s", ancillary_filename); H5Fclose(hdf_file_id); return ERROR; } /* Read the ephemeris data from the file. */ ephemeris_read = read_ephemeris_data(hdf_file_id, file_format_version); if (ephemeris_read == NULL) { IAS_LOG_ERROR("Reading ephemeris data from ancillary data file %s", ancillary_filename); ias_ancillary_free_attitude(attitude_read); H5Fclose(hdf_file_id); return ERROR; } /* Close the file now that the attitude and ephemeris data have been read from it. */ hdf_error_status = H5Fclose(hdf_file_id); if (hdf_error_status < 0) { IAS_LOG_ERROR("Closing ancillary data file %s", ancillary_filename); ias_ancillary_free_attitude(attitude_read); ias_ancillary_free_ephemeris(ephemeris_read); return ERROR; } /* Point the input pointers to the working buffers. */ *attitude_data = attitude_read; *ephemeris_data = ephemeris_read; /* Done */ return SUCCESS; }
/*---------------------------------------------------------------------- NAME: read_epoch_time PURPOSE: Reads the requested epoch time attribute from the ancillary data file RETURNS: Integer status code of SUCCESS or ERROR -------------------------------------------------------------------------*/ static int read_epoch_time ( hid_t hdf_file_id, /* I: Open ancillary data file handle */ const char *epoch_name, /* I: Epoch time name */ double epoch_time[3] /* O: Array containing epoch time components */ ) { herr_t hdf_error_status = -1; /* HDF5 error status code */ hsize_t epoch_dims = 0; /* Epoch array dimension */ H5T_class_t type_class; /* Type class identifier */ size_t type_size = 0; /* Size of datatype in bytes */ int rank = 0; /* Number of dimensions for the epoch time attribute */ /* Verify the epoch time array attribute has an array dimension of 1 */ hdf_error_status = H5LTget_attribute_ndims(hdf_file_id, "/", epoch_name, &rank); if (hdf_error_status < 0) { IAS_LOG_ERROR("Retrieving epoch time attribute dimensions"); return ERROR; } if (rank != 1) /* Should only be 1D array */ { IAS_LOG_ERROR("Invalid rank %d detected for epoch time array, " "should be 1", rank); return ERROR; } /* The epoch time attribute should be a 1D, 3-element array of datatype double */ hdf_error_status = H5LTget_attribute_info(hdf_file_id, "/", epoch_name, &epoch_dims, &type_class, &type_size); if ((hdf_error_status < 0) || (epoch_dims != 3) || (type_class != H5T_FLOAT) || (type_size != sizeof(double))) { IAS_LOG_ERROR("Invalid epoch time array dimensions/datatype class/" "datatype size information"); return ERROR; } /* Now get the epoch time components */ hdf_error_status = H5LTget_attribute_double(hdf_file_id, "/", epoch_name, epoch_time); if (hdf_error_status < 0) { IAS_LOG_ERROR("Retrieving epoch time attribute values"); return ERROR; } /* Done */ return SUCCESS; }