//------------------------------------------------------------------------------ // Description: // Returns the double array static void GetDoubleArrayByName( const hid_t rootIdx, const char *name, std::vector<double> &array) { // turn off warnings void *pContext = NULL; H5E_auto_t erorFunc; H5Eget_auto(&erorFunc, &pContext); H5Eset_auto(NULL, NULL); hid_t arrayIdx = H5Dopen(rootIdx, name); if (arrayIdx < 0) { vtkGenericWarningMacro("Cannot open array: " << name << "\n"); return; } // turn warnings back on H5Eset_auto(erorFunc, pContext); pContext = NULL; // get the number of particles hsize_t dimValus[3]; hid_t spaceIdx = H5Dget_space(arrayIdx); H5Sget_simple_extent_dims(spaceIdx, dimValus, NULL); int numbPnts = dimValus[0]; array.resize(numbPnts); H5Dread(arrayIdx, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &array[0]); // H5Dclose( spaceIdx ); // H5Dclose( arrayIdx ); }
//const hid_t hdf_archive::is_closed; hdf_archive::hdf_archive(Communicate* c, bool use_collective) : file_id(is_closed), access_id(H5P_DEFAULT), xfer_plist(H5P_DEFAULT) { H5Eget_auto (&err_func, &client_data); H5Eset_auto (NULL, NULL); set_access_plist(use_collective,c); }
hdf_archive::~hdf_archive() { close(); if(xfer_plist != H5P_DEFAULT) H5Pclose(xfer_plist); if(access_id!= H5P_DEFAULT) H5Pclose(access_id); H5Eset_auto (err_func, client_data); }
void MGL_EXPORT mgl_datac_save_hdf(HCDT dat,const char *fname,const char *data,int rewrite) { const mglDataC *d = dynamic_cast<const mglDataC *>(dat); // NOTE: only for mglDataC if(!d) { mgl_data_save_hdf(dat,fname,data,rewrite); return; } hid_t hf,hd,hs; hsize_t dims[4]; long rank = 3, res; H5Eset_auto(0,0); res=H5Fis_hdf5(fname); if(res>0 && !rewrite) hf = H5Fopen(fname, H5F_ACC_RDWR, H5P_DEFAULT); else hf = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); if(hf<0) return; if(d->nz==1 && d->ny == 1) { rank=2; dims[0]=d->nx; dims[1]=2; } else if(d->nz==1) { rank=3; dims[0]=d->ny; dims[1]=d->nx; dims[2]=2; } else { rank=4; dims[0]=d->nz; dims[1]=d->ny; dims[2]=d->nx; dims[3]=2; } hs = H5Screate_simple(rank, dims, 0); #if MGL_USE_DOUBLE hid_t mem_type_id = H5T_NATIVE_DOUBLE; #else hid_t mem_type_id = H5T_NATIVE_FLOAT; #endif hd = H5Dcreate(hf, data, mem_type_id, hs, H5P_DEFAULT); H5Dwrite(hd, mem_type_id, hs, hs, H5P_DEFAULT, d->a); H5Dclose(hd); H5Sclose(hs); H5Fclose(hf); }
hdf_archive::~hdf_archive() { #if defined(H5_HAVE_PARALLEL) && defined(ENABLE_PHDF5) if(xfer_plist != H5P_DEFAULT) H5Pclose(xfer_plist); if(access_id != H5P_DEFAULT) H5Pclose(access_id); #endif close(); H5Eset_auto (err_func, client_data); }
/*------------------------------------------------------------------------- * Function: test_value_dsnt_exist * * Purpose: Create an enumeration datatype with "gaps in values" * and then request a name of non-existing value within * an existing range by calling H5Tenum_nameof function. * Function should fail instead of succeeding and returning * a name of one of the existing values. * Request a value by supplying non-existing name by calling * H5Tenum_nameof function. Function should fail. * * * Return: Success: 0 * * Failure: number of errors * * Programmer: Elena Pourmal * Wednesday, June 7, 2002 * * Modifications: * *------------------------------------------------------------------------- */ static int test_value_dsnt_exist(void) { hid_t datatype_id=(-1); /* identifiers */ int val; char nam[100]; size_t size = 100; TESTING("for non-existing name and value"); /* Turn off error reporting since we expect failure in this test */ if (H5Eset_auto(NULL, NULL) < 0) goto error; if ((datatype_id = H5Tenum_create(H5T_NATIVE_INT))< 0) goto error; /* These calls should fail, since no memebrs exist yet */ if (H5Tenum_valueof(datatype_id, "SAX", &val) >= 0) goto error; val = 3; if (H5Tenum_nameof(datatype_id, &val, nam, size) >= 0) goto error; val = 2; if (H5Tenum_insert(datatype_id, "TWO", (int *)&val) < 0) goto error; val = 6; if (H5Tenum_insert(datatype_id, "SIX", (int *)&val) < 0) goto error; val = 10; if (H5Tenum_insert(datatype_id, "TEN", (int *)&val) < 0) goto error; /* This call should fail since we did not create a member with value = 3*/ val = 3; if (H5Tenum_nameof(datatype_id, &val, nam, size) >= 0) goto error; /* This call should fail since we did not create a member with value = 11*/ val = 11; if (H5Tenum_nameof(datatype_id, &val, nam, size) >= 0) goto error; /* This call should fail since we did not create a member with value = 0*/ val = 0; if (H5Tenum_nameof(datatype_id, &val, nam, size) >= 0) goto error; /* This call should fail since we do not have SAX name in the type */ if (H5Tenum_valueof(datatype_id, "SAX", &val) >= 0) goto error; /* This call should fail since we do not have TEEN name in the type */ if (H5Tenum_valueof(datatype_id, "TEEN", &val) >= 0) goto error; /* This call should fail since we do not have A name in the type */ if (H5Tenum_valueof(datatype_id, "A", &val) >= 0) goto error; if (H5Tclose(datatype_id) < 0) goto error; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Tclose(datatype_id); } H5E_END_TRY; return 1; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- HDF5ScopedFileSentinel::HDF5ScopedFileSentinel(hid_t* fileId, bool turnOffErrors) : m_FileId(fileId), m_TurnOffErrors(turnOffErrors) { if (m_TurnOffErrors == true) { H5Eget_auto(H5E_DEFAULT, &_oldHDF_error_func, &_oldHDF_error_client_data); H5Eset_auto(H5E_DEFAULT, NULL, NULL); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- HDF5ScopedObjectSentinel::HDF5ScopedObjectSentinel(hid_t* gid, bool turnOffErrors) : m_TurnOffErrors(turnOffErrors) { m_Groups.push_back(gid); if (m_TurnOffErrors == true) { H5Eget_auto(H5E_DEFAULT, &_oldHDF_error_func, &_oldHDF_error_client_data); H5Eset_auto(H5E_DEFAULT, NULL, NULL); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- HDF5ScopedObjectSentinel::~HDF5ScopedObjectSentinel() { if (m_TurnOffErrors == true) { H5Eset_auto(H5E_DEFAULT, _oldHDF_error_func, _oldHDF_error_client_data); } for(std::vector<hid_t*>::size_type i = 0; i < m_Groups.size(); ++i) { hid_t* temp = m_Groups[i]; if (*temp > 0) { H5Utilities::closeHDF5Object(*temp); *temp = -1; } } }
/* * init() is called when the plugin is loaded, before any other functions * are called. Put global initialization here. */ extern int init(void) { if (!_run_in_daemon()) return SLURM_SUCCESS; debug_flags = slurm_get_debug_flags(); /* Move HDF5 trace printing to log file instead of stderr */ H5Eset_auto(H5E_DEFAULT, (herr_t (*)(hid_t, void *))H5Eprint, log_fp()); return SLURM_SUCCESS; }
void fh5f_open_(char *locfn, int *iaccess, int *hdferr) { unsigned flags; hid_t access_id; extern hid_t fileid; /* Turn off default error handling */ H5Eset_auto(NULL, NULL); access_id = H5P_DEFAULT; if(*iaccess == 1) flags = H5F_ACC_RDONLY; if(*iaccess == 2) flags = H5F_ACC_RDWR; fileid = H5Fopen(locfn, flags, access_id); //printf("fh5f_open_ - fileid: %d\n",fileid); *hdferr = fileid; return; }
bool avtGTCFileFormat::Initialize() { const char *mName = "avtGTCFileFormat::Initialize: "; if(initialized) return true; // Init HDF5 and turn off error message printing. H5open(); H5Eset_auto( NULL, NULL ); bool err = false; // Check for a valid GTC file if( H5Fis_hdf5( GetFilename() ) < 0 ) EXCEPTION1( InvalidFilesException, GetFilename() ); if ((fileHandle = H5Fopen(GetFilename(), H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) EXCEPTION1( InvalidFilesException, GetFilename() ); if ((particleHandle = H5Dopen(fileHandle, "particle_data")) < 0) { H5Fclose(fileHandle); EXCEPTION1( InvalidFilesException, GetFilename() ); } // At this point consider the file to truly be a GTC file. If // some other file NonCompliantExceptions will be thrown. // Continue as normal reporting NonCompliantExceptions //Check variable's size. hid_t dataspace = H5Dget_space(particleHandle); hsize_t dims[3]; hid_t sid = H5Dget_space(particleHandle); int ndims = H5Sget_simple_extent_dims(dataspace, dims, NULL); if(ndims < 0 || ndims > 2) { debug4 << mName << "Could not determine number of dimensions" << endl; H5Sclose(sid); H5Dclose(particleHandle); H5Fclose(fileHandle); EXCEPTION1( InvalidVariableException, "GTC Dataset Extents - Dataset 'particle_data' has an invalid extents"); } debug4 << mName << "Determining variable size" << endl; int val = H5Sget_simple_extent_dims(sid, dims, NULL); if(val < 0 || dims[1] < 3) { debug4 << mName << "Could not determine variable size" << endl; H5Sclose(sid); H5Dclose(particleHandle); H5Fclose(fileHandle); EXCEPTION1( InvalidVariableException, "GTC Dataset Extents - Dataset 'particle_data' has an insufficient number of variables"); } H5Sclose(dataspace); debug4 << mName << "variable size (" << dims[0] << ", " << dims[1] << ")" << endl; nTotalPoints = dims[0]; nVars = dims[1]; #ifdef PARALLEL nProcs = PAR_Size(); rank = PAR_Rank(); nPoints = nTotalPoints / nProcs; int remainder = nTotalPoints % nProcs; startOffset = rank * nPoints; if ( rank < remainder ) startOffset += rank; else startOffset += remainder; if ( rank < remainder ) nPoints++; #else nPoints = nTotalPoints; startOffset = 0; #endif initialized = true; return initialized; }
void H5File::init(const hid_t fapl) { bool opened = false; #if !defined(__HDF5ERROR_PRINT__) H5Eset_auto(H5E_DEFAULT, 0, 0); #endif if (filename.empty()) { throw H5Exception(__LINE__, __FILE__, _("Invalid hdf5 file: empty filename.")); } switch (flags) { case RDONLY: if (!FileExist(const_cast<char *>(filename.c_str())) || H5Fis_hdf5(filename.c_str()) <= 0) { throw H5Exception(__LINE__, __FILE__, _("Invalid hdf5 file: %s."), filename.c_str()); } file = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, fapl); if (file < 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot open the given hdf5 file: %s."), filename.c_str()); } opened = true; break; case RDWR: if (!FileExist(const_cast<char *>(filename.c_str())) || H5Fis_hdf5(filename.c_str()) <= 0) { throw H5Exception(__LINE__, __FILE__, _("Invalid hdf5 file: %s."), filename.c_str()); } file = H5Fopen(filename.c_str(), H5F_ACC_RDWR, fapl); if (file < 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot open the given hdf5 file: %s."), filename.c_str()); } opened = true; break; case TRUNC: file = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, fapl); if (file < 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot create the given hdf5 file: %s."), filename.c_str()); } break; case EXCL: file = H5Fcreate(filename.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, fapl); if (file < 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot create the given hdf5 file: %s."), filename.c_str()); } break; case APPEND: if (FileExist(const_cast<char *>(filename.c_str()))) { if (H5Fis_hdf5(filename.c_str()) > 0) { file = H5Fopen(filename.c_str(), H5F_ACC_RDWR, fapl); if (file < 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot open the given hdf5 file: %s."), filename.c_str()); } opened = true; } else { struct stat stat_buf; int rc = stat(filename.c_str(), &stat_buf); if (!rc && stat_buf.st_size == 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot open the file: %s, an empty file with the same name already exists."), filename.c_str()); } throw H5Exception(__LINE__, __FILE__, _("Cannot append the file (not HDF5): %s."), filename.c_str()); } } else { file = H5Fcreate(filename.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, fapl); if (file < 0) { throw H5Exception(__LINE__, __FILE__, _("Cannot create the given hdf5 file: %s."), filename.c_str()); } } break; default: throw H5Exception(__LINE__, __FILE__, _("Invalid flag.")); } if (opened && path != "/" && H5Lexists(file, path.c_str(), H5P_DEFAULT) <= 0) { H5Fclose(file); throw H5Exception(__LINE__, __FILE__, _("Invalid path: %s"), path.c_str()); } }
void disable_h5_errors(err_state_t *err_state) { assert(H5Eget_auto(H5E_DEFAULT, &(err_state->old_func), &(err_state->old_client_data)) >= 0); assert(H5Eset_auto(H5E_DEFAULT, NULL, NULL) >= 0); }
void ProgXrayImport::run() { // Delete output stack if it exists fnOut = fnRoot + ".mrc"; fnOut.deleteFile(); /* Turn off error handling */ H5Eset_auto(H5E_DEFAULT, NULL, NULL); if (dSource == MISTRAL) H5File.openFile(fnInput, H5F_ACC_RDONLY); // Reading bad pixels mask if ( !fnBPMask.empty() ) { std::cerr << "Reading bad pixels mask from "+fnBPMask << "." << std::endl; bpMask.read(fnBPMask); if ( (cropSizeX + cropSizeY ) > 0 ) bpMask().selfWindow(cropSizeY,cropSizeX, (int)(YSIZE(bpMask())-cropSizeY-1),(int)(XSIZE(bpMask())-cropSizeX-1)); STARTINGX(bpMask()) = STARTINGY(bpMask()) = 0; } // Setting the image projections list switch (dSource) { case MISTRAL: { inMD.read(fnInput); H5File.getDataset("NXtomo/data/rotation_angle", anglesArray, false); H5File.getDataset("NXtomo/instrument/sample/ExpTimes", expTimeArray, false); H5File.getDataset("NXtomo/instrument/sample/current", cBeamArray); /* In case there is no angles information we set them to to an increasing sequence * just to be able to continue importing data */ if ( anglesArray.size() != inMD.size() ) { reportWarning("Input file does not contains angle information. Default sequence used."); anglesArray.resizeNoCopy(inMD.size()); anglesArray.enumerate(); } // If expTime is empty or only one single value in nexus file then we fill with 1 if (expTimeArray.size() < 2) { reportWarning("Input file does not contains tomogram exposition time information."); expTimeArray.initConstant(anglesArray.size(), 1.); } // If current is empty or only one single value in nexus file then we fill with 1 if (cBeamArray.size() < 2) { reportWarning("Input file does not contains tomogram current beam information."); cBeamArray.initConstant(anglesArray.size(), 1.); } // Since Alba does not provide slit width, we set to ones slitWidthArray.initConstant(anglesArray.size(), 1.); } break; case BESSY: { size_t objId; for (size_t i = tIni; i <= tEnd; ++i) { objId = inMD.addObject(); inMD.setValue(MDL_IMAGE, fnInput + formatString("/img%d.spe", i), objId); } break; } case GENERIC: { // Get Darkfield std::cerr << "Getting darkfield from "+fnInput << " ..." << std::endl; getDarkfield(fnInput, IavgDark); if (XSIZE(IavgDark())!=0) IavgDark.write(fnRoot+"_darkfield.xmp"); std::vector<FileName> listDir; fnInput.getFiles(listDir); size_t objId; for (size_t i = 0; i < listDir.size(); ++i) { if (!listDir[i].hasImageExtension()) continue; objId = inMD.addObject(); inMD.setValue(MDL_IMAGE, fnInput+"/"+listDir[i], objId); } } break; } inMD.findObjects(objIds); size_t nIm = inMD.size(); // Create empty output stack file getImageInfo(inMD, imgInfo); /* Get the flatfield:: We get the FF after the image list because we need the image size to adapt the FF * in case they were already cropped. */ if (!fnFlat.empty()) { std::cout << "Getting flatfield from "+fnFlat << " ..." << std::endl; getFlatfield(fnFlat,IavgFlat); if ( XSIZE(IavgFlat()) != 0 ) { FileName ffName = fnRoot+"_flatfield_avg.xmp"; IavgFlat.write(ffName); fMD.setValue(MDL_IMAGE, ffName, fMD.addObject()); } } createEmptyFile(fnOut, imgInfo.adim.xdim-cropSizeXi-cropSizeXe, imgInfo.adim.ydim-cropSizeYi-cropSizeYe, 1, nIm); // Process images td = new ThreadTaskDistributor(nIm, XMIPP_MAX(1, nIm/30)); tm = new ThreadManager(thrNum, this); std::cerr << "Getting data from " << fnInput << " ...\n"; init_progress_bar(nIm); tm->run(runThread); progress_bar(nIm); // Write Metadata and angles MetaData MDSorted; MDSorted.sort(outMD,MDL_ANGLE_TILT); MDSorted.write("tomo@"+fnRoot + ".xmd"); if ( fMD.size() > 0 ) fMD.write("flatfield@"+fnRoot + ".xmd", MD_APPEND); // We also reference initial and final images at 0 degrees for Mistral tomograms if ( dSource == MISTRAL ) { fMD.clear(); FileName degree0Fn = "NXtomo/instrument/sample/0_degrees_initial_image"; if ( H5File.checkDataset(degree0Fn.c_str())) fMD.setValue(MDL_IMAGE, degree0Fn + "@" + fnInput, fMD.addObject()); degree0Fn = "NXtomo/instrument/sample/0_degrees_final_image"; if ( H5File.checkDataset(degree0Fn.c_str())) fMD.setValue(MDL_IMAGE, degree0Fn + "@" + fnInput, fMD.addObject()); if ( fMD.size() > 0 ) fMD.write("degree0@"+fnRoot + ".xmd", MD_APPEND); } // Write tlt file for IMOD std::ofstream fhTlt; fhTlt.open((fnRoot+".tlt").c_str()); if (!fhTlt) REPORT_ERROR(ERR_IO_NOWRITE,fnRoot+".tlt"); FOR_ALL_OBJECTS_IN_METADATA(MDSorted) { double tilt; MDSorted.getValue(MDL_ANGLE_TILT,tilt,__iter.objId); fhTlt << tilt << std::endl; } fhTlt.close(); delete td; delete tm; }
herr_t arma_H5Eset_auto(hid_t estack_id, H5E_auto_t func, void* client_data) { return H5Eset_auto(estack_id, func, client_data); }
void hdfFileSaver::saveNow(void) { QDir prnt; herr_t status; hsize_t maxdims[1]; hsize_t d_dims[1]; int rank = 1; hsize_t datasetlength; size_t memdims[1]; hsize_t count[1]; /* size of subset in the file */ hsize_t offset[1]; /* subset offset in the file */ hsize_t mcount[1]; hsize_t moffset[1]; hid_t prop; if (events==0) return; if (access(fname.toStdString().c_str(), F_OK) ==-1) { hfile = H5Fcreate( fname.toStdString().c_str(), H5F_ACC_EXCL , H5P_DEFAULT, H5P_DEFAULT ) ; topgroup = H5Gcreate( hfile, "iqdata_raw", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); hid_t aid3 = H5Screate(H5S_SCALAR); hid_t atype = H5Tcopy(H5T_C_S1); H5Tset_size(atype, 4); hid_t attr3 = H5Acreate1(topgroup, "type", atype, aid3, H5P_DEFAULT); status = H5Awrite(attr3, atype,"dict"); H5Aclose(attr3); H5Tclose(atype); H5Sclose(aid3); } else { //printf("File already exists, will append\n"); hfile = H5Fopen( fname.toStdString().c_str(), H5F_ACC_RDWR, H5P_DEFAULT ); topgroup = H5Gopen(hfile, "iqdata_raw", H5P_DEFAULT); //fprintf(stderr,"Bad Hdf file already existant, cannot open\n"); } if (hfile <=0 || topgroup <=0) { fprintf(stderr,"Bad Hdf file, cannot open\n"); return; } if (true) { //QHash<int,QHash<QString,QList<float> > > events; QList<int> keys1=(*events).keys(); for (int i=0;i<keys1.length();i++) { int chan = keys1[i]; if ((*events)[chan]["bin"].length() > 0) { int bin = (int)((*events)[chan]["bin"][0]); QString dirname = QString("keyint_%1").arg(chan); //turn off errors when we query the group, using open hid_t error_stack = H5Eget_current_stack(); H5E_auto2_t oldfunc; void *old_client_data; H5Eget_auto(error_stack, &oldfunc, &old_client_data); H5Eset_auto(error_stack, NULL, NULL); channelgroup = H5Gopen( topgroup, dirname.toStdString().c_str(), H5P_DEFAULT); //turn errors back on. H5Eset_auto(error_stack, oldfunc, old_client_data); if (channelgroup<0) { channelgroup = H5Gcreate( topgroup, dirname.toStdString().c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); hid_t aid3 = H5Screate(H5S_SCALAR); hid_t atype = H5Tcopy(H5T_C_S1); H5Tset_size(atype, 4); hid_t attr3 = H5Acreate1(channelgroup, "type", atype, aid3, H5P_DEFAULT); status = H5Awrite(attr3, atype,"dict"); H5Aclose(attr3); H5Tclose(atype); H5Sclose(aid3); } if (channelgroup!=0) { QList<QString> keys2=(*events)[keys1[i]].keys(); for (int i2=0;i2<keys2.length();i2++) { QString dname = QString("keystr_%1").arg(keys2[i2]); datasetlength = (*events)[keys1[i]][keys2[i2]].length(); if (datasetlength>0) { //Try to open dataset if it exists //turn off errors when we query the group, using open hid_t error_stack = H5Eget_current_stack(); H5E_auto2_t oldfunc; void *old_client_data; H5Eget_auto(error_stack, &oldfunc, &old_client_data); H5Eset_auto(error_stack, NULL, NULL); //query or open dataset curdataset = H5Dopen(channelgroup,dname.toStdString().c_str(),H5P_DEFAULT); //turn errors back on. H5Eset_auto(error_stack, oldfunc, old_client_data); //if cannot open dataset, create it, and make it chunked. if (curdataset<=0) { //set up size info, chunks etc... maxdims[0]=H5S_UNLIMITED; rank = 1; d_dims[0]=datasetlength; curdataspace= H5Screate_simple(rank, d_dims,maxdims); prop = H5Pcreate(H5P_DATASET_CREATE); status = H5Pset_chunk(prop, rank, d_dims); if (status) trap(); curdataset = H5Dcreate( channelgroup, dname.toStdString().c_str(), H5T_NATIVE_FLOAT, curdataspace, H5P_DEFAULT, prop, H5P_DEFAULT); hid_t aid3 = H5Screate(H5S_SCALAR); hid_t atype = H5Tcopy(H5T_C_S1); H5Tset_size(atype, 5); hid_t attr3 = H5Acreate1(curdataset, "type", atype, aid3, H5P_DEFAULT); status = H5Awrite(attr3, atype,"array"); H5Aclose(attr3); H5Tclose(atype); H5Sclose(aid3); H5Pclose(prop); }//if (curdataset<=0) else { //get dataspace from exant dataset curdataspace = H5Dget_space(curdataset); H5Sget_simple_extent_dims(curdataspace, d_dims, maxdims); H5Sclose(curdataspace); //if dataset already exist, extend its size d_dims[0] = d_dims[0] + datasetlength; status = H5Dset_extent(curdataset, d_dims); if (status) trap(); curdataspace = H5Dget_space(curdataset); H5Sget_simple_extent_dims(curdataspace, d_dims, maxdims); }//else if (curdataset>0) { // // Set up stride, offset, count block in dastasets... // // stride[0]=1;//hop size between floats in dataset... //block[0]=1;//get 1 slab count[0]=datasetlength;//size of hyperslab or chunk of data offset[0]=d_dims[0] - datasetlength;//offset from beginning of file. status = H5Sselect_hyperslab( curdataspace, H5S_SELECT_SET, offset, NULL, count, NULL); if (status) trap(); rank = 1; memdims[0]=datasetlength; memdataspace= H5Screate_simple(rank, (const hsize_t*)memdims,NULL); mcount[0] = datasetlength; moffset[0] = 0; status = H5Sselect_hyperslab( memdataspace, H5S_SELECT_SET, moffset, NULL, mcount, NULL); if (status) trap(); for (int mmm=0;mmm<datasetlength;mmm++) this->rawdata[mmm]=(*events)[keys1[i]][keys2[i2]][mmm]; status = H5Dwrite( curdataset, H5T_NATIVE_FLOAT, memdataspace, curdataspace, H5P_DEFAULT, this->rawdata); if (status) trap(); H5Sclose(memdataspace); H5Sclose(curdataspace); H5Dclose(curdataset); } //if (curdataset>0) } }//for (int i2=0;i2<keys2.length();i2++) status = H5Gclose(channelgroup); }//if (channelgroup!=0) }//if ((*events)[chan]["bin"].length() > 0) }//for (int i=0;i<keys1.length();i++) }//if (true) status = H5Gclose(topgroup); status = H5Fclose(hfile); }
int main (int argc, char ** argv) { char filename [256]; int rank, size, gidx, i, j, k,l; MPI_Comm comm_dummy = MPI_COMM_WORLD; /* MPI_Comm is defined through adios_read.h */ enum ADIOS_DATATYPES attr_type; void * data = NULL; uint64_t start[] = {0,0,0,0,0,0,0,0,0,0}; uint64_t count[MAX_DIMS], hcount[MAX_DIMS], bytes_read = 0; herr_t h5_err; char h5name[256],aname[256],fname[256]; int dims [MAX_DIMS]; int h5rank[MAX_DIMS]; int h5i, level; hid_t grp_id [GMAX+1], space_id, dataset_id; hid_t memspace_id, dataspace_id, att_id; char ** grp_name; hid_t type_id; hid_t h5_type_id; hsize_t adims; if (argc < 2) { printf("Usage: %s <BP-file> <HDF5-file>\n", argv[0]); return 1; } MPI_Init(&argc, &argv); h5_err = H5Eset_auto(NULL, NULL ); ADIOS_FILE * f = adios_fopen (argv[1], comm_dummy); HDF5_FILE = H5Fcreate(argv[2],H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* create the complex types for HDF5 */ complex_real_id = H5Tcreate (H5T_COMPOUND, sizeof (complex_real_t)); H5Tinsert (complex_real_id, "real", HOFFSET(complex_real_t,re), H5T_NATIVE_FLOAT); H5Tinsert (complex_real_id, "imaginary", HOFFSET(complex_real_t,im), H5T_NATIVE_FLOAT); complex_double_id = H5Tcreate (H5T_COMPOUND, sizeof (complex_double_t)); H5Tinsert (complex_double_id, "real", HOFFSET(complex_double_t,re), H5T_NATIVE_DOUBLE); H5Tinsert (complex_double_id, "imaginary", HOFFSET(complex_double_t,im), H5T_NATIVE_DOUBLE); if (f == NULL) { if (DEBUG) printf ("%s\n", adios_errmsg()); return -1; } /* For all groups */ for (gidx = 0; gidx < f->groups_count; gidx++) { if (DEBUG) printf("Group %s:\n", f->group_namelist[gidx]); ADIOS_GROUP * g = adios_gopen (f, f->group_namelist[gidx]); if (g == NULL) { if (DEBUG) printf ("%s\n", adios_errmsg()); return -1; } /* First create all of the groups */ grp_id [0] = HDF5_FILE; for (i = 0; i < g->vars_count; i++) { ADIOS_VARINFO * v = adios_inq_var_byid (g, i); strcpy(h5name,g->var_namelist[i]); grp_name = bp_dirparser (h5name, &level); for (j = 0; j < level-1; j++) { grp_id [j + 1] = H5Gopen (grp_id [j], grp_name [j]); if (grp_id [j + 1] < 0) { grp_id [j + 1] = H5Gcreate (grp_id [j], grp_name [j], 0); } } for (j=1; j<level; j++) { H5Gclose(grp_id[j]); } } /* Now we can write data into these scalars */ /* For all variables */ if (DEBUG) printf(" Variables=%d:\n", g->vars_count); for (i = 0; i < g->vars_count; i++) { ADIOS_VARINFO * v = adios_inq_var_byid (g, i); uint64_t total_size = adios_type_size (v->type, v->value); for (j = 0; j < v->ndim; j++) total_size *= v->dims[j]; strcpy(h5name,g->var_namelist[i]); if (DEBUG) printf(" %-9s %s", adios_type_to_string(v->type), g->var_namelist[i]); h5_err = bp_getH5TypeId (v->type, &h5_type_id); if (v->type==adios_string) H5Tset_size(h5_type_id,strlen(v->value)); if (v->ndim == 0) { /* Scalars do not need to be read in, we get it from the metadata when using adios_inq_var */ if (DEBUG) printf(" = %s\n", value_to_string(v->type, v->value, 0)); // add the hdf5 dataset, these are scalars for (h5i = 0;h5i<MAX_DIMS;h5i++) count[0] = 0; count[0] = 1; // we are writing just 1 element, RANK=1 h5_err = bp_getH5TypeId (v->type, &h5_type_id); H5LTmake_dataset(HDF5_FILE,h5name,1,count,h5_type_id,v->value); } else { h5_err = readVar(g, v, h5name); } adios_free_varinfo (v); } /* variables */ /* For all attributes */ if (DEBUG) printf(" Attributes=%d:\n", g->attrs_count); for (i = 0; i < g->attrs_count; i++) { enum ADIOS_DATATYPES atype; int asize; void *adata; adios_get_attr_byid (g, i, &atype, &asize, &adata); grp_name = bp_dirparser (g->attr_namelist[i], &level); strcpy(aname,grp_name[level-1]); // the name of the attribute is the last in the array // we then need to concat the rest together strcpy(fname,"/"); for (j=0;j<level-1;j++) { strcat(fname,grp_name[j]); } h5_err = bp_getH5TypeId (atype, &h5_type_id); // let's create the attribute adims = 1; if (atype==adios_string) H5Tset_size(h5_type_id,strlen(adata)); space_id = H5Screate(H5S_SCALAR); // just a scalar att_id = H5Acreate(HDF5_FILE, g->attr_namelist[i], h5_type_id, space_id,H5P_DEFAULT); h5_err = H5Awrite(att_id, h5_type_id, adata); h5_err = H5Aclose(att_id); h5_err = H5Sclose(space_id); if (DEBUG) printf(" %-9s %s = %s\n", adios_type_to_string(atype), g->attr_namelist[i], value_to_string(atype, adata, 0)); free(adata); } /* attributes */ adios_gclose (g); } /* groups */ adios_fclose (f); h5_err = H5Fclose(HDF5_FILE); MPI_Finalize(); return 0; }
void PWOrbitalBuilder::transform2GridData(PWBasis::GIndex_t& nG, int spinIndex, PWOrbitalSet& pwFunc) { ostringstream splineTag; splineTag << "eigenstates_"<<nG[0]<<"_"<<nG[1]<<"_"<<nG[2]; herr_t status = H5Eset_auto(NULL, NULL); app_log() << " splineTag " << splineTag.str() << endl; hid_t es_grp_id; status = H5Gget_objinfo (hfileID, splineTag.str().c_str(), 0, NULL); if(status) { es_grp_id = H5Gcreate(hfileID,splineTag.str().c_str(),0); HDFAttribIO<PWBasis::GIndex_t> t(nG); t.write(es_grp_id,"grid"); } else { es_grp_id = H5Gopen(hfileID,splineTag.str().c_str()); } string tname=myParam->getTwistName(); hid_t twist_grp_id; status = H5Gget_objinfo (es_grp_id, tname.c_str(), 0, NULL); if(status) twist_grp_id = H5Gcreate(es_grp_id,tname.c_str(),0); else twist_grp_id = H5Gopen(es_grp_id,tname.c_str()); HDFAttribIO<PosType> hdfobj_twist(TwistAngle); hdfobj_twist.write(twist_grp_id,"twist_angle"); ParticleSet::ParticleLayout_t& lattice(targetPtcl.Lattice); RealType dx=1.0/static_cast<RealType>(nG[0]-1); RealType dy=1.0/static_cast<RealType>(nG[1]-1); RealType dz=1.0/static_cast<RealType>(nG[2]-1); #if defined(VERYTINYMEMORY) typedef Array<ValueType,3> StorageType; StorageType inData(nG[0],nG[1],nG[2]); int ib=0; while(ib<myParam->numBands) { string bname(myParam->getBandName(ib)); status = H5Gget_objinfo (twist_grp_id, bname.c_str(), 0, NULL); hid_t band_grp_id, spin_grp_id=-1; if(status) { band_grp_id = H5Gcreate(twist_grp_id,bname.c_str(),0); } else { band_grp_id = H5Gopen(twist_grp_id,bname.c_str()); } hid_t parent_id=band_grp_id; if(myParam->hasSpin) { bname=myParam->getSpinName(spinIndex); status = H5Gget_objinfo (band_grp_id, bname.c_str(), 0, NULL); if(status) { spin_grp_id = H5Gcreate(band_grp_id,bname.c_str(),0); } else { spin_grp_id = H5Gopen(band_grp_id,bname.c_str()); } parent_id=spin_grp_id; } for(int ig=0; ig<nG[0]; ig++) { RealType x=ig*dx; for(int jg=0; jg<nG[1]; jg++) { RealType y=jg*dy; for(int kg=0; kg<nG[2]; kg++) { inData(ig,jg,kg)= pwFunc.evaluate(ib,lattice.toCart(PosType(x,y,kg*dz))); } } } app_log() << " Add spline data " << ib << " h5path=" << tname << "/eigvector" << endl; HDFAttribIO<StorageType> t(inData); t.write(parent_id,myParam->eigvecTag.c_str()); if(spin_grp_id>=0) H5Gclose(spin_grp_id); H5Gclose(band_grp_id); ++ib; } #else typedef Array<ValueType,3> StorageType; vector<StorageType*> inData; int nb=myParam->numBands; for(int ib=0; ib<nb; ib++) inData.push_back(new StorageType(nG[0],nG[1],nG[2])); PosType tAngle=targetPtcl.Lattice.k_cart(TwistAngle); PWOrbitalSet::ValueVector_t phi(nb); for(int ig=0; ig<nG[0]; ig++) { RealType x=ig*dx; for(int jg=0; jg<nG[1]; jg++) { RealType y=jg*dy; for(int kg=0; kg<nG[2]; kg++) { targetPtcl.R[0]=lattice.toCart(PosType(x,y,kg*dz)); pwFunc.evaluate(targetPtcl,0,phi); RealType x(dot(targetPtcl.R[0],tAngle)); ValueType phase(std::cos(x),-std::sin(x)); for(int ib=0; ib<nb; ib++) (*inData[ib])(ig,jg,kg)=phase*phi[ib]; } } } for(int ib=0; ib<nb; ib++) { string bname(myParam->getBandName(ib)); status = H5Gget_objinfo (twist_grp_id, bname.c_str(), 0, NULL); hid_t band_grp_id, spin_grp_id=-1; if(status) { band_grp_id = H5Gcreate(twist_grp_id,bname.c_str(),0); } else { band_grp_id = H5Gopen(twist_grp_id,bname.c_str()); } hid_t parent_id=band_grp_id; if(myParam->hasSpin) { bname=myParam->getSpinName(spinIndex); status = H5Gget_objinfo (band_grp_id, bname.c_str(), 0, NULL); if(status) { spin_grp_id = H5Gcreate(band_grp_id,bname.c_str(),0); } else { spin_grp_id = H5Gopen(band_grp_id,bname.c_str()); } parent_id=spin_grp_id; } app_log() << " Add spline data " << ib << " h5path=" << tname << "/eigvector" << endl; HDFAttribIO<StorageType> t(*(inData[ib])); t.write(parent_id,myParam->eigvecTag.c_str()); if(spin_grp_id>=0) H5Gclose(spin_grp_id); H5Gclose(band_grp_id); } for(int ib=0; ib<nb; ib++) delete inData[ib]; #endif H5Gclose(twist_grp_id); H5Gclose(es_grp_id); }
/*------------------------------------------------------------------------- * Function: main * * Purpose: HDF5 user block unjammer * * Return: Success: 0 * Failure: 1 * * Programmer: * * Modifications: * *------------------------------------------------------------------------- */ int main (int argc, const char *argv[]) { char *ifname; void *edata; H5E_auto_t func; hid_t ifile; hsize_t usize; htri_t testval; herr_t status; hid_t plist; /* Disable error reporting */ H5Eget_auto(&func, &edata); H5Eset_auto(NULL, NULL); parse_command_line (argc, argv); if (argc <= (opt_ind)) { error_msg (progname, "missing file name\n"); usage (progname); return (EXIT_FAILURE); } ifname = strdup (argv[opt_ind]); testval = H5Fis_hdf5 (ifname); if (testval <= 0) { error_msg (progname, "Input HDF5 file is not HDF \"%s\"\n", ifname); return (EXIT_FAILURE); } ifile = H5Fopen (ifname, H5F_ACC_RDONLY, H5P_DEFAULT); if (ifile < 0) { error_msg (progname, "Can't open input HDF5 file \"%s\"\n", ifname); return (EXIT_FAILURE); } plist = H5Fget_create_plist (ifile); if (plist < 0) { error_msg (progname, "Can't get file creation plist for file \"%s\"\n", ifname); return (EXIT_FAILURE); } status = H5Pget_userblock (plist, &usize); if (status < 0) { error_msg (progname, "Can't get user block for file \"%s\"\n", ifname); return (EXIT_FAILURE); } printf ("%ld\n", (long) usize); H5Pclose (plist); H5Fclose (ifile); return (EXIT_SUCCESS); }
void enable_h5_errors(err_state_t *err_state) { assert(H5Eset_auto(H5E_DEFAULT, err_state->old_func, err_state->old_client_data) >= 0); }
/*------------------------------------------------------------------------- * Function: main * * Purpose: HDF5 user block jammer * * Return: Success: 0 * Failure: 1 * * Programmer: * * Modifications: * *------------------------------------------------------------------------- */ int main (int argc, const char *argv[]) { int ufid; int h5fid; int ofid; void *edata; H5E_auto_t func; hid_t ifile; hid_t plist; herr_t status; htri_t testval; hsize_t usize; hsize_t h5fsize; hsize_t startub; hsize_t where; hsize_t newubsize; off_t fsize; struct stat sbuf; struct stat sbuf2; int res; /* Disable error reporting */ H5Eget_auto (&func, &edata); H5Eset_auto (NULL, NULL); parse_command_line (argc, argv); if (ub_file == NULL) { /* no user block */ error_msg (progname, "no user block file name\n"); usage (progname); exit (EXIT_FAILURE); } if (input_file == NULL) { /* no user block */ error_msg (progname, "no HDF5 file\n"); usage (progname); exit (EXIT_FAILURE); } testval = H5Fis_hdf5 (input_file); if (testval <= 0) { error_msg (progname, "Input HDF5 file is not HDF \"%s\"\n", input_file); exit (EXIT_FAILURE); } ifile = H5Fopen (input_file, H5F_ACC_RDONLY, H5P_DEFAULT); if (ifile < 0) { error_msg (progname, "Can't open input HDF5 file \"%s\"\n", input_file); exit (EXIT_FAILURE); } plist = H5Fget_create_plist (ifile); if (plist < 0) { error_msg (progname, "Can't get file creation plist for file \"%s\"\n", input_file); exit (EXIT_FAILURE); } status = H5Pget_userblock (plist, &usize); if (status < 0) { error_msg (progname, "Can't get user block for file \"%s\"\n", input_file); exit (EXIT_FAILURE); } H5Pclose (plist); H5Fclose (ifile); ufid = HDopen (ub_file, O_RDONLY, 0); if (ufid < 0) { error_msg (progname, "unable to open user block file \"%s\"\n", ub_file); exit (EXIT_FAILURE); } res = stat (ub_file, &sbuf); if (res < 0) { error_msg (progname, "Can't stat file \"%s\"\n", ub_file); exit (EXIT_FAILURE); } fsize = sbuf.st_size; h5fid = HDopen (input_file, O_RDONLY, 0); if (h5fid < 0) { error_msg (progname, "unable to open HDF5 file for read \"%s\"\n", input_file); exit (EXIT_FAILURE); } res = stat (input_file, &sbuf2); if (res < 0) { error_msg (progname, "Can't stat file \"%s\"\n", input_file); exit (EXIT_FAILURE); } h5fsize = sbuf2.st_size; if (output_file == NULL) { ofid = HDopen (input_file, O_WRONLY, 0); if (ofid < 0) { error_msg (progname, "unable to open output file \"%s\"\n", output_file); exit (EXIT_FAILURE); } } else { ofid = HDopen (output_file, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (ofid < 0) { error_msg (progname, "unable to create output file \"%s\"\n", output_file); exit (EXIT_FAILURE); } } newubsize = compute_user_block_size ((hsize_t) fsize); startub = usize; if (usize > 0) { if (do_clobber == TRUE) { /* where is max of the current size or the new UB */ if (usize > newubsize) { newubsize = usize; } startub = 0; /*blast the old */ } else { /* add new ub to current ublock, pad to new offset */ newubsize += usize; newubsize = compute_user_block_size ((hsize_t) newubsize); } } /* copy the HDF5 from starting at usize to starting at newubsize: * makes room at 'from' for new ub */ /* if no current ub, usize is 0 */ copy_some_to_file (h5fid, ofid, usize, newubsize, (ssize_t) (h5fsize - usize)); /* copy the old ub to the beginning of the new file */ if (!do_clobber) { where = copy_some_to_file (h5fid, ofid, (hsize_t) 0, (hsize_t) 0, (ssize_t) usize); } /* copy the new ub to the end of the ub */ where = copy_some_to_file (ufid, ofid, (hsize_t) 0, startub, (ssize_t) - 1); /* pad the ub */ where = write_pad (ofid, where); HDclose (ufid); HDclose (h5fid); HDclose (ofid); return d_status; }
int getBaxData(BaxData *b, char *fname) { hid_t field_space; hid_t field_set; hsize_t field_len[2]; hid_t file_id; herr_t stat; int ecode; hid_t type; hid_t attr; char *name; H5Eset_auto(H5E_DEFAULT,0,0); // silence hdf5 error stack file_id = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT); if (file_id < 0) return (CANNOT_OPEN_BAX_FILE); #ifdef DEBUG printf("PROCESSING %s, file_id: %d\n", baxFileName, file_id); #endif #define GET_SIZE(path,error) \ { ecode = error; \ if ((field_set = H5Dopen2(file_id, path, H5P_DEFAULT)) < 0) goto exit0; \ if ((field_space = H5Dget_space(field_set)) < 0) goto exit1; \ H5Sget_simple_extent_dims(field_space, field_len, NULL); \ } #define FETCH(field,type) \ { stat = H5Dread(field_set, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, b->field); \ H5Sclose(field_space); \ H5Dclose(field_set); \ if (stat < 0) goto exit0; \ } #define CHECK_FETCH(path,error,field,type,cntr) \ { GET_SIZE(path,error) \ if (b->cntr != field_len[0]) goto exit2; \ FETCH(field,type) \ } ecode = BAX_MOVIENAME_ERR; if ((field_set = H5Gopen2(file_id,"/ScanData/RunInfo",H5P_DEFAULT)) < 0) goto exit0; if ((attr = H5Aopen(field_set,"MovieName",H5P_DEFAULT)) < 0) goto exit3; if ((field_space = H5Aget_space(attr)) < 0) goto exit4; if ((type = H5Aget_type(attr)) < 0) goto exit5; H5Aread(attr,type,&name); ensureMovie(b,strlen(name)); strcpy(b->movieName,name); H5Tclose(type); H5Sclose(field_space); H5Aclose(attr); H5Gclose(field_set); GET_SIZE("/PulseData/BaseCalls/Basecall",BAX_BASECALL_ERR) ensureBases(b,field_len[0]); FETCH(baseCall,H5T_NATIVE_UCHAR) if (b->arrow) CHECK_FETCH("/PulseData/BaseCalls/WidthInFrames",BAX_PULSE_ERR,pulseW,H5T_NATIVE_USHORT,numBP) if (b->fastq) CHECK_FETCH("/PulseData/BaseCalls/QualityValue",BAX_QV_ERR,fastQV,H5T_NATIVE_UCHAR,numBP) if (b->quivqv) { CHECK_FETCH("/PulseData/BaseCalls/DeletionQV", BAX_DEL_ERR,delQV, H5T_NATIVE_UCHAR,numBP) CHECK_FETCH("/PulseData/BaseCalls/DeletionTag", BAX_TAG_ERR,delTag, H5T_NATIVE_UCHAR,numBP) CHECK_FETCH("/PulseData/BaseCalls/InsertionQV", BAX_INS_ERR,insQV, H5T_NATIVE_UCHAR,numBP) CHECK_FETCH("/PulseData/BaseCalls/MergeQV", BAX_MRG_ERR,mergeQV,H5T_NATIVE_UCHAR,numBP) CHECK_FETCH("/PulseData/BaseCalls/SubstitutionQV",BAX_SUB_ERR,subQV, H5T_NATIVE_UCHAR,numBP) } GET_SIZE("/PulseData/BaseCalls/ZMW/HoleStatus",BAX_HOLESTATUS_ERR) ensureZMW(b,field_len[0]); FETCH(holeType,H5T_NATIVE_UCHAR) CHECK_FETCH("/PulseData/BaseCalls/ZMW/NumEvent",BAX_NR_EVENTS_ERR,readLen,H5T_NATIVE_INT,numZMW) if (b->arrow) { CHECK_FETCH("/PulseData/BaseCalls/ZMWMetrics/HQRegionSNR",BAX_SNR_ERR,snrVec, H5T_NATIVE_FLOAT,numZMW) ecode = BAX_CHIPSET_ERR; if ((field_set = H5Gopen2(file_id,"/ScanData/DyeSet",H5P_DEFAULT)) < 0) goto exit0; if ((attr = H5Aopen(field_set,"BaseMap",H5P_DEFAULT)) < 0) goto exit3; if ((field_space = H5Aget_space(attr)) < 0) goto exit4; if ((type = H5Aget_type(attr)) < 0) goto exit5; H5Aread(attr,type,&name); { int i; for (i = 0; i < 4; i++) b->chan[i] = DNA_2_NUMBER[(int) name[i]]; } H5Tclose(type); H5Sclose(field_space); H5Aclose(attr); H5Gclose(field_set); } GET_SIZE("/PulseData/Regions",BAX_REGION_ERR) ensureHQR(b,field_len[0]); FETCH(regions,H5T_NATIVE_INT) // Find the Del QV associated with N's in the Del Tag if (b->quivqv) { hsize_t i; for (i = 0; i < b->numBP; i++) if (b->delTag[i] == 'N') { b->delLimit = b->delQV[i]; break; } } H5Fclose(file_id); return (0); exit5: H5Sclose(field_space); exit4: H5Aclose(attr); exit3: H5Gclose(field_set); H5Fclose(file_id); return (ecode); exit2: H5Sclose(field_space); exit1: H5Dclose(field_set); exit0: H5Fclose(file_id); return (ecode); }