这篇教程C++ H5Fopen函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中H5Fopen函数的典型用法代码示例。如果您正苦于以下问题:C++ H5Fopen函数的具体用法?C++ H5Fopen怎么用?C++ H5Fopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了H5Fopen函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,
示例2: h5repack_cmp_plint 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,
示例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,
示例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_ttest_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,
示例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,
示例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 inttoomany(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,
示例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_ttest_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,
示例8: mainintmain (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,
示例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,
示例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,
示例11: cow_histogram_dumphdf5void 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,
示例12: mainint 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,
示例13: main/*------------------------------------------------------------------------- * Function: main * * Purpose: HDF5 user block unjammer * * Return: Success: 0 * Failure: 1 * * Programmer: * * Modifications: * *------------------------------------------------------------------------- */intmain(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,
示例14: strlenGDALDataset *HDF5ImageDataset::Open( GDALOpenInfo * poOpenInfo ){ int i; HDF5ImageDataset *poDS; char szFilename[2048]; if(!EQUALN( poOpenInfo->pszFilename, "HDF5:", 5 ) || strlen(poOpenInfo->pszFilename) > sizeof(szFilename) - 3 ) return NULL;/* -------------------------------------------------------------------- *//* Confirm the requested access is supported. *//* -------------------------------------------------------------------- */ if( poOpenInfo->eAccess == GA_Update ) { CPLError( CE_Failure, CPLE_NotSupported, "The HDF5ImageDataset driver does not support update access to existing" " datasets./n" ); return NULL; } poDS = new HDF5ImageDataset(); /* -------------------------------------------------------------------- */ /* Create a corresponding GDALDataset. */ /* -------------------------------------------------------------------- */ /* printf("poOpenInfo->pszFilename %s/n",poOpenInfo->pszFilename); */ char **papszName = CSLTokenizeString2( poOpenInfo->pszFilename, ":", CSLT_HONOURSTRINGS|CSLT_PRESERVEESCAPES ); if( !((CSLCount(papszName) == 3) || (CSLCount(papszName) == 4)) ) { CSLDestroy(papszName); delete poDS; return NULL; } poDS->SetDescription( poOpenInfo->pszFilename ); /* -------------------------------------------------------------------- */ /* Check for drive name in windows HDF5:"D:/... */ /* -------------------------------------------------------------------- */ strcpy(szFilename, papszName[1]); if( strlen(papszName[1]) == 1 && papszName[3] != NULL ) { strcat(szFilename, ":"); strcat(szFilename, papszName[2]); poDS->SetSubdatasetName( papszName[3] ); } else poDS->SetSubdatasetName( papszName[2] ); CSLDestroy(papszName); papszName = NULL; if( !H5Fis_hdf5(szFilename) ) { delete poDS; return NULL; } poDS->SetPhysicalFilename( szFilename ); /* -------------------------------------------------------------------- */ /* Try opening the dataset. */ /* -------------------------------------------------------------------- */ poDS->hHDF5 = H5Fopen(szFilename, H5F_ACC_RDONLY, H5P_DEFAULT ); if( poDS->hHDF5 < 0 ) { delete poDS; return NULL; } poDS->hGroupID = H5Gopen( poDS->hHDF5, "/" ); if( poDS->hGroupID < 0 ) { poDS->bIsHDFEOS=false; delete poDS; return NULL; }/* -------------------------------------------------------------------- *//* THIS IS AN HDF5 FILE *//* -------------------------------------------------------------------- */ poDS->bIsHDFEOS=TRUE; poDS->ReadGlobalAttributes( FALSE );/* -------------------------------------------------------------------- *//* Create HDF5 Data Hierarchy in a link list *//* -------------------------------------------------------------------- */ poDS->poH5Objects = poDS->HDF5FindDatasetObjectsbyPath( poDS->poH5RootGroup, (char *)poDS->GetSubdatasetName() ); if( poDS->poH5Objects == NULL ) {//.........这里部分代码省略.........
开发者ID:afarnham,项目名称:gdal,代码行数:101,
示例15: cklinks/*------------------------------------------------------------------------- * Function: cklinks * * Purpose: Open the file created in the first step and check that the * links look correct. * * Return: Success: 0 * * Failure: -1 * * Programmer: Robb Matzke * Friday, August 14, 1998 * * Modifications: * *------------------------------------------------------------------------- */static intcklinks(hid_t fapl){ hid_t file; H5G_stat_t sb1, sb2; char linkval[LINK_BUF_SIZE]; char filename[NAME_BUF_SIZE]; herr_t status; TESTING("link queries"); /* Open the file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if ((file=H5Fopen(filename, H5F_ACC_RDONLY, fapl))<0) { goto error; } /* Hard link */ if (H5Gget_objinfo(file, "d1", TRUE, &sb1)<0) goto error; if (H5Gget_objinfo(file, "grp1/hard", TRUE, &sb2)<0) goto error; if (H5G_DATASET!=sb2.type) { H5_FAILED(); puts(" Unexpected object type should have been a dataset"); goto error; } if (sb1.objno[0]!=sb2.objno[0] || sb1.objno[1]!=sb2.objno[1]) { H5_FAILED(); puts(" Hard link test failed. Link seems not to point to the "); puts(" expected file location."); goto error; } /* Symbolic link */ if (H5Gget_objinfo(file, "grp1/soft", TRUE, &sb2)<0) goto error; if (H5G_DATASET!=sb2.type) { H5_FAILED(); puts(" Unexpected object type should have been a dataset"); goto error; } if (sb1.objno[0]!=sb2.objno[0] || sb1.objno[1]!=sb2.objno[1]) { H5_FAILED(); puts(" Soft link test failed. Link seems not to point to the "); puts(" expected file location."); goto error; } if (H5Gget_linkval(file, "grp1/soft", sizeof linkval, linkval)<0) { goto error; } if (HDstrcmp(linkval, "/d1")) { H5_FAILED(); puts(" Soft link test failed. Wrong link value"); goto error; } /* Dangling link */ H5E_BEGIN_TRY { status = H5Gget_objinfo(file, "grp1/dangle", TRUE, &sb2); } H5E_END_TRY; if (status>=0) { H5_FAILED(); puts(" H5Gget_objinfo() should have failed for a dangling link."); goto error; } if (H5Gget_objinfo(file, "grp1/dangle", FALSE, &sb2)<0) goto error; if (H5G_LINK!=sb2.type) { H5_FAILED(); puts(" Unexpected object type should have been a symbolic link"); goto error; } if (H5Gget_linkval(file, "grp1/dangle", sizeof linkval, linkval)<0) { goto error; } if (HDstrcmp(linkval, "foobar")) { H5_FAILED(); puts(" Dangling link test failed. Wrong link value"); goto error; } /* Recursive link */ H5E_BEGIN_TRY { status = H5Gget_objinfo(file, "grp1/recursive", TRUE, &sb2); } H5E_END_TRY; if (status>=0) {//.........这里部分代码省略.........
开发者ID:MattNapsAlot,项目名称:rHDF5,代码行数:101,
示例16: mainintmain (void){ hid_t file, filetype, memtype, space, dset, attr; /* Handles */ herr_t status; hvl_t wdata[2], /* Array of vlen structures */ *rdata; /* Pointer to vlen structures */ hsize_t dims[1] = {2}; int *ptr, ndims, i, j; /* * Initialize variable-length data. wdata[0] is a countdown of * length LEN0, wdata[1] is a Fibonacci sequence of length LEN1. */ wdata[0].len = LEN0; ptr = (int *) malloc (wdata[0].len * sizeof (int)); for (i=0; i<wdata[0].len; i++) ptr[i] = wdata[0].len - i; /* 3 2 1 */ wdata[0].p = (void *) ptr; wdata[1].len = LEN1; ptr = (int *) malloc (wdata[1].len * sizeof (int)); ptr[0] = 1; ptr[1] = 1; for (i=2; i<wdata[1].len; i++) ptr[i] = ptr[i-1] + ptr[i-2]; /* 1 1 2 3 5 8 etc. */ wdata[1].p = (void *) ptr; /* * Create a new file using the default properties. */ file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Create variable-length datatype for file and memory. */ filetype = H5Tvlen_create (H5T_STD_I32LE); memtype = H5Tvlen_create (H5T_NATIVE_INT); /* * Create dataset with a scalar dataspace. */ 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 variable-length data to it */ attr = H5Acreate (dset, ATTRIBUTE, filetype, space, H5P_DEFAULT); status = H5Awrite (attr, memtype, wdata); /* * Close and release resources. Note the use of H5Dvlen_reclaim * removes the need to manually free() the previously malloc'ed * data. */ status = H5Dvlen_reclaim (memtype, space, H5P_DEFAULT, wdata); status = H5Aclose (attr); status = H5Dclose (dset); status = H5Sclose (space); status = H5Tclose (filetype); status = H5Tclose (memtype); 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 array of vlen structures. * This does not actually allocate memory for the vlen data, that * will be done by the library. */ space = H5Aget_space (attr); ndims = H5Sget_simple_extent_dims (space, dims, NULL); rdata = (hvl_t *) malloc (dims[0] * sizeof (hvl_t)); /* * Create the memory datatype.//.........这里部分代码省略.........
开发者ID:FrankLIKE,项目名称:d_hdf5,代码行数:101,
示例17: ck_new_links/*------------------------------------------------------------------------- * Function: ck_new_links * * Purpose: Open the file created in the first step and check that the * links look correct. * * Return: Success: 0 * * Failure: -1 * * Programmer: Raymond Lu * Thursday, April 25, 2002 * * Modifications: * *------------------------------------------------------------------------- */static intck_new_links(hid_t fapl){ hid_t file; H5G_stat_t sb_dset, sb_hard1, sb_hard2, sb_soft1, sb_soft2; char filename[NAME_BUF_SIZE]; char linkval[LINK_BUF_SIZE]; TESTING("new link queries"); /* Open the file */ h5_fixname(FILENAME[1], fapl, filename, sizeof filename); if ((file=H5Fopen(filename, H5F_ACC_RDONLY, fapl))<0) { goto error; } /* Get hard link info */ if(H5Gget_objinfo(file, "/grp1/dataset2", TRUE, &sb_dset)<0) goto error; if(H5Gget_objinfo(file, "/grp1/hard1", TRUE, &sb_hard1)<0) goto error; if(H5Gget_objinfo(file, "/grp2/hard2", TRUE, &sb_hard2)<0) goto error; /* Check hard links */ if(H5G_DATASET!=sb_hard1.type || H5G_DATASET!=sb_hard2.type) { H5_FAILED(); puts(" Unexpected object type, should have been a dataset"); goto error; } if( sb_dset.objno[0]!=sb_hard1.objno[0] || sb_dset.objno[1]!=sb_hard1.objno[1] || sb_dset.objno[0]!=sb_hard2.objno[0] || sb_dset.objno[1]!=sb_hard2.objno[1] ) { H5_FAILED(); puts(" Hard link test failed. Link seems not to point to the "); puts(" expected file location."); goto error; } /* Get soft link info */ if(H5Gget_objinfo(file, "/grp1/soft1", TRUE, &sb_soft1)<0) goto error; if(H5Gget_objinfo(file, "/grp2/soft2", TRUE, &sb_soft2)<0) goto error; /* Check soft links */ if(H5G_DATASET!=sb_soft1.type || H5G_DATASET!=sb_soft2.type) { H5_FAILED(); puts(" Unexpected object type, should have been a dataset"); goto error; } if( sb_dset.objno[0]!=sb_soft1.objno[0] || sb_dset.objno[1]!=sb_soft1.objno[1] || sb_dset.objno[0]!=sb_soft2.objno[0] || sb_dset.objno[1]!=sb_soft2.objno[1] ) { H5_FAILED(); puts(" Soft link test failed. Link seems not to point to the "); puts(" expected file location."); goto error; } if (H5Gget_linkval(file, "grp2/soft2", sizeof linkval, linkval)<0) { goto error; } if (HDstrcmp(linkval, "/grp1/dataset2")) { H5_FAILED(); puts(" Soft link test failed. Wrong link value"); goto error; } /* Cleanup */ if(H5Fclose(file)<0) goto error; PASSED(); return 0; error: return -1;}
开发者ID:MattNapsAlot,项目名称:rHDF5,代码行数:95,
示例18: _io_writevoid _io_write(cow_dfield *f, char *fname)// -----------------------------------------------------------------------------// This function uses a collective MPI-IO procedure to write the contents of// 'data' to the HDF5 file named 'fname', which is assumed to have been created// already. The dataset with name 'dname', which is being written to, must not// exist already. Chunking is enabled as per the ChunkSize variable, and is// disabled by default. Recommended chunk size is local subdomain size. This// will result in optimized read/write on the same decomposition layout, but// poor performance for different access patterns, for example the slabs used by// cluster-FFT functions.//// WARNING!//// All processors must define the same chunk size, the behavior of this function// is not defined otherwise. This implies that chunking should be disabled when// running on a strange number of cores, and subdomain sizes are non-uniform.// -----------------------------------------------------------------------------{#if (COW_HDF5) cow_domain *d = f->domain; char **pnames = f->members; void *data = f->data; char *gname = f->name; int n_memb = f->n_members; int n_dims = d->n_dims; hsize_t *L_nint = d->L_nint_h5; hsize_t *G_strt = d->G_strt_h5; hsize_t *G_ntot = d->G_ntot_h5; hsize_t ndp1 = n_dims + 1; hsize_t l_nint[4]; hsize_t l_ntot[4]; hsize_t l_strt[4]; hsize_t stride[4]; for (int i=0; i<n_dims; ++i) { l_nint[i] = d->L_nint[i]; // Selection size, target and destination l_ntot[i] = d->L_ntot[i]; // Memory space total size l_strt[i] = d->L_strt[i]; // Memory space selection start stride[i] = 1; } l_nint[ndp1 - 1] = 1; l_ntot[ndp1 - 1] = n_memb; stride[ndp1 - 1] = n_memb; // The loop over processors is needed if COW_MPI support is enabled and // COW_HDF5_MPI is not. If either COW_MPI is disabled, or COW_HDF5_MPI is // enabled, then the write calls occur without the loop. // ---------------------------------------------------------------------------#if (!COW_HDF5_MPI && COW_MPI) for (int rank=0; rank<d->cart_size; ++rank) { if (rank == d->cart_rank) {#endif hid_t file = H5Fopen(fname, H5F_ACC_RDWR, d->fapl); hid_t memb = H5Gopen(file, gname, H5P_DEFAULT); hid_t mspc = H5Screate_simple(ndp1, l_ntot, NULL); hid_t fspc = H5Screate_simple(n_dims, G_ntot, NULL); for (int n=0; n<n_memb; ++n) { int dset = H5Dcreate(memb, pnames[n], H5T_NATIVE_DOUBLE, fspc, H5P_DEFAULT, d->dcpl, H5P_DEFAULT); l_strt[ndp1 - 1] = n; H5Sselect_hyperslab(mspc, H5S_SELECT_SET, l_strt, stride, l_nint, NULL); H5Sselect_hyperslab(fspc, H5S_SELECT_SET, G_strt, NULL, L_nint, NULL); H5Dwrite(dset, H5T_NATIVE_DOUBLE, mspc, fspc, d->dxpl, data); H5Dclose(dset); } H5Sclose(fspc); H5Sclose(mspc); H5Gclose(memb); H5Fclose(file);#if (!COW_HDF5_MPI && COW_MPI) } if (cow_mpirunning()) { MPI_Barrier(d->mpi_cart); } }#endif // !COW_HDF5_MPI && COW_MPI#endif}
开发者ID:darien0,项目名称:cow,代码行数:79,
示例19: H5Fopen//------------------------------------------------------------------------------vtkPolyData *vtkAMRSimPlaParticlesReader::GetParticles( const char *file, const int blockIdx){ vtkPolyData *particles = vtkPolyData::New(); vtkPoints *positions = vtkPoints::New(); positions->SetDataTypeToDouble(); vtkPointData *pdata = particles->GetPointData(); hid_t fileIndx = H5Fopen(file, H5F_ACC_RDONLY, H5P_DEFAULT); if (fileIndx < 0) { vtkErrorMacro("Failed opening particles file!"); return NULL; } hid_t rootIndx; if (!FindBlockIndex(fileIndx, blockIdx + 1, rootIndx)) { vtkErrorMacro("Could not locate target block!"); return NULL; } // // Load the particles position arrays by name. // In SimPla the following arrays are available: // ( 1 ) particle_position_i // ( 2 ) tracer_particle_position_i // // where i /in {x,y,z}. std::vector<double> xcoords; std::vector<double> ycoords; std::vector<double> zcoords; // TODO: should we handle 2-D particle datasets? GetDoubleArrayByName(rootIndx, "particle_position_x", xcoords); GetDoubleArrayByName(rootIndx, "particle_position_y", ycoords); GetDoubleArrayByName(rootIndx, "particle_position_z", zcoords); vtkIntArray *particleTypes = vtkIntArray::SafeDownCast( this->GetParticlesTypeArray(blockIdx)); assert("Coordinate arrays must have the same size: " && (xcoords.size() == ycoords.size())); assert("Coordinate arrays must have the same size: " && (ycoords.size() == zcoords.size())); int TotalNumberOfParticles = static_cast<int>(xcoords.size()); positions->SetNumberOfPoints(TotalNumberOfParticles); vtkIdList *ids = vtkIdList::New(); ids->SetNumberOfIds(TotalNumberOfParticles); vtkIdType NumberOfParticlesLoaded = 0; for (int i = 0; i < TotalNumberOfParticles; ++i) { if ((i % this->Frequency) == 0) { if (this->CheckLocation(xcoords[i], ycoords[i], zcoords[i]) && this->CheckParticleType(i, particleTypes)) { int pidx = NumberOfParticlesLoaded; ids->InsertId(pidx, i); positions->SetPoint(pidx, xcoords[i], ycoords[i], zcoords[i]); ++NumberOfParticlesLoaded; } // END if within requested region } // END if within requested interval } // END for all particles H5Gclose(rootIndx); H5Fclose(fileIndx); ids->SetNumberOfIds(NumberOfParticlesLoaded); ids->Squeeze(); positions->SetNumberOfPoints(NumberOfParticlesLoaded); positions->Squeeze(); particles->SetPoints(positions); positions->Delete(); // Create CellArray consisting of a single polyvertex cell vtkCellArray *polyVertex = vtkCellArray::New(); polyVertex->InsertNextCell(NumberOfParticlesLoaded); for (vtkIdType idx = 0; idx < NumberOfParticlesLoaded; ++idx) polyVertex->InsertCellPoint(idx); particles->SetVerts(polyVertex); polyVertex->Delete(); // Release the particle types array particleTypes->Delete(); int numArrays = this->ParticleDataArraySelection->GetNumberOfArrays(); for (int i = 0; i < numArrays; ++i) { const char *name = this->ParticleDataArraySelection->GetArrayName(i); if (this->ParticleDataArraySelection->ArrayIsEnabled(name)) { // Note: 0-based indexing is used for loading particles//.........这里部分代码省略.........
开发者ID:kwosingyu,项目名称:SimPla,代码行数:101,
示例20: _io_readvoid _io_read(cow_dfield *f, char *fname){#if (COW_HDF5) cow_domain *d = f->domain; char **pnames = f->members; void *data = f->data; char *gname = f->name; int n_memb = f->n_members; int n_dims = d->n_dims; hsize_t *L_nint = d->L_nint_h5; hsize_t *G_strt = d->G_strt_h5; hsize_t *G_ntot = d->G_ntot_h5; hsize_t ndp1 = n_dims + 1; hsize_t l_nint[4]; hsize_t l_ntot[4]; hsize_t l_strt[4]; hsize_t stride[4]; for (int i=0; i<n_dims; ++i) { l_nint[i] = d->L_nint[i]; // Selection size, target and destination l_ntot[i] = d->L_ntot[i]; // Memory space total size l_strt[i] = d->L_strt[i]; // Memory space selection start stride[i] = 1; } l_nint[ndp1 - 1] = 1; l_ntot[ndp1 - 1] = n_memb; stride[ndp1 - 1] = n_memb; // The loop over processors is needed if COW_MPI support is enabled and // COW_HDF5_MPI is not. If either COW_MPI is disabled, or COW_HDF5_MPI is // enabled, then the write calls occur without the loop. // ---------------------------------------------------------------------------#if (!COW_HDF5_MPI && COW_MPI) for (int rank=0; rank<d->cart_size; ++rank) { if (rank == d->cart_rank) {#endif hid_t file = H5Fopen(fname, H5F_ACC_RDONLY, d->fapl); hid_t memb = H5Gopen(file, gname, H5P_DEFAULT); hid_t mspc = H5Screate_simple(ndp1, l_ntot, NULL); hid_t fspc = H5Screate_simple(n_dims, G_ntot, NULL); for (int n=0; n<n_memb; ++n) { hid_t dset = H5Dopen(memb, pnames[n], H5P_DEFAULT); l_strt[ndp1 - 1] = n; H5Sselect_hyperslab(mspc, H5S_SELECT_SET, l_strt, stride, l_nint, NULL); H5Sselect_hyperslab(fspc, H5S_SELECT_SET, G_strt, NULL, L_nint, NULL); H5Dread(dset, H5T_NATIVE_DOUBLE, mspc, fspc, d->dxpl, data); H5Dclose(dset); } H5Sclose(fspc); H5Sclose(mspc); H5Gclose(memb); H5Fclose(file);#if (!COW_HDF5_MPI && COW_MPI) } if (cow_mpirunning()) { MPI_Barrier(d->mpi_cart); } }#endif // !COW_HDF5_MPI && COW_MPI#endif}
开发者ID:darien0,项目名称:cow,代码行数:62,
示例21: test_family/*------------------------------------------------------------------------- * Function: test_family * * Purpose: Tests the file handle interface for FAMILY 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 * June 2, 2005 * Added a function test_family_opens() to test different * wrong way to reopen family files. * *------------------------------------------------------------------------- */static herr_ttest_family(void){ hid_t file=(-1), fapl, fapl2=(-1), space=(-1), dset=(-1); hid_t access_fapl = -1; char filename[1024]; char dname[]="dataset"; unsigned int i, j; int *fhandle=NULL, *fhandle2=NULL; int buf[FAMILY_NUMBER][FAMILY_SIZE]; hsize_t dims[2]={FAMILY_NUMBER, FAMILY_SIZE}; hsize_t file_size; TESTING("FAMILY file driver"); /* Set property list and file name for FAMILY driver */ fapl = h5_fileaccess(); if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT) < 0) TEST_ERROR; h5_fixname(FILENAME[2], fapl, filename, sizeof filename); if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Test different wrong ways to reopen family files where there's only * one member file existing. */ if(test_family_opens(filename, fapl) < 0) TEST_ERROR; /* Reopen the file with default member file size */ if(H5Pset_fapl_family(fapl, (hsize_t)H5F_FAMILY_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR; if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; /* Check file size API */ if(H5Fget_filesize(file, &file_size) < 0) TEST_ERROR; /* The file size is supposed to be about 800 bytes right now. */ if(file_size < (KB / 2) || file_size > KB) TEST_ERROR; /* Create and write dataset */ if((space=H5Screate_simple(2, dims, NULL)) < 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((dset=H5Dcreate2(file, dname, H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; for(i=0; i<FAMILY_NUMBER; i++) for(j=0; j<FAMILY_SIZE; j++) buf[i][j] = i*10000+j; if(H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) TEST_ERROR; /* check file handle API */ if((fapl2=H5Pcreate(H5P_FILE_ACCESS)) < 0) TEST_ERROR; if(H5Pset_family_offset(fapl2, (hsize_t)0) < 0) TEST_ERROR;//.........这里部分代码省略.........
开发者ID:chaako,项目名称:sceptic3D,代码行数:101,
示例22: read_datastatic int read_data(char *fname){ char pathname[1024]; char *srcdir = getenv("srcdir"); /*where the src code is located*/ hid_t file, dataset; /* handles */ hid_t datatype; hid_t dt; double data_in[NX][NY]; /* input buffer */ double data_out[NX][NY]; /* output buffer */ int i, j; unsigned nerrors = 0; pathname[0] = '/0'; /* Generate correct name for test file by prepending the source path */ if(srcdir && ((strlen(srcdir) + strlen(fname) + 1) < sizeof(pathname))) { strcpy(pathname, srcdir); strcat(pathname, "/"); } strcat(pathname, fname); /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { data_in[j][i] = i + j; data_out[j][i] = 0; } } /* * 0 1 2 3 4 5 * 1 2 3 4 5 6 * 2 3 4 5 6 7 * 3 4 5 6 7 8 * 4 5 6 7 8 9 */ /* * Open the file and the dataset. */ if((file = H5Fopen(pathname, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) TEST_ERROR; if((dataset = H5Dopen2(file, DATASETNAME, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Get datatype and dataspace handles and then query * dataset class, order, size, rank and dimensions. */ if((dt = H5Dget_type(dataset)) < 0) /* datatype handle */ TEST_ERROR; if((datatype = H5Tget_native_type(dt, H5T_DIR_DEFAULT)) < 0) TEST_ERROR; /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<NX; j++) { for (i=0; i<NY; i++) { if (data_out[j][i] != data_in[j][i]) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %g but should have been %g/n", j, i, data_out[j][i], data_in[j][i]); } } } } /* * Close/release resources. */ H5Tclose(dt); H5Tclose(datatype); H5Dclose(dataset); H5Fclose(file); /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements/n", nerrors, NX*NY); return 1; } PASSED(); return 0;error: H5E_BEGIN_TRY { H5Fclose(file); } H5E_END_TRY; return 1;}
开发者ID:chaako,项目名称:sceptic3D,代码行数:97,
示例23: test_multi/*------------------------------------------------------------------------- * Function: test_multi * * Purpose: Tests the file handle interface for MUTLI 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. * *------------------------------------------------------------------------- */static herr_ttest_multi(void){ hid_t file=(-1), fapl, fapl2=(-1), dset=(-1), space=(-1); hid_t root, attr, aspace, atype; hid_t access_fapl = -1; char filename[1024]; int *fhandle2=NULL, *fhandle=NULL; hsize_t file_size; H5FD_mem_t mt, memb_map[H5FD_MEM_NTYPES]; hid_t memb_fapl[H5FD_MEM_NTYPES]; haddr_t memb_addr[H5FD_MEM_NTYPES]; const char *memb_name[H5FD_MEM_NTYPES]; char sv[H5FD_MEM_NTYPES][32]; hsize_t dims[2]={MULTI_SIZE, MULTI_SIZE}; hsize_t adims[1]={1}; char dname[]="dataset"; char meta[] = "this is some metadata on this file"; int i, j; int buf[MULTI_SIZE][MULTI_SIZE]; TESTING("MULTI file driver"); /* Set file access property list for MULTI driver */ fapl = h5_fileaccess(); HDmemset(memb_map, 0, sizeof memb_map); HDmemset(memb_fapl, 0, sizeof memb_fapl); HDmemset(memb_name, 0, sizeof memb_name); HDmemset(memb_addr, 0, sizeof memb_addr); HDmemset(sv, 0, sizeof sv); for(mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) { memb_fapl[mt] = H5P_DEFAULT; memb_map[mt] = H5FD_MEM_SUPER; } memb_map[H5FD_MEM_DRAW] = H5FD_MEM_DRAW; memb_map[H5FD_MEM_BTREE] = H5FD_MEM_BTREE; memb_map[H5FD_MEM_GHEAP] = H5FD_MEM_GHEAP; sprintf(sv[H5FD_MEM_SUPER], "%%s-%c.h5", 's'); memb_name[H5FD_MEM_SUPER] = sv[H5FD_MEM_SUPER]; memb_addr[H5FD_MEM_SUPER] = 0; sprintf(sv[H5FD_MEM_BTREE], "%%s-%c.h5", 'b'); memb_name[H5FD_MEM_BTREE] = sv[H5FD_MEM_BTREE]; memb_addr[H5FD_MEM_BTREE] = HADDR_MAX/4; sprintf(sv[H5FD_MEM_DRAW], "%%s-%c.h5", 'r'); memb_name[H5FD_MEM_DRAW] = sv[H5FD_MEM_DRAW]; memb_addr[H5FD_MEM_DRAW] = HADDR_MAX/2; sprintf(sv[H5FD_MEM_GHEAP], "%%s-%c.h5", 'g'); memb_name[H5FD_MEM_GHEAP] = sv[H5FD_MEM_GHEAP]; memb_addr[H5FD_MEM_GHEAP] = HADDR_MAX*3/4; if(H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, TRUE) < 0) TEST_ERROR; h5_fixname(FILENAME[4], fapl, filename, sizeof filename); if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Test wrong ways to reopen multi files */ if(test_multi_opens(filename) < 0) TEST_ERROR; /* Reopen the file */ if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; /* Create and write data set */ if((space=H5Screate_simple(2, dims, NULL)) < 0) TEST_ERROR; /* Retrieve the access property list... */ if ((access_fapl = H5Fget_access_plist(file)) < 0)//.........这里部分代码省略.........
开发者ID:chaako,项目名称:sceptic3D,代码行数:101,
示例24: mainint main (void){ hid_t file; hid_t grp; hid_t dataset, dataspace; hid_t plist; herr_t status; hsize_t dims[2]; hsize_t cdims[2]; int idx_f, idx_g; /* * Create a file. */ file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Create a group in the file. */ grp = H5Gcreate(file, "/Data", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); /* * Create dataset "Compressed Data" in the group using absolute * name. Dataset creation property list is modified to use * GZIP compression with the compression effort set to 6. * Note that compression can be used only when dataset is chunked. */ dims[0] = 1000; dims[1] = 20; cdims[0] = 20; cdims[1] = 20; dataspace = H5Screate_simple(RANK, dims, NULL); plist = H5Pcreate(H5P_DATASET_CREATE); H5Pset_chunk(plist, 2, cdims); H5Pset_deflate( plist, 6); dataset = H5Dcreate(file, "/Data/Compressed_Data", H5T_NATIVE_INT, dataspace, H5P_DEFAULT, plist, H5P_DEFAULT); /* * Close the first dataset . */ H5Sclose(dataspace); H5Dclose(dataset); /* * Create the second dataset. */ dims[0] = 500; dims[1] = 20; dataspace = H5Screate_simple(RANK, dims, NULL); dataset = H5Dcreate(file, "/Data/Float_Data", H5T_NATIVE_FLOAT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); /* *Close the second dataset and file. */ H5Sclose(dataspace); H5Dclose(dataset); H5Pclose(plist); H5Gclose(grp); H5Fclose(file); /* * Now reopen the file and group in the file. */ file = H5Fopen(H5FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT); grp = H5Gopen(file, "Data", H5P_DEFAULT); /* * Access "Compressed_Data" dataset in the group. */ dataset = H5Dopen(grp, "Compressed_Data", H5P_DEFAULT); if( dataset < 0) printf(" Dataset 'Compressed-Data' is not found. /n"); printf("/"/Data/Compressed_Data/" dataset is open /n"); /* * Close the dataset. */ status = H5Dclose(dataset); /* * Create hard link to the Data group. */ status = H5Lcreate_hard(file, "Data", H5L_SAME_LOC, "Data_new", H5P_DEFAULT, H5P_DEFAULT); /* * We can access "Compressed_Data" dataset using created * hard link "Data_new". */ dataset = H5Dopen(file, "/Data_new/Compressed_Data", H5P_DEFAULT); if( dataset < 0) printf(" Dataset is not found. /n"); printf("/"/Data_new/Compressed_Data/" dataset is open /n"); /* * Close the dataset. */ status = H5Dclose(dataset); //.........这里部分代码省略.........
开发者ID:SterVeen,项目名称:DAL1,代码行数:101,
示例25: mainintmain (void){ hid_t file, filetype, memtype, space, dset; /* Handles */ herr_t status; hsize_t dims[2] = {DIM0, DIM1}; phase_t wdata[DIM0][DIM1], /* Write buffer */ **rdata, /* Read buffer */ val; char *names[4] = {"SOLID", "LIQUID", "GAS", "PLASMA"}, name[NAME_BUF_SIZE]; int ndims, i, j; /* * Initialize data. */ for (i=0; i<DIM0; i++) for (j=0; j<DIM1; j++) wdata[i][j] = (phase_t) ( (i + 1) * j - j) % (int) (PLASMA + 1); /* * Create a new file using the default properties. */ file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Create the enumerated datatypes for file and memory. This * process is simplified if native types are used for the file, * as only one type must be defined. */ filetype = H5Tenum_create (F_BASET); memtype = H5Tenum_create (M_BASET); for (i = (int) SOLID; i <= (int) PLASMA; i++) { /* * Insert enumerated value for memtype. */ val = (phase_t) i; status = H5Tenum_insert (memtype, names[i], &val); /* * Insert enumerated value for filetype. We must first convert * the numerical value val to the base type of the destination. */ status = H5Tconvert (M_BASET, F_BASET, 1, &val, NULL, H5P_DEFAULT); status = H5Tenum_insert (filetype, names[i], &val); } /* * Create dataspace. Setting maximum size to NULL sets the maximum * size to be the current size. */ space = H5Screate_simple (2, dims, NULL); /* * Create the dataset and write the enumerated data to it. */ dset = H5Dcreate (file, DATASET, filetype, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); status = H5Dwrite (dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata[0]); /* * Close and release resources. */ status = H5Dclose (dset); status = H5Sclose (space); status = H5Tclose (filetype); status = H5Fclose (file); /* * Now we begin the read section of this example. Here we assume * the dataset has the same name and rank, but can have any size. * Therefore we must allocate a new array to read in data using * malloc(). For simplicity, we do not rebuild memtype. */ /* * Open file and dataset. */ file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT); dset = H5Dopen (file, DATASET, H5P_DEFAULT); /* * Get dataspace and allocate memory for read buffer. This is a * two dimensional dataset so the dynamic allocation must be done * in steps. */ space = H5Dget_space (dset); ndims = H5Sget_simple_extent_dims (space, dims, NULL); /* * Allocate array of pointers to rows. */ rdata = (phase_t **) malloc (dims[0] * sizeof (phase_t *)); /* * Allocate space for enumerated data. *///.........这里部分代码省略.........
开发者ID:LaHaine,项目名称:ohpc,代码行数:101,
示例26: read_file/*! This function reads a snapshot file and distributes the data it contains * to tasks 'readTask' to 'lastTask'. */void read_file(char *fname, int readTask, int lastTask){ int blockmaxlen; int i, n_in_file, n_for_this_task, ntask, pc, offset = 0, task; int blksize1, blksize2; MPI_Status status; FILE *fd = 0; int nall; int type; char label[4]; int nstart, bytes_per_blockelement, npart, nextblock, typelist[6]; enum iofields blocknr;#ifdef HAVE_HDF5 char buf[500]; int rank, pcsum; hid_t hdf5_file, hdf5_grp[6], hdf5_dataspace_in_file; hid_t hdf5_datatype, hdf5_dataspace_in_memory, hdf5_dataset; hsize_t dims[2], count[2], start[2];#endif#define SKIP {my_fread(&blksize1,sizeof(int),1,fd);}#define SKIP2 {my_fread(&blksize2,sizeof(int),1,fd);} if(ThisTask == readTask) { if(All.ICFormat == 1 || All.ICFormat == 2) { if(!(fd = fopen(fname, "r"))) { printf("can't open file `%s' for reading initial conditions./n", fname); endrun(123); } if(All.ICFormat == 2) { SKIP; my_fread(&label, sizeof(char), 4, fd); my_fread(&nextblock, sizeof(int), 1, fd); printf("Reading header => '%c%c%c%c' (%d byte)/n", label[0], label[1], label[2], label[3], nextblock); SKIP2; } SKIP; my_fread(&header, sizeof(header), 1, fd); SKIP2; if(blksize1 != 256 || blksize2 != 256) { printf("incorrect header format/n"); fflush(stdout); endrun(890); } }#ifdef HAVE_HDF5 if(All.ICFormat == 3) { read_header_attributes_in_hdf5(fname); hdf5_file = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT); for(type = 0; type < 6; type++) { if(header.npart[type] > 0) { sprintf(buf, "/PartType%d", type); hdf5_grp[type] = H5Gopen(hdf5_file, buf); } } }#endif for(task = readTask + 1; task <= lastTask; task++) MPI_Ssend(&header, sizeof(header), MPI_BYTE, task, TAG_HEADER, MPI_COMM_WORLD); } else MPI_Recv(&header, sizeof(header), MPI_BYTE, readTask, TAG_HEADER, MPI_COMM_WORLD, &status); if(All.TotNumPart == 0) { if(header.num_files <= 1) for(i = 0; i < 6; i++) header.npartTotal[i] = header.npart[i]; All.TotN_gas = header.npartTotal[0] + (((long long) header.npartTotalHighWord[0]) << 32); for(i = 0, All.TotNumPart = 0; i < 6; i++) { All.TotNumPart += header.npartTotal[i]; All.TotNumPart += (((long long) header.npartTotalHighWord[i]) << 32); }//.........这里部分代码省略.........
开发者ID:Christian-Schultz,项目名称:dark_energy,代码行数:101,
示例27: h5repack_verifyinth5repack_verify(const char *out_fname, pack_opt_t *options){ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ hid_t fidout = -1; /* file ID for output file*/ hid_t did = -1; /* dataset ID */ hid_t pid = -1; /* dataset creation property list ID */ hid_t sid = -1; /* space ID */ hid_t tid = -1; /* type ID */ unsigned int i; trav_table_t *travt = NULL; int ok = 1; /* open the output file */ if((fidout = H5Fopen(out_fname, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0 ) return -1; for(i = 0; i < options->op_tbl->nelems; i++) { char* name = options->op_tbl->objs[i].path; pack_info_t *obj = &options->op_tbl->objs[i]; /*------------------------------------------------------------------------- * open *------------------------------------------------------------------------- */ if((did = H5Dopen2(fidout, name, H5P_DEFAULT)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); if((sid = H5Dget_space(did)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); if((pid = H5Dget_create_plist(did)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed"); if((tid = H5Dget_type(did)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type failed"); /*------------------------------------------------------------------------- * filter check *------------------------------------------------------------------------- */ if(verify_filters(pid, tid, obj->nfilters, obj->filter) <= 0) ok = 0; /*------------------------------------------------------------------------- * layout check *------------------------------------------------------------------------- */ if((obj->layout != -1) && (verify_layout(pid, obj) == 0)) ok = 0; /*------------------------------------------------------------------------- * close *------------------------------------------------------------------------- */ if(H5Pclose(pid) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); if (H5Sclose(sid) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if (H5Dclose(did) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); if (H5Tclose(tid) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); } /*------------------------------------------------------------------------- * check for the "all" objects option *------------------------------------------------------------------------- */ if(options->all_filter == 1 || options->all_layout == 1) { /* init table */ trav_table_init(&travt); /* get the list of objects in the file */ if(h5trav_gettable(fidout, travt) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5trav_gettable failed"); for(i = 0; i < travt->nobjs; i++) { char *name = travt->objs[i].name; if(travt->objs[i].type == H5TRAV_TYPE_DATASET) { /*------------------------------------------------------------------------- * open *------------------------------------------------------------------------- */ if((did = H5Dopen2(fidout, name, H5P_DEFAULT)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); if((sid = H5Dget_space(did)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); if((pid = H5Dget_create_plist(did)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed"); if((tid = H5Dget_type(did)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type failed");//.........这里部分代码省略.........
开发者ID:AndyHuang7601,项目名称:EpicGames-UnrealEngine,代码行数:101,
示例28: mainintmain (void){ hid_t file, space, dtype, dset; /* Handles */ herr_t status; hsize_t dims[1] = {DIM0}; size_t len; char wdata[DIM0*LEN], /* Write buffer */ *rdata, /* Read buffer */ str[LEN] = "OPAQUE", *tag; int ndims, i, j; /* * Initialize data. */ for (i=0; i<DIM0; i++) { for (j=0; j<LEN-1; j++) wdata[j + i * LEN] = str[j]; wdata[LEN - 1 + i * LEN] = (char) i + '0'; } /* * Create a new file using the default properties. */ file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Create opaque datatype and set the tag to something appropriate. * For this example we will write and view the data as a character * array. */ dtype = H5Tcreate (H5T_OPAQUE, LEN); status = H5Tset_tag (dtype, "Character array"); /* * Create dataspace. Setting maximum size to NULL sets the maximum * size to be the current size. */ space = H5Screate_simple (1, dims, NULL); /* * Create the dataset and write the opaque data to it. */ dset = H5Dcreate (file, DATASET, dtype, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); status = H5Dwrite (dset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata); /* * Close and release resources. */ status = H5Dclose (dset); status = H5Sclose (space); status = H5Tclose (dtype); status = H5Fclose (file); /* * Now we begin the read section of this example. Here we assume * the dataset 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 and dataset. */ file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT); dset = H5Dopen (file, DATASET, H5P_DEFAULT); /* * Get datatype and properties for the datatype. Note that H5Tget_tag * allocates space for the string in tag, so we must remember to free() it * later. */ dtype = H5Dget_type (dset); len = H5Tget_size (dtype); tag = H5Tget_tag (dtype); /* * Get dataspace and allocate memory for read buffer. */ space = H5Dget_space (dset); ndims = H5Sget_simple_extent_dims (space, dims, NULL); rdata = (char *) malloc (dims[0] * len); /* * Read the data. */ status = H5Dread (dset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata); /* * Output the data to the screen. */ printf ("Datatype tag for %s is: /"%s/"/n", DATASET, tag); for (i=0; i<dims[0]; i++) { printf ("%s[%u]: ", DATASET, i); for (j=0; j<len; j++) printf ("%c", rdata[j + i * len]);//.........这里部分代码省略.........
开发者ID:LaHaine,项目名称:ohpc,代码行数:101,
示例29: mainint main() { double *data_out; // buffer int nx = 1/DX; // hyperslab and output buffer dimensions int ny = 1/DY; // int i, j; // Allocate memory for data if((data_out = (double *)malloc(STEPS * nx * ny * sizeof(double))) == NULL) printf("Error malloc matrix data_out[%d]/n",nx * ny); // Create NetCDF file. NC_CLOBBER tells NetCDF to overwrite this file, if it already exists int ncid, retval; // if( retval = nc_create( NC_FILE_NAME_NETCDF, NC_CLOBBER|NC_NETCDF4, &ncid ) ) { if( retval = nc_create( NC_FILE_NAME_NETCDF, NC_CLOBBER, &ncid ) ) { ERR_NETCDF(retval); } // Define the x and y dimensions. NetCDF will hand back and ID for each. int x_dimid, y_dimid, t_dimid; if( retval = nc_def_dim( ncid, "x", nx, &x_dimid ) ) { ERR_NETCDF(retval); } if( retval = nc_def_dim( ncid, "y", ny, &y_dimid ) ) { ERR_NETCDF(retval); } // Define the t dimension at NetCDF. if( retval = nc_def_dim( ncid, "t", NC_UNLIMITED, &t_dimid ) ) { ERR_NETCDF(retval); } // Define coordinate variables for x and y at NetCDF int x_varid, y_varid, t_varid; if( retval = nc_def_var( ncid, "x", NC_DOUBLE, 1, &x_dimid, &x_varid ) ) { ERR_NETCDF(retval); } if( retval = nc_def_var( ncid, "y", NC_DOUBLE, 1, &y_dimid, &y_varid ) ) { ERR_NETCDF(retval); } if( retval = nc_def_var( ncid, "t", NC_DOUBLE, 1, &t_dimid, &t_varid ) ) { ERR_NETCDF(retval); } // Define the nc-variable to store temperature data. The t dimension should be the one which varies more slowly at NetCDF. int varid; int dimids[3] = { t_dimid, x_dimid, y_dimid }; if( retval = nc_def_var( ncid, "temperature", NC_DOUBLE, 3, dimids, &varid )){ ERR_NETCDF(retval); } // Write x, y, t and temperature units at NetCDF char * space_units = "meters"; char * time_units = "seconds since start of the experiment"; char * temp_units = "kelvin"; if( retval = nc_put_att_text( ncid, x_varid, "units", strlen(space_units), space_units ) ) { ERR_NETCDF(retval); } if( retval = nc_put_att_text( ncid, y_varid, "units", strlen(space_units), space_units ) ) { ERR_NETCDF(retval); } if( retval = nc_put_att_text( ncid, t_varid, "units", strlen(time_units), time_units ) ) { ERR_NETCDF(retval); } if( retval = nc_put_att_text( ncid, varid, "units", strlen(temp_units), temp_units ) ) { ERR_NETCDF(retval); } double scale_factor = 300.0; if( retval = nc_put_att_double( ncid, varid, "scale_factor", NC_DOUBLE, 1, &scale_factor ) ) { ERR_NETCDF(retval); } // End define mode: this tells NetCDF that we are done defining metadata at NetCDF if( retval = nc_enddef( ncid ) ) { ERR_NETCDF(retval); } // Write x coordinates at NetCDF size_t pos; for( pos = 0; pos < nx; ++pos ) { double x = DX*pos; if( retval = nc_put_var1_double( ncid, x_varid, &pos, &x ) ) { ERR_NETCDF(retval); } } // Write y coordinates at NetCDF for( pos = 0; pos < ny; ++pos ) { double y = DY*pos; if( retval = nc_put_var1_double( ncid, y_varid, &pos, &y ) ) { ERR_NETCDF(retval); } } // Open an existing HDF5 file for Output buffer hid_t file_id = H5Fopen(H5_FILE_NAME_HDF5, H5F_ACC_RDONLY, H5P_DEFAULT); if( file_id < 0 ) { ERR_HDF5; } // Open an existing HDF5 dataset hid_t tempD = H5Dopen(file_id, "temperature", H5P_DEFAULT);//.........这里部分代码省略.........
开发者ID:xancandal,项目名称:hdf5-heat,代码行数:101,
示例30: load_H5_Data_4Dvoid* load_H5_Data_4D(const char* filename, int datatype, const char* datasetname, int W, int H, int D, int ox, int oy, int oz, int timestep, int comp, bool fit){// fprintf(stderr, "%s:%s()/n", __FILE__, __func__);//only handle h5 data with one component for now assert(comp == 1); hid_t input_file = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT); if (input_file < 0) { fprintf(stderr, "%s:%s(): Error opening input file %s/n", __FILE__, __func__, filename); exit(1); } hid_t dataset = H5Dopen(input_file, datasetname); if (dataset < 0) { H5Eprint(NULL); H5Fclose(input_file); fprintf(stderr, "Error opening dataset on file %s/n", filename); //throw IOException(string("Error opening dataset")); exit(1); } hid_t dataspace = H5Dget_space(dataset); assert(dataspace >=0); hsize_t maxdims[4]; hsize_t dims[4]; int dimensions = H5Sget_simple_extent_dims(dataspace, dims, maxdims); assert (dimensions == 4);#ifdef _DEBUG fprintf(stderr, "data dimension(%d, %d, %d, %d)/n", (int)dims[0], (int)dims[1], (int)dims[2], (int)dims[3]); fprintf(stderr, "origin(%d,%d,%d,%d), count(%d,%d,%d,%d)/n", ox, oy, oz, timestep, W, H, D, 1); if(fit) fprintf(stderr, "read data to fit/n");#endif hsize_t start[4]; hsize_t start_out[4]; hsize_t stride[4]; hsize_t stride_out[4]; hsize_t count[4]; hsize_t count_out[4]; hsize_t block[4]; hsize_t block_out[4]; start[0] = timestep; start_out[0] = 0; start[1] = oz; start_out[1] = 0; start[2] = oy; start_out[2] = 0; start[3] = ox; start_out[3] = 0; stride[0] = 1; stride_out[0] = 1; stride[1] = fit? dims[0]/D : 1; stride_out[1] = 1; stride[2] = fit? dims[1]/H : 1; stride_out[2] = 1; stride[3] = fit? dims[2]/W : 1; stride_out[3] = 1; count[0] = 1; count_out[0] = count[0]; count[1] = D; count_out[1] = count[1]; count[2] = H; count_out[2] = count[2]; count[3] = W; count_out[3] = count[3]; block[0] = 1; block_out[0] = 1; block[1] = 1; block_out[1] = 1; block[2] = 1; block_out[2] = 1; block[3] = 1; block_out[3] = 1; herr_t status; status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, start, stride, count, block); int b = get_depth(datatype); size_t my_val = count[0] * count[1] * count[2] * count[3] * b; //printf("set to read %ld bytes data/n", my_val); assert(H5Sget_select_npoints(dataspace) * b == my_val); //allocate the output buffer void *wholedata = malloc(my_val); if(wholedata == NULL) { fprintf(stderr, "can't allocate output buffer/n"); exit(1); } if ( status < 0 ) { H5Eprint(NULL); fprintf(stderr, "Cannot select data slab/n"); //throw IOException("Cannot select data slab");//.........这里部分代码省略.........
开发者ID:jinghuage,项目名称:pcaster,代码行数:101,
注:本文中的H5Fopen函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ H5Gcreate2函数代码示例 C++ H5Fcreate函数代码示例 |