static int NC4_get_propattr(NC_HDF5_FILE_INFO_T* h5) { int ncstat = NC_NOERR; size_t size; H5T_class_t t_class; hid_t grp = -1; hid_t attid = -1; hid_t aspace = -1; hid_t atype = -1; hid_t ntype = -1; herr_t herr = 0; char* text = NULL; /* Get root group */ grp = h5->root_grp->hdf_grpid; /* get root group */ /* Try to extract the NCPROPS attribute */ if(H5Aexists(grp,NCPROPS) > 0) { /* Does exist */ attid = H5Aopen_name(grp, NCPROPS); herr = -1; aspace = H5Aget_space(attid); /* dimensions of attribute data */ atype = H5Aget_type(attid); /* Verify that atype and size */ t_class = H5Tget_class(atype); if(t_class != H5T_STRING) {ncstat = NC_EATTMETA; goto done;} size = H5Tget_size(atype); if(size == 0) goto done; text = (char*)malloc(size+1); if(text == NULL) {ncstat = NC_ENOMEM; goto done;} HCHECK((ntype = H5Tget_native_type(atype, H5T_DIR_ASCEND))); HCHECK((H5Aread(attid, ntype, text))); /* Make sure its null terminated */ text[size] = '\0'; /* Try to parse text */ ncstat = NC4_properties_parse(&h5->fileinfo->propattr,text); herr = 0; } done: if(attid >= 0) HCHECK((H5Aclose(attid))); if(aspace >= 0) HCHECK((H5Sclose(aspace))); if(ntype >= 0) HCHECK((H5Tclose(ntype))); if(atype >= 0) HCHECK((H5Tclose(atype))); if(text != NULL) free(text); return ncstat; }
static int NC4_get_propattr(NC_HDF5_FILE_INFO_T* h5) { int ncstat = NC_NOERR; size_t size; H5T_class_t t_class; char text[NCPROPS_LENGTH+1]; hid_t grp = -1; hid_t attid = -1; hid_t aspace = -1; hid_t atype = -1; hid_t ntype = -1; herr_t herr = 0; /* Get root group */ grp = h5->root_grp->hdf_grpid; /* get root group */ /* Try to extract the NCPROPS attribute */ attid = H5Aopen_name(grp, NCPROPS); if(attid >= 0) { herr = -1; aspace = H5Aget_space(attid); /* dimensions of attribute data */ atype = H5Aget_type(attid); /* Verify that atype and size */ t_class = H5Tget_class(atype); if(t_class != H5T_STRING) {ncstat = NC_EATTMETA; goto done;} size = H5Tget_size(atype); if(size != NCPROPS_LENGTH) {ncstat = NC_EATTMETA; goto done;} HCHECK((ntype = H5Tget_native_type(atype, H5T_DIR_ASCEND))); HCHECK((H5Aread(attid, ntype, text))); /* Try to parse text */ strncpy(h5->fileinfo->propattr.text,text,NCPROPS_LENGTH); h5->fileinfo->propattr.text[NCPROPS_LENGTH-1] = '\0'; ncstat = NC4_properties_parse(&h5->fileinfo->propattr); herr = 0; } done: if(attid >= 0) HCHECK((H5Aclose(attid))); if(aspace >= 0) HCHECK((H5Sclose(aspace))); if(ntype >= 0) HCHECK((H5Tclose(ntype))); if(atype >= 0) HCHECK((H5Tclose(atype))); return ncstat; }