/*------------------------------------------------------------------------- * Function: create_symbol_datatype * * Purpose: Create's the HDF5 datatype used for elements in the SWMR * testing datasets. * * Parameters: N/A * * Return: Success: An HDF5 type ID * Failure: -1 * *------------------------------------------------------------------------- */ hid_t create_symbol_datatype(void) { hid_t sym_type_id; /* Datatype ID for symbol */ hid_t opaq_type_id; /* Datatype ID for opaque part of record */ /* Create opaque datatype to represent other information for this record */ if((opaq_type_id = H5Tcreate(H5T_OPAQUE, (size_t)DTYPE_SIZE)) < 0) return -1; /* Create compound datatype for symbol */ if((sym_type_id = H5Tcreate(H5T_COMPOUND, sizeof(symbol_t))) < 0) return -1; /* Insert fields in symbol datatype */ if(H5Tinsert(sym_type_id, "rec_id", HOFFSET(symbol_t, rec_id), H5T_NATIVE_UINT64) < 0) return -1; if(H5Tinsert(sym_type_id, "info", HOFFSET(symbol_t, info), opaq_type_id) < 0) return -1; /* Close opaque datatype */ if(H5Tclose(opaq_type_id) < 0) return -1; return sym_type_id; } /* end create_symbol_datatype() */
/*------------------------------------------------------------------------- * function to create a datatype representing the particle struct *------------------------------------------------------------------------- */ static hid_t make_particle_type(void) { hid_t type_id; hid_t string_type; size_t type_size = sizeof(particle_t); /* Create the memory data type. */ if ((type_id = H5Tcreate (H5T_COMPOUND, type_size )) < 0 ) return -1; /* Insert fields. */ string_type = H5Tcopy( H5T_C_S1 ); H5Tset_size( string_type, (size_t)16 ); if ( H5Tinsert(type_id, "Name", HOFFSET(particle_t, name) , string_type ) < 0 ) return -1; if ( H5Tinsert(type_id, "Lat", HOFFSET(particle_t, lati) , H5T_NATIVE_INT ) < 0 ) return -1; if ( H5Tinsert(type_id, "Long", HOFFSET(particle_t, longi) , H5T_NATIVE_INT ) < 0 ) return -1; if ( H5Tinsert(type_id, "Pressure", HOFFSET(particle_t, pressure) , H5T_NATIVE_FLOAT ) < 0 ) return -1; if ( H5Tinsert(type_id, "Temperature", HOFFSET(particle_t, temperature) , H5T_NATIVE_DOUBLE ) < 0 ) return -1; return type_id; }
/* Counterpart for complex256 */ hid_t create_ieee_complex256(const char *byteorder) { herr_t err = 0; hid_t float_id, complex_id; H5T_order_t h5order = H5Tget_order(H5T_NATIVE_LDOUBLE); complex_id = H5Tcreate(H5T_COMPOUND, sizeof(npy_complex256)); float_id = H5Tcopy(H5T_NATIVE_LDOUBLE); if (float_id < 0) { H5Tclose(complex_id); return float_id; } if ((strcmp(byteorder, "little") == 0) && (h5order != H5T_ORDER_LE)) err = H5Tset_order(float_id, H5T_ORDER_LE); else if ((strcmp(byteorder, "big") == 0) && (h5order != H5T_ORDER_BE)) err = H5Tset_order(float_id, H5T_ORDER_BE); if (err < 0) { H5Tclose(complex_id); return err; } H5Tinsert(complex_id, "r", HOFFSET(npy_complex256, real), float_id); H5Tinsert(complex_id, "i", HOFFSET(npy_complex256, imag), float_id); H5Tclose(float_id); return complex_id; }
int main(int argc, char *argv[]) { hdf_sa_t arr[LEN]; initArr(arr, LEN); // create data type corresponding to compound struct hid_t cid = H5Tcreate(H5T_COMPOUND, sizeof(hdf_sa_t)); H5Tinsert(cid, "a", HOFFSET(hdf_sa_t, a), H5T_NATIVE_INT); H5Tinsert(cid, "b", HOFFSET(hdf_sa_t, b), H5T_NATIVE_FLOAT); H5Tinsert(cid, "c", HOFFSET(hdf_sa_t, c), H5T_NATIVE_DOUBLE); // write data to file hid_t fid = H5Fcreate("compound.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); // create data space hsize_t dim[1] = {LEN}; hid_t space = H5Screate_simple(1, dim, NULL); hid_t dataset = H5Dcreate(fid, "compound", cid, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); // write data H5Dwrite(dataset, cid, H5S_ALL, H5S_ALL, H5P_DEFAULT, arr); H5Sclose(space); H5Dclose(dataset); H5Fclose(fid); return 0; }
hid_t createNestedType(void) { hid_t tid, tid2, tid3; size_t offset, offset2; offset = 1; offset2 = 2; // Create a coumpound type large enough (>= 20) tid = H5Tcreate(H5T_COMPOUND, 21); // Insert an atomic type tid2 = H5Tcopy(H5T_NATIVE_FLOAT); H5Tinsert(tid, "float", offset, tid2); H5Tclose(tid2); offset += 4 + 2; // add two to the offset so as to create gaps // Insert a nested compound tid2 = H5Tcreate(H5T_COMPOUND, 12); tid3 = H5Tcopy(H5T_NATIVE_CHAR); H5Tinsert(tid2, "char", offset2, tid3); H5Tclose(tid3); offset2 += 2; // add one space (for introducing gaps) tid3 = H5Tcopy(H5T_NATIVE_DOUBLE); H5Tinsert(tid2, "double", offset2, tid3); H5Tclose(tid3); offset2 += 5; // add one space (for introducing gaps) H5Tinsert(tid, "compound", offset, tid2); H5Tclose(tid2); offset += 12 + 1; return(tid); }
// Author & Date: Ehsan Azar Nov 13, 2012 // Purpose: Create type for BmiChanExt2Attr_t and commit // Inputs: // loc - where to add the type // Outputs: // Returns the type id hid_t CreateChanExt2AttrType(hid_t loc) { herr_t ret; hid_t tid = -1; std::string strLink = "BmiChanExt2Attr_t"; // If already there return it if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT)) { tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT); return tid; } hid_t tid_attr_unit_str = H5Tcopy(H5T_C_S1); ret = H5Tset_size(tid_attr_unit_str, 16); tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiChanExt2Attr_t)); ret = H5Tinsert(tid, "DigitalMin", offsetof(BmiChanExt2Attr_t, digmin), H5T_NATIVE_INT32); ret = H5Tinsert(tid, "DigitalMax", offsetof(BmiChanExt2Attr_t, digmax), H5T_NATIVE_INT32); ret = H5Tinsert(tid, "AnalogMin", offsetof(BmiChanExt2Attr_t, anamin), H5T_NATIVE_INT32); ret = H5Tinsert(tid, "AnalogMax", offsetof(BmiChanExt2Attr_t, anamax), H5T_NATIVE_INT32); ret = H5Tinsert(tid, "AnalogUnit", offsetof(BmiChanExt2Attr_t, anaunit), tid_attr_unit_str); ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Tclose(tid_attr_unit_str); return tid; }
/** Creates a HDF5 type identifier for the [kmer,abundance] structure. This type will be used * for dumping Count instances in a HDF5 file (like SortingCount algorithm does). * \param[in] isCompound : tells whether the structure is compound (SHOULD BE OBSOLETE IN THE FUTURE) * \return the HDF5 identifier for the type. */ static hid_t hdf5 (bool& isCompound) { hid_t abundanceType = H5T_NATIVE_UINT16; if (sizeof(Number)==1) { abundanceType = H5T_NATIVE_UINT8; } else if (sizeof(Number)==2) { abundanceType = H5T_NATIVE_UINT16; } else if (sizeof(Number)==4) { abundanceType = H5T_NATIVE_UINT32; } else if (sizeof(Number)==8) { abundanceType = H5T_NATIVE_UINT64; } else { throw "Bad type size for Abundance HDF5 serialization"; } hid_t result = H5Tcreate (H5T_COMPOUND, sizeof(Abundance)); H5Tinsert (result, "value", HOFFSET(Abundance, value), Type::hdf5(isCompound)); H5Tinsert (result, "abundance", HOFFSET(Abundance, abundance), abundanceType); isCompound = true; return result; }
// Author & Date: Ehsan Azar Nov 13, 2012 // Purpose: Create type for BmiTrackingAttr_t and commit // Inputs: // loc - where to add the type // Outputs: // Returns the type id hid_t CreateTrackingAttrType(hid_t loc) { herr_t ret; hid_t tid = -1; std::string strLink = "BmiTrackingAttr_t"; // If already there return it if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT)) { tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT); return tid; } hid_t tid_attr_label_str = H5Tcopy(H5T_C_S1); ret = H5Tset_size(tid_attr_label_str, 128); tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiTrackingAttr_t)); ret = H5Tinsert(tid, "Label", offsetof(BmiTrackingAttr_t, szLabel), tid_attr_label_str); ret = H5Tinsert(tid, "Type", offsetof(BmiTrackingAttr_t, type), H5T_NATIVE_UINT16); ret = H5Tinsert(tid, "TrackID", offsetof(BmiTrackingAttr_t, trackID), H5T_NATIVE_UINT16); ret = H5Tinsert(tid, "MaxPoints", offsetof(BmiTrackingAttr_t, maxPoints), H5T_NATIVE_UINT16); ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Tclose(tid_attr_label_str); return tid; }
// Author & Date: Ehsan Azar Nov 13, 2012 // Purpose: Create type for BmiSpike16_t and commit // Note: For performance reasons and because spike length is constant during // and experiment we use fixed-length array here instead of varible-length // Inputs: // loc - where to add the type // spikeLength - the spike length to use // Outputs: // Returns the type id hid_t CreateSpike16Type(hid_t loc, UINT16 spikeLength) { herr_t ret; hid_t tid = -1; // e.g. for spike length of 48 type name will be "BmiSpike16_48_t" char szNum[4] = {'\0'}; sprintf(szNum, "%u", spikeLength); std::string strLink = "BmiSpike16_"; strLink += szNum; strLink += "_t"; // If already there return it if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT)) { tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT); return tid; } hsize_t dims[1] = {spikeLength}; hid_t tid_arr_wave = H5Tarray_create(H5T_NATIVE_INT16, 1, dims); tid = H5Tcreate(H5T_COMPOUND, offsetof(BmiSpike16_t, wave) + sizeof(INT16) * spikeLength); ret = H5Tinsert(tid, "TimeStamp", offsetof(BmiSpike16_t, dwTimestamp), H5T_NATIVE_UINT32); ret = H5Tinsert(tid, "Unit", offsetof(BmiSpike16_t, unit), H5T_NATIVE_UINT8); ret = H5Tinsert(tid, "Wave", offsetof(BmiSpike16_t, wave), tid_arr_wave); ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Tclose(tid_arr_wave); return tid; }
/*------------------------------------------------------------------------- * Function: gent_compound * * Purpose: Generate a compound dataset in LOC_ID * *------------------------------------------------------------------------- */ static void gent_compound(hid_t loc_id) { typedef struct s_t { char str1[20]; char str2[20]; } s_t; hid_t sid, did, tid_c, tid_s; hsize_t dims[1] = {2}; s_t buf[2] = {{"str1", "str2"}, {"str3", "str4"}}; /* create dataspace */ sid = H5Screate_simple(1, dims, NULL); /* create a compound type */ tid_c = H5Tcreate(H5T_COMPOUND, sizeof(s_t)); tid_s = H5Tcopy(H5T_C_S1); H5Tset_size(tid_s, 20); H5Tinsert(tid_c, "str1", HOFFSET(s_t,str1), tid_s); H5Tinsert(tid_c, "str2", HOFFSET(s_t,str2), tid_s); /* create dataset */ did = H5Dcreate2(loc_id, DATASET_COMPOUND, tid_c, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); /* write */ H5Dwrite(did, tid_c, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); /* close */ H5Sclose(sid); H5Dclose(did); H5Tclose(tid_c); H5Tclose(tid_s); }
inline static hid_t hdf5 (bool& compound) { hid_t result = H5Tcreate (H5T_COMPOUND, sizeof(Entry)); H5Tinsert (result, "index", HOFFSET(Entry, index), H5T_NATIVE_UINT16); H5Tinsert (result, "abundance", HOFFSET(Entry, abundance), H5T_NATIVE_UINT64); compound = true; return result; }
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 OHDF5mpipp::registerHDF5DataSet(HDF5DataSet& dataset, char* name) { //hsize_t dimsext[2] = {1,1}; //dataset.memspace = H5Screate_simple (RANK, dimsext, NULL); int chunk_size = buf_size/dataset.sizeof_entry; std::cout << "chunk_size=" << chunk_size << std::endl; std::cout << "dataset.all_window_size=" << dataset.all_window_size << std::endl; hsize_t maxdims[2]={H5S_UNLIMITED,1}; hsize_t dims[2]={dataset.all_window_size, 1}; hsize_t chunk_dims[2]={5*chunk_size,1}; //numberOfValues is to small /* Create the data space with unlimited dimensions. */ dataset.plist_id = H5Pcreate(H5P_DATASET_XFER); if (logger_type==nestio::Standard || logger_type==nestio::Buffered) H5Pset_dxpl_mpio(dataset.plist_id, H5FD_MPIO_INDEPENDENT); else H5Pset_dxpl_mpio(dataset.plist_id, H5FD_MPIO_COLLECTIVE); //hid_t filespace=H5Screate_simple (RANK, dims, maxdims); dataset.filespace=H5Screate_simple (RANK, dims, maxdims); /* Modify dataset creation properties, i.e. enable chunking */ hid_t prop=H5Pcreate (H5P_DATASET_CREATE); status = H5Pset_chunk (prop, RANK, chunk_dims); /* * Create the compound datatype for the file. Because the standard * types we are using for the file may have different sizes than * the corresponding native types, we must manually calculate the * offset of each member. */ hid_t filetype = H5Tcreate (H5T_COMPOUND, 3*8+dataset.max_numberOfValues*8); status = H5Tinsert (filetype, "id", 0, H5T_STD_I64BE); status = H5Tinsert (filetype, "neuron id", 8, H5T_STD_I64BE); status = H5Tinsert (filetype, "timestamp", 16, H5T_STD_I64BE); for (int i=0; i<dataset.max_numberOfValues; i++) { std::stringstream ss; ss << "V" << i; status = H5Tinsert (filetype, ss.str().c_str(), 24+i*8, H5T_IEEE_F64BE); //third argument: offset } /* Create a new dataset within the file using chunk creation properties. */ std::cout << "H5Dcreate2 name=" << name << " max_numberOfValues=" << dataset.max_numberOfValues << std::endl; dataset.dset_id=H5Dcreate2 (file, name, filetype, dataset.filespace, H5P_DEFAULT, prop, H5P_DEFAULT); status = H5Pclose(prop); status = H5Tclose(filetype); //status = H5Sclose (filespace); }
void NSDFWriter::createEventMap() { herr_t status; hid_t eventMapContainer = require_group(filehandle_, MAPEVENTSRC); // Open the container for the event maps // Create the Datasets themselves (one for each field - each row // for one object). for (map< string, vector < string > >::iterator ii = classFieldToEventSrc_.begin(); ii != classFieldToEventSrc_.end(); ++ii){ vector < string > pathTokens; tokenize(ii->first, "/", pathTokens); string className = pathTokens[0]; string fieldName = pathTokens[1]; hid_t classGroup = require_group(eventMapContainer, className); hid_t strtype = H5Tcopy(H5T_C_S1); status = H5Tset_size(strtype, H5T_VARIABLE); // create file space hid_t ftype = H5Tcreate(H5T_COMPOUND, sizeof(hvl_t) +sizeof(hobj_ref_t)); status = H5Tinsert(ftype, "source", 0, strtype); status = H5Tinsert(ftype, "data", sizeof(hvl_t), H5T_STD_REF_OBJ); hsize_t dims[1] = {ii->second.size()}; hid_t space = H5Screate_simple(1, dims, NULL); // The dataset for mapping is named after the field hid_t ds = H5Dcreate2(classGroup, fieldName.c_str(), ftype, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); status = H5Sclose(space); map_type * buf = (map_type*)calloc(ii->second.size(), sizeof(map_type)); // Populate the buffer entries with source uid and data // reference for (unsigned int jj = 0; jj < ii->second.size(); ++jj){ buf->source = ii->second[jj].c_str(); char * dsname = (char*)calloc(256, sizeof(char)); ssize_t size = H5Iget_name(classFieldToEvent_[ii->first][jj], dsname, 255); if (size > 255){ free(dsname); dsname = (char*)calloc(size, sizeof(char)); size = H5Iget_name(classFieldToEvent_[ii->first][jj], dsname, 255); } status = H5Rcreate(&(buf->data), filehandle_, dsname, H5R_OBJECT, -1); free(dsname); assert(status >= 0); } // create memory space hid_t memtype = H5Tcreate(H5T_COMPOUND, sizeof(map_type)); status = H5Tinsert(memtype, "source", HOFFSET(map_type, source), strtype); status = H5Tinsert(memtype, "data", HOFFSET(map_type, data), H5T_STD_REF_OBJ); status = H5Dwrite(ds, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); free(buf); status = H5Tclose(strtype); status = H5Tclose(ftype); status = H5Tclose(memtype); status = H5Dclose(ds); } }
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; }
inline hid_t get_hdf5_type< std::complex<float> >() { hid_t type = H5Tcreate(H5T_COMPOUND, sizeof(hdf5_complex_t<float>)); H5Tinsert(type, "real", HOFFSET(hdf5_complex_t<float>, real), H5T_NATIVE_FLOAT); H5Tinsert(type, "imag", HOFFSET(hdf5_complex_t<float>, imag), H5T_NATIVE_FLOAT); return type; }
inline hid_t get_hdf5_type< std::complex<double> >() { hid_t type = H5Tcreate(H5T_COMPOUND, sizeof(hdf5_complex_t<double>)); H5Tinsert(type, "real", HOFFSET(hdf5_complex_t<double>, real), H5T_NATIVE_DOUBLE); H5Tinsert(type, "imag", HOFFSET(hdf5_complex_t<double>, imag), H5T_NATIVE_DOUBLE); return type; }
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; }
// Author & Date: Ehsan Azar Nov 13, 2012 // Purpose: Create type for BmiSynch_t and commit // Inputs: // loc - where to add the type // Outputs: // Returns the type id hid_t CreateSynchType(hid_t loc) { herr_t ret; hid_t tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiSynch_t)); ret = H5Tinsert(tid, "TimeStamp", offsetof(BmiSynch_t, dwTimestamp), H5T_NATIVE_UINT32); ret = H5Tinsert(tid, "Split", offsetof(BmiSynch_t, split), H5T_NATIVE_UINT16); ret = H5Tinsert(tid, "Frame", offsetof(BmiSynch_t, frame), H5T_NATIVE_UINT32); ret = H5Tinsert(tid, "ElapsedTime", offsetof(BmiSynch_t, etime), H5T_NATIVE_UINT32); ret = H5Tcommit(loc, "BmiSynch_t", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); return tid; }
hid_t linkDatatype() { hid_t tLink; hid_t tPosition; hid_t tNumber; tLink = H5Tcreate(H5T_COMPOUND, sizeof(link_t)); tPosition = H5Tcopy(H5T_NATIVE_INT32); tNumber = H5Tcopy(H5T_NATIVE_INT32); H5Tinsert(tLink, "position", HOFFSET(link_t, position), tPosition); H5Tinsert(tLink, "number", HOFFSET(link_t, number), tNumber); H5Tclose(tPosition); H5Tclose(tNumber); return tLink; }
/* Counterpart for complex128 */ hid_t create_ieee_complex128(const char *byteorder) { hid_t float_id, complex_id; complex_id = H5Tcreate(H5T_COMPOUND, sizeof(npy_complex128)); if (byteorder == NULL) float_id = H5Tcopy(H5T_NATIVE_DOUBLE); else if (strcmp(byteorder, "little") == 0) float_id = H5Tcopy(H5T_IEEE_F64LE); else float_id = H5Tcopy(H5T_IEEE_F64BE); H5Tinsert(complex_id, "r", HOFFSET(npy_complex128, real), float_id); H5Tinsert(complex_id, "i", HOFFSET(npy_complex128, imag), float_id); H5Tclose(float_id); return complex_id; }
/** This method sets a field name for the volume record. The volume * must be of class "MI_CLASS_UNIFORM_RECORD". The size of record * type will be increased if necessary to accomodate the new field. */ int miset_record_field_name(mihandle_t volume, int index, const char *name) { hid_t mtype_id; hid_t ftype_id; size_t offset; if (volume == NULL || name == NULL) { return (MI_ERROR); } if (volume->volume_class != MI_CLASS_UNIFORM_RECORD && volume->volume_class != MI_CLASS_NON_UNIFORM_RECORD) { return (MI_ERROR); } /* Get the type of the record's fields. This is recorded as the * type of the volume. */ ftype_id = mitype_to_hdftype(volume->volume_type, FALSE); mtype_id = mitype_to_hdftype(volume->volume_type, TRUE); /* Calculate the offset of the new member. */ offset = index * H5Tget_size(ftype_id); /* If the offset plus the size of the member is larger than the * current size of the structure, increase the size of the structure. */ if (offset + H5Tget_size(ftype_id) > H5Tget_size(volume->ftype_id)) { H5Tset_size(volume->ftype_id, offset + H5Tget_size(ftype_id)); } if (offset + H5Tget_size(mtype_id) > H5Tget_size(volume->mtype_id)) { H5Tset_size(volume->mtype_id, offset + H5Tget_size(mtype_id)); } /* Actually define the field within the structure. */ H5Tinsert(volume->ftype_id, name, offset, ftype_id); H5Tinsert(volume->mtype_id, name, offset, mtype_id); /* Delete the HDF5 type object returned by mitype_to_hdftype(). */ H5Tclose(ftype_id); H5Tclose(mtype_id); return (MI_NOERROR); }
int readDoubleComplexMatrix(int _iDatasetId, double *_pdblReal, double *_pdblImg) { hid_t compoundId; herr_t status; int iDims = 0; int* piDims = NULL; int iComplex = 0; int iSize = 1; doublecomplex* pData = NULL; int i = 0; /*define compound dataset*/ compoundId = H5Tcreate(H5T_COMPOUND, sizeof(doublecomplex)); H5Tinsert(compoundId, "real", HOFFSET(doublecomplex, r), H5T_NATIVE_DOUBLE); H5Tinsert(compoundId, "imag", HOFFSET(doublecomplex, i), H5T_NATIVE_DOUBLE); //get dimension from dataset getDatasetInfo(_iDatasetId, &iComplex, &iDims, NULL); piDims = (int*)MALLOC(sizeof(int) * iDims); iSize = getDatasetInfo(_iDatasetId, &iComplex, &iDims, piDims); if (iSize < 0) { FREE(piDims); return -1; } FREE(piDims); //alloc temp array pData = (doublecomplex*)MALLOC(sizeof(doublecomplex) * iSize); //Read the data. status = H5Dread(_iDatasetId, compoundId, H5S_ALL, H5S_ALL, H5P_DEFAULT, pData); if (status < 0) { FREE(pData); return -1; } vGetPointerFromDoubleComplex(pData, iSize, _pdblReal, _pdblImg); FREE(pData); status = H5Dclose(_iDatasetId); if (status < 0) { return -1; } return 0; }
int main(){ hid_t fprop; hid_t fid; hid_t vol_id = H5VL_memvol_init(); char name[1024]; // create some datatypes hid_t tid = H5Tcreate (H5T_COMPOUND, sizeof(complex_type)); H5Tinsert(tid, "re", HOFFSET(complex_type,re), H5T_NATIVE_DOUBLE); H5Tinsert(tid, "im", HOFFSET(complex_type,im), H5T_NATIVE_DOUBLE); hid_t s10 = H5Tcopy(H5T_C_S1); H5Tset_size(s10, 10); H5Tinsert(tid, "name", HOFFSET(complex_type,name), s10); H5Tinsert(tid, "val", HOFFSET(complex_type,val), H5T_NATIVE_INT); // packed version of the datatype hid_t disk_tid = H5Tcopy (tid); H5Tpack(disk_tid); fprop = H5Pcreate(H5P_FILE_ACCESS); H5Pset_vol(fprop, vol_id, &fprop); fid = H5Fcreate("test", H5F_ACC_TRUNC, H5P_DEFAULT, fprop); H5VLget_plugin_name(fid, name, 1024); printf ("%s using VOL %s\n", __FILE__ , name); assert(H5Tcommit(fid, "t_complex", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) >= 0); assert(H5Tcommit(fid, "t_complex_p", disk_tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) >= 0); hid_t tid_stored1 = H5Topen(fid, "t_complex", H5P_DEFAULT); hid_t tid_stored2 = H5Topen(fid, "t_complex_p", H5P_DEFAULT); // hid_t tid_stored3 = H5Topen(fid, "NotExisting", H5P_DEFAULT); // assert(tid_stored3 < 0); assert(H5Tequal(tid_stored1, tid)); assert(H5Tequal(tid_stored2, disk_tid)); H5Fclose(fid); H5Tclose(tid); H5Tclose(disk_tid); H5VL_memvol_finalize(); return 0; }
// Author & Date: Ehsan Azar Nov 13, 2012 // Purpose: Create type for BmiRootAttr_t and commit // Inputs: // loc - where to add the type // Outputs: // Returns the type id hid_t CreateRootAttrType(hid_t loc) { herr_t ret; hid_t tid = -1; std::string strLink = "BmiRootAttr_t"; // If already there return it if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT)) { tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT); return tid; } hid_t tid_attr_str = H5Tcopy(H5T_C_S1); ret = H5Tset_size(tid_attr_str, 64); hid_t tid_attr_comment_str = H5Tcopy(H5T_C_S1); ret = H5Tset_size(tid_attr_comment_str, 1024); tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiRootAttr_t)); ret = H5Tinsert(tid, "MajorVersion", offsetof(BmiRootAttr_t, nMajorVersion), H5T_NATIVE_UINT32); ret = H5Tinsert(tid, "MinorVersion", offsetof(BmiRootAttr_t, nMinorVersion), H5T_NATIVE_UINT32); ret = H5Tinsert(tid, "Flags", offsetof(BmiRootAttr_t, nFlags), H5T_NATIVE_UINT32); ret = H5Tinsert(tid, "GroupCount", offsetof(BmiRootAttr_t, nGroupCount), H5T_NATIVE_UINT32); ret = H5Tinsert(tid, "Date", offsetof(BmiRootAttr_t, szDate), tid_attr_str); // date of the file creation ret = H5Tinsert(tid, "Application", offsetof(BmiRootAttr_t, szApplication), tid_attr_str); // application that created the file ret = H5Tinsert(tid, "Comment", offsetof(BmiRootAttr_t, szComment), tid_attr_comment_str); // file comments ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Tclose(tid_attr_str); H5Tclose(tid_attr_comment_str); return tid; }
// Author & Date: Ehsan Azar Nov 23, 2012 // Purpose: Create type for BmiDig16_t and commit // Inputs: // loc - where to add the type // Outputs: // Returns the type id hid_t CreateDig16Type(hid_t loc) { herr_t ret; hid_t tid = -1; std::string strLink = "BmiDig16_t"; // If already there return it if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT)) { tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT); return tid; } tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiDig16_t)); ret = H5Tinsert(tid, "TimeStamp", offsetof(BmiDig16_t, dwTimestamp), H5T_NATIVE_UINT32); ret = H5Tinsert(tid, "Value", offsetof(BmiDig16_t, value), H5T_NATIVE_UINT16); ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); return tid; }
// Author & Date: Ehsan Azar Nov 19, 2012 // Purpose: Create type for BmiComment_t and commit // Inputs: // loc - where to add the type // Outputs: // Returns the type id hid_t CreateCommentType(hid_t loc) { herr_t ret; // Use fixed-size comments because // it is faster, more tools support it, and also allows compression hid_t tid_str_array = H5Tcopy(H5T_C_S1); ret = H5Tset_size(tid_str_array, BMI_COMMENT_LEN); hid_t tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiComment_t)); ret = H5Tinsert(tid, "TimeStamp", offsetof(BmiComment_t, dwTimestamp), H5T_NATIVE_UINT32); ret = H5Tinsert(tid, "Data", offsetof(BmiComment_t, data), H5T_NATIVE_UINT32); ret = H5Tinsert(tid, "Flags", offsetof(BmiComment_t, flags), H5T_NATIVE_UINT8); ret = H5Tinsert(tid, "Comment", offsetof(BmiComment_t, szComment), tid_str_array); ret = H5Tcommit(loc, "BmiComment_t", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Tclose(tid_str_array); return tid; }
// Author & Date: Ehsan Azar Nov 13, 2012 // Purpose: Create type for BmiSamplingAttr_t and commit // Inputs: // loc - where to add the type // Outputs: // Returns the type id hid_t CreateSamplingAttrType(hid_t loc) { herr_t ret; hid_t tid = -1; std::string strLink = "BmiSamplingAttr_t"; // If already there return it if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT)) { tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT); return tid; } tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiSamplingAttr_t)); ret = H5Tinsert(tid, "Clock", offsetof(BmiSamplingAttr_t, fClock), H5T_NATIVE_FLOAT); ret = H5Tinsert(tid, "SampleRate", offsetof(BmiSamplingAttr_t, fSampleRate), H5T_NATIVE_FLOAT); ret = H5Tinsert(tid, "SampleBits", offsetof(BmiSamplingAttr_t, nSampleBits), H5T_NATIVE_UINT8); ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); return tid; }
// Author & Date: Ehsan Azar Nov 13, 2012 // Purpose: Create type for BmiChanExt1Attr_t and commit // Inputs: // loc - where to add the type // Outputs: // Returns the type id hid_t CreateChanExt1AttrType(hid_t loc) { herr_t ret; hid_t tid = -1; std::string strLink = "BmiChanExt1Attr_t"; // If already there return it if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT)) { tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT); return tid; } tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiChanExt1Attr_t)); ret = H5Tinsert(tid, "SortCount", offsetof(BmiChanExt1Attr_t, sortCount), H5T_NATIVE_UINT8); ret = H5Tinsert(tid, "EnergyThreshold", offsetof(BmiChanExt1Attr_t, energy_thresh), H5T_NATIVE_UINT32); ret = H5Tinsert(tid, "HighThreshold", offsetof(BmiChanExt1Attr_t, high_thresh), H5T_NATIVE_INT32); ret = H5Tinsert(tid, "LowThreshold", offsetof(BmiChanExt1Attr_t, low_thresh), H5T_NATIVE_INT32); ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); return tid; }
// Author & Date: Ehsan Azar Nov 13, 2012 // Purpose: Create type for BmiChanExtAttr_t and commit // Inputs: // loc - where to add the type // Outputs: // Returns the type id hid_t CreateChanExtAttrType(hid_t loc) { herr_t ret; hid_t tid = -1; std::string strLink = "BmiChanExtAttr_t"; // If already there return it if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT)) { tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT); return tid; } tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiChanExtAttr_t)); ret = H5Tinsert(tid, "NanoVoltsPerLSB", offsetof(BmiChanExtAttr_t, dFactor), H5T_NATIVE_DOUBLE); ret = H5Tinsert(tid, "PhysicalConnector", offsetof(BmiChanExtAttr_t, phys_connector), H5T_NATIVE_UINT8); ret = H5Tinsert(tid, "ConnectorPin", offsetof(BmiChanExtAttr_t, connector_pin), H5T_NATIVE_UINT8); ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); return tid; }