/* Read and verify attribute for group or dataset. */ int read_attribute(hid_t obj_id, int this_type, int num) { hid_t aid; hsize_t group_block[2]={1,1}, dset_block[2]={1, 8}; int i, mpi_rank, in_num, in_data[8], out_data[8], vrfy_errors = 0; char attr_name[32]; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); if(this_type == is_group) { sprintf(attr_name, "Group Attribute %d", num); aid = H5Aopen_name(obj_id, attr_name); if(MAINPROCESS) { H5Aread(aid, H5T_NATIVE_INT, &in_num); vrfy_errors = dataset_vrfy(NULL, NULL, NULL, group_block, &in_num, &num); } H5Aclose(aid); } else if(this_type == is_dset) { sprintf(attr_name, "Dataset Attribute %d", num); for(i=0; i<8; i++) out_data[i] = i; aid = H5Aopen_name(obj_id, attr_name); if(MAINPROCESS) { H5Aread(aid, H5T_NATIVE_INT, in_data); vrfy_errors = dataset_vrfy(NULL, NULL, NULL, dset_block, in_data, out_data); } H5Aclose(aid); } return vrfy_errors; }
int AMRreader:: getIntfInfo( hid_t gid ) { hid_t aid = H5Aopen_name( gid, intf_np_name ); if( aid<0 ) { nvert_=0; debug1 << "Failed to find number of interface points.\n"; return -1; } else { H5Aread( aid, H5T_NATIVE_INT, &nvert_ ); H5Aclose(aid); } debug2 << "nvert is " << nvert_ << "\n"; aid = H5Aopen_name( gid, intf_ne_name ); if( aid<0 ) { nrect_=0; debug1 << "Failed to find number of interface elements.\n"; return -2; } else { H5Aread( aid, H5T_NATIVE_INT, &nrect_ ); H5Aclose(aid); } debug2 << "nrect is " << nrect_ << "\n"; return 0; }
void AbstractHdf5Access::SetUnlimitedDatasetId() { // Now deal with the unlimited dimension // In terms of an Unlimited dimension dataset: // * Files pre - r16738 (inc. Release 3.1 and earlier) use simply "Time" for "Data"'s unlimited variable. // * Files generated by r16738 - r18257 used "<DatasetName>_Time" for "<DatasetName>"'s unlimited variable, // - These are not to be used and there is no backwards compatibility for them, since they weren't in a release. // * Files post r18257 (inc. Release 3.2 onwards) use "<DatasetName>_Unlimited" for "<DatasetName>"'s // unlimited variable, // - a new attribute "Name" has been added to the Unlimited Dataset to allow it to assign // any name to the unlimited variable. Which can then be easily read by Hdf5DataReader. // - if this dataset is missing we look for simply "Time" to remain backwards compatible with Releases <= 3.1 if (DoesDatasetExist(mDatasetName + "_Unlimited")) { mUnlimitedDatasetId = H5Dopen(mFileId, (mDatasetName + "_Unlimited").c_str()); hid_t name_attribute_id = H5Aopen_name(mUnlimitedDatasetId, "Name"); hid_t unit_attribute_id = H5Aopen_name(mUnlimitedDatasetId, "Unit"); hid_t attribute_type = H5Aget_type(name_attribute_id); // Read into it. char* string_array = (char *)malloc(sizeof(char)*MAX_STRING_SIZE); H5Aread( name_attribute_id, attribute_type, string_array); std::string name_string(&string_array[0]); mUnlimitedDimensionName = name_string; H5Aread( unit_attribute_id, attribute_type, string_array); std::string unit_string(&string_array[0]); mUnlimitedDimensionUnit = unit_string; free(string_array); H5Tclose(attribute_type); H5Aclose(name_attribute_id); H5Aclose(unit_attribute_id); } else if (DoesDatasetExist("Time")) { mUnlimitedDimensionName = "Time"; mUnlimitedDimensionUnit = "msec"; mUnlimitedDatasetId = H5Dopen(mFileId, mUnlimitedDimensionName.c_str()); } else { NEVER_REACHED; } mIsUnlimitedDimensionSet = true; }
static herr_t get_attribute_mem(hid_t obj_id, const char *attr_name, hid_t mem_type_id, void *data) { hid_t attr_id; herr_t status; attr_id = H5Aopen_name(obj_id, attr_name); if (attr_id < 0) return -1; status = H5Aread(attr_id, mem_type_id, data); if (status < 0) { H5Aclose(attr_id); return -1; } status = H5Aclose(attr_id); if (status < 0) return -1; return 0; }
static herr_t get_attribute_float(hid_t input, const char *name, float *val) { hid_t attr_id; hid_t type_id; H5T_class_t type_class; size_t type_size; herr_t status; char *strval; attr_id = H5Aopen_name(input, name); type_id = H5Aget_type(attr_id); type_class = H5Tget_class(type_id); type_size = H5Tget_size(type_id); H5Tclose(type_id); H5Aclose(attr_id); switch(type_class) { case H5T_STRING: status = get_attribute_str(input, name, &strval); if (status < 0) return -1; *val = atof(strval); free(strval); return 0; case H5T_FLOAT: status = get_attribute(input, name, H5T_NATIVE_FLOAT, val); if (status < 0) return -1; return 0; } return -1; }
static herr_t get_attribute_disk(hid_t loc_id, const char *attr_name, void *attr_out) { hid_t attr_id; hid_t attr_type; herr_t status; attr_id = H5Aopen_name(loc_id, attr_name); if (attr_id < 0) return -1; attr_type = H5Aget_type(attr_id); if (attr_type < 0) goto out; status = H5Aread(attr_id, attr_type, attr_out); if (status < 0) goto out; status = H5Tclose(attr_type); if (status < 0) goto out; status = H5Aclose(attr_id); if (status < 0) return -1; return 0; out: H5Tclose(attr_type); H5Aclose(attr_id); return -1; }
bool read_attribute(const char * name, const H5ID & dataset, T & value) { H5ID attribute(H5Aopen_name(dataset, name), H5Aclose); if (!attribute) return false; herr_t status = H5Aread(attribute, H5T_NATIVE_FLOAT, &value); return status >= 0; }
void mhdf_getElemTypeName( mhdf_FileHandle file_handle, const char* elem_handle, char* buffer, size_t buf_len, mhdf_Status* status ) { FileHandle* file_ptr; hid_t elem_id, type_id, attr_id; char bytes[16]; herr_t rval; API_BEGIN; if (NULL == buffer || buf_len < 2) { mhdf_setFail( status, "invalid input" ); return; } buffer[0] = '\0'; file_ptr = (FileHandle*)(file_handle); if (!mhdf_check_valid_file( file_ptr, status )) return; elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status ); if (elem_id < 0) return; attr_id = H5Aopen_name( elem_id, ELEM_TYPE_ATTRIB ); H5Gclose( elem_id ); if (attr_id < 0) { mhdf_setFail( status, "Missing element type attribute. Invalid file." ); return; } type_id = H5Aget_type( attr_id ); assert( type_id > 0 ); rval = H5Aread( attr_id, type_id, bytes ); H5Aclose( attr_id ); if (rval < 0) { H5Tclose( type_id ); mhdf_setFail( status, "Failed to read element type attribute. Invalid file." ); return; } rval = H5Tenum_nameof( type_id, bytes, buffer, buf_len ); H5Tclose( type_id ); if (rval < 0) { mhdf_setFail( status, "Invalid datatype for element type attribute. Invalid file." ); return; } mhdf_setOkay( status ); API_END; return ; }
/* fetch num_cols and the col for a particular trackname */ void get_cols(chromosome_t *chromosome, char *trackname, hsize_t *num_cols, hsize_t *col) { hid_t attr, root, dataspace, datatype; hsize_t data_size, cell_size, num_cells; char *attr_data; /* Tracknames are stored in the attributes of the root group of each file */ root = H5Gopen(chromosome->h5group, "/", H5P_DEFAULT); assert(root >= 0); attr = H5Aopen_name(root, "tracknames"); assert(attr >= 0); dataspace = H5Aget_space(attr); assert(dataspace >= 0); assert(H5Sget_simple_extent_dims(dataspace, num_cols, NULL) == 1); assert(H5Sclose(dataspace) >= 0); if (trackname && col) { datatype = H5Aget_type(attr); assert(datatype >= 0); assert(H5Tget_class(datatype) == H5T_STRING); cell_size = H5Tget_size(datatype); assert(cell_size > 0); data_size = H5Aget_storage_size(attr); assert(data_size > 0); num_cells = data_size / cell_size; /* allocate room for tracknames */ attr_data = xmalloc(data_size); assert(attr_data); assert(H5Aread(attr, datatype, attr_data) >= 0); *col = 0; for (*col = 0; *col <= num_cells; (*col)++) { if (*col == num_cells) { fprintf(stderr, "can't find trackname: %s\n", trackname); free(attr_data); exit(EXIT_FAILURE); } else { if (!strncmp(attr_data + (*col * cell_size), trackname, cell_size)) { break; } } } /* clean up read tracknames */ free(attr_data); } assert(H5Aclose(attr) >= 0); }
void get_attr(hid_t loc, const char *name, hid_t mem_type_id, void *buf) { hid_t attr; attr = H5Aopen_name(loc, name); assert(attr >= 0); assert(H5Aread(attr, mem_type_id, buf) >= 0); assert(H5Aclose(attr) >= 0); }
/* * check if the dataset is an image */ void H5Dataset_check_image(H5Dataset *d, hid_t did) { hid_t aid=-1; char *buf; if (!d) return; aid = H5Aopen_name(did, "CLASS"); if (aid > 0) { buf = (char *) H5Dataset_read_attr_value(aid); if (buf) { if(strncmp(buf, "IMAGE", 5)==0) d->time |= H5D_IMAGE_FLAG; free(buf); } H5Aclose(aid); } aid = H5Aopen_name(did, "IMAGE_SUBCLASS"); if (aid > 0) { buf = (char *) H5Dataset_read_attr_value(aid); if (buf) { if(strncmp(buf, "IMAGE_TRUECOLOR", 15)==0) d->time |= H5D_IMAGE_TRUECOLOR_FLAG; free(buf); } H5Aclose(aid); } aid = H5Aopen_name(did, "INTERLACE_MODE"); if (aid > 0) { buf = (char *) H5Dataset_read_attr_value(aid); if (buf) { if(strncmp(buf, "INTERLACE_PIXEL", 15)==0) d->time |= H5D_IMAGE_INTERLACE_PIXEL_FLAG; else if(strncmp(buf, "INTERLACE_PLANE", 15)==0) d->time |= H5D_IMAGE_INTERLACE_PLANE_FLAG; free(buf); } H5Aclose(aid); } }
static herr_t get_attribute_str(hid_t obj_id, const char *attr_name, char **data) { hid_t attr_id; hid_t attr_type; size_t type_size; herr_t status; *data = NULL; attr_id = H5Aopen_name(obj_id, attr_name); if (attr_id < 0) return -1; attr_type = H5Aget_type(attr_id); if (attr_type < 0) goto out; /* Get the size */ type_size = H5Tget_size(attr_type); if (type_size < 0) goto out; /* malloc enough space for the string, plus 1 for trailing '\0' */ *data = (char *)malloc(type_size + 1); status = H5Aread(attr_id, attr_type, *data); if (status < 0) goto out; /* Set the last character to '\0' in case we are dealing with * null padded or space padded strings */ (*data)[type_size] = '\0'; status = H5Tclose(attr_type); if (status < 0) goto out; status = H5Aclose(attr_id); if (status < 0) return -1; return 0; out: H5Tclose(attr_type); H5Aclose(attr_id); if (*data) free(*data); return -1; }
static herr_t get_attribute_info(hid_t obj_id, const char *attr_name, hsize_t *dims, H5T_class_t *type_class, size_t *type_size, hid_t *type_id) { hid_t attr_id; hid_t space_id; herr_t status; int rank; /* Open the attribute. */ attr_id = H5Aopen_name(obj_id, attr_name); if (attr_id < 0) return -1; /* Get an identifier for the datatype. */ *type_id = H5Aget_type(attr_id); /* Get the class. */ *type_class = H5Tget_class(*type_id); /* Get the size. */ *type_size = H5Tget_size(*type_id); /* Get the dataspace handle */ space_id = H5Aget_space(attr_id); if (space_id < 0) goto out; /* Get dimensions */ rank = H5Sget_simple_extent_dims(space_id, dims, NULL); if (rank < 0) goto out; /* Terminate access to the dataspace */ status = H5Sclose(space_id); if (status < 0) goto out; /* End access to the attribute */ status = H5Aclose(attr_id); if (status < 0) goto out; return 0; out: H5Tclose(*type_id); H5Aclose(attr_id); return -1; }
static herr_t get_max_id( hid_t group_id, const char* subgroup, const char* datatable, unsigned long* data ) { unsigned long id; hid_t elem_id, conn_id, attr_id, space_id; herr_t rval; int rank; hsize_t dims[2]; #if defined(H5Gopen_vers) && H5Gopen_vers > 1 elem_id = H5Gopen2( group_id, subgroup, H5P_DEFAULT ); #else elem_id = H5Gopen( group_id, subgroup ); #endif if (elem_id < 0) return (herr_t)-1; #if defined(H5Dopen_vers) && H5Dopen_vers > 1 conn_id = H5Dopen2( elem_id, datatable, H5P_DEFAULT ); #else conn_id = H5Dopen( elem_id, datatable ); #endif H5Gclose( elem_id ); if (conn_id < 0) return (herr_t)-1; space_id = H5Dget_space( conn_id ); if (space_id < 0) { H5Dclose( conn_id ); return -1; } rank = H5Sget_simple_extent_ndims( space_id ); if (rank <= 0 || rank > 2) { H5Dclose(conn_id); H5Sclose(space_id); return -1; } rval = H5Sget_simple_extent_dims( space_id, dims, NULL ); H5Sclose( space_id ); if (rval < 0) { H5Dclose( conn_id ); return -1; } attr_id = H5Aopen_name( conn_id, START_ID_ATTRIB ); H5Dclose( conn_id ); if (attr_id < 0) return (herr_t)-1; rval = H5Aread( attr_id, H5T_NATIVE_ULONG, &id ); H5Aclose( attr_id ); if (rval < 0) return rval; id += dims[0]; if (id > *data) *data = id; return 0; }
bool GH5_FetchAttribute( hid_t loc_id, const char *pszAttrName, CPLString &osResult, bool bReportError ) { bool retVal = false; hid_t hAttr = H5Aopen_name( loc_id, pszAttrName ); osResult.clear(); if( hAttr < 0 ) { if( bReportError ) CPLError( CE_Failure, CPLE_AppDefined, "Attempt to read attribute %s failed, not found.", pszAttrName ); return false; } hid_t hAttrTypeID = H5Aget_type( hAttr ); hid_t hAttrNativeType = H5Tget_native_type( hAttrTypeID, H5T_DIR_DEFAULT ); if( H5Tget_class( hAttrNativeType ) == H5T_STRING ) { int nAttrSize = H5Tget_size( hAttrTypeID ); char *pachBuffer = (char *) CPLCalloc(nAttrSize+1,1); H5Aread( hAttr, hAttrNativeType, pachBuffer ); osResult = pachBuffer; CPLFree( pachBuffer ); retVal = true; } else { if( bReportError ) CPLError( CE_Failure, CPLE_AppDefined, "Attribute %s of unsupported type for conversion to string.", pszAttrName ); retVal = false; } H5Tclose( hAttrNativeType ); H5Tclose( hAttrTypeID ); H5Aclose( hAttr ); return retVal; }
/* reads the references of palettes into an array * Each reference requires eight bytes storage. Therefore, the array length * is 8*numberOfPalettes. */ hobj_ref_t* H5Dataset_get_paletteRef(hid_t did) { hid_t aid=-1; hobj_ref_t *ref_buf=NULL; aid = H5Aopen_name(did, "PALETTE"); if (aid > 0) { ref_buf = (hobj_ref_t *) H5Dataset_read_attr_value(aid); H5Aclose(aid); } return ref_buf; }
int _GetValue(hid_t loc_id, const char *attr_name, void *strname) { int iQualityIndex; hid_t hAttributeID; if(strcmp(attr_name,(char *)strname)==0) { hAttributeID = H5Aopen_name(loc_id, attr_name); H5Aread(hAttributeID, H5T_NATIVE_INT, &iQualityIndex); H5Aclose(hAttributeID); return iQualityIndex; } else return 0; }
void read_header_attributes_in_hdf5(char *fname) { hid_t hdf5_file, hdf5_headergrp, hdf5_attribute; hdf5_file = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT); hdf5_headergrp = H5Gopen(hdf5_file, "/Header"); hdf5_attribute = H5Aopen_name(hdf5_headergrp, "NumPart_ThisFile"); H5Aread(hdf5_attribute, H5T_NATIVE_INT, header.npart); H5Aclose(hdf5_attribute); hdf5_attribute = H5Aopen_name(hdf5_headergrp, "NumPart_Total"); H5Aread(hdf5_attribute, H5T_NATIVE_UINT, header.npartTotal); H5Aclose(hdf5_attribute); hdf5_attribute = H5Aopen_name(hdf5_headergrp, "NumPart_Total_HighWord"); H5Aread(hdf5_attribute, H5T_NATIVE_UINT, header.npartTotalHighWord); H5Aclose(hdf5_attribute); hdf5_attribute = H5Aopen_name(hdf5_headergrp, "MassTable"); H5Aread(hdf5_attribute, H5T_NATIVE_DOUBLE, header.mass); H5Aclose(hdf5_attribute); hdf5_attribute = H5Aopen_name(hdf5_headergrp, "Time"); H5Aread(hdf5_attribute, H5T_NATIVE_DOUBLE, &header.time); H5Aclose(hdf5_attribute); #ifdef LT_STELLAREVOLUTION hdf5_attribute = H5Aopen_name(hdf5_headergrp, "BoxSize"); H5Aread(hdf5_attribute, H5T_NATIVE_DOUBLE, &header.BoxSize); H5Aclose(hdf5_attribute); #endif hdf5_attribute = H5Aopen_name(hdf5_headergrp, "NumFilesPerSnapshot"); H5Aread(hdf5_attribute, H5T_NATIVE_INT, &header.num_files); H5Aclose(hdf5_attribute); hdf5_attribute = H5Aopen_name(hdf5_headergrp, "Flag_IC_Info"); H5Aread(hdf5_attribute, H5T_NATIVE_INT, &header.flag_ic_info); H5Aclose(hdf5_attribute); H5Gclose(hdf5_headergrp); H5Fclose(hdf5_file); }
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; }
/* * Class: hdf_hdf5lib_H5 * Method: H5Aopen_name * Signature: (JLjava/lang/String;)J */ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aopen_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring name) { hid_t attr_id = -1; const char *aName; PIN_JAVA_STRING(name, aName); if (aName != NULL) { attr_id = H5Aopen_name((hid_t)loc_id, aName); UNPIN_JAVA_STRING(name,aName); if (attr_id < 0) h5libraryError(env); } return (jlong)attr_id; } /* end Java_hdf_hdf5lib_H5__1H5Aopen_1name */
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; }
/* * - Nom de la fonction : _MEDattrStringLire * - Description : lecture d'un attribut chaine de caracteres * - Parametres : * - pere (IN) : l'ID de l'objet HDF pere ou placer l'attribut * - nom (IN) : le nom de l'attribut * - longueur (IN) : strlen(val) * - val (OUT) : la valeur de l'attribut * - Resultat : 0 en cas de succes, -1 sinon */ med_err _MEDattrStringLire(med_idt pere,char *nom,int longueur,char *val) { med_idt attid,datatype; med_err ret; if ((datatype = H5Tcopy(H5T_C_S1)) < 0) return -1; if ((ret = H5Tset_size(datatype,longueur+1)) < 0) return -1; if ((attid = H5Aopen_name(pere,nom)) < 0) return -1; if ((ret = H5Aread(attid,datatype,val)) < 0) return -1; if ((ret = H5Tclose(datatype)) < 0) return -1; if ((ret = H5Aclose(attid)) < 0) return -1; return 0; }
int VsFilter::visitAttrib(hid_t dId, const char* name, const H5A_info_t* ai, void* opdata) { RECURSION_DATA* data = static_cast< RECURSION_DATA* >(opdata); VsObject* parent = data->parent; VsLog::debugLog() << "VsFilter::visitAttrib(...): getting attribute '" << name << "'." << std::endl; if (!parent) { VsLog::errorLog() <<"VsFilter::visitAttrib(): Parent is NULL?" <<std::endl; return 0; } //TODO - actually load & cache string attribute values here hid_t attId = H5Aopen_name(dId, name); parent->addAttribute(name, attId); return 0; }
int pioReadAttributeString(PIOObject pioObject, const char* attr_name, char** attr_value) { hid_t attr; size_t storage; if (pioHasAttribute(pioObject, attr_name)) { attr = H5Aopen_name(pioObject.identifier, attr_name); storage = H5Aget_storage_size(attr); H5Aclose(attr); *attr_value = (char*)malloc( storage + sizeof(char)); H5LTget_attribute_string(pioObject.identifier, ".", attr_name, *attr_value); return 1; } else { return -1; } }
static int find_attr(hid_t attr_id, const char *name, void *op_data) { hid_t obj, type; int status; h5item *parent = (h5item *)op_data; h5item *item = (h5item *)malloc(sizeof(h5item)); h5item *itm; item->item_type = -1; item->name=strcpy(malloc(strlen(name)+1),name); item->child = 0; item->brother = 0; item->parent = parent; item->obj = 0; item->attribute = 0; if(parent) { if (parent->attribute == NULL) { parent->attribute = item; } else { for (itm = parent->attribute; itm->brother; itm = itm->brother); itm->brother = item; } } if ((obj = H5Aopen_name(attr_id,name)) >= 0) { int size; char dtype; int htype = 42; int is_signed; hsize_t ds_dims[64]; hid_t space = H5Aget_space(obj); int n_ds_dims = H5Sget_simple_extent_dims(space,ds_dims,0); size_t precision; H5Sclose(space); item->obj = obj; } return 0; }
/* * - Nom de la fonction : _MEDattrNumLire * - Description : lecture d'un attribut entier * - Parametres : * - pere (IN) : l'ID de l'objet HDF pere ou placer l'attribut * - type (IN) : le type du champ {MED_FLOAT64,MED_INT} * - nom (IN) : le nom de l'attribut * - val (OUT) : la valeur de l'attribut * - Resultat : 0 en cas de succes, -1 sinon */ med_err _MEDattrNumLire(med_idt pere,med_field_type type,char *nom,unsigned char *val) { med_idt attid; med_err ret; hid_t type_hdf; /* ISCRUTE(sizeof(med_int)); */ /* ISCRUTE_id(pere); */ /* SSCRUTE(nom); */ if ((attid = H5Aopen_name(pere,nom)) < 0) return -1; switch(type) { case MED_FLOAT64 : type_hdf = H5T_NATIVE_DOUBLE; break; case MED_INT : #if defined(HAVE_F77INT64) type_hdf = H5T_NATIVE_LONG; #else type_hdf = H5T_NATIVE_INT; #endif break; default : return -1; } if ((ret = H5Aread(attid,type_hdf, val)) < 0) return -1; if ((ret = H5Aclose(attid)) < 0) return -1; return 0; }
/*---------------------------------------------------------------------------- * Name: h5aopen_name _c * Purpose: Call H5Aopen_name to open an attribute * Inputs: obj_id - object identifier * name - name of the attribute * namelen - name length * Outputs: attr_id - dataset identifier * Returns: 0 on success, -1 on failure * Programmer: Elena Pourmal * Thursday, August 12, 1999 * Modifications: *---------------------------------------------------------------------------*/ int_f nh5aopen_name_c (hid_t_f *obj_id, _fcd name, size_t_f *namelen, hid_t_f *attr_id) { char *c_name=NULL; /* Buffer to hold C string */ int_f ret_value=0; /* Return value */ /* * Convert FORTRAN name to C name */ if ((c_name = HD5f2cstring(name, (size_t)*namelen)) == NULL) HGOTO_DONE(FAIL); /* * Call H5Aopen function. */ if ((*attr_id = (hid_t_f)H5Aopen_name((hid_t)*obj_id, c_name)) < 0) HGOTO_DONE(FAIL); done: if(c_name) HDfree(c_name); return ret_value; }
med_err _MED21attrNumLire(med_idt pere,med_type_champ type,char *nom, unsigned char *val,hid_t hdf_file) { med_idt attid; med_err ret; int type_hdf; if ((attid = H5Aopen_name(pere,nom)) < 0) return -1; switch(type) { case MED_FLOAT64 : if (H5Tequal(hdf_file,H5T_IEEE_F64BE)) type_hdf = H5T_IEEE_F64LE; if (H5Tequal(hdf_file,H5T_IEEE_F64LE)) type_hdf = H5T_IEEE_F64BE; break; case MED_INT : #if defined(HAVE_F77INT64) type_hdf = H5T_NATIVE_LONG; #else type_hdf = H5T_NATIVE_INT; #endif break; default : return -1; } if ((ret = H5Aread(attid,type_hdf,val)) < 0) return -1; if ((ret = H5Aclose(attid)) < 0) return -1; return 0; }
void read_header_attributes_in_hdf5(char *fname) { hid_t hdf5_file, hdf5_headergrp, hdf5_attribute; hdf5_file = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT); hdf5_headergrp = H5Gopen(hdf5_file, "/Header"); hdf5_attribute = H5Aopen_name(hdf5_headergrp, "NumPart_ThisFile"); H5Aread(hdf5_attribute, H5T_NATIVE_INT, header.npart); H5Aclose(hdf5_attribute); hdf5_attribute = H5Aopen_name(hdf5_headergrp, "NumPart_Total"); H5Aread(hdf5_attribute, H5T_NATIVE_UINT, header.npartTotal); H5Aclose(hdf5_attribute); hdf5_attribute = H5Aopen_name(hdf5_headergrp, "NumPart_Total_HighWord"); H5Aread(hdf5_attribute, H5T_NATIVE_UINT, header.npartTotalHighWord); H5Aclose(hdf5_attribute); hdf5_attribute = H5Aopen_name(hdf5_headergrp, "MassTable"); H5Aread(hdf5_attribute, H5T_NATIVE_DOUBLE, header.mass); H5Aclose(hdf5_attribute); hdf5_attribute = H5Aopen_name(hdf5_headergrp, "Time"); H5Aread(hdf5_attribute, H5T_NATIVE_DOUBLE, &header.time); H5Aclose(hdf5_attribute); hdf5_attribute = H5Aopen_name(hdf5_headergrp, "NumFilesPerSnapshot"); H5Aread(hdf5_attribute, H5T_NATIVE_INT, &header.num_files); H5Aclose(hdf5_attribute); hdf5_attribute = H5Aopen_name(hdf5_headergrp, "Flag_Entropy_ICs"); H5Aread(hdf5_attribute, H5T_NATIVE_INT, &header.flag_entropy_instead_u); H5Aclose(hdf5_attribute); H5Gclose(hdf5_headergrp); H5Fclose(hdf5_file); }
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; }