hid_t AH5_H5Tcreate_cpx_filetype(void) { hid_t cpx_filetype; cpx_filetype = H5Tcreate(H5T_COMPOUND, H5Tget_size(AH5_NATIVE_FLOAT) * 2); H5Tinsert(cpx_filetype, "r", 0, AH5_NATIVE_FLOAT); H5Tinsert(cpx_filetype, "i", H5Tget_size(AH5_NATIVE_FLOAT), AH5_NATIVE_FLOAT); return cpx_filetype; }
int main(int argc, char **argv) { char file_name[256], dset_name[256]; hid_t file_id, dataset_id, space_id, plist_id, type_id; hsize_t dims[1], dims_chunk[1]; hsize_t maxdims[1] = { H5S_UNLIMITED }; size_t disk_type_size, computed_type_size, packed_type_size; if (argc < 3) { printf("Pass the name of the file and dataset to check as arguments\n"); return(0); } strcpy(file_name, argv[1]); strcpy(dset_name, argv[2]); dims[0] = 20; // Create 20 records dims_chunk[0] = 10; // Create a new file file_id = H5Fcreate(file_name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); // Create a simple data space with unlimited size space_id = H5Screate_simple(1, dims, maxdims); // Modify dataset creation properties, i.e. enable chunking plist_id = H5Pcreate (H5P_DATASET_CREATE); H5Pset_chunk(plist_id, 1, dims_chunk); // Get the nested type type_id = createNestedType(); // Create the dataset dataset_id = H5Dcreate(file_id, dset_name, type_id, space_id, plist_id); // Free resources H5Sclose(space_id); H5Pclose(plist_id); H5Dclose(dataset_id); H5Fclose(file_id); // Compute type sizes for native and packed disk_type_size = H5Tget_size(type_id); computed_type_size = getNestedSizeType(type_id); H5Tpack(type_id); // pack type packed_type_size = H5Tget_size(type_id); printf("Disk type size: %d\n", disk_type_size); printf("Packed type size: %d (should be %d)\n", packed_type_size, computed_type_size); H5Tclose(type_id); return(1); }
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; }
void read_vector( hid_t dataset_id, hid_t datatype_id, hid_t dataspace_id, std::vector<std::string>& out) { hsize_t size; hsize_t dims[1]; H5Sget_simple_extent_dims(dataspace_id, dims, NULL); size = H5Tget_size(datatype_id); char *pool = new char[ size * dims[0] ]; char *ptr = pool; char *buf = new char[size]; H5Dread(dataset_id, datatype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, pool); out.reserve(dims[0]); for (size_t i = 0; i < dims[0]; ++i, ptr += size) { memcpy(buf, ptr, size); out.push_back( buf ); } delete [] pool; delete [] buf; }
// Read string attribute <attr_name> given by address <path> char AH5_read_str_attr(hid_t loc_id, const char *path, char *attr_name, char **rdata) { hid_t attr_id, filetype, memtype; size_t sdim; char success = AH5_FALSE; if (AH5_path_valid(loc_id, path) || strcmp(path, ".") == 0) if (H5Aexists_by_name(loc_id, path, attr_name, H5P_DEFAULT) > 0) { attr_id = H5Aopen_by_name(loc_id, path, attr_name, H5P_DEFAULT, H5P_DEFAULT); filetype = H5Aget_type(attr_id); sdim = H5Tget_size(filetype); sdim++; // make a space for null terminator *rdata = (char *) malloc(sdim * sizeof(char)); memtype = H5Tcopy(H5T_C_S1); H5Tset_size(memtype, sdim); if (H5Aread(attr_id, memtype, *rdata) >= 0) success = AH5_TRUE; else free(*rdata); H5Tclose(memtype); H5Tclose(filetype); H5Aclose(attr_id); } if (!success) *rdata = NULL; return success; }
/*------------------------------------------------------------------------- * Function: print_dset_dtype_meta * * Purpose: Prints datasets' datatype information * * Return: Success: 0 * * Failure: Never fails * * Programmer: Vailin Choi; October 2009 * *------------------------------------------------------------------------- */ static herr_t print_dset_dtype_meta(const iter_t *iter) { unsigned long total; /* Total count for various statistics */ size_t dtype_size; /* Size of encoded datatype */ unsigned u; /* Local index variable */ if(iter->dset_ntypes) { printf("Dataset datatype information:\n"); printf("\t# of unique datatypes used by datasets: %lu\n", iter->dset_ntypes); total = 0; for(u = 0; u < iter->dset_ntypes; u++) { H5Tencode(iter->dset_type_info[u].tid, NULL, &dtype_size); printf("\tDataset datatype #%u:\n", u); printf("\t\tCount (total/named) = (%lu/%lu)\n", iter->dset_type_info[u].count, iter->dset_type_info[u].named); printf("\t\tSize (desc./elmt) = (%lu/%lu)\n", (unsigned long)dtype_size, (unsigned long)H5Tget_size(iter->dset_type_info[u].tid)); H5Tclose(iter->dset_type_info[u].tid); total += iter->dset_type_info[u].count; } /* end for */ printf("\tTotal dataset datatype count: %lu\n", total); } /* end if */ return 0; } /* print_dset_dtype_meta() */
void h5_value_doubles(hid_t file_id, char *group, char *name, double **values, int *numValues) { int kk; hid_t group_id = H5Gopen(file_id, group, H5P_DEFAULT); hid_t data_id = H5Dopen(group_id, name, H5P_DEFAULT); hid_t data_space = H5Dget_space(data_id); int rank = H5Sget_simple_extent_ndims(data_space); hsize_t dims[H5S_MAX_RANK], maxdim[H5S_MAX_RANK]; H5Sget_simple_extent_dims(data_space, dims, maxdim); hid_t data_type = H5Dget_type(data_id); H5T_class_t data_class = H5Tget_native_type(data_type, H5T_DIR_DEFAULT); size_t data_size = H5Tget_size(data_class); hsize_t elements = 1; for (kk=0; kk<rank; kk++) elements *= dims[kk]; void *buf = (void *) MALLOC((size_t)(elements*data_size)); H5Dread(data_id, data_class, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); *values = buf; *numValues = elements; H5Tclose(data_type); H5Tclose(data_class); H5Sclose(data_space); H5Dclose(data_id); H5Gclose(group_id); }
int luaC_h5_read_string(lua_State *L) { const char *dsetnm = luaL_checkstring(L, 1); if (PresentFile < 0) { luaL_error(L, "no open file"); } hid_t dset = H5Dopen(PresentFile, dsetnm, H5P_DEFAULT); if (dset < 0) { luaL_error(L, "no data set named %s", dsetnm); } hid_t fspc = H5Dget_space(dset); hid_t strn = H5Dget_type(dset); hsize_t msize = H5Tget_size(strn); char *string = (char*) malloc((msize+1)*sizeof(char)); H5Dread(dset, strn, fspc, fspc, H5P_DEFAULT, string); string[msize] = '\0'; // Make sure to null-terminate the string lua_pushstring(L, string); H5Tclose(strn); H5Sclose(fspc); H5Dclose(dset); free(string); return 1; }
/** Return the byte size of the voxel datatytpe */ int miget_data_type_size ( mihandle_t volume, misize_t *voxel_size ) { hid_t grp_id; hid_t dset_id; hid_t type_id; hid_t file_id = volume->hdf_id; grp_id = midescend_path ( file_id, MI_FULLIMAGE_PATH ); if ( grp_id < 0 ) { return ( MI_ERROR ); } dset_id = H5Dopen1 ( grp_id, "image" ); if ( dset_id < 0 ) { return ( MI_ERROR ); } type_id = H5Dget_type ( dset_id ); if ( type_id < 0 ) { return ( MI_ERROR ); } *voxel_size = H5Tget_size ( type_id ); H5Tclose ( type_id ); H5Dclose ( dset_id ); H5Gclose ( grp_id ); return ( MI_NOERROR ); }
size_t getNestedSizeType(hid_t type_id) { hid_t member_type_id; H5T_class_t class_id; hsize_t i, nfields; size_t itemsize, offset; nfields = H5Tget_nmembers(type_id); offset = 0; // Iterate thru the members for (i=0; i < nfields; i++) { // Get the member type member_type_id = H5Tget_member_type(type_id, i); // Get the HDF5 class class_id = H5Tget_class(member_type_id); if (class_id == H5T_COMPOUND) { // Get the member size for compound type itemsize = getNestedSizeType(member_type_id); } else { // Get the atomic member size itemsize = H5Tget_size(member_type_id); } // Update the offset offset = offset + itemsize; } return(offset); }
/* read attribute value */ char* H5Dataset_read_attr_value(hid_t aid) { hid_t asid=-1, atid=-1; int i, rank; hsize_t *dims; size_t size=1; char *attr_buf=NULL; asid = H5Aget_space(aid); atid = H5Aget_type(aid); rank = H5Sget_simple_extent_ndims(asid); if (rank > 0) { dims = (hsize_t *)malloc(rank * sizeof(hsize_t)); H5Sget_simple_extent_dims(asid, dims, NULL); for (i=0; i<rank; i++) { size *= (size_t)dims[i]; free(dims); } size *= H5Tget_size(atid); attr_buf = (char *)malloc(size); if (H5Aread( aid, atid, attr_buf) < 0) { free(attr_buf); attr_buf = NULL; } } if( atid > 0) H5Tclose(atid); if (asid > 0) H5Sclose(asid); return attr_buf; }
/* 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); }
char *test_read_complex_dataset() { int i,rank = 1; hsize_t dims[1]; hid_t dataspace_id, dset_id, dtr_id, dti_id, file_id; size_t type_size; hid_t type_id; herr_t status, status_2; float *real_part, *imag_part; const char* path = "dataset_name"; AH5_complex_t cplx[2]; AH5_complex_t * rdata; file_id = AH5_auto_test_file(); cplx[0].re=10.; cplx[0].im=20.; cplx[1].re=10.5; cplx[1].im=20.5; //first write complex array set with hdf5 lib real_part = (float *)malloc(2 * sizeof(float)); imag_part = (float *)malloc(2 * sizeof(float)); for( i=0;i<2;i++) { real_part[i] = cplx[i].re; imag_part[i] = cplx[i].im; } type_id = create_type_id(H5T_NATIVE_FLOAT); dims[0] = 2; dataspace_id = H5Screate_simple(rank, dims, NULL); dset_id = H5Dcreate(file_id,path,type_id,dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); type_size = H5Tget_size(H5T_NATIVE_FLOAT); dtr_id = H5Tcreate(H5T_COMPOUND,type_size); status = H5Tinsert(dtr_id,"r",0, H5T_NATIVE_FLOAT); dti_id = H5Tcreate(H5T_COMPOUND,type_size); status = H5Tinsert(dti_id,"i",0, H5T_NATIVE_FLOAT); status = H5Dwrite(dset_id,dtr_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,real_part); status = H5Dwrite(dset_id,dti_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,imag_part); status = H5Tclose(dtr_id); status = H5Tclose(dti_id); free(real_part); free(imag_part); mu_assert("Read complex dataset.", AH5_read_cpx_dataset(file_id,"dataset_name", 2, &rdata)); for (i = 0; i < 2; i++) { printf("Real parts : %f %f\n", cplx[i].re, rdata[i].re); printf("Imaginary parts : %f %f\n", cplx[i].im, rdata[i].im); mu_assert_equal("Check the real values.", cplx[i].re, rdata[i].re); mu_assert_equal("Check the imaginary value.", cplx[i].im, rdata[i].im); } return MU_FINISHED_WITHOUT_ERRORS; }
void print_sizes( const char *obj1, const char *obj2, hid_t f_tid1, hid_t f_tid2, hid_t m_tid1, hid_t m_tid2 ) { size_t f_size1, f_size2; /* size of type in file */ size_t m_size1, m_size2; /* size of type in memory */ f_size1 = H5Tget_size( f_tid1 ); f_size2 = H5Tget_size( f_tid2 ); m_size1 = H5Tget_size( m_tid1 ); m_size2 = H5Tget_size( m_tid2 ); parallel_print("\n"); parallel_print("------------------\n"); parallel_print("sizeof(char) %u\n", sizeof(char) ); parallel_print("sizeof(short) %u\n", sizeof(short) ); parallel_print("sizeof(int) %u\n", sizeof(int) ); parallel_print("sizeof(long) %u\n", sizeof(long) ); parallel_print("<%s> ------------------\n", obj1); parallel_print("type on file "); print_type(f_tid1); parallel_print("\n"); parallel_print("size on file %u\n", f_size1 ); parallel_print("type on memory "); print_type(m_tid1); parallel_print("\n"); parallel_print("size on memory %u\n", m_size1 ); parallel_print("<%s> ------------------\n", obj2); parallel_print("type on file "); print_type(f_tid2); parallel_print("\n"); parallel_print("size on file %u\n", f_size2 ); parallel_print("type on memory "); print_type(m_tid2); parallel_print("\n"); parallel_print("size on memory %u\n", m_size2 ); parallel_print("\n"); }
DataType ImageBase::datatypeH5(hid_t h5datatype) { H5T_sign_t h5sign = H5Tget_sign(h5datatype); // if (h5sign == H5T_SGN_ERROR) // REPORT_ERROR(ERR_IO, "datatypeHDF5: Integer sign error in dataset."); bool sign = (h5sign > H5T_SGN_NONE); size_t size = H5Tget_size(h5datatype); DataType dt; switch(H5Tget_class(h5datatype)) { case H5T_FLOAT: { switch(size) { case 4: dt = DT_Float; break; case 8: dt = DT_Double; break; default: REPORT_ERROR(ERR_IO_SIZE, "datatypeHDF5: bad datatype size"); } } break; case H5T_INTEGER: { switch(size) { case 1: dt = (sign)? DT_SChar : DT_UChar; break; case 2: dt = (sign)? DT_Short : DT_UShort; break; case 4: dt = (sign)? DT_Int : DT_UInt; break; case 8: dt = (sign)? DT_Long : DT_ULong; break; default: REPORT_ERROR(ERR_IO_SIZE, "datatypeHDF5: bad datatype size"); } } break; case H5T_NO_CLASS: default: dt = DT_Unknown; break; } return dt; }
size_t getSize() const { size_t myElements = H5Tget_size(this->type); /* for variable length string the size is first known after reading * the actual data or attribute, so we forward HDF5's behaviour */ if( H5Tis_variable_str(this->type) ) return myElements; /* == sizeof(char*) see H5Tget_size description */ else return sizeof(char) * (myElements - 1); /* just as strlen() */ }
size_t hdf5_datatype::get_size() const { size_t size = H5Tget_size(get_id()); if(!size) { boost::serialization::throw_exception( hdf5_archive_exception( hdf5_archive_exception::hdf5_archive_datatype_access_error ) ); } return size; }
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; }
size_t DCDataSet::getDataTypeSize() throw (DCException) { if (!opened) throw DCException(getExceptionString("getDataTypeSize: dataset is not opened")); size_t size = H5Tget_size(this->datatype); if (size == 0) throw DCException(getExceptionString("getDataTypeSize: could not get size of datatype")); return size; }
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; }
hid_t create_type_id(hid_t real_or_double) { hid_t type_id; hid_t type_size, two_type_size; herr_t status; type_size = H5Tget_size(real_or_double); two_type_size = type_size * 2; type_id = H5Tcreate(H5T_COMPOUND, two_type_size); status = H5Tinsert(type_id, "r", 0, real_or_double); status = H5Tinsert(type_id, "i", type_size, real_or_double); return type_id; }
void Fast5Files::getFastq(hid_t dataset){ hid_t dt; size_t size; char *data; dt = H5Dget_type(dataset); size = H5Tget_size(dt); data = (char*)malloc(size); H5Dread(dataset, H5T_C_S1, H5S_ALL, H5S_ALL, H5P_DEFAULT, data); qDebug() << data; free(data); H5Dclose(dataset); }
static int try_read_string(hid_t loc, char * name, char ** dest){ if(H5Lexists(loc,name,H5P_DEFAULT)){ hid_t ds = H5Dopen(loc,name,H5P_DEFAULT); hid_t t = H5Dget_type(ds); if(H5Tget_class(t) == H5T_STRING){ *dest = malloc(sizeof(char)*H5Tget_size(t)); H5Dread(ds,t,H5S_ALL,H5S_ALL,H5P_DEFAULT,*dest); } H5Tclose(t); H5Dclose(ds); return 1; } return 0; }
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); }
/*----------------------------------------------------------------- * Function: match_up_memsize * * Purpose: match smaller memory size up to bigger memory size *------------------------------------------------------------------ */ herr_t match_up_memsize (hid_t f_tid1_id, hid_t f_tid2_id, hid_t *m_tid1, hid_t *m_tid2, size_t *m_size1, size_t *m_size2) { herr_t ret = SUCCEED; if( (*m_size1) != (*m_size2) ) { if( (*m_size1) < (*m_size2) ) { H5Tclose( *m_tid1 ); if(( (*m_tid1) = h5tools_get_native_type(f_tid2_id)) < 0) { ret = FAIL; goto out; } *m_size1 = H5Tget_size( *m_tid1 ); } /* end if */ else { H5Tclose(*m_tid2); if(( (*m_tid2) = h5tools_get_native_type(f_tid1_id)) < 0) { ret = FAIL; goto out; } *m_size2 = H5Tget_size(*m_tid2); } /* end else */ } /* end if */ HDassert( (*m_size1) == (*m_size2) ); out: return ret; }
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; }
/** Calculates and returns the number of bytes required to store the * hyperslab specified by the \a n_dimensions and the * \a count parameters, using hdf type id */ void miget_hyperslab_size_hdf(hid_t hdf_type_id, int n_dimensions, const hsize_t count[], misize_t *size_ptr) { size_t voxel_size; misize_t temp; int i; voxel_size = H5Tget_size(hdf_type_id); temp = 1; for (i = 0; i < n_dimensions; i++) { temp *= count[i]; } *size_ptr = (temp * voxel_size); }
std::string compare_and_read_scalar_attribute(hid_t attribute_id, hid_t type_id) { if(H5Tget_class(type_id) == H5T_STRING) { int size = H5Tget_size(type_id); std::string data(size+1, ' '); herr_t status = H5Aread(attribute_id, type_id, &(data[0])); if(status >= 0) { data.resize(size); return data; } } throw std::runtime_error("type mismatch"); }
/*! \ingroup h5multiblock_static \internal Takes a contiguous buffer of data and rearranges it in place to add padding with \c radius layers. Assumes that \c buffer is already large enough to perform this operation. \return H5PART_SUCCESS or error code */ static h5part_int64_t _pad_block ( const H5PartFile *f, /*!< IN: file handle */ char *data, /*!< IN/OUT: buffer to pad */ hid_t type /*!< IN: HDF5 datatype of buffer */ ) { size_t typesize; h5part_int64_t j, k; h5part_int64_t iDst, iSrc; h5part_int64_t xSize, xySize; h5part_int64_t hxSize, hxySize; h5part_int64_t hxInset; struct H5MultiBlockStruct *mb = f->multiblock; /* size of datatype */ typesize = H5Tget_size ( type ); /* size of row in original block */ xSize = mb->block_dims[2] * typesize; /* size of slab in original block */ xySize = xSize * mb->block_dims[1]; /* size of row/slab with halo regions */ hxSize = mb->halo_dims[2] * typesize; hxySize = hxSize * mb->halo_dims[1]; /* inset of row in halo region */ hxInset = mb->halo_radii[2] * typesize; for (k=(mb->block_dims[0]-1);k>=0;k--) { for (j=(mb->block_dims[1]-1);j>=0;j--) { iSrc = k*xySize + j*xSize; iDst = (k + mb->halo_radii[0]) * hxySize + (j + mb->halo_radii[1]) * hxSize + hxInset; memcpy ( data + iDst, data + iSrc, xSize ); } } return H5PART_SUCCESS; }
/*------------------------------------------------------------------------------ * Purpose: converts data value into strings * Parameters: H5Dataset* d-- The dataset its value to be vonverted. hid_t tid -- the datatype identifier * Return: Returns a non-negative value if successful; otherwise returns a negative value. *------------------------------------------------------------------------------ */ int H5Dataset_value_to_string(H5Dataset *d, hid_t tid, hid_t sid) { int ret_value=0; unsigned int i=0; char **strs; unsigned char *vp=NULL; h5str_t h5str; size_t offset=0, tsize=0, valuelen=0; void *value; assert(d); assert(d->value); value = d->value; vp = (unsigned char *)d->value; d->value = (char **)malloc(d->space.npoints*sizeof(char *)); assert(d->value); strs = (char**)d->value; offset = 0; tsize = H5Tget_size(tid); memset(&h5str, 0, sizeof(h5str_t)); h5str_new(&h5str, 4*tsize); d->nvalue = 0; for (i=0; i<d->space.npoints; i++) { h5str_empty(&h5str); ret_value = h5str_sprintf(&h5str, tid, vp + offset, " || "); if (ret_value > 0) { valuelen = strlen(h5str.s)+1; strs[i] = (char *)malloc(valuelen); strcpy(strs[i], h5str.s); /* d->nvalue += valuelen; XXXX changed by MW */ d->nvalue ++; } offset += tsize; } h5str_free(&h5str); /* reclaim memory allocated to store variable length data */ if (H5Tdetect_class(tid, H5T_VLEN) > 0) H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, value); free (value); return ret_value; }