本文整理汇总了C++中H5Fopen函数的典型用法代码示例。如果您正苦于以下问题:C++ H5Fopen函数的具体用法?C++ H5Fopen怎么用?C++ H5Fopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了H5Fopen函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: malloc
/*
* Open a file through the HDF5 interface.
*/
static void *HDF5_Open(char *testFileName, IOR_param_t * param)
{
hid_t accessPropList, createPropList;
hsize_t memStart[NUM_DIMS],
dataSetDims[NUM_DIMS],
memStride[NUM_DIMS],
memCount[NUM_DIMS], memBlock[NUM_DIMS], memDataSpaceDims[NUM_DIMS];
int tasksPerDataSet;
unsigned fd_mode = (unsigned)0;
hid_t *fd;
MPI_Comm comm;
MPI_Info mpiHints = MPI_INFO_NULL;
fd = (hid_t *) malloc(sizeof(hid_t));
if (fd == NULL)
ERR("malloc() failed");
/*
* HDF5 uses different flags than those for POSIX/MPIIO
*/
if (param->open == WRITE) { /* WRITE flags */
param->openFlags = IOR_TRUNC;
} else { /* READ or check WRITE/READ flags */
param->openFlags = IOR_RDONLY;
}
/* set IOR file flags to HDF5 flags */
/* -- file open flags -- */
if (param->openFlags & IOR_RDONLY) {
fd_mode |= H5F_ACC_RDONLY;
}
if (param->openFlags & IOR_WRONLY) {
fprintf(stdout, "File write only not implemented in HDF5\n");
}
if (param->openFlags & IOR_RDWR) {
fd_mode |= H5F_ACC_RDWR;
}
if (param->openFlags & IOR_APPEND) {
fprintf(stdout, "File append not implemented in HDF5\n");
}
if (param->openFlags & IOR_CREAT) {
fd_mode |= H5F_ACC_CREAT;
}
if (param->openFlags & IOR_EXCL) {
fd_mode |= H5F_ACC_EXCL;
}
if (param->openFlags & IOR_TRUNC) {
fd_mode |= H5F_ACC_TRUNC;
}
if (param->openFlags & IOR_DIRECT) {
fprintf(stdout, "O_DIRECT not implemented in HDF5\n");
}
/* set up file creation property list */
createPropList = H5Pcreate(H5P_FILE_CREATE);
HDF5_CHECK(createPropList, "cannot create file creation property list");
/* set size of offset and length used to address HDF5 objects */
HDF5_CHECK(H5Pset_sizes
(createPropList, sizeof(hsize_t), sizeof(hsize_t)),
"cannot set property list properly");
/* set up file access property list */
accessPropList = H5Pcreate(H5P_FILE_ACCESS);
HDF5_CHECK(accessPropList, "cannot create file access property list");
/*
* someday HDF5 implementation will allow subsets of MPI_COMM_WORLD
*/
/* store MPI communicator info for the file access property list */
if (param->filePerProc) {
comm = MPI_COMM_SELF;
} else {
comm = testComm;
}
SetHints(&mpiHints, param->hintsFileName);
/*
* note that with MP_HINTS_FILTERED=no, all key/value pairs will
* be in the info object. The info object that is attached to
* the file during MPI_File_open() will only contain those pairs
* deemed valid by the implementation.
*/
/* show hints passed to file */
if (rank == 0 && param->showHints) {
fprintf(stdout, "\nhints passed to access property list {\n");
ShowHints(&mpiHints);
fprintf(stdout, "}\n");
}
HDF5_CHECK(H5Pset_fapl_mpio(accessPropList, comm, mpiHints),
"cannot set file access property list");
/* set alignment */
HDF5_CHECK(H5Pset_alignment(accessPropList, param->setAlignment,
param->setAlignment),
"cannot set alignment");
/* open file */
if (param->open == WRITE) { /* WRITE */
//.........这里部分代码省略.........
开发者ID:plaguedbypenguins,项目名称:ior,代码行数:101,代码来源:aiori-HDF5.c
示例2: h5repack_cmp_pl
int h5repack_cmp_pl(const char *fname1,
const char *fname2)
{
int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
hid_t fid1=-1; /* file ID */
hid_t fid2=-1; /* file ID */
hid_t dset1=-1; /* dataset ID */
hid_t dset2=-1; /* dataset ID */
hid_t gid=-1; /* group ID */
hid_t dcpl1=-1; /* dataset creation property list ID */
hid_t dcpl2=-1; /* dataset creation property list ID */
hid_t gcplid=-1; /* group creation property list */
unsigned crt_order_flag1; /* group creation order flag */
unsigned crt_order_flag2; /* group creation order flag */
trav_table_t *trav=NULL;
int ret=1;
unsigned int i;
/*-------------------------------------------------------------------------
* open the files
*-------------------------------------------------------------------------
*/
/* disable error reporting */
H5E_BEGIN_TRY
{
/* Open the files */
if ((fid1 = H5Fopen(fname1,H5F_ACC_RDONLY,H5P_DEFAULT)) < 0 )
{
error_msg("<%s>: %s\n", fname1, H5FOPENERROR );
return -1;
}
if ((fid2 = H5Fopen(fname2,H5F_ACC_RDONLY,H5P_DEFAULT)) < 0 )
{
error_msg("<%s>: %s\n", fname2, H5FOPENERROR );
H5Fclose(fid1);
return -1;
}
/* enable error reporting */
} H5E_END_TRY;
/*-------------------------------------------------------------------------
* get file table list of objects
*-------------------------------------------------------------------------
*/
trav_table_init(&trav);
if(h5trav_gettable(fid1, trav) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5trav_gettable failed");
/*-------------------------------------------------------------------------
* traverse the suppplied object list
*-------------------------------------------------------------------------
*/
for(i = 0; i < trav->nobjs; i++)
{
if(trav->objs[i].type == H5TRAV_TYPE_GROUP)
{
if ((gid = H5Gopen2(fid1, trav->objs[i].name, H5P_DEFAULT)) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed");
if ((gcplid = H5Gget_create_plist(gid)) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gget_create_plist failed");
if (H5Pget_link_creation_order(gcplid, &crt_order_flag1) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pget_link_creation_order failed");
if (H5Pclose(gcplid) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
if (H5Gclose(gid) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed");
if ((gid = H5Gopen2(fid2, trav->objs[i].name, H5P_DEFAULT)) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed");
if ((gcplid = H5Gget_create_plist(gid)) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gget_create_plist failed");
if (H5Pget_link_creation_order(gcplid, &crt_order_flag2) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pget_link_creation_order failed");
if (H5Pclose(gcplid) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
if (H5Gclose(gid) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed");
if (crt_order_flag1 != crt_order_flag2) {
error_msg("property lists for <%s> are different\n",trav->objs[i].name);
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "property lists failed");
}
}
else if(trav->objs[i].type == H5TRAV_TYPE_DATASET)
{
if((dset1 = H5Dopen2(fid1, trav->objs[i].name, H5P_DEFAULT)) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
if((dset2 = H5Dopen2(fid2, trav->objs[i].name, H5P_DEFAULT)) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
if((dcpl1 = H5Dget_create_plist(dset1)) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed");
if((dcpl2 = H5Dget_create_plist(dset2)) < 0)
//.........这里部分代码省略.........
开发者ID:AndyHuang7601,项目名称:EpicGames-UnrealEngine,代码行数:101,代码来源:h5repack_verify.c
示例3: open
static file open(std::string const& name, unsigned int flags)
{
hid_t id = H5Fopen(name.c_str(), flags, H5P_DEFAULT);
if (id < 0) throw std::runtime_error("H5Fopen failed");
return file(std::move(id));
}
开发者ID:andreabedini,项目名称:isaw-sq-flatperm,代码行数:6,代码来源:file.hpp
示例4: test_family_compat
/*-------------------------------------------------------------------------
* Function: test_family_compat
*
* Purpose: Tests the backward compatibility for FAMILY driver.
* See if we can open files created with v1.6 library.
* The source file was created by the test/file_handle.c
* of the v1.6 library. Then tools/misc/h5repart.c was
* used to concantenated. The command was "h5repart -m 5k
* family_file%05d.h5 family_v16_%05d.h5".
*
* Return: Success: 0
* Failure: -1
*
* Programmer: Raymond Lu
* June 3, 2005
*
*-------------------------------------------------------------------------
*/
static herr_t
test_family_compat(void)
{
hid_t file = (-1), fapl;
hid_t dset;
char dname[]="dataset";
char filename[1024];
char pathname[1024], pathname_individual[1024];
char newname[1024], newname_individual[1024];
FILE *tmp_fp, *old_fp; /* Pointers to temp & old files */
int counter = 0;
TESTING("FAMILY file driver backward compatibility");
/* Set property list and file name for FAMILY driver */
fapl = h5_fileaccess();
if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE2, H5P_DEFAULT) < 0)
TEST_ERROR;
h5_fixname(COMPAT_BASENAME, fapl, filename, sizeof filename);
h5_fixname(FILENAME[3], fapl, newname, sizeof newname);
pathname[0] = '\0';
HDstrcat(pathname, filename);
/* The following code makes the copies of the family files in the source directory.
* Since we're going to open the files with write mode, this protects the original
* files.
*/
sprintf(newname_individual, newname, counter);
sprintf(pathname_individual, pathname, counter);
while (h5_make_local_copy(pathname_individual, newname_individual) >= 0) {
counter++;
sprintf(newname_individual, newname, counter);
sprintf(pathname_individual, pathname, counter);
}
if ((NULL != (old_fp = HDfopen(pathname_individual,"rb"))) &&
(NULL != (tmp_fp = HDfopen(newname_individual,"wb"))))
TEST_ERROR;
/* Make sure we can open the file. Use the read and write mode to flush the
* superblock. */
if((file = H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR;
if((dset = H5Dopen2(file, dname, H5P_DEFAULT)) < 0)
TEST_ERROR;
if(H5Dclose(dset) < 0)
TEST_ERROR;
if(H5Fclose(file) < 0)
TEST_ERROR;
/* Open the file again to make sure it isn't corrupted. */
if((file = H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR;
if((dset = H5Dopen2(file, dname, H5P_DEFAULT)) < 0)
TEST_ERROR;
if(H5Dclose(dset) < 0)
TEST_ERROR;
if(H5Fclose(file) < 0)
TEST_ERROR;
h5_cleanup(FILENAME, fapl);
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
H5Fclose(file);
H5Pclose(fapl);
} H5E_END_TRY;
//.........这里部分代码省略.........
开发者ID:chaako,项目名称:sceptic3D,代码行数:101,代码来源:vfd.c
示例5: fillIDMatrix
bool FWSingleOMP::run()
{
hdf_WGT_data.setFileName(xmlrootName);
hdf_OBS_data.setFileName(xmlrootName);
if (doWeights==1)
{
fillIDMatrix();
hdf_WGT_data.makeFile();
hdf_WGT_data.openFile();
hdf_WGT_data.addFW(0);
for (int i=0;i<Weights.size();i++) hdf_WGT_data.addStep(i,Weights[i]);
hdf_WGT_data.closeFW();
hdf_WGT_data.closeFile();
for(int ill=1;ill<weightLength;ill++)
{
transferParentsOneGeneration();
FWOneStep();
// WeightHistory.push_back(Weights);
hdf_WGT_data.openFile();
hdf_WGT_data.addFW(ill);
for (int i=0;i<Weights.size();i++) hdf_WGT_data.addStep(i,Weights[i]);
hdf_WGT_data.closeFW();
hdf_WGT_data.closeFile();
}
}
else
{
fillIDMatrix();
// find weight length from the weight file
hid_t f_file = H5Fopen(hdf_WGT_data.getFileName().c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
hsize_t numGrps = 0;
H5Gget_num_objs(f_file, &numGrps);
weightLength = static_cast<int> (numGrps)-1;
if (H5Fclose(f_file)>-1) f_file=-1;
if (verbose>0) app_log()<<" weightLength "<<weightLength<<endl;
}
if (verbose>0) app_log()<<" Done Computing Weights"<<endl;
if (doObservables==1)
{
int nprops = H.sizeOfObservables();//local energy, local potnetial and all hamiltonian elements
int FirstHamiltonian = H.startIndex();
// vector<vector<vector<RealType> > > savedValues;
int nelectrons = W[0]->R.size();
int nfloats=OHMMS_DIM*nelectrons;
// W.clearEnsemble();
makeClones(W,Psi,H);
vector<ForwardWalkingData* > FWvector;
for(int ip=0; ip<NumThreads; ip++) FWvector.push_back(new ForwardWalkingData(nelectrons));
if (myComm->rank()==0) hdf_OBS_data.makeFile();
hdf_float_data.openFile(fname.str());
for(int step=0;step<numSteps;step++)
{
hdf_float_data.setStep(step);
vector<RealType> stepObservables(walkersPerBlock[step]*(nprops+2), 0);
for(int wstep=0; wstep<walkersPerBlock[step];)
{
vector<float> ThreadsCoordinate(NumThreads*nfloats);
int nwalkthread = hdf_float_data.getFloat(wstep*nfloats, (wstep+NumThreads)*nfloats, ThreadsCoordinate) / nfloats;
// for(int j=0;j<ThreadsCoordinate.size();j++)cout<<ThreadsCoordinate[j]<<" ";
// cout<<endl;
#pragma omp parallel for
for(int ip=0; ip<nwalkthread; ip++)
{
vector<float> SINGLEcoordinate(0);
vector<float>::iterator TCB1(ThreadsCoordinate.begin()+ip*nfloats), TCB2(ThreadsCoordinate.begin()+(1+ip)*nfloats);
SINGLEcoordinate.insert(SINGLEcoordinate.begin(),TCB1,TCB2);
FWvector[ip]->fromFloat(SINGLEcoordinate);
wClones[ip]->R=FWvector[ip]->Pos;
wClones[ip]->update();
RealType logpsi(psiClones[ip]->evaluateLog(*wClones[ip]));
RealType eloc=hClones[ip]->evaluate( *wClones[ip] );
hClones[ip]->auxHevaluate(*wClones[ip]);
int indx=(wstep+ip)*(nprops+2);
stepObservables[indx]= eloc;
stepObservables[indx+1]= hClones[ip]->getLocalPotential();
for(int i=0;i<nprops;i++) stepObservables[indx+i+2] = hClones[ip]->getObservable(i) ;
}
wstep+=nwalkthread;
for(int ip=0; ip<NumThreads; ip++) wClones[ip]->resetCollectables();
}
hdf_OBS_data.openFile();
hdf_OBS_data.addStep(step, stepObservables);
hdf_OBS_data.closeFile();
// savedValues.push_back(stepObservables);
hdf_float_data.endStep();
if (verbose >1) cout<<"Done with step: "<<step<<endl;
}
//.........这里部分代码省略.........
开发者ID:digideskio,项目名称:qmcpack,代码行数:101,代码来源:FWSingleOMP.cpp
示例6: toomany
/*-------------------------------------------------------------------------
* Function: toomany
*
* Purpose: Build a file with too many symbolic links
*
* Return: Success: 0
*
* Failure: -1
*
* Programmer: Quincey Koziol
* Tuesday, August 9, 2005
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
toomany(hid_t fapl)
{
hid_t fid = (-1); /* File ID */
hid_t gid = (-1); /* Group ID */
hid_t gid2 = (-1); /* Datatype ID */
char objname[NAME_BUF_SIZE]; /* Object name */
ssize_t name_len; /* Length of object name */
char filename[NAME_BUF_SIZE];
TESTING("too many links");
/* Make certain test is valid */
/* XXX: should probably make a "generic" test that creates the proper
* # of links based on this value - QAK
*/
HDassert(H5G_NLINKS == 16);
/* Create files */
h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
if((fid=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR;
/* Create group with short name in file (used as target for hard links) */
if((gid=H5Gcreate (fid, "final", (size_t)0))<0) TEST_ERROR;
/* Create chain of hard links to existing object (no limit on #) */
if(H5Glink2(fid, "final", H5G_LINK_HARD, fid, "hard1") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard1", H5G_LINK_HARD, fid, "hard2") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard2", H5G_LINK_HARD, fid, "hard3") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard3", H5G_LINK_HARD, fid, "hard4") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard4", H5G_LINK_HARD, fid, "hard5") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard5", H5G_LINK_HARD, fid, "hard6") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard6", H5G_LINK_HARD, fid, "hard7") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard7", H5G_LINK_HARD, fid, "hard8") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard8", H5G_LINK_HARD, fid, "hard9") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard9", H5G_LINK_HARD, fid, "hard10") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard10", H5G_LINK_HARD, fid, "hard11") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard11", H5G_LINK_HARD, fid, "hard12") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard12", H5G_LINK_HARD, fid, "hard13") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard13", H5G_LINK_HARD, fid, "hard14") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard14", H5G_LINK_HARD, fid, "hard15") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard15", H5G_LINK_HARD, fid, "hard16") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard16", H5G_LINK_HARD, fid, "hard17") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard17", H5G_LINK_HARD, fid, "hard18") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard18", H5G_LINK_HARD, fid, "hard19") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard19", H5G_LINK_HARD, fid, "hard20") < 0) TEST_ERROR;
if(H5Glink2(fid, "hard20", H5G_LINK_HARD, fid, "hard21") < 0) TEST_ERROR;
/* Create chain of soft links to existing object (limited) */
if(H5Glink2(fid, "final", H5G_LINK_SOFT, fid, "soft1") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft1", H5G_LINK_SOFT, fid, "soft2") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft2", H5G_LINK_SOFT, fid, "soft3") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft3", H5G_LINK_SOFT, fid, "soft4") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft4", H5G_LINK_SOFT, fid, "soft5") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft5", H5G_LINK_SOFT, fid, "soft6") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft6", H5G_LINK_SOFT, fid, "soft7") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft7", H5G_LINK_SOFT, fid, "soft8") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft8", H5G_LINK_SOFT, fid, "soft9") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft9", H5G_LINK_SOFT, fid, "soft10") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft10", H5G_LINK_SOFT, fid, "soft11") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft11", H5G_LINK_SOFT, fid, "soft12") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft12", H5G_LINK_SOFT, fid, "soft13") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft13", H5G_LINK_SOFT, fid, "soft14") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft14", H5G_LINK_SOFT, fid, "soft15") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft15", H5G_LINK_SOFT, fid, "soft16") < 0) TEST_ERROR;
if(H5Glink2(fid, "soft16", H5G_LINK_SOFT, fid, "soft17") < 0) TEST_ERROR;
/* Close objects */
if(H5Gclose(gid)<0) TEST_ERROR;
if(H5Fclose(fid)<0) TEST_ERROR;
/* Open file */
if((fid=H5Fopen(filename, H5F_ACC_RDWR, fapl))<0) TEST_ERROR;
/* Open object through last hard link */
if((gid = H5Gopen(fid, "hard21")) < 0) TEST_ERROR;
/* Check name */
if((name_len = H5Iget_name( gid, objname, (size_t)NAME_BUF_SIZE )) < 0) TEST_ERROR
if(HDstrcmp(objname, "/hard21")) TEST_ERROR
/* Create object in hard-linked group */
if((gid2 = H5Gcreate(gid, "new_hard", (size_t)0)) < 0) TEST_ERROR
//.........这里部分代码省略.........
开发者ID:MattNapsAlot,项目名称:rHDF5,代码行数:101,代码来源:links.c
示例7: test_core
/*-------------------------------------------------------------------------
* Function: test_core
*
* Purpose: Tests the file handle interface for CORE driver
*
* Return: Success: 0
* Failure: -1
*
* Programmer: Raymond Lu
* Tuesday, Sept 24, 2002
*
* Modifications:
*
* Raymond Lu
* Wednesday, June 23, 2004
* Added test for H5Fget_filesize.
*
* Raymond Lu, 2006-11-30
* Enabled the driver to read an existing file depending on
* the setting of the backing_store and file open flags.
*-------------------------------------------------------------------------
*/
static herr_t
test_core(void)
{
hid_t file=(-1), fapl, access_fapl = -1;
char filename[1024];
void *fhandle=NULL;
hsize_t file_size;
int *points, *check, *p1, *p2;
hid_t dset1=-1, space1=-1;
hsize_t dims1[2];
int i, j, n;
TESTING("CORE file driver");
/* Set property list and file name for CORE driver */
fapl = h5_fileaccess();
if(H5Pset_fapl_core(fapl, (size_t)CORE_INCREMENT, TRUE) < 0)
TEST_ERROR;
h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
TEST_ERROR;
/* Retrieve the access property list... */
if ((access_fapl = H5Fget_access_plist(file)) < 0)
TEST_ERROR;
/* ...and close the property list */
if (H5Pclose(access_fapl) < 0)
TEST_ERROR;
if(H5Fget_vfd_handle(file, H5P_DEFAULT, &fhandle) < 0)
TEST_ERROR;
if(fhandle==NULL)
{
printf("fhandle==NULL\n");
TEST_ERROR;
}
/* Check file size API */
if(H5Fget_filesize(file, &file_size) < 0)
TEST_ERROR;
/* There is no garantee the size of metadata in file is constant.
* Just try to check if it's reasonable. Why is this 4KB?
*/
if(file_size<2*KB || file_size>6*KB)
TEST_ERROR;
if(H5Fclose(file) < 0)
TEST_ERROR;
/* Open the file with backing store off for read and write.
* Changes won't be saved in file. */
if(H5Pset_fapl_core(fapl, (size_t)CORE_INCREMENT, FALSE) < 0)
TEST_ERROR;
if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR;
/* Allocate memory for data set. */
points=(int*)malloc(DSET1_DIM1*DSET1_DIM2*sizeof(int));
check=(int*)malloc(DSET1_DIM1*DSET1_DIM2*sizeof(int));
/* Initialize the dset1 */
p1 = points;
for(i = n = 0; i < DSET1_DIM1; i++)
for(j = 0; j < DSET1_DIM2; j++)
*p1++ = n++;
/* Create the data space1 */
dims1[0] = DSET1_DIM1;
dims1[1] = DSET1_DIM2;
if((space1 = H5Screate_simple(2, dims1, NULL)) < 0)
TEST_ERROR;
/* Create the dset1 */
//.........这里部分代码省略.........
开发者ID:chaako,项目名称:sceptic3D,代码行数:101,代码来源:vfd.c
示例8: main
int
main (void)
{
hid_t file, space, dset, obj, attr; /* Handles */
herr_t status;
hsize_t dims[1] = {DIM0};
hobj_ref_t wdata[DIM0], /* Write buffer */
*rdata; /* Read buffer */
H5G_obj_t objtype;
ssize_t size;
char *name;
int ndims,
i;
/*
* Create a new file using the default properties.
*/
file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create a dataset with a scalar dataspace.
*/
space = H5Screate (H5S_SCALAR);
obj = H5Dcreate (file, "DS2", H5T_STD_I32LE, space, H5P_DEFAULT);
status = H5Dclose (obj);
status = H5Sclose (space);
/*
* Create a group.
*/
obj = H5Gcreate (file, "G1", H5P_DEFAULT);
status = H5Gclose (obj);
/*
* Create references to the previously created objects. Passing -1
* as space_id causes this parameter to be ignored. Other values
* besides valid dataspaces result in an error.
*/
status = H5Rcreate (&wdata[0], file, "G1", H5R_OBJECT, -1);
status = H5Rcreate (&wdata[1], file, "DS2", H5R_OBJECT, -1);
/*
* Create dataset with a scalar dataspace to serve as the parent
* for the attribute.
*/
space = H5Screate (H5S_SCALAR);
dset = H5Dcreate (file, DATASET, H5T_STD_I32LE, space, H5P_DEFAULT);
status = H5Sclose (space);
/*
* Create dataspace. Setting maximum size to NULL sets the maximum
* size to be the current size.
*/
space = H5Screate_simple (1, dims, NULL);
/*
* Create the attribute and write the object references to it.
*/
attr = H5Acreate (dset, ATTRIBUTE, H5T_STD_REF_OBJ, space, H5P_DEFAULT);
status = H5Awrite (attr, H5T_STD_REF_OBJ, wdata);
/*
* Close and release resources.
*/
status = H5Aclose (attr);
status = H5Dclose (dset);
status = H5Sclose (space);
status = H5Fclose (file);
/*
* Now we begin the read section of this example. Here we assume
* the attribute has the same name and rank, but can have any size.
* Therefore we must allocate a new array to read in data using
* malloc().
*/
/*
* Open file, dataset, and attribute.
*/
file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen (file, DATASET);
attr = H5Aopen_name (dset, ATTRIBUTE);
/*
* Get dataspace and allocate memory for read buffer.
*/
space = H5Aget_space (attr);
ndims = H5Sget_simple_extent_dims (space, dims, NULL);
rdata = (hobj_ref_t *) malloc (dims[0] * sizeof (hobj_ref_t));
/*
* Read the data.
*/
status = H5Aread (attr, H5T_STD_REF_OBJ, rdata);
/*
* Output the data to the screen.
*/
for (i=0; i<dims[0]; i++) {
//.........这里部分代码省略.........
开发者ID:FrankLIKE,项目名称:d_hdf5,代码行数:101,代码来源:h5ex_t_objrefatt.c
示例9: FTI_RecoverHDF5
/*-------------------------------------------------------------------------*/
int FTI_RecoverHDF5(FTIT_configuration* FTI_Conf, FTIT_execution* FTI_Exec, FTIT_checkpoint* FTI_Ckpt,
FTIT_dataset* FTI_Data)
{
char str[FTI_BUFS], fn[FTI_BUFS];
snprintf(fn, FTI_BUFS, "%s/%s", FTI_Ckpt[FTI_Exec->ckptLvel].dir, FTI_Exec->meta[FTI_Exec->ckptLvel].ckptFile);
if( FTI_Exec->h5SingleFile ) {
snprintf( fn, FTI_BUFS, "%s/%s-ID%08d.h5", FTI_Conf->h5SingleFileDir, FTI_Conf->h5SingleFilePrefix, FTI_Exec->ckptID );
}
sprintf(str, "Trying to load FTI checkpoint file (%s)...", fn);
FTI_Print(str, FTI_DBUG);
hid_t file_id;
//Open hdf5 file
if( FTI_Exec->h5SingleFile ) {
hid_t plid = H5Pcreate( H5P_FILE_ACCESS );
H5Pset_fapl_mpio( plid, FTI_COMM_WORLD, MPI_INFO_NULL );
file_id = H5Fopen( fn, H5F_ACC_RDONLY, plid );
H5Pclose( plid );
} else {
file_id = H5Fopen(fn, H5F_ACC_RDONLY, H5P_DEFAULT);
}
if (file_id < 0) {
FTI_Print("Could not open FTI checkpoint file.", FTI_EROR);
return FTI_NREC;
}
FTI_Exec->H5groups[0]->h5groupID = file_id;
FTIT_H5Group* rootGroup = FTI_Exec->H5groups[0];
int i;
for (i = 0; i < FTI_Exec->H5groups[0]->childrenNo; i++) {
FTI_OpenGroup(FTI_Exec->H5groups[rootGroup->childrenID[i]], file_id, FTI_Exec->H5groups);
}
for (i = 0; i < FTI_Exec->nbVar; i++) {
FTI_CreateComplexType(FTI_Data[i].type, FTI_Exec->FTI_Type);
}
if( FTI_Exec->h5SingleFile ) {
FTI_OpenGlobalDatasets( FTI_Exec );
}
for (i = 0; i < FTI_Exec->nbVar; i++) {
herr_t res;
if( FTI_Exec->h5SingleFile ) {
res = FTI_ReadSharedFileData( FTI_Data[i] );
} else {
res = FTI_ReadHDF5Var(&FTI_Data[i]);
}
if (res < 0) {
FTI_Print("Could not read FTI checkpoint file.", FTI_EROR);
int j;
for (j = 0; j < FTI_Exec->H5groups[0]->childrenNo; j++) {
FTI_CloseGroup(FTI_Exec->H5groups[rootGroup->childrenID[j]], FTI_Exec->H5groups);
}
H5Fclose(file_id);
return FTI_NREC;
}
}
for (i = 0; i < FTI_Exec->nbVar; i++) {
FTI_CloseComplexType(FTI_Data[i].type, FTI_Exec->FTI_Type);
}
int j;
for (j = 0; j < FTI_Exec->H5groups[0]->childrenNo; j++) {
FTI_CloseGroup(FTI_Exec->H5groups[rootGroup->childrenID[j]], FTI_Exec->H5groups);
}
if( FTI_Exec->h5SingleFile ) {
FTI_CloseGlobalDatasets( FTI_Exec );
}
FTI_Exec->H5groups[0]->h5groupID = -1;
if (H5Fclose(file_id) < 0) {
FTI_Print("Could not close FTI checkpoint file.", FTI_EROR);
return FTI_NREC;
}
FTI_Exec->reco = 0;
return FTI_SCES;
}
开发者ID:leobago,项目名称:fti,代码行数:82,代码来源:hdf5.c
示例10: parameters
/*+++++++++++++++++++++++++
.IDENTifer SDMF_get_OrbitalDark_30
.PURPOSE obtain dark correction parameters (SDMF v3.0)
.INPUT/OUTPUT
call as found = SDMF_get_OrbitalDark_30( orbit, orbitPhase
analogOffs, darkCurrent,
analogOffsError, darkCurrentError );
input:
unsigned short absOrbit : orbit number
float orbitPhase : orbit phase
in/output:
float *analogOffs : analog offset (BU)
float *darkCurrent : leakage current (BU/s)
float *analogOffsError : analog offset error (BU)
float *darkCurrentError : leakage current error (BU/s)
.RETURNS solution found (True or False)
error status passed by global variable ``nadc_stat''
.COMMENTS none
-------------------------*/
bool SDMF_get_OrbitalDark_30( unsigned short absOrbit, float orbitPhase,
float *analogOffs, float *darkCurrent,
float *analogOffsError, float *darkCurrentError )
{
register unsigned short np;
hid_t fid = -1;
hid_t gid = -1;
bool found = FALSE;
int numIndx, metaIndx;
float orbvar, orbsig;
float amp1[CHANNEL_SIZE], sig_amp1[CHANNEL_SIZE];
char str_msg[MAX_STRING_LENGTH];
char sdmf_db[MAX_STRING_LENGTH];
struct mtbl_simudark_rec *mtbl = NULL;
const int orbit = (int) absOrbit;
const int pixelRange[] = {0, CHANNEL_SIZE-1};
const long sz_chan_byte = CHANNEL_SIZE * ENVI_FLOAT;
const char msg_found[] =
"\n\tapplied SDMF SimuDark (v3.0) of orbit: %-d";
/*
* initialize returned values
*/
(void) memset( analogOffs, 0, sz_chan_byte );
(void) memset( darkCurrent, 0, sz_chan_byte );
(void) memset( analogOffsError, 0, sz_chan_byte );
(void) memset( darkCurrentError, 0, sz_chan_byte );
/*
* open SDMF simu-dark database
*/
(void) snprintf( sdmf_db, MAX_STRING_LENGTH, "%s/%s",
SDMF_PATH("3.0"), "sdmf_simudark.h5" );
H5E_BEGIN_TRY {
fid = H5Fopen( sdmf_db, H5F_ACC_RDONLY, H5P_DEFAULT );
} H5E_END_TRY;
if ( fid < 0 ) NADC_GOTO_ERROR( NADC_ERR_HDF_FILE, sdmf_db );
if ( (gid = H5Gopen( fid, "ch8", H5P_DEFAULT )) < 0 )
NADC_GOTO_ERROR( NADC_ERR_HDF_GRP, "/ch8" );
/*
* obtain indices relevant entries
*/
numIndx = 1;
metaIndx = -1;
(void) SDMF_get_metaIndex( gid, orbit, &numIndx, &metaIndx );
if ( numIndx == 0 ) goto done;
found = TRUE;
/*
* read simu-dark data
*/
SDMF_rd_simudarkTable( gid, &numIndx, &metaIndx, &mtbl );
SDMF_rd_float_Array( gid, "ao", 1, &metaIndx, pixelRange, analogOffs );
SDMF_rd_float_Array( gid, "lc", 1, &metaIndx, pixelRange, darkCurrent );
SDMF_rd_float_Array( gid, "sig_ao", 1, &metaIndx, pixelRange,
analogOffsError );
SDMF_rd_float_Array( gid, "sig_lc", 1, &metaIndx, pixelRange,
darkCurrentError );
SDMF_rd_float_Array( gid, "amp1", 1, &metaIndx, pixelRange, amp1 );
SDMF_rd_float_Array( gid, "sig_amp1", 1, &metaIndx, pixelRange, sig_amp1 );
/*
* calculate orbital dark for requested orbit-phase
*/
orbvar = (float)
(cos(2 * PI * (mtbl->orbitPhase + orbitPhase))
+ mtbl->amp2 * cos(4 * PI * (mtbl->phase2 + orbitPhase)));
orbsig = (float)
(cos(2 * PI * (mtbl->orbitPhase + orbitPhase))
+ mtbl->sig_amp2 * cos(4 * PI * (mtbl->phase2 + orbitPhase)));
for ( np = 0; np < CHANNEL_SIZE; np++ ) {
darkCurrent[np] += orbvar * amp1[np];
darkCurrentError[np] += orbsig * sig_amp1[np];
}
(void) snprintf( str_msg, SHORT_STRING_LENGTH, msg_found, mtbl->absOrbit );
NADC_ERROR( NADC_ERR_NONE, str_msg );
done:
if ( mtbl != NULL ) free( mtbl );
//.........这里部分代码省略.........
开发者ID:rmvanhees,项目名称:nadc_tools,代码行数:101,代码来源:sdmf_get_orbitaldark.c
示例11: cow_histogram_dumphdf5
void cow_histogram_dumphdf5(cow_histogram *h, char *fn, char *gn)
// -----------------------------------------------------------------------------
// Dumps the histogram to the HDF5 file named `fn`, under the group
// `gn`/h->nickname, gn may be NULL. The function uses rank 0 to do the write.
// -----------------------------------------------------------------------------
{
#if (COW_HDF5)
if (!(h->committed && h->sealed)) {
return;
}
char gname[1024];
int rank = 0;
if (gn) {
snprintf(gname, 1024, "%s/%s", gn, h->nickname);
}
else {
snprintf(gname, 1024, "%s", h->nickname);
}
#if (COW_MPI)
if (cow_mpirunning()) {
MPI_Comm_rank(h->comm, &rank);
}
#endif
if (rank == 0) {
// -------------------------------------------------------------------------
// The write functions assume the file is already created. Have master
// create the file if it's not there already.
// -------------------------------------------------------------------------
FILE *testf = fopen(fn, "r");
hid_t fid;
if (testf == NULL) {
fid = H5Fcreate(fn, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
}
else {
fclose(testf);
fid = H5Fopen(fn, H5F_ACC_RDWR, H5P_DEFAULT);
}
if (H5Lexists_safe(fid, gname)) {
printf("[%s] writing histogram as HDF5 to %s/%s (clobber existing)\n",
MODULE, fn, gname);
H5Gunlink(fid, gname);
}
else {
printf("[%s] writing histogram as HDF5 to %s/%s\n", MODULE, fn, gname);
}
hid_t gcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(gcpl, 1);
hid_t memb = H5Gcreate(fid, gname, gcpl, H5P_DEFAULT, H5P_DEFAULT);
H5Pclose(gcpl);
H5Gclose(memb);
H5Fclose(fid);
}
else {
return;
}
// Create a group to represent this histogram, and an attribute to name it
// ---------------------------------------------------------------------------
hid_t fid = H5Fopen(fn, H5F_ACC_RDWR, H5P_DEFAULT);
hid_t grp = H5Gopen(fid, gname, H5P_DEFAULT);
if (h->fullname != NULL) {
hid_t aspc = H5Screate(H5S_SCALAR);
hid_t strn = H5Tcopy(H5T_C_S1);
H5Tset_size(strn, strlen(h->fullname));
hid_t attr = H5Acreate(grp, "fullname", strn, aspc, H5P_DEFAULT, H5P_DEFAULT);
H5Awrite(attr, strn, h->fullname); // write the full name
H5Aclose(attr);
H5Tclose(strn);
H5Sclose(aspc);
}
// Create the data sets in the group: binloc (bin centers) and binval (values)
// ---------------------------------------------------------------------------
double *binlocX = h->binlocx;
double *binlocY = h->binlocy;
double *binvalV = h->binvalv;
hsize_t sizeX[1] = { h->nbinsx };
hsize_t sizeY[1] = { h->nbinsy };
hsize_t SizeX[1] = { h->nbinsx + 1 }; // to hold bin edges
hsize_t SizeY[1] = { h->nbinsy + 1 }; // below, cap S/F refers to bin edges
hsize_t sizeZ[2] = { h->nbinsx, h->nbinsy };
hid_t fspcZ = H5Screate_simple(h->n_dims, sizeZ, NULL);
if (h->n_dims >= 1) {
hid_t fspcX = H5Screate_simple(1, sizeX, NULL);
hid_t FspcX = H5Screate_simple(1, SizeX, NULL);
hid_t dsetbinX = H5Dcreate(grp, "binlocX", H5T_NATIVE_DOUBLE, fspcX,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
hid_t dsetedgX = H5Dcreate(grp, "binedgX", H5T_NATIVE_DOUBLE, FspcX,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dsetbinX, H5T_NATIVE_DOUBLE, fspcX, fspcX, H5P_DEFAULT, binlocX);
H5Dwrite(dsetedgX, H5T_NATIVE_DOUBLE, FspcX, FspcX, H5P_DEFAULT, h->bedgesx);
H5Dclose(dsetbinX);
H5Sclose(FspcX);
H5Sclose(fspcX);
}
if (h->n_dims >= 2) {
hid_t fspcY = H5Screate_simple(1, sizeY, NULL);
hid_t FspcY = H5Screate_simple(1, SizeY, NULL);
hid_t dsetbinY = H5Dcreate(grp, "binlocY", H5T_NATIVE_DOUBLE, fspcY,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
hid_t dsetedgY = H5Dcreate(grp, "binedgY", H5T_NATIVE_DOUBLE, FspcY,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
//.........这里部分代码省略.........
开发者ID:geoffryan,项目名称:calvis,代码行数:101,代码来源:hist.c
示例12: main
int main(int argc , char **argv)
{
BYTE *Image;
/* compression structs */
CHAR *HDFName = NULL;
CHAR *GIFName = NULL;
BYTE* b;
BYTE GlobalPalette[256][3];
BYTE Red[256];
BYTE Green[256];
BYTE Blue[256];
int RWidth, RHeight;
int ColorMapSize, InitCodeSize, Background, BitsPerPixel;
int j,nc;
int i;
int numcols;
BYTE pc2nc[256] , r1[256] , g1[256] , b1[256];
int arg_index = 2;
int bool_is_image = 0; /* 0 = false , 1 = true */
char *image_name = NULL;
int idx;
if ( argv[1] && (strcmp("-V",argv[1])==0) )
{
print_version("gif2h5");
exit(EXIT_SUCCESS);
}
if (argc < 4)
{
/* they didn't supply at least one image -- bail */
usage();
return 1;
}
HDFName = argv[1];
GIFName = argv[2];
/* get the options */
while (arg_index++ < argc - 1)
{
if (!strcmp(argv[arg_index] , "-i")) {
bool_is_image = 1;
continue;
}
if (bool_is_image)
{
/* allocate space to store the image name */
size_t len = strlen(argv[arg_index]);
image_name = (CHAR*) malloc( len + 1);
strcpy(image_name , argv[arg_index]);
bool_is_image = 0;
continue;
}
/* oops. This was not meant to happen */
usage();
goto out;
}
/* Do Endian Order testing and set Endian Order */
idx = 0x0001;
b = (BYTE *) &idx;
EndianOrder = (b[0] ? 1:0);
if (!(fpGif = fopen(GIFName , "wb")))
{
printf("Error opening gif file for output. Aborting.\n");
goto out;
}
Background = 0;
{
hsize_t width, height, planes;
hid_t fid;
char interlace[20];
hssize_t npals;
hsize_t pal_dims[2];
unsigned char *pal;
if ((fid = H5Fopen(HDFName , H5F_ACC_RDONLY , H5P_DEFAULT)) < 0)
{
fprintf(stderr , "Unable to open HDF file for input. Aborting.\n");
goto out;
}
/* read image */
if ( H5IMget_image_info( fid, image_name, &width, &height, &planes, interlace, &npals ) < 0 )
goto out;
//.........这里部分代码省略.........
开发者ID:MattNapsAlot,项目名称:rHDF5,代码行数:101,代码来源:hdf2gif.c
示例13: main
/*-------------------------------------------------------------------------
* Function: main
*
* Purpose: HDF5 user block unjammer
*
* Return: Success: 0
* Failure: 1
*
* Programmer:
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
int
main(int argc, const char *argv[])
{
void *edata;
H5E_auto2_t func;
hid_t ifile = -1;
hid_t plist = -1;
off_t fsize;
hsize_t usize;
htri_t testval;
herr_t status;
int res;
h5_stat_t sbuf;
h5tools_setprogname(PROGRAMNAME);
h5tools_setstatus(EXIT_SUCCESS);
/* Disable error reporting */
H5Eget_auto2(H5E_DEFAULT, &func, &edata);
H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
/* Initialize h5tools lib */
h5tools_init();
if(EXIT_FAILURE == parse_command_line(argc, argv))
goto done;
if (input_file == NULL) {
/* no user block */
error_msg("missing arguemnt for HDF5 file input.\n");
help_ref_msg(stderr);
h5tools_setstatus(EXIT_FAILURE);
goto done;
}
testval = H5Fis_hdf5(input_file);
if (testval <= 0) {
error_msg("Input HDF5 file \"%s\" is not HDF\n", input_file);
help_ref_msg (stderr);
h5tools_setstatus(EXIT_FAILURE);
goto done;
}
ifile = H5Fopen(input_file, H5F_ACC_RDONLY , H5P_DEFAULT);
if (ifile < 0) {
error_msg("Can't open input HDF5 file \"%s\"\n", input_file);
h5tools_setstatus(EXIT_FAILURE);
goto done;
}
plist = H5Fget_create_plist(ifile);
if (plist < 0) {
error_msg("Can't get file creation plist for file \"%s\"\n", input_file);
h5tools_setstatus(EXIT_FAILURE);
goto done;
}
status = H5Pget_userblock(plist, & usize);
if (status < 0) {
error_msg("Can't get user block for file \"%s\"\n", input_file);
h5tools_setstatus(EXIT_FAILURE);
goto done;
}
status = H5Pclose(plist);
HDassert(status >= 0);
status = H5Fclose(ifile);
HDassert(status >= 0);
if (usize == 0) {
/* no user block to remove: message? */
error_msg("\"%s\" has no user block: no change to file\n", input_file);
h5tools_setstatus(EXIT_SUCCESS);
goto done;
}
res = HDfstat(HDfileno(rawinstream), &sbuf);
if(res < 0) {
error_msg("Can't stat file \"%s\"\n", input_file);
h5tools_setstatus(EXIT_FAILURE);
goto done;
}
fsize = sbuf.st_size;
//.........这里部分代码省略.........
开发者ID:AndyHuang7601,项目名称:EpicGames-UnrealEngine,代码行数:101,代码来源:h5unjam.c
示例14: strlen
GDALDataset *HDF5ImageDataset::Open( GDALOpenInfo * poOpenInfo )
{
int i;
HDF5ImageDataset *poDS;
char szFilename[2048];
if(!EQUALN( poOpenInfo->pszFilename, "HDF5:", 5 ) ||
|
请发表评论