int NC4_put_propattr(NC_HDF5_FILE_INFO_T* h5) { int ncstat = NC_NOERR; H5T_class_t t_class; size_t size; hid_t grp = -1; hid_t exists = -1; hid_t attid = -1; hid_t aspace = -1; hid_t atype = -1; herr_t herr = 0; char* text = NULL; /* Get root group */ grp = h5->root_grp->hdf_grpid; /* get root group */ /* See if the NCPROPS attribute exists */ if(H5Aexists(grp,NCPROPS) == 0) { /* Does not exist */ ncstat = NC4_buildpropinfo(&h5->fileinfo->propattr,&text); if(text == NULL || ncstat != NC_NOERR) { goto done; } herr = -1; /* Create a datatype to refer to. */ HCHECK((atype = H5Tcopy(H5T_C_S1))); HCHECK((H5Tset_cset(atype, H5T_CSET_ASCII))); HCHECK((H5Tset_size(atype, strlen(text)+1))); /*keep nul term */ HCHECK((aspace = H5Screate(H5S_SCALAR))); HCHECK((attid = H5Acreate(grp, NCPROPS, atype, aspace, H5P_DEFAULT))); HCHECK((H5Awrite(attid, atype, text))); herr = 0; } done: if(ncstat != NC_NOERR) { if(text != NULL) { free(text); text = NULL; } } if(attid >= 0) HCHECK((H5Aclose(attid))); if(aspace >= 0) HCHECK((H5Sclose(aspace))); if(atype >= 0) HCHECK((H5Tclose(atype))); return ncstat; }
int NC4_put_propattr(NC_HDF5_FILE_INFO_T* h5) { int ncstat = NC_NOERR; char text[NCPROPS_LENGTH+1]; H5T_class_t t_class; size_t size; hid_t grp = -1; hid_t exists = -1; hid_t attid = -1; hid_t aspace = -1; hid_t atype = -1; herr_t herr = 0; /* Get root group */ grp = h5->root_grp->hdf_grpid; /* get root group */ /* See if the NCPROPS attribute exists */ exists = H5Aopen_name(grp, NCPROPS); if(exists < 0) {/* Does not exist */ herr = -1; /* Create a datatype to refer to. */ HCHECK((atype = H5Tcopy(H5T_C_S1))); HCHECK((H5Tset_cset(atype, H5T_CSET_UTF8))); HCHECK((H5Tset_size(atype, NCPROPS_LENGTH))); HCHECK((aspace = H5Screate(H5S_SCALAR))); HCHECK((attid = H5Acreate(grp, NCPROPS, atype, aspace, H5P_DEFAULT))); HCHECK((H5Awrite(attid, atype, h5->fileinfo->propattr.text))); herr = 0; } done: if(exists >= 0) HCHECK((H5Aclose(exists))); if(attid >= 0) HCHECK((H5Aclose(attid))); if(aspace >= 0) HCHECK((H5Sclose(aspace))); if(atype >= 0) HCHECK((H5Tclose(atype))); 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; 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; }