void Simulation3D::dumpCenterFields(double* eFields, hsize_t nSteps) { std::ostringstream filename(std::ios::out); filename << dumpDir << "/center_fields_dx" << dx << "_dt" << dt << ".h5"; hid_t file_id=H5Fcreate(filename.str().c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); hid_t fieldspace=H5Screate_simple(1, & nSteps, NULL); hid_t dx_space = H5Screate(H5S_SCALAR); hid_t dt_space = H5Screate(H5S_SCALAR); hid_t field_dset_id = H5Dcreate(file_id, "timings", H5T_NATIVE_DOUBLE, fieldspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); hid_t dx_attr_id = H5Acreate(field_dset_id, "dx", H5T_NATIVE_DOUBLE, dx_space, H5P_DEFAULT, H5P_DEFAULT); hid_t dt_attr_id = H5Acreate(field_dset_id, "dt", H5T_NATIVE_DOUBLE, dt_space, H5P_DEFAULT, H5P_DEFAULT); herr_t status = H5Dwrite(field_dset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, eFields); status = H5Awrite(dx_attr_id, H5T_NATIVE_DOUBLE, & dx); status = H5Awrite(dt_attr_id, H5T_NATIVE_DOUBLE, & dt); H5Sclose(fieldspace); H5Sclose(dx_space); H5Sclose(dt_space); H5Aclose(dx_attr_id); H5Aclose(dt_attr_id); H5Dclose(field_dset_id); H5Fclose(file_id); }
/* Create and write attribute for a group or a dataset. For groups, attribute * is a scalar datum; for dataset, it is a one-dimensional array. */ void write_attribute(hid_t obj_id, int this_type, int num) { hid_t sid, aid; hsize_t dspace_dims[1]={8}; int i, mpi_rank, attr_data[8], dspace_rank=1; char attr_name[32]; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); if(this_type == is_group) { sprintf(attr_name, "Group Attribute %d", num); sid = H5Screate(H5S_SCALAR); aid = H5Acreate(obj_id, attr_name, H5T_NATIVE_INT, sid, H5P_DEFAULT); H5Awrite(aid, H5T_NATIVE_INT, &num); H5Aclose(aid); H5Sclose(sid); } else if(this_type == is_dset) { sprintf(attr_name, "Dataset Attribute %d", num); for(i=0; i<8; i++) attr_data[i] = i; sid = H5Screate_simple(dspace_rank, dspace_dims, NULL); aid = H5Acreate(obj_id, attr_name, H5T_NATIVE_INT, sid, H5P_DEFAULT); H5Awrite(aid, H5T_NATIVE_INT, attr_data); H5Aclose(aid); H5Sclose(sid); } }
void Simulation3D::dumpTimings(unsigned long* timings, hsize_t total_timings, unsigned int steps_per_timing) { std::ostringstream filename(std::ios::out); filename << dumpDir << "/timing_s" << blockSize << "_p" << world.size() << ".h5"; hid_t file_id=H5Fcreate(filename.str().c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); hid_t timingspace=H5Screate_simple(1, & total_timings, NULL); hid_t dx_space = H5Screate(H5S_SCALAR); hid_t dt_space = H5Screate(H5S_SCALAR); hid_t bs_space = H5Screate(H5S_SCALAR); hid_t ns_space = H5Screate(H5S_SCALAR); hid_t alg_name_space = H5Screate(H5S_SCALAR); hid_t atype = H5Tcopy(H5T_C_S1); #ifndef YEE H5Tset_size(atype, xUpdateRHSs->getAlgName().length()); #else H5Tset_size(atype, std::string("Yee").length()); #endif H5Tset_strpad(atype, H5T_STR_NULLTERM); hid_t timing_dset_id = H5Dcreate(file_id, "timings", H5T_NATIVE_LONG, timingspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); hid_t dx_attr_id = H5Acreate(timing_dset_id, "dx", H5T_NATIVE_DOUBLE, dx_space, H5P_DEFAULT, H5P_DEFAULT); hid_t dt_attr_id = H5Acreate(timing_dset_id, "dt", H5T_NATIVE_DOUBLE, dt_space, H5P_DEFAULT, H5P_DEFAULT); hid_t bs_attr_id = H5Acreate(timing_dset_id, "blockSize", H5T_NATIVE_UINT, bs_space, H5P_DEFAULT, H5P_DEFAULT); hid_t ns_attr_id = H5Acreate(timing_dset_id, "stepsPerTiming", H5T_NATIVE_UINT, ns_space, H5P_DEFAULT, H5P_DEFAULT); hid_t alg_attr_id = H5Acreate(timing_dset_id,"communicationStrategy", atype, alg_name_space, H5P_DEFAULT, H5P_DEFAULT); herr_t status = H5Dwrite(timing_dset_id, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, timings); status = H5Awrite(dx_attr_id, H5T_NATIVE_DOUBLE, & dx); status = H5Awrite(dt_attr_id, H5T_NATIVE_DOUBLE, & dt); status = H5Awrite(bs_attr_id, H5T_NATIVE_UINT, & blockSize); status = H5Awrite(ns_attr_id, H5T_NATIVE_UINT, & steps_per_timing); #ifndef YEE status = H5Awrite(alg_attr_id, atype, xUpdateRHSs->getAlgName().c_str()); #else status = H5Awrite(alg_attr_id, atype, "Yee"); #endif H5Sclose(timingspace); H5Sclose(dx_space); H5Sclose(dt_space); H5Sclose(alg_name_space); H5Sclose(bs_space); H5Sclose(ns_space); H5Tclose(atype); H5Aclose(dx_attr_id); H5Aclose(dt_attr_id); H5Aclose(bs_attr_id); H5Aclose(alg_attr_id); H5Aclose(ns_attr_id); H5Dclose(timing_dset_id); H5Fclose(file_id); }
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; }
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; }
bool save_bc(hid_t parent_group_id, Mesh *mesh) { herr_t status; // create main group hid_t group_id = H5Gcreate(parent_group_id, "bc", 0); // count hid_t dataspace_id = H5Screate(H5S_SCALAR); hid_t attr_count = H5Acreate(group_id, "count", H5T_NATIVE_UINT32, dataspace_id, H5P_DEFAULT); uint count = mesh->boundaries.count(); status = H5Awrite(attr_count, H5T_NATIVE_UINT32, &count); H5Aclose(attr_count); H5Sclose(dataspace_id); /// /// JudyArray<Boundary *> tri, quad; for (int i = 0; i < count; i++) { Boundary *bnd = mesh->boundaries[i]; switch (bnd->get_mode()) { case HERMES_MODE_TRIANGLE: tri.add(bnd); break; case HERMES_MODE_QUAD: quad.add(bnd); break; } } save_tri_bc(group_id, tri); save_quad_bc(group_id, quad); status = H5Gclose(group_id); // close the group }
bool save_hex(hid_t parent_group_id, JudyArray<Element *> &elems) { herr_t status; // create main group hid_t group_id = H5Gcreate(parent_group_id, "hex", 0); // count hid_t dataspace_id = H5Screate(H5S_SCALAR); hid_t attr_count = H5Acreate(group_id, "count", H5T_NATIVE_UINT32, dataspace_id, H5P_DEFAULT); uint count = elems.count(); status = H5Awrite(attr_count, H5T_NATIVE_UINT32, &count); H5Aclose(attr_count); H5Sclose(dataspace_id); /// hsize_t dims = Hex::NUM_VERTICES; hid_t elem_dataspace_id = H5Screate_simple(1, &dims, NULL); // dump vertices for (int i = 0; i < count; i++) { char name[256]; sprintf(name, "%d", i); // the dataset hid_t dataset_id = H5Dcreate(group_id, name, H5T_NATIVE_UINT32, elem_dataspace_id, H5P_DEFAULT); status = H5Dwrite(dataset_id, H5T_NATIVE_UINT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, elems[i]->get_vertices()); status = H5Dclose(dataset_id); } H5Sclose(elem_dataspace_id); status = H5Gclose(group_id); // close the group }
bool save_elements(hid_t parent_group_id, Mesh *mesh) { herr_t status; // create main group hid_t group_id = H5Gcreate(parent_group_id, "elements", 0); // count hid_t dataspace_id = H5Screate(H5S_SCALAR); hid_t attr_count = H5Acreate(group_id, "count", H5T_NATIVE_UINT32, dataspace_id, H5P_DEFAULT); uint count = mesh->elements.count(); status = H5Awrite(attr_count, H5T_NATIVE_UINT32, &count); H5Aclose(attr_count); H5Sclose(dataspace_id); /// JudyArray<Element *> tet, hex, pri; for (int i = 0; i < count; i++) { Element *elem = mesh->elements[i]; switch (elem->get_mode()) { case HERMES_MODE_TET: tet.add(elem); break; case HERMES_MODE_HEX: hex.add(elem); break; case HERMES_MODE_PRISM: pri.add(elem); break; } } save_tetra(group_id, tet); save_hex(group_id, hex); save_prism(group_id, pri); status = H5Gclose(group_id); // close the group }
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); }
escdf_errno_t utils_hdf5_create_attr(hid_t loc_id, const char *name, hid_t type_id, hsize_t *dims, unsigned int ndims, hid_t *attr_pt) { hid_t attr_id, dtspace_id; /* Create space dimensions. */ if ((dtspace_id = H5Screate_simple(ndims, dims, NULL)) < 0) { RETURN_WITH_ERROR(dtspace_id); } if ((attr_id = H5Acreate(loc_id, name, type_id, dtspace_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) { DEFER_FUNC_ERROR(attr_id); goto cleanup_dtspace; } H5Sclose(dtspace_id); if (attr_pt) *attr_pt = attr_id; else H5Aclose(attr_id); return ESCDF_SUCCESS; cleanup_dtspace: H5Sclose(attr_id); return ESCDF_ERROR; }
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; }
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); }
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; }
// Write complex attribute <attr_name> given by address <path> char AH5_write_cpx_attr(hid_t loc_id, const char* path, char* attr_name, const AH5_complex_t wdata) { char success = AH5_FALSE; hid_t attr_id = 0, cpx_filetype, cpx_memtype, object_id, space; hsize_t dims[1] = {1}; cpx_filetype = AH5_H5Tcreate_cpx_filetype(); cpx_memtype = AH5_H5Tcreate_cpx_memtype(); space = H5Screate_simple (1, dims, NULL); if (AH5_path_valid(loc_id, path)) { if ((object_id = H5Oopen(loc_id, path, H5P_DEFAULT)) >= 0) { if ((attr_id = H5Acreate(object_id, attr_name, cpx_filetype, space, H5P_DEFAULT, H5P_DEFAULT)) >= 0) { if (H5Awrite(attr_id, cpx_memtype, &wdata) >= 0) { success = AH5_TRUE; } H5Aclose(attr_id); } H5Oclose(object_id); } } H5Sclose(space); H5Tclose(cpx_memtype); H5Tclose(cpx_filetype); return success; }
bool save_vertices(hid_t parent_group_id, Mesh *mesh) { herr_t status; // create main group hid_t group_id = H5Gcreate(parent_group_id, "vertices", 0); // count hid_t dataspace_id = H5Screate(H5S_SCALAR); hid_t attr_count = H5Acreate(group_id, "count", H5T_NATIVE_UINT32, dataspace_id, H5P_DEFAULT); uint count = mesh->vertices.count(); status = H5Awrite(attr_count, H5T_NATIVE_UINT32, &count); H5Aclose(attr_count); H5Sclose(dataspace_id); hsize_t dims = 3; hid_t vertex_dataspace_id = H5Screate_simple(1, &dims, NULL); // dump vertices for (int i = 0; i < count; i++) { char name[256]; sprintf(name, "%d", i); // Create the dataset hid_t dataset_id = H5Dcreate(group_id, name, H5T_NATIVE_DOUBLE, vertex_dataspace_id, H5P_DEFAULT); double pt[] = { mesh->vertices[i]->x, mesh->vertices[i]->y, mesh->vertices[i]->z }; status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, pt); status = H5Dclose(dataset_id); } H5Sclose(vertex_dataspace_id); status = H5Gclose(group_id); // close the group }
extern void put_int_attribute(hid_t parent, char *name, int value) { hid_t attr, space_attr; hsize_t dim_attr[1] = {1}; // Single dimension array of values space_attr = H5Screate_simple(1, dim_attr, NULL); if (space_attr < 0) { debug3("PROFILE: failed to create space for attribute %s", name); return; } attr = H5Acreate(parent, name, H5T_NATIVE_INT, space_attr, H5P_DEFAULT, H5P_DEFAULT); if (attr < 0) { H5Sclose(space_attr); debug3("PROFILE: failed to create attribute %s", name); return; } if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) { debug3("PROFILE: failed to write attribute %s", name); // Fall through to release resources } H5Sclose(space_attr); H5Aclose(attr); return; }
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; }
void HDF5Attribute::create(const HDF5Id location_id, const String &name, const HDF5Id type_id, const HDF5Id space_id) { // create the attribute in memory m_id = H5Acreate(location_id, name.c_str(), type_id, space_id, H5P_DEFAULT, H5P_DEFAULT); }
static attribute create(handle const& loc, const char* name, datatype const& type, dataspace const& space) { hid_t id = H5Acreate(loc.getId(), name, type, space, H5P_DEFAULT, H5P_DEFAULT); assert(id >= 0); return attribute(std::move(id)); }
bool dump_hdf5(const char *file_name, Mesh *mesh) { herr_t status; // init HDF5 H5open(); // create a file hid_t file_id = H5Fcreate(file_name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); // create main group hid_t mesh_group_id = H5Gcreate(file_id, "/mesh3d", 0); // version hsize_t dims = 2; hid_t dataspace_id = H5Screate_simple(1, &dims, NULL); hid_t attr_ver = H5Acreate(mesh_group_id, "version", H5T_STD_I8BE, dataspace_id, H5P_DEFAULT); char attr_data[2] = { 1, 0 }; status = H5Awrite(attr_ver, H5T_NATIVE_CHAR, attr_data); H5Aclose(attr_ver); H5Sclose(dataspace_id); // description hid_t type = H5Tcopy(H5T_C_S1); status = H5Tset_size(type, H5T_VARIABLE); const char *descr = "Test mesh"; hid_t dataspace_id2 = H5Screate(H5S_SCALAR); hid_t attr_descr = H5Acreate(mesh_group_id, "description", type, dataspace_id2, H5P_DEFAULT); status = H5Awrite(attr_descr, type, &descr); H5Aclose(attr_descr); H5Tclose(type); H5Sclose(dataspace_id2); save_vertices(mesh_group_id, mesh); save_elements(mesh_group_id, mesh); save_bc(mesh_group_id, mesh); status = H5Gclose(mesh_group_id); // close the group status = H5Fclose(file_id); // close the file // deinit HDF5 H5close(); return 0; }
herr_t writeAttribute_int(hid_t file_id, const char *dsName, const char *attrName,void *val) { hid_t dataset = H5Dopen(file_id,dsName,H5P_DEFAULT); hid_t aid = H5Screate(H5S_SCALAR); hid_t attr = H5Acreate(dataset,attrName, H5T_NATIVE_INT, aid, H5P_DEFAULT,H5P_DEFAULT); herr_t ret = H5Awrite(attr,H5T_NATIVE_INT,val); ret = H5Sclose(aid); ret = H5Aclose(attr); return ret; }
int fclib_create_int_attributes_in_info(const char *path, const char * attr_name, int attr_value) { hid_t file_id, id, dataspace_id, attr_id; hsize_t dim = 1; hsize_t dims[1]; FILE *f; if ((f = fopen (path, "r"))) /* HDF5 outputs lots of warnings when file does not exist */ { fclose (f); if ((file_id = H5Fopen (path, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { fprintf (stderr, "ERROR: opening file failed\n"); return 0; } } if (H5Lexists (file_id, "/fclib_local/info", H5P_DEFAULT)) { IO (id = H5Gopen (file_id, "/fclib_local/info", H5P_DEFAULT)); dims[0]=1; dataspace_id = H5Screate_simple(1, dims, NULL); attr_id = H5Acreate (id, attr_name, H5T_NATIVE_INT, dataspace_id, H5P_DEFAULT, H5P_DEFAULT); IO(H5Awrite(attr_id, H5T_NATIVE_INT , &attr_value )); IO(H5Aclose (attr_id)); IO (H5Gclose (id)); } else { IO (id = H5Gmake (file_id, "/fclib_local/info")); dims[0]=1; dataspace_id = H5Screate_simple(1, dims, NULL); attr_id = H5Acreate (id, attr_name, H5T_NATIVE_INT, dataspace_id, H5P_DEFAULT, H5P_DEFAULT); IO(H5Awrite(attr_id, H5T_NATIVE_INT , &attr_value )); IO(H5Aclose (attr_id)); IO (H5Gclose (id)); } IO (H5Fclose (file_id)); return 1; }
bool save_quad_bc(hid_t parent_group_id, JudyArray<Boundary *> &bcs) { herr_t status; // create main group hid_t group_id = H5Gcreate(parent_group_id, "quad", 0); // count hid_t dataspace_id = H5Screate(H5S_SCALAR); hid_t attr_count = H5Acreate(group_id, "count", H5T_NATIVE_UINT32, dataspace_id, H5P_DEFAULT); uint count = bcs.count(); status = H5Awrite(attr_count, H5T_NATIVE_UINT32, &count); H5Aclose(attr_count); /// hsize_t dims = Quad::NUM_VERTICES; hid_t elem_dataspace_id = H5Screate_simple(1, &dims, NULL); hid_t merker_dataspace_id = H5Screate(H5S_SCALAR); // dump vertices for (int i = 0; i < count; i++) { char name[256]; sprintf(name, "%d", i); // the dataset hid_t dataset_id = H5Dcreate(group_id, name, H5T_NATIVE_UINT32, elem_dataspace_id, H5P_DEFAULT); status = H5Dwrite(dataset_id, H5T_NATIVE_UINT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, bcs[i]->get_vertices()); // marker hid_t attr_marker = H5Acreate(dataset_id, "marker", H5T_NATIVE_UINT32, dataspace_id, H5P_DEFAULT); uint marker = bcs[i]->get_marker(); status = H5Awrite(attr_marker, H5T_NATIVE_UINT32, &marker); H5Aclose(attr_marker); status = H5Dclose(dataset_id); } H5Sclose(elem_dataspace_id); H5Sclose(dataspace_id); status = H5Gclose(group_id); // close the group }
herr_t attribute_read(char *attribute_name, enum my_hdf5_types hdf5_type, hid_t hdf5_file_handle, void *buf) { hid_t hdf5_attribute_id, hdf5_dataspace, hdf5_datatype; herr_t hdf5_status = 0; //here we get an identifier for a datatype switch (hdf5_type) { case my_hdf5_int: hdf5_datatype = H5Tcopy(H5T_NATIVE_INT); break; case my_hdf5_long: hdf5_datatype = H5Tcopy(H5T_NATIVE_LONG); break; case my_hdf5_float: hdf5_datatype = H5Tcopy(H5T_NATIVE_FLOAT); break; case my_hdf5_double: hdf5_datatype = H5Tcopy(H5T_NATIVE_DOUBLE); break; default: exit(-1); break; } hdf5_dataspace = H5Screate(H5S_SCALAR); hdf5_attribute_id = H5Acreate(hdf5_file_handle, attribute_name, hdf5_datatype, hdf5_dataspace, H5P_DEFAULT); //here we 'create' an attribute switch (hdf5_type) { case my_hdf5_int: hdf5_status = H5Aread(hdf5_attribute_id, hdf5_datatype, (int *) buf); break; case my_hdf5_long: hdf5_status = H5Aread(hdf5_attribute_id, hdf5_datatype, (long *) buf); break; case my_hdf5_float: hdf5_status = H5Aread(hdf5_attribute_id, hdf5_datatype, (float *) buf); break; case my_hdf5_double: hdf5_status = H5Aread(hdf5_attribute_id, hdf5_datatype, (double *) buf); break; default: exit(-1); break; } H5Tclose(hdf5_datatype); H5Aclose(hdf5_attribute_id); H5Sclose(hdf5_dataspace); return hdf5_status; }
/* add a single attribute */ int add_attr(hid_t oid, const char *name, hid_t tid, hid_t sid, void *buf) { hid_t aid; aid = H5Acreate (oid, name, tid, sid, H5P_DEFAULT, H5P_DEFAULT); if (aid <0) return 0; H5Awrite(aid, tid, buf); H5Aclose(aid); return 1; }
herr_t ASDF_write_double_attribute(hid_t dataset_id, const char *attr_name, double attr_value) { hid_t space_id, attr_id; CHK_H5(space_id = H5Screate(H5S_SCALAR)); CHK_H5(attr_id = H5Acreate(dataset_id, attr_name, H5T_IEEE_F64LE, space_id, H5P_DEFAULT, H5P_DEFAULT)); CHK_H5(H5Awrite(attr_id, H5T_IEEE_F64LE, &attr_value)); CHK_H5(H5Aclose(attr_id)); CHK_H5(H5Sclose(space_id)); return 0; // Success }
herr_t ASDF_write_integer_attribute(hid_t dataset_id, const char *attr_name, long long int attr_value) { hid_t space_id, attr_id; CHK_H5(space_id = H5Screate(H5S_SCALAR)); CHK_H5(attr_id = H5Acreate(dataset_id, attr_name, H5T_STD_I64LE, space_id, H5P_DEFAULT, H5P_DEFAULT)); CHK_H5(H5Awrite(attr_id, H5T_STD_I64LE, &attr_value)); CHK_H5(H5Aclose(attr_id)); CHK_H5(H5Sclose(space_id)); return 0; // Success }
hid_t _write_grid(hid_t loc_id, std::string attr_name, double *attr_array, const hsize_t size) { herr_t status; hid_t attr_id; DataspaceCreate x_grid_space(H5S_SCALAR); status = H5Sset_extent_simple(x_grid_space.dataspace_id, 1, &size, NULL); attr_id = H5Acreate(loc_id, attr_name.c_str(), H5T_NATIVE_DOUBLE, x_grid_space.dataspace_id, H5P_DEFAULT, H5P_DEFAULT); status = H5Awrite(attr_id, H5T_NATIVE_DOUBLE, attr_array); H5Aclose(attr_id); return status; }
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; }
herr_t ASDF_write_string_attribute(hid_t dataset_id, const char *attr_name, const char *attr_value) { hid_t space_id, type_id, attr_id; CHK_H5(space_id = H5Screate(H5S_SCALAR)); CHK_H5(type_id = H5Tcopy(H5T_C_S1)); CHK_H5(H5Tset_size(type_id, strlen(attr_value))); CHK_H5(H5Tset_strpad(type_id,H5T_STR_NULLPAD)); CHK_H5(attr_id = H5Acreate(dataset_id, attr_name, type_id, space_id, H5P_DEFAULT, H5P_DEFAULT)); CHK_H5(H5Awrite(attr_id, type_id, attr_value)); CHK_H5(H5Aclose(attr_id)); CHK_H5(H5Tclose(type_id)); CHK_H5(H5Sclose(space_id)); return 0; // Success }