AccessTraceReader::AccessTraceReader(std::string _fname) : fname(_fname.c_str()) { hid_t fid = H5Fopen(fname.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); if (fid == H5I_INVALID_HID) panic("Could not open HDF5 file %s", fname.c_str()); // Check that the trace finished hid_t fAttr = H5Aopen(fid, "finished", H5P_DEFAULT); uint32_t finished; H5Aread(fAttr, H5T_NATIVE_UINT, &finished); H5Aclose(fAttr); if (!finished) panic("Trace file %s unfinished (halted simulation?)", fname.c_str()); // Populate numRecords & numChildren hsize_t nPackets; hid_t table = H5PTopen(fid, "accs"); if (table == H5I_INVALID_HID) panic("Could not open HDF5 packet table"); H5PTget_num_packets(table, &nPackets); numRecords = nPackets; hid_t ncAttr = H5Aopen(fid, "numChildren", H5P_DEFAULT); H5Aread(ncAttr, H5T_NATIVE_UINT, &numChildren); H5Aclose(ncAttr); curFrameRecord = 0; cur = 0; max = MIN(PT_CHUNKSIZE, numRecords); buf = max? gm_calloc<PackedAccessRecord>(max) : nullptr; if (max) { H5PTread_packets(table, 0, max, buf); } H5PTclose(table); H5Fclose(fid); }
char AH5_write_str_root_attr(hid_t loc_id, const char *attr_name, const char *wdata) { char success = AH5_FALSE; hid_t aid = H5Screate(H5S_SCALAR); hid_t atype = H5Tcopy(H5T_C_S1); htri_t attr_exists = H5Aexists(loc_id, attr_name); hid_t attr = -1; H5Tset_size(atype, strlen(wdata)); if (atype >= 0) { if (attr_exists == 0) { attr = H5Acreate(loc_id, attr_name, atype, aid, H5P_DEFAULT, H5P_DEFAULT); } else if (attr_exists > 0) { attr = H5Aopen(loc_id, attr_name, H5P_DEFAULT); } if (attr && H5Awrite(attr, atype, wdata) >= 0 && H5Aclose(attr) >= 0) success = AH5_TRUE; } success &= (H5Tclose(atype) >= 0); success &= (H5Sclose(aid) >= 0); return success; }
int e5_write_attr_list_double( hid_t e5_group_id, e5_attr_double* e5_attr_list) { int i; hid_t e5_attribute_id; hid_t e5_dataspace_id = H5Screate(H5S_SCALAR); for(i = 0; e5_attr_list && e5_attr_list[i].name != 0; i++) { e5_attr_double *attr = &e5_attr_list[i]; if(attr->name == 0 || strlen(attr->name) < 1) continue; if(H5Aexists(e5_group_id, attr->name) <= 0) e5_attribute_id = H5Acreate(e5_group_id, attr->name, H5T_IEEE_F64LE, e5_dataspace_id, H5P_DEFAULT); else e5_attribute_id = H5Aopen(e5_group_id, attr->name, H5P_DEFAULT); e5_info(e5_group_id, "Adding attribute [type='double', name='%s', value='%f']\n", attr->name, attr->value); H5Awrite(e5_attribute_id, H5T_NATIVE_DOUBLE, &(attr->value)); H5Aclose(e5_attribute_id); } H5Sclose(e5_dataspace_id); return E5_SUCCESS; }
static int readIntAttribute(int _iDatasetId, const char *_pstName) { hid_t iAttributeId; herr_t status; int iVal = -1; hsize_t n = 0; if (H5Aiterate(_iDatasetId, H5_INDEX_NAME, H5_ITER_NATIVE, &n, find_attr_by_name, (void *)_pstName) > 0) { iAttributeId = H5Aopen(_iDatasetId, _pstName, H5P_DEFAULT); if (iAttributeId < 0) { return -1; } status = H5Aread(iAttributeId, H5T_NATIVE_INT, &iVal); if (status < 0) { return -1; } status = H5Aclose(iAttributeId); if (status < 0) { return -1; } } return iVal; }
estatus_t e5_write_attr_list_str( hid_t e5_group_id, e5_attr_str* e5_attr_list) { int i; hid_t e5_attribute_id; hid_t e5_dataspace_id = H5Screate(H5S_SCALAR); hid_t e5_string_type = H5Tcopy(H5T_C_S1); H5Tset_size(e5_string_type, E5_MAX_ATTR_STRING_LENGTH); for(i = 0; e5_attr_list && e5_attr_list[i].name != 0; i++) { e5_attr_str *attr = &e5_attr_list[i]; if(attr->name == 0 || strlen(attr->name) < 1) continue; if(attr->value == 0 || strlen(attr->value) < 1) continue; if(H5Aexists(e5_group_id, attr->name) <= 0) e5_attribute_id = H5Acreate(e5_group_id, attr->name, e5_string_type, e5_dataspace_id, H5P_DEFAULT); else e5_attribute_id = H5Aopen(e5_group_id, attr->name, H5P_DEFAULT); e5_info(e5_group_id, "Adding attribute [type='string', name='%s', value='%s']\n", attr->name, attr->value); H5Awrite(e5_attribute_id, e5_string_type, &(attr->value)); H5Aclose(e5_attribute_id); } H5Sclose(e5_dataspace_id); return E5_SUCCESS; }
void DCAttribute::writeAttribute(const char* name, const hid_t type, hid_t parent, uint32_t ndims, const Dimensions dims, const void* src) throw (DCException) { hid_t attr = -1; if (H5Aexists(parent, name)) attr = H5Aopen(parent, name, H5P_DEFAULT); else { hid_t dsp; if( ndims == 1 && dims.getScalarSize() == 1 ) dsp = H5Screate(H5S_SCALAR); else dsp = H5Screate_simple( ndims, dims.getPointer(), dims.getPointer() ); attr = H5Acreate(parent, name, type, dsp, H5P_DEFAULT, H5P_DEFAULT); H5Sclose(dsp); } if (attr < 0) throw DCException(getExceptionString(name, "Attribute could not be opened or created")); if (H5Awrite(attr, type, src) < 0) { H5Aclose(attr); throw DCException(getExceptionString(name, "Attribute could not be written")); } H5Aclose(attr); }
estatus_t e5_read_attr_list_float( hid_t e5_group_id, e5_attr_float* e5_attr_list) { int i; hid_t e5_attribute_id; estatus_t status = E5_SUCCESS; for(i = 0; e5_attr_list && e5_attr_list[i].name != 0; i++) { e5_attr_float *attr = &e5_attr_list[i]; if(attr->name == 0 || strlen(attr->name) < 1) continue; if(H5Aexists(e5_group_id, attr->name) <= 0) { status = E5_INVALID_ATTRIBUTE; e5_error(e5_group_id, status, "Specified attribute '%s' does not exist\n", attr->name); continue; } e5_attribute_id = H5Aopen(e5_group_id, attr->name, H5P_DEFAULT); H5Aread(e5_attribute_id, H5T_NATIVE_FLOAT, &(attr->value)); H5Aclose(e5_attribute_id); e5_info(e5_group_id, "Read attribute [type='float', name='%s', value='%f']\n", attr->name, attr->value); } return status; }
void write_internal(hdf5dataset& hdataset, const std::string& name, hid_t type_id, const void* buffer, bool overwrite) { bool exists = H5Aexists(hdataset.handle(), name.c_str()); hid_t attribute_id = -1; if(exists && overwrite) { attribute_id = H5Aopen(hdataset.handle(), name.c_str(), H5P_DEFAULT); //H5Ldelete(_hfile.handle(), name.c_str(), H5P_DEFAULT); } else if(exists && !overwrite) throw std::runtime_error("Attribute already exists: (" + name + ")"); else { hsize_t dims = 1; hid_t space_id = H5Screate_simple(1, &dims, NULL); attribute_id = H5Acreate(hdataset.handle(), name.c_str(), type_id, space_id, H5P_DEFAULT, H5P_DEFAULT); H5Sclose(space_id); } if(attribute_id < 0) throw std::runtime_error("Error creating or opening attribute () in file (" + name + ")"); H5Awrite(attribute_id, type_id, buffer); H5Tclose(type_id); H5Aclose(attribute_id); }
escdf_errno_t utils_hdf5_check_attr(hid_t loc_id, const char *name, hsize_t *dims, unsigned int ndims, hid_t *attr_pt) { hid_t attr_id, dtspace_id; if ((attr_id = H5Aopen(loc_id, name, H5P_DEFAULT)) < 0) RETURN_WITH_ERROR(attr_id); /* Check space dimensions. */ if ((dtspace_id = H5Aget_space(attr_id)) < 0) { DEFER_FUNC_ERROR(dtspace_id); goto cleanup_attr; } if (utils_hdf5_check_shape(dtspace_id, dims, ndims) != ESCDF_SUCCESS) { goto cleanup_dtspace; } H5Sclose(dtspace_id); if (attr_pt) *attr_pt = attr_id; else H5Aclose(attr_id); return ESCDF_SUCCESS; cleanup_dtspace: H5Sclose(dtspace_id); cleanup_attr: H5Aclose(attr_id); return ESCDF_ERROR; }
estatus_t e5_read_attr_list_str( hid_t e5_group_id, e5_attr_str* e5_attr_list) { int i; estatus_t status = E5_SUCCESS; hid_t e5_attribute_id; hid_t e5_dataspace_id = H5Screate(H5S_SCALAR); hid_t e5_string_type = H5Tcopy(H5T_C_S1); H5Tset_size(e5_string_type, E5_MAX_ATTR_STRING_LENGTH); for(i = 0; e5_attr_list && e5_attr_list[i].name != 0; i++) { e5_attr_str *attr = &e5_attr_list[i]; if(attr->name == 0 || strlen(attr->name) < 1) continue; if(H5Aexists(e5_group_id, attr->name) <= 0) { status = E5_INVALID_ATTRIBUTE; e5_error(e5_group_id, status, "Specified attribute '%s' does not exist\n", attr->name); continue; } e5_attribute_id = H5Aopen(e5_group_id, attr->name, H5P_DEFAULT); H5Aread(e5_attribute_id, e5_string_type, &(attr->value)); H5Aclose(e5_attribute_id); e5_info(e5_group_id, "Read attribute [type='str', name='%s', value='%s']\n", attr->name, attr->value); } H5Sclose(e5_dataspace_id); return status; }
estatus_t e5_write_attr_list( hid_t e5_group_id, e5_attr* e5_attr_list) { int i; eid_t status = E5_SUCCESS; hid_t e5_attribute_id; hid_t e5_dataspace_id = H5Screate(H5S_SCALAR); for(i = 0; e5_attr_list && e5_attr_list[i].name != 0; i++) { e5_attr *attr = &e5_attr_list[i]; if(attr->name == 0 || strlen(attr->name) < 1) continue; if(e5_is_valid_type(e5_attr_list[i].type) != E5_TRUE) { status = E5_INVALID_TYPE; e5_error(e5_group_id, status, "Invalid type requested for attribute [type='%d', name='%s', value='%p']\n", attr->type, attr->name, attr->value); continue; } hid_t hdf_type = e5_convert_type_to_hdf(e5_attr_list[i].type); hid_t hdf_format = e5_convert_format_to_hdf(e5_attr_list[i].type); if(H5Aexists(e5_group_id, attr->name) <= 0) e5_attribute_id = H5Acreate(e5_group_id, attr->name, hdf_type, e5_dataspace_id, H5P_DEFAULT); e5_info(e5_group_id, "Adding attribute [type='integer', name='%s', value='%d']\n", attr->name, attr->value); e5_attribute_id = H5Aopen(e5_group_id, attr->name, H5P_DEFAULT); H5Awrite(e5_attribute_id, hdf_format, &(attr->value)); H5Aclose(e5_attribute_id); } H5Sclose(e5_dataspace_id); return E5_SUCCESS; }
hid_t seissol::checkpoint::h5::Fault::initFile(int odd, const char* filename) { hid_t h5file; if (loaded()) { // Open the file h5file = open(filename, false); checkH5Err(h5file); // Fault writer m_h5timestepFault[odd] = H5Aopen(h5file, "timestep_fault", H5P_DEFAULT); checkH5Err(m_h5timestepFault[odd]); // Data for (unsigned int i = 0; i < NUM_VARIABLES; i++) { m_h5data[odd][i] = H5Dopen(h5file, VAR_NAMES[i], H5P_DEFAULT); checkH5Err(m_h5data[odd][i]); } } else { // Create the file hid_t h5plist = H5Pcreate(H5P_FILE_ACCESS); checkH5Err(h5plist); checkH5Err(H5Pset_libver_bounds(h5plist, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST)); #ifdef USE_MPI checkH5Err(H5Pset_fapl_mpio(h5plist, comm(), MPI_INFO_NULL)); #endif // USE_MPI h5file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, h5plist); checkH5Err(h5file); checkH5Err(H5Pclose(h5plist)); // Create scalar dataspace for attributes hid_t h5spaceScalar = H5Screate(H5S_SCALAR); checkH5Err(h5spaceScalar); // Fault writer m_h5timestepFault[odd] = H5Acreate(h5file, "timestep_fault", H5T_STD_I32LE, h5spaceScalar, H5P_DEFAULT, H5P_DEFAULT); checkH5Err(m_h5timestepFault[odd]); int t = 0; checkH5Err(H5Awrite(m_h5timestepFault[odd], H5T_NATIVE_INT, &t)); checkH5Err(H5Sclose(h5spaceScalar)); // Variables for (unsigned int i = 0; i < NUM_VARIABLES; i++) { h5plist = H5Pcreate(H5P_DATASET_CREATE); checkH5Err(h5plist); checkH5Err(H5Pset_layout(h5plist, H5D_CONTIGUOUS)); checkH5Err(H5Pset_alloc_time(h5plist, H5D_ALLOC_TIME_EARLY)); m_h5data[odd][i] = H5Dcreate(h5file, VAR_NAMES[i], H5T_IEEE_F64LE, m_h5fSpaceData, H5P_DEFAULT, h5plist, H5P_DEFAULT); checkH5Err(m_h5data[odd][i]); checkH5Err(H5Pclose(h5plist)); } } return h5file; }
hdf5attribute::hdf5attribute(hdf5dataset& hdataset, const std::string& name) { _attribute_id = H5Aopen(hdataset.handle(), name.c_str(), H5P_DEFAULT); if(_attribute_id < 0) throw std::runtime_error("Failed to open attribute (" + name + ") in dataset (" + "not available" + ") file (" + "not available" + ")"); _type_id = H5Aget_type(_attribute_id); }
/*-------------------------------------------------------------*/ static void validateFloat3Attribute(pNXVcontext self, hid_t dpField, char *name) { hid_t attID, attType, attSpace; H5T_class_t h5class; hsize_t dims[2], maxDims[2]; char fname[512]; memset(fname,0,sizeof(fname)); H5Iget_name(dpField,fname,sizeof(fname)); if(!H5LTfind_attribute(dpField,name)){ NXVsetLog(self,"sev","error"); NXVprintLog(self,"message", "Missing attribute %s on %s", name, fname); NXVlog(self); self->errCount++; } else { attID = H5Aopen(dpField,name,H5P_DEFAULT); assert(attID >= 0); attType = H5Aget_type(attID); assert(attType >= 0); h5class = H5Tget_class(attType); if(h5class != H5T_FLOAT){ NXVsetLog(self,"sev","error"); NXVprintLog(self,"message", "%s attribute on %s is of wrong type, expected float", name, fname); NXVlog(self); self->errCount++; } else { attSpace = H5Aget_space(attID); if(H5Sget_simple_extent_ndims(attSpace) != 1){ NXVsetLog(self,"sev","error"); NXVprintLog(self,"message", "%s attribute on %s is of wrong rank, expected 1", name, fname); NXVlog(self); self->errCount++; } else { H5Sget_simple_extent_dims(attSpace,dims,maxDims); if(dims[0] != 3){ NXVsetLog(self,"sev","error"); NXVprintLog(self,"message", "%s attribute on %s is of wrong size, expected 3", name, fname); NXVlog(self); self->errCount++; } } H5Sclose(attSpace); } H5Tclose(attType); H5Aclose(attID); } }
/*-------------------------------------------------------------- This validates the lesser depends_on chain fields like vector, offset and transformation_type ----------------------------------------------------------------*/ static void validateDependsOnAttributes(pNXVcontext self,hid_t dpField) { char fname[512], transData[512]; hid_t attID, attType, attSpace; H5T_class_t h5class; memset(fname,0,sizeof(fname)); memset(transData,0,sizeof(transData)); H5Iget_name(dpField,fname,sizeof(fname)); /* deal with transformation_type */ if(!H5LTfind_attribute(dpField,"transformation_type")){ NXVsetLog(self,"sev","error"); NXVprintLog(self,"message", "Missing attribute transformation_type on %s", fname); NXVlog(self); self->errCount++; } else { attID = H5Aopen(dpField,"transformation_type",H5P_DEFAULT); assert(attID >= 0); attType = H5Aget_type(attID); assert(attType >= 0); h5class = H5Tget_class(attType); if(h5class != H5T_STRING){ NXVsetLog(self,"sev","error"); NXVprintLog(self,"message", "transformation_type on %s is of wrong type, expected string", fname); NXVlog(self); self->errCount++; } else { H5NXget_attribute_string(self->fileID, fname, "transformation_type",transData); if(strcmp(transData,"translation") != 0 && strcmp(transData,"rotation") != 0){ NXVsetLog(self,"sev","error"); NXVprintLog(self,"message", "transformation_type on %s contains bad data: %s", fname, "expected rotation or translation"); NXVlog(self); self->errCount++; } } H5Tclose(attType); H5Aclose(attID); } validateFloat3Attribute(self,dpField,"offset"); validateFloat3Attribute(self,dpField,"vector"); }
bool seissol::checkpoint::h5::Wavefield::validate(hid_t h5file) const { // Turn of error printing H5ErrHandler errHandler; // Check #partitions hid_t h5attr = H5Aopen(h5file, "partitions", H5P_DEFAULT); if (h5attr < 0) { logWarning(rank()) << "Checkpoint does not have a partition attribute."; return false; } int p; herr_t err = H5Aread(h5attr, H5T_NATIVE_INT, &p); checkH5Err(H5Aclose(h5attr)); if (err < 0 || p != partitions()) { logWarning(rank()) << "Partitions in checkpoint do not match."; return false; } // Check dimensions hid_t h5data = H5Dopen(h5file, "values", H5P_DEFAULT); if (h5data < 0) { logWarning(rank()) << "Checkpoint does not contains a data array."; return false; } hid_t h5space = H5Dget_space(h5data); checkH5Err(H5Dclose(h5data)); if (h5space < 0) { logWarning(rank()) << "Could not get space identifier in checkpoint."; return false; } bool isValid = true; int dims = H5Sget_simple_extent_ndims(h5space); if (dims != 1) { isValid = false; logWarning(rank()) << "Number of dimensions in checkpoint does not match."; } else { hsize_t dimSize; if (H5Sget_simple_extent_dims(h5space, &dimSize, 0L) != 1) { isValid = false; logWarning(rank()) << "Could not get dimension sizes of checkpoint."; } else { if (dimSize != numTotalElems()) { isValid = false; logWarning(rank()) << "Number of elements in checkpoint does not match."; } } } checkH5Err(H5Sclose(h5space)); return isValid; }
void HDF5Attribute::open(const HDF5Id location_id, const String &name) { if (isValid()) { THROW(Iex::IoExc, "Tried to open attribute that has already " "been opened or created"); } m_id = H5Aopen(location_id, name.c_str(), H5P_DEFAULT); }
H5Attribute::H5Attribute(H5Object & _parent, const std::string & _name) : H5Object(_parent, _name) { if (H5Aexists(getParent().getH5Id(), name.c_str()) <= 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot open attribute: %s"), name.c_str()); } attr = H5Aopen(getParent().getH5Id(), name.c_str(), H5P_DEFAULT); if (attr < 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot open attribute: %s"), name.c_str()); } }
//-------------------------------------------------------------------------- // Function: H5Object::openAttribute ///\brief Opens an attribute given its name. ///\param name - IN: Name of the attribute ///\return Attribute instance ///\exception H5::AttributeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- Attribute H5Object::openAttribute( const char* name ) const { hid_t attr_id = H5Aopen(getId(), name, H5P_DEFAULT); if( attr_id > 0 ) { Attribute attr( attr_id ); return( attr ); } else { throw AttributeIException(inMemFunc("openAttribute"), "H5Aopen failed"); } }
void ReadStringsT( hid_t iParent, const std::string &iAttrName, size_t iNumStrings, StringT *oStrings ) { ABCA_ASSERT( iParent >= 0, "Invalid parent in ReadStringsT" ); // Open the attribute. hid_t attrId = H5Aopen( iParent, iAttrName.c_str(), H5P_DEFAULT ); ABCA_ASSERT( attrId >= 0, "Couldn't open attribute named: " << iAttrName ); AttrCloser attrCloser( attrId ); // Checking code. { hid_t attrFtype = H5Aget_type( attrId ); DtypeCloser dtypeCloser( attrFtype ); hid_t nativeDtype = GetNativeDtype<CharT>(); ABCA_ASSERT( H5Tget_class( attrFtype ) == H5Tget_class( nativeDtype ) && H5Tget_sign( attrFtype ) == H5Tget_sign( nativeDtype ), "Invalid datatype for stringT" ); } hid_t attrSpace = H5Aget_space( attrId ); ABCA_ASSERT( attrSpace >= 0, "Couldn't get dataspace for attribute: " << iAttrName ); DspaceCloser dspaceCloser( attrSpace ); hssize_t numPoints = H5Sget_simple_extent_npoints( attrSpace ); ABCA_ASSERT( numPoints > 0, "Degenerate string dimensions in ReadStringsT" ); // Create temporary char storage buffer. std::vector<CharT> charStorage( ( size_t )( 1 + numPoints ), ( CharT )0 ); // Read into it. herr_t status = H5Aread( attrId, GetNativeDtype<CharT>(), ( void * )&charStorage.front() ); ABCA_ASSERT( status >= 0, "Couldn't read from attribute: " << iAttrName ); // Extract 'em. ExtractStrings( oStrings, ( const CharT * )&charStorage.front(), 1 + numPoints, iNumStrings ); }
int hdf5_read(void *output, hid_t file, char *n_group, char *n_dset, char *n_attr, int c){ hid_t memtype, type, group=-1, dset=-1, attr=-1, tmp_id, space; herr_t status; size_t sdim; int ndims; tmp_id = file; if(strlen(n_group)>0){ group = H5Gopen(tmp_id, n_group, H5P_DEFAULT); tmp_id = group; } if(strlen(n_dset)>0){ dset = H5Dopen(tmp_id, n_dset, H5P_DEFAULT); tmp_id = dset; } if(strlen(n_attr)>0){ attr = H5Aopen(tmp_id, n_attr, H5P_DEFAULT); tmp_id = attr; } if(c == 'c'){ memtype = H5Tcopy (H5T_C_S1); type = H5Aget_type (tmp_id); sdim = H5Tget_size (type); sdim++; status = H5Tset_size (memtype, sdim); } else if(c == 'd'){ memtype = H5T_NATIVE_DOUBLE; } else if(c == 'i' || c == 'n'){ memtype = H5T_NATIVE_INT; } else if(c == 'f'){ memtype = H5T_NATIVE_FLOAT; } if (tmp_id == attr){ status = H5Aread(tmp_id, memtype, output); } else if(tmp_id == dset && c == 'n'){ space = H5Dget_space (dset); ndims = H5Sget_simple_extent_dims (space, output, NULL); } else{ return(-1); } return(1); }
estatus_t e5_read_attr_list( hid_t e5_group_id, e5_attr* e5_attr_list) { int i; estatus_t status = E5_SUCCESS; hid_t h5_type; hid_t h5_native_type; hid_t h5_space; hid_t e5_attribute_id; for(i = 0; e5_attr_list && e5_attr_list[i].name != 0; i++) { e5_attr *attr = &e5_attr_list[i]; if(attr->name == 0 || strlen(attr->name) < 1) continue; e5_info(e5_group_id, "Reading attribute [name='%s']\n", attr->name); if(H5Aexists(e5_group_id, attr->name) <= 0) { status = E5_INVALID_ATTRIBUTE; e5_error(e5_group_id, status, "Invalid name requested for attribute [type='%d', name='%s', value='%p']\n", attr->type, attr->name, attr->value); continue; } e5_attribute_id = H5Aopen(e5_group_id, attr->name, H5P_DEFAULT); h5_type = H5Aget_type(e5_attribute_id); h5_space = H5Aget_space(e5_attribute_id); h5_native_type = e5_get_native_h5_type(h5_type); attr->type = e5_convert_hdf_type(h5_type); if(e5_is_valid_type(attr->type) != E5_TRUE) { status = E5_INVALID_TYPE; e5_error(e5_group_id, status, "Invalid type requested for attribute [type='%d', name='%s', value='%p']\n", attr->type, attr->name, attr->value); continue; } H5Aread(e5_attribute_id, h5_native_type, attr->value); H5Aclose(e5_attribute_id); e5_info(e5_group_id, "Read attribute [type='%s', name='%s', value='%p']\n", e5_typename(attr->type), attr->name, attr->value); } return status; }
//-***************************************************************************** void ReadTimeSamples( hid_t iParent, std::vector < AbcA::TimeSamplingPtr > & oTimeSamples ) { oTimeSamples.clear(); // add the intrinsic default sampling AbcA::TimeSamplingPtr ts( new AbcA::TimeSampling() ); oTimeSamples.push_back( ts ); uint32_t i = 1; AbcA::TimeSamplingType tst; std::string tstname = "1"; // keep trying to read till we can't find anymore while ( ReadTimeSamplingType( iParent, tstname, tst ) ) { // try to open the time samples attribute std::string timeName = tstname + ".time"; hid_t aid = H5Aopen( iParent, timeName.c_str(), H5P_DEFAULT ); ABCA_ASSERT( aid >= 0, "Couldn't open time samples named: " << timeName ); AttrCloser attrCloser( aid ); // figure out how big it is hid_t sid = H5Aget_space( aid ); ABCA_ASSERT( sid >= 0, "Couldn't get dataspace for time samples: " << timeName ); DspaceCloser dspaceCloser( sid ); hssize_t numPoints = H5Sget_simple_extent_npoints( sid ); ABCA_ASSERT( numPoints > 0, "No time samples data: " << timeName ); std::vector < chrono_t > times(numPoints); // do the read herr_t status = H5Aread( aid, H5T_NATIVE_DOUBLE, &(times.front()) ); ABCA_ASSERT( status >= 0, "Can't read time samples: " << timeName ); // create the TimeSampling and add it to our vector ts.reset( new AbcA::TimeSampling(tst, times) ); oTimeSamples.push_back( ts ); // increment to try and read the next one i++; std::stringstream strm; strm << i; tstname = strm.str(); } }
void seissol::checkpoint::h5::Fault::load(int ×tepFault) { if (numSides() == 0) return; logInfo(rank()) << "Loading fault checkpoint"; seissol::checkpoint::CheckPoint::load(); hid_t h5file = open(linkFile()); checkH5Err(h5file); // Attributes hid_t h5attr = H5Aopen(h5file, "timestep_fault", H5P_DEFAULT); checkH5Err(h5attr); checkH5Err(H5Aread(h5attr, H5T_NATIVE_INT, ×tepFault)); checkH5Err(H5Aclose(h5attr)); // Set the memory space (this is the same for all variables) hsize_t count[2] = {numSides(), numBndGP()}; hid_t h5memSpace = H5Screate_simple(2, count, 0L); checkH5Err(h5memSpace); checkH5Err(H5Sselect_all(h5memSpace)); // Offset for the file space hsize_t fStart[2] = {fileOffset(), 0}; // Read the data for (unsigned int i = 0; i < NUM_VARIABLES; i++) { hid_t h5data = H5Dopen(h5file, VAR_NAMES[i], H5P_DEFAULT); checkH5Err(h5data); hid_t h5fSpace = H5Dget_space(h5data); checkH5Err(h5fSpace); // Read the data checkH5Err(H5Sselect_hyperslab(h5fSpace, H5S_SELECT_SET, fStart, 0L, count, 0L)); checkH5Err(H5Dread(h5data, H5T_NATIVE_DOUBLE, h5memSpace, h5fSpace, h5XferList(), data(i))); checkH5Err(H5Sclose(h5fSpace)); checkH5Err(H5Dclose(h5data)); } checkH5Err(H5Sclose(h5memSpace)); checkH5Err(H5Fclose(h5file)); }
void ReadStringT<std::string,char>( hid_t iParent, const std::string &iAttrName, std::string &oString ) { ABCA_ASSERT( iParent >= 0, "Invalid parent in ReadStringT" ); // Open the attribute. hid_t attrId = H5Aopen( iParent, iAttrName.c_str(), H5P_DEFAULT ); ABCA_ASSERT( attrId >= 0, "Couldn't open attribute named: " << iAttrName ); AttrCloser attrCloser( attrId ); // Checking code. hid_t attrFtype = H5Aget_type( attrId ); DtypeCloser dtypeCloser( attrFtype ); ssize_t numChars = H5Tget_size( attrFtype ); ABCA_ASSERT( numChars >= 0, "ReadStringT() H5Aget_size() failed" ); // Read and check space { hid_t attrSpace = H5Aget_space( attrId ); ABCA_ASSERT( attrSpace >= 0, "Couldn't get dataspace for attribute: " << iAttrName ); DspaceCloser dspaceCloser( attrSpace ); H5S_class_t attrSpaceClass = H5Sget_simple_extent_type( attrSpace ); ABCA_ASSERT( attrSpaceClass == H5S_SCALAR, "Tried to read non-scalar attribute: " << iAttrName << " as scalar" ); } // Create temporary char storage buffer. std::vector<char> charStorage( ( size_t )( 1 + numChars ), ( char )0 ); // Read into it. herr_t status = H5Aread( attrId, attrFtype, ( void * )&charStorage.front() ); ABCA_ASSERT( status >= 0, "Couldn't read from attribute: " << iAttrName ); // Return it. oString = ( const char * )&charStorage.front(); }
bool Hdf5Dataset::open() { const char *filepath = this->path_.c_str(); const char *name = this->filename_.c_str(); char fullpath[100]; strcpy(fullpath, filepath); strcat(fullpath, name); ROS_INFO("Opening map %s", this->filename_.c_str()); this->file_ = H5Fopen(fullpath, H5F_ACC_RDONLY, H5P_DEFAULT); this->group_poses_ = H5Gopen(this->file_, "/Poses", H5P_DEFAULT); this->poses_dataset_ = H5Dopen(this->group_poses_, "poses_dataset", H5P_DEFAULT); this->group_spheres_ = H5Gopen(this->file_, "/Spheres", H5P_DEFAULT); this->sphere_dataset_ = H5Dopen(this->group_spheres_, "sphere_dataset", H5P_DEFAULT); this->attr_ = H5Aopen(this->sphere_dataset_, "Resolution", H5P_DEFAULT); herr_t ret = H5Aread(this->attr_, H5T_NATIVE_FLOAT, &this->res_); }
/* * Class: hdf_hdf5lib_H5 * Method: _H5Aopen * Signature: (JLjava/lang/String;J)J */ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aopen (JNIEnv *env, jclass clss, jlong obj_id, jstring name, jlong access_plist) { hid_t retVal = -1; const char *aName; PIN_JAVA_STRING(name, aName); if (aName != NULL) { retVal = H5Aopen((hid_t)obj_id, aName, (hid_t)access_plist); UNPIN_JAVA_STRING(name, aName); if (retVal < 0) h5libraryError(env); } return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Aopen */
void DCAttribute::readAttribute(const char* name, hid_t parent, void* dst) throw (DCException) { hid_t attr = H5Aopen(parent, name, H5P_DEFAULT); if (attr < 0) throw DCException(getExceptionString(name, "Attribute could not be opened for reading")); hid_t attr_type = H5Aget_type(attr); if (attr_type < 0) { H5Aclose(attr); throw DCException(getExceptionString(name, "Could not get type of attribute")); } if (H5Aread(attr, attr_type, dst) < 0) { H5Aclose(attr); throw DCException(getExceptionString(name, "Attribute could not be read")); } H5Aclose(attr); }
// from scrappie float fast5_read_float_attribute(hid_t group, const char *attribute) { float val = NAN; if (group < 0) { #ifdef DEBUG_FAST5_IO fprintf(stderr, "Invalid group passed to %s:%d.", __FILE__, __LINE__); #endif return val; } hid_t attr = H5Aopen(group, attribute, H5P_DEFAULT); if (attr < 0) { #ifdef DEBUG_FAST5_IO fprintf(stderr, "Failed to open attribute '%s' for reading.", attribute); #endif return val; } H5Aread(attr, H5T_NATIVE_FLOAT, &val); H5Aclose(attr); return val; }
/// Return the attribute name of obj, and "" if the attribute does not exist. void h5_read_attribute(hid_t id, std::string const &name, std::string & s) { s = ""; // if the attribute is not present, return 0 if (H5LTfind_attribute(id, name.c_str()) == 0) return; // not present attribute attr = H5Aopen(id, name.c_str(), H5P_DEFAULT); if (!attr.is_valid()) TRIQS_RUNTIME_ERROR << "Cannot open the attribute " << name; dataspace space = H5Aget_space(attr); int rank = H5Sget_simple_extent_ndims(space); if (rank != 0) TRIQS_RUNTIME_ERROR << "Reading a string attribute and got rank !=0"; datatype strdatatype = H5Aget_type(attr); std::vector<char> buf(H5Aget_storage_size(attr) + 1, 0x00); auto err = H5Aread(attr, strdatatype, (void *)(&buf[0])); if (err < 0) TRIQS_RUNTIME_ERROR << "Cannot read the attribute " << name; s.append(&(buf.front())); }