这篇教程C++ H5Dread函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中H5Dread函数的典型用法代码示例。如果您正苦于以下问题:C++ H5Dread函数的具体用法?C++ H5Dread怎么用?C++ H5Dread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了H5Dread函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: main//.........这里部分代码省略......... printf(" Source filename %s/n", filename); /* Get source dataset name */ len = H5Pget_virtual_dsetname (dcpl, (size_t)i, NULL, 0); dsetname = (char *)malloc((size_t)len*sizeof(char)+1); H5Pget_virtual_dsetname (dcpl, (size_t)i, dsetname, len+1); printf(" Source dataset name %s/n", dsetname); /* Get selection in the source dataset */ printf(" Selection in the source dataset /n"); src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i); if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) { if (H5Sis_regular_hyperslab(src_space)) { status = H5Sget_regular_hyperslab (src_space, start_out, stride_out, count_out, block_out); printf(" start = [%llu, %llu, %llu] /n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]); printf(" stride = [%llu, %llu, %llu] /n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]); printf(" count = [%llu, %llu, %llu] /n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]); printf(" block = [%llu, %llu, %llu] /n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]); } } H5Sclose(vspace); H5Sclose(src_space); free(filename); free(dsetname); } /* * Read data from VDS. */ vspace = H5Dget_space (vdset); H5Sget_simple_extent_dims (vspace, vdsdims_out, vdsdims_max_out); printf ("VDS dimensions second time /n"); printf (" Current: "); for (i=0; i<RANK; i++) printf (" %d ", (int)vdsdims_out[i]); printf ("/n"); /* Read all VDS data */ /* EIP We should be able to do it by using H5S_ALL instead of making selection * or using H5Sselect_all from vspace. */ start[0] = 0; start[1] = 0; start[2] = 0; count[0] = 1; count[1] = 1; count[2] = 1; block[0] = vdsdims_out[0]; block[1] = vdsdims_out[1]; block[2] = vdsdims_out[2]; status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, NULL, count, block); mem_space = H5Screate_simple(RANK, vdsdims_out, NULL); status = H5Dread (vdset, H5T_NATIVE_INT, mem_space, vspace, H5P_DEFAULT, rdata); printf (" All data: /n"); for (i=0; i < (int)vdsdims_out[0]; i++) { for (j=0; j < (int)vdsdims_out[1]; j++) { printf ("(%d, %d, 0)", i, j); for (k=0; k < (int)vdsdims_out[2]; k++) printf (" %d ", rdata[i][j][k]); printf ("/n"); } } /* Read VDS, but only data mapeed to dataset a.h5 */ start[0] = 0; start[1] = 0; start[2] = 0; stride[0] = PLANE_STRIDE; stride[1] = 1; stride[2] = 1; count[0] = 2*DIM0_1; count[1] = 1; count[2] = 1; block[0] = 1; block[1] = vdsdims_out[1]; block[2] = vdsdims_out[2]; dims[0] = 2*DIM0_1; status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block); mem_space = H5Screate_simple(RANK, dims, NULL); status = H5Dread (vdset, H5T_NATIVE_INT, mem_space, vspace, H5P_DEFAULT, a_rdata); printf (" All data: /n"); for (i=0; i < 2*DIM0_1; i++) { for (j=0; j < (int)vdsdims_out[1]; j++) { printf ("(%d, %d, 0)", i, j); for (k=0; k < (int)vdsdims_out[2]; k++) printf (" %d ", a_rdata[i][j][k]); printf ("/n"); } } /* * Close and release resources. */ status = H5Sclose(mem_space); status = H5Pclose (dcpl); status = H5Dclose (vdset); status = H5Fclose (vfile); return 0;}
开发者ID:Starlink,项目名称:hdf5,代码行数:101,
示例2: import_structstatic types::InternalType* import_struct(int dataset){ //get struct dims node int complex = 0; std::vector<int> pdims; int size = getDimsNode(dataset, &complex, pdims); types::Struct* str = new types::Struct(static_cast<int>(pdims.size()), pdims.data()); size = str->getSize(); if (size == 0) { //empty struct closeList6(dataset); delete str; return new types::Struct(); } types::SingleStruct** sstr = str->get(); int fieldCount = 0; int ret = getListDims6(dataset, &fieldCount); if (ret < 0) { closeList6(dataset); return str; } //get fields name int dfield = getDataSetIdFromName(dataset, "__fields__"); int dim = 0; getDatasetInfo(dfield, &complex, &dim, NULL); std::vector<int> d(dim); size = getDatasetInfo(dfield, &complex, &dim, d.data()); if (size < 0) { closeList6(dataset); delete str; return nullptr; } //get dims value std::vector<char*> fields(size); readStringMatrix(dfield, fields.data()); //open __refs__ node int refs = getDataSetIdFromName(dataset, "__refs__"); for (const auto & name : fields) { wchar_t* field = to_wide_string(name); str->addField(field); int dataref = getDataSetIdFromName(dataset, name); if (dataref < 0) { closeList6(dataset); freeStringMatrix(dfield, fields.data()); FREE(field); delete str; return nullptr; } int refdim = 0; getDatasetInfo(dataref, &complex, &refdim, NULL); std::vector<int> refdims(refdim); int refcount = getDatasetInfo(dataref, &complex, &refdim, refdims.data()); std::vector<hobj_ref_t> vrefs(refcount); ret = H5Dread(dataref, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, vrefs.data()); if (ret < 0) { freeStringMatrix(dfield, fields.data()); FREE(field); delete str; return nullptr; } //import field for (int j = 0; j < refcount; ++j) { int data = H5Rdereference(refs, H5R_OBJECT, &vrefs[j]); if (data < 0) { freeStringMatrix(dfield, fields.data()); FREE(field); delete str; return nullptr; } types::InternalType* val = import_data(data); if (val == nullptr) { freeStringMatrix(dfield, fields.data()); FREE(field); delete str; return nullptr; } sstr[j]->set(field, val);//.........这里部分代码省略.........
开发者ID:ScilabOrg,项目名称:scilab,代码行数:101,
示例3: switchCPLErr HDF5ImageDataset::CreateProjections(){ switch(iSubdatasetType) { case CSK_PRODUCT: { const char *osMissionLevel = NULL; int productType = PROD_UNKNOWN; if(GetMetadataItem("Product_Type")!=NULL) { //Get the format's level osMissionLevel = HDF5Dataset::GetMetadataItem("Product_Type"); if(EQUALN(osMissionLevel,"RAW",3)) productType = PROD_CSK_L0; if(EQUALN(osMissionLevel,"SSC",3)) productType = PROD_CSK_L1A; if(EQUALN(osMissionLevel,"DGM",3)) productType = PROD_CSK_L1B; if(EQUALN(osMissionLevel,"GEC",3)) productType = PROD_CSK_L1C; if(EQUALN(osMissionLevel,"GTC",3)) productType = PROD_CSK_L1D; } CaptureCSKGeoTransform(productType); CaptureCSKGeolocation(productType); CaptureCSKGCPs(productType); break; } case UNKNOWN_PRODUCT: {#define NBGCPLAT 100#define NBGCPLON 30 hid_t LatitudeDatasetID = -1; hid_t LongitudeDatasetID = -1; hid_t LatitudeDataspaceID; hid_t LongitudeDataspaceID; float* Latitude; float* Longitude; int i,j; int nDeltaLat; int nDeltaLon; nDeltaLat = nRasterYSize / NBGCPLAT; nDeltaLon = nRasterXSize / NBGCPLON; if( nDeltaLat == 0 || nDeltaLon == 0 ) return CE_None; /* -------------------------------------------------------------------- */ /* Create HDF5 Data Hierarchy in a link list */ /* -------------------------------------------------------------------- */ poH5Objects=HDF5FindDatasetObjects( poH5RootGroup, "Latitude" ); if( !poH5Objects ) { return CE_None; } /* -------------------------------------------------------------------- */ /* The Lattitude and Longitude arrays must have a rank of 2 to */ /* retrieve GCPs. */ /* -------------------------------------------------------------------- */ if( poH5Objects->nRank != 2 ) { return CE_None; } /* -------------------------------------------------------------------- */ /* Retrieve HDF5 data information */ /* -------------------------------------------------------------------- */ LatitudeDatasetID = H5Dopen( hHDF5,poH5Objects->pszPath ); LatitudeDataspaceID = H5Dget_space( dataset_id ); poH5Objects=HDF5FindDatasetObjects( poH5RootGroup, "Longitude" ); LongitudeDatasetID = H5Dopen( hHDF5,poH5Objects->pszPath ); LongitudeDataspaceID = H5Dget_space( dataset_id ); if( ( LatitudeDatasetID > 0 ) && ( LongitudeDatasetID > 0) ) { Latitude = ( float * ) CPLCalloc( nRasterYSize*nRasterXSize, sizeof( float ) ); Longitude = ( float * ) CPLCalloc( nRasterYSize*nRasterXSize, sizeof( float ) ); memset( Latitude, 0, nRasterXSize*nRasterYSize*sizeof( float ) ); memset( Longitude, 0, nRasterXSize*nRasterYSize*sizeof( float ) ); H5Dread ( LatitudeDatasetID, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, Latitude ); H5Dread ( LongitudeDatasetID, H5T_NATIVE_FLOAT,//.........这里部分代码省略.........
开发者ID:imincik,项目名称:pkg-gdal,代码行数:101,
示例4: mainintmain (int argc, char **argv){ hid_t file_id, dset_id, grp_id; hid_t fapl, sid, mem_dataspace; herr_t ret; char filename[1024]; int mpi_size, mpi_rank, ndims, i, j; MPI_Comm comm = MPI_COMM_WORLD; MPI_Info info = MPI_INFO_NULL; hsize_t dims[RANK]; hsize_t start[RANK]; hsize_t count[RANK]; hsize_t stride[RANK]; hsize_t block[RANK]; DATATYPE *data_array = NULL, *dataptr; /* data buffer */ MPI_Init(&argc, &argv); MPI_Comm_size(comm, &mpi_size); MPI_Comm_rank(comm, &mpi_rank); if(MAINPROCESS) TESTING("proper shutdown of HDF5 library"); /* Set up file access property list with parallel I/O access */ fapl = H5Pcreate(H5P_FILE_ACCESS); VRFY((fapl >= 0), "H5Pcreate succeeded"); ret = H5Pset_fapl_mpio(fapl, comm, info); VRFY((ret >= 0), ""); h5_fixname(FILENAME[0], fapl, filename, sizeof filename); file_id = H5Fopen(filename, H5F_ACC_RDONLY, fapl); VRFY((file_id >= 0), "H5Fopen succeeded"); grp_id = H5Gopen2(file_id, "Group", H5P_DEFAULT); VRFY((grp_id >= 0), "H5Gopen succeeded"); dset_id = H5Dopen2(grp_id, "Dataset", H5P_DEFAULT); VRFY((dset_id >= 0), "H5Dopen succeeded"); sid = H5Dget_space(dset_id); VRFY((dset_id >= 0), "H5Dget_space succeeded"); ndims = H5Sget_simple_extent_dims(sid, dims, NULL); VRFY((ndims == 2), "H5Sget_simple_extent_dims succeeded"); VRFY(dims[0] == ROW_FACTOR*mpi_size, "Wrong dataset dimensions"); VRFY(dims[1] == COL_FACTOR*mpi_size, "Wrong dataset dimensions"); /* allocate memory for data buffer */ data_array = (DATATYPE *)HDmalloc(dims[0]*dims[1]*sizeof(DATATYPE)); VRFY((data_array != NULL), "data_array HDmalloc succeeded"); /* Each process takes a slabs of rows. */ block[0] = dims[0]/mpi_size; block[1] = dims[1]; stride[0] = block[0]; stride[1] = block[1]; count[0] = 1; count[1] = 1; start[0] = mpi_rank*block[0]; start[1] = 0; ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, start, stride, count, block); VRFY((ret >= 0), "H5Sset_hyperslab succeeded"); /* create a memory dataspace independently */ mem_dataspace = H5Screate_simple (RANK, block, NULL); VRFY((mem_dataspace >= 0), ""); /* write data independently */ ret = H5Dread(dset_id, H5T_NATIVE_INT, mem_dataspace, sid, H5P_DEFAULT, data_array); VRFY((ret >= 0), "H5Dwrite succeeded"); dataptr = data_array; for (i=0; i < block[0]; i++){ for (j=0; j < block[1]; j++){ if(*dataptr != mpi_rank+1) { printf("Dataset Verify failed at [%lu][%lu](row %lu, col %lu): expect %d, got %d/n", (unsigned long)i, (unsigned long)j, (unsigned long)(i+start[0]), (unsigned long)(j+start[1]), mpi_rank+1, *(dataptr)); nerrors ++; } dataptr++; } } MPI_Finalize(); HDremove(filename); /* release data buffers */ if(data_array) HDfree(data_array); nerrors += GetTestNumErrs(); if(MAINPROCESS) { if(0 == nerrors) PASSED()//.........这里部分代码省略.........
开发者ID:Starlink,项目名称:hdf5,代码行数:101,
示例5: H5Fopenbool HDFWalkerInput_0_0::put(xmlNodePtr cur){ hid_t h_file = H5Fopen(FileName.c_str(),H5F_ACC_RDWR,H5P_DEFAULT); hid_t h_config = H5Gopen(h_file,"config_collection"); if(h_config<0) { app_error() << " HDFWalkerInput_0_0::put config_collection is not found in " << FileName << "." << endl; H5Fclose(h_file); return false; } int NumSets=0; hid_t h1=H5Dopen(h_config,"NumOfConfigurations"); if(h1>-1) { H5Dread(h1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,&(NumSets)); H5Dclose(h1); } if(!NumSets) { //resolve the integer and long problem with 64bit hsize_t nset; H5Gget_num_objs(h_config,&nset); NumSets=nset; } if(!NumSets) { app_error() << " HDFWalkerInput_0_0::put " << FileName << " does not contain walkers!" << endl; H5Gclose(h_config); H5Gclose(h_file); return false; } //select the last block int selected=NumSets-1; typedef MCWalkerConfiguration::PosType PosType; typedef MCWalkerConfiguration::PropertyContainer_t ProtertyContainer_t; typedef Matrix<PosType> PosContainer_t; int nwt = 0; int npt = 0; //2D array of PosTypes (x,y,z) indexed by (walker,particle) PosContainer_t Pos_temp; //open the group char GrpName[128]; sprintf(GrpName,"config%04d",selected); hid_t group_id = H5Gopen(h_config,GrpName); HDFAttribIO<PosContainer_t> Pos_in(Pos_temp); //read the dataset Pos_in.read(group_id,"coord"); //close groups H5Gclose(group_id); H5Gclose(h_config); H5Fclose(h_file); /*check to see if the number of walkers and particles is consistent with W */ int nptcl = Pos_temp.cols(); nwt = Pos_temp.rows(); int curWalker = targetW.getActiveWalkers(); if(curWalker) { app_log() << "HDFWalkerInput_0_0::put Adding " << nwt << " walkers to " << curWalker << endl; targetW.createWalkers(nwt); } else { app_log() << "HDFWalkerInput_0_0::put Creating " << nwt << " walkers." << endl; targetW.resize(nwt,nptcl); } //assign configurations to W int iw=0; MCWalkerConfiguration::iterator it = targetW.begin()+curWalker; MCWalkerConfiguration::iterator it_end = targetW.end(); while(it != it_end) { std::copy(Pos_temp[iw],Pos_temp[iw+1], (*it)->R.begin()); ++it; ++iw; } return true;}
开发者ID:digideskio,项目名称:qmcpack,代码行数:77,
示例6: memsetCPLErr BAGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage ){ const int nXOff = nBlockXOff * nBlockXSize; H5OFFSET_TYPE offset[3] = { static_cast<H5OFFSET_TYPE>( std::max(0, nRasterYSize - (nBlockYOff + 1) * nBlockYSize)), static_cast<H5OFFSET_TYPE>(nXOff), static_cast<H5OFFSET_TYPE>(0) }; const int nSizeOfData = static_cast<int>(H5Tget_size(native)); memset(pImage, 0, nBlockXSize * nBlockYSize * nSizeOfData); // Blocksize may not be a multiple of imagesize. hsize_t count[3] = { std::min(static_cast<hsize_t>(nBlockYSize), GetYSize() - offset[0]), std::min(static_cast<hsize_t>(nBlockXSize), GetXSize() - offset[1]), static_cast<hsize_t>(0) }; if( nRasterYSize - (nBlockYOff + 1) * nBlockYSize < 0 ) { count[0] += (nRasterYSize - (nBlockYOff + 1) * nBlockYSize); } // Select block from file space. { const herr_t status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, nullptr, count, nullptr); if( status < 0 ) return CE_Failure; } // Create memory space to receive the data. hsize_t col_dims[3] = { static_cast<hsize_t>(nBlockYSize), static_cast<hsize_t>(nBlockXSize), static_cast<hsize_t>(0) }; const int rank = 2; const hid_t memspace = H5Screate_simple(rank, col_dims, nullptr); H5OFFSET_TYPE mem_offset[3] = { 0, 0, 0 }; const herr_t status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, mem_offset, nullptr, count, nullptr); if( status < 0 ) return CE_Failure; const herr_t status_read = H5Dread(hDatasetID, native, memspace, dataspace, H5P_DEFAULT, pImage); H5Sclose(memspace); // Y flip the data. const int nLinesToFlip = static_cast<int>(count[0]); const int nLineSize = nSizeOfData * nBlockXSize; GByte * const pabyTemp = static_cast<GByte *>(CPLMalloc(nLineSize)); GByte * const pbyImage = static_cast<GByte *>(pImage); for( int iY = 0; iY < nLinesToFlip / 2; iY++ ) { memcpy(pabyTemp, pbyImage + iY * nLineSize, nLineSize); memcpy(pbyImage + iY * nLineSize, pbyImage + (nLinesToFlip - iY - 1) * nLineSize, nLineSize); memcpy(pbyImage + (nLinesToFlip - iY - 1) * nLineSize, pabyTemp, nLineSize); } CPLFree(pabyTemp); // Return success or failure. if( status_read < 0 ) { CPLError(CE_Failure, CPLE_AppDefined, "H5Dread() failed for block."); return CE_Failure; } return CE_None;}
开发者ID:ksshannon,项目名称:gdal,代码行数:82,
示例7: VecLoad_HDF5//.........这里部分代码省略.........#if (H5_VERS_MAJOR * 10000 + H5_VERS_MINOR * 100 + H5_VERS_RELEASE >= 10800) dset_id = H5Dopen2(group, vecname, H5P_DEFAULT);#else dset_id = H5Dopen(group, vecname);#endif if (dset_id == -1) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Could not H5Dopen() with Vec named %s",vecname); /* Retrieve the dataspace for the dataset */ filespace = H5Dget_space(dset_id); if (filespace == -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Could not H5Dget_space()"); dim = 0; if (timestep >= 0) ++dim; ++dim; if (bs >= 1) ++dim;#if defined(PETSC_USE_COMPLEX) ++dim;#endif rdim = H5Sget_simple_extent_dims(filespace, dims, NULL);#if defined(PETSC_USE_COMPLEX) bsInd = rdim-2;#else bsInd = rdim-1;#endif lenInd = timestep >= 0 ? 1 : 0; if (rdim != dim) { if (rdim == dim+1 && bs == -1) bs = dims[bsInd]; else SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED, "Dimension of array in file %d not %d as expected",rdim,dim); } else if (bs >= 1 && bs != (PetscInt) dims[bsInd]) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_FILE_UNEXPECTED, "Block size %d specified for vector does not match blocksize in file %d",bs,dims[bsInd]); /* Set Vec sizes,blocksize,and type if not already set */ if ((xin)->map->n < 0 && (xin)->map->N < 0) { ierr = VecSetSizes(xin, PETSC_DECIDE, dims[lenInd]*bs);CHKERRQ(ierr); } /* If sizes and type already set,check if the vector global size is correct */ ierr = VecGetSize(xin, &N);CHKERRQ(ierr); if (N/bs != (PetscInt) dims[lenInd]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED, "Vector in file different length (%d) then input vector (%d)", (PetscInt) dims[lenInd], N/bs); /* Each process defines a dataset and reads it from the hyperslab in the file */ ierr = VecGetLocalSize(xin, &n);CHKERRQ(ierr); dim = 0; if (timestep >= 0) { count[dim] = 1; ++dim; } ierr = PetscHDF5IntCast(n/bs,count + dim);CHKERRQ(ierr); ++dim; if (bs >= 1) { count[dim] = bs; ++dim; }#if defined(PETSC_USE_COMPLEX) count[dim] = 2; ++dim;#endif memspace = H5Screate_simple(dim, count, NULL); if (memspace == -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Could not H5Screate_simple()"); /* Select hyperslab in the file */ ierr = VecGetOwnershipRange(xin, &low, NULL);CHKERRQ(ierr); dim = 0; if (timestep >= 0) { offset[dim] = timestep; ++dim; } ierr = PetscHDF5IntCast(low/bs,offset + dim);CHKERRQ(ierr); ++dim; if (bs >= 1) { offset[dim] = 0; ++dim; }#if defined(PETSC_USE_COMPLEX) offset[dim] = 0; ++dim;#endif status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, count, NULL);CHKERRQ(status); /* Create property list for collective dataset read */ plist_id = H5Pcreate(H5P_DATASET_XFER); if (plist_id == -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Could not H5Pcreate()");#if defined(PETSC_HAVE_H5PSET_FAPL_MPIO) status = H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);CHKERRQ(status);#endif /* To write dataset independently use H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_INDEPENDENT) */ ierr = VecGetArray(xin, &x);CHKERRQ(ierr); status = H5Dread(dset_id, H5T_NATIVE_DOUBLE, memspace, filespace, plist_id, x);CHKERRQ(status); ierr = VecRestoreArray(xin, &x);CHKERRQ(ierr); /* Close/release resources */ if (group != file_id) { status = H5Gclose(group);CHKERRQ(status); } status = H5Pclose(plist_id);CHKERRQ(status); status = H5Sclose(filespace);CHKERRQ(status); status = H5Sclose(memspace);CHKERRQ(status); status = H5Dclose(dset_id);CHKERRQ(status); ierr = VecAssemblyBegin(xin);CHKERRQ(ierr); ierr = VecAssemblyEnd(xin);CHKERRQ(ierr); PetscFunctionReturn(0);}
开发者ID:ZJLi2013,项目名称:petsc,代码行数:101,
示例8: diff_datasetid//.........这里部分代码省略......... H5Tclose(m_tid2); if ((m_tid2=h5tools_get_native_type(f_tid1)) < 0) goto error; m_size2 = H5Tget_size( m_tid2 ); } } assert(m_size1==m_size2); /* print names */ if (obj1_name) { name1=diff_basename(obj1_name); } if (obj2_name) { name2=diff_basename(obj2_name); } /*------------------------------------------------------------------------- * read/compare *------------------------------------------------------------------------- */ need = (size_t)(nelmts1*m_size1); /* bytes needed */ if ( need < H5TOOLS_MALLOCSIZE) { buf1 = HDmalloc(need); buf2 = HDmalloc(need); } if ( buf1!=NULL && buf2!=NULL) { if ( H5Dread(did1,m_tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf1) < 0 ) goto error; if ( H5Dread(did2,m_tid2,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf2) < 0 ) goto error; /* array diff */ nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, options, name1, name2, m_tid1, did1, did2); } else /* possibly not enough memory, read/compare by hyperslabs */ { size_t p_type_nbytes = m_size1; /*size of memory type */ hsize_t p_nelmts = nelmts1; /*total selected elmts */ hsize_t elmtno; /*counter */ int carry; /*counter carry value */ unsigned int vl_data = 0; /*contains VL datatypes */ /* stripmine info */ hsize_t sm_size[H5S_MAX_RANK]; /*stripmine size */ hsize_t sm_nbytes; /*bytes per stripmine */ hsize_t sm_nelmts; /*elements per stripmine*/
开发者ID:ihutch,项目名称:sceptic3D,代码行数:67,
示例9: mainintmain (int argc, char **argv){ char myh5[STR_LENG] = { 0 }; int rec_start = rec_max/2; float *qr, *qi; float k1r, k1i, k2r, k2i, x1, x2; char name[500]; double chi1[6]; hid_t memspace; hsize_t count[2]; hsize_t offset[2]; hsize_t col_dims[1]; hid_t file_id, dataset_id, dataspace_id; hid_t filespace; herr_t status; offset[0] = 0; count[0] = rec_max; count[1] = 1; col_dims[0] = rec_max; qr = (float *) malloc (sizeof (float) * rec_max); qi = (float *) malloc (sizeof (float) * rec_max); int pair, rec, k, g; if (argc == 3) { pair=atoi(argv[1]); offset[1]=atoi(argv[2]); } else { printf ("Error: usage: dist_chi0 sample_index beta_index/n"); return 0; } // for (pair = 0; pair < SAMPLES; pair++) { sprintf(myh5,"sample_pair_%05d.h5",pair); file_id = H5Fopen (myh5, H5F_ACC_RDONLY, H5P_DEFAULT); if(file_id<0){ printf("File do not exist!/n"); exit(0); } for(k=0;k<6;k++) { x1 = 0.0f; k1r = 0.0f; k1i= 0.0f; sprintf (name, "qk_real_%02d",k+4); dataset_id = H5Dopen2 (file_id, name, H5P_DEFAULT); filespace = H5Dget_space (dataset_id); memspace = H5Screate_simple (RANKC, col_dims, NULL); status = H5Sselect_hyperslab (filespace, H5S_SELECT_SET, offset, NULL, count, NULL); status = H5Dread (dataset_id, H5T_NATIVE_FLOAT, memspace, filespace, H5P_DEFAULT, qr); status = H5Dclose (dataset_id); sprintf (name, "qk_imag_%02d",k+4); dataset_id = H5Dopen2 (file_id, name, H5P_DEFAULT); filespace = H5Dget_space (dataset_id); memspace = H5Screate_simple (RANKC, col_dims, NULL); status = H5Sselect_hyperslab (filespace, H5S_SELECT_SET, offset, NULL, count, NULL); status = H5Dread (dataset_id, H5T_NATIVE_FLOAT, memspace, filespace, H5P_DEFAULT, qi); status = H5Dclose (dataset_id); for (rec = rec_start; rec < rec_max; rec++) { x1 += qr[rec] * qr[rec] + qi[rec]*qi[rec]; k1r += qr[rec]; k1i += qi[rec]; } double ax1 = x1 / (rec_max - rec_start); double aq1r = k1r / (rec_max - rec_start); double aq1i = k1i / (rec_max - rec_start);//.........这里部分代码省略.........
开发者ID:GeauxMushroom,项目名称:GeauxIsing,代码行数:101,
示例10: phdf5read2voidphdf5read2(char *filename, hio_context_t context){ hid_t fid1; /* HDF5 file IDs */ hid_t acc_tpl1; /* File access templates */ hid_t file_dataspace; /* File dataspace ID */ hid_t mem_dataspace; /* memory dataspace ID */ hid_t dataset1, dataset2; /* Dataset ID */ DATATYPE data_array1[SPACE1_DIM1][SPACE1_DIM2]; /* data buffer */ DATATYPE data_origin1[SPACE1_DIM1][SPACE1_DIM2]; /* expected data buffer */ hsize_t start[SPACE1_RANK]; /* for hyperslab setting */ hsize_t count[SPACE1_RANK], stride[SPACE1_RANK]; /* for hyperslab setting */ herr_t ret; /* Generic return value */ if (verbose) printf("Collective read test on file %s/n", filename); /* ------------------- * OPEN AN HDF5 FILE * -------------------*/ /* setup file access template with hio IO access. */ acc_tpl1 = H5Pcreate (H5P_FILE_ACCESS); assert(acc_tpl1 != FAIL); MESG("H5Pcreate access succeed"); /* set Hio access with communicator */ H5FD_hio_set_read_io(&settings, H5FD_HIO_STRIDED); ret = H5Pset_fapl_hio(acc_tpl1, &settings); assert(ret != FAIL); MESG("H5Pset_fapl_hio succeed"); /* open the file collectively */ fid1=H5Fopen(filename,H5F_ACC_RDONLY, acc_tpl1); assert(fid1 != FAIL); MESG("H5Fopen succeed"); /* Release file-access template */ ret=H5Pclose(acc_tpl1); assert(ret != FAIL); /* -------------------------- * Open the datasets in it * ------------------------- */ /* open the dataset1 collectively */ dataset1 = H5Dopen2(fid1, DATASETNAME1, H5P_DEFAULT); assert(dataset1 != FAIL); MESG("H5Dopen2 succeed"); /* open another dataset collectively */ dataset2 = H5Dopen2(fid1, DATASETNAME2, H5P_DEFAULT); assert(dataset2 != FAIL); MESG("H5Dopen2 2 succeed"); /* * Set up dimensions of the slab this process accesses. */ /* Dataset1: each process takes a block of columns. */ slab_set(start, count, stride, BYROW);if (verbose) printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu/n", (unsigned long)start[0], (unsigned long)start[1], (unsigned long)count[0], (unsigned long)count[1], (unsigned long)(count[0]*count[1])); /* create a file dataspace independently */ file_dataspace = H5Dget_space (dataset1); assert(file_dataspace != FAIL); MESG("H5Dget_space succeed"); ret=H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride, count, NULL); assert(ret != FAIL); MESG("H5Sset_hyperslab succeed"); /* create a memory dataspace independently */ mem_dataspace = H5Screate_simple (SPACE1_RANK, count, NULL); assert (mem_dataspace != FAIL); /* fill dataset with test data */ dataset_fill(start, count, stride, &data_origin1[0][0]); MESG("data_array initialized"); if (verbose){ MESG("data_array created"); dataset_print(start, count, stride, &data_origin1[0][0]); } /* read data collectively */ ret = H5Dread(dataset1, H5T_NATIVE_INT, mem_dataspace, file_dataspace, H5P_DEFAULT, data_array1); assert(ret != FAIL); MESG("H5Dread succeed"); /* verify the read data with original expected data */ ret = dataset_vrfy(start, count, stride, &data_array1[0][0], &data_origin1[0][0]); assert(ret != FAIL);//.........这里部分代码省略.........
开发者ID:hugegreenbug,项目名称:libhio,代码行数:101,
示例11: _get_all_samplesstatic void* _get_all_samples(hid_t gid_series, char* nam_series, uint32_t type, int nsamples){ void* data = NULL; hid_t id_data_set, dtyp_memory, g_sample, sz_dest; herr_t ec; int smpx ,len; void *data_prior = NULL, *data_cur = NULL; char name_sample[MAX_GROUP_NAME+1]; hdf5_api_ops_t* ops; ops = profile_factory(type); if (ops == NULL) { error("Failed to create operations for %s", acct_gather_profile_type_to_string(type)); return NULL; } data = (*(ops->init_job_series))(nsamples); if (data == NULL) { xfree(ops); error("Failed to get memory for combined data"); return NULL; } dtyp_memory = (*(ops->create_memory_datatype))(); if (dtyp_memory < 0) { xfree(ops); xfree(data); error("Failed to create %s memory datatype", acct_gather_profile_type_to_string(type)); return NULL; } for (smpx=0; smpx<nsamples; smpx++) { len = H5Lget_name_by_idx(gid_series, ".", H5_INDEX_NAME, H5_ITER_INC, smpx, name_sample, MAX_GROUP_NAME, H5P_DEFAULT); if (len<1 || len>MAX_GROUP_NAME) { error("Invalid group name %s", name_sample); continue; } g_sample = H5Gopen(gid_series, name_sample, H5P_DEFAULT); if (g_sample < 0) { info("Failed to open %s", name_sample); } id_data_set = H5Dopen(g_sample, get_data_set_name(name_sample), H5P_DEFAULT); if (id_data_set < 0) { H5Gclose(g_sample); error("Failed to open %s dataset", acct_gather_profile_type_to_string(type)); continue; } sz_dest = (*(ops->dataset_size))(); data_cur = xmalloc(sz_dest); if (data_cur == NULL) { H5Dclose(id_data_set); H5Gclose(g_sample); error("Failed to get memory for prior data"); continue; } ec = H5Dread(id_data_set, dtyp_memory, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_cur); if (ec < 0) { xfree(data_cur); H5Dclose(id_data_set); H5Gclose(g_sample); error("Failed to read %s data", acct_gather_profile_type_to_string(type)); continue; } (*(ops->merge_step_series))(g_sample, data_prior, data_cur, data+(smpx)*sz_dest); xfree(data_prior); data_prior = data_cur; H5Dclose(id_data_set); H5Gclose(g_sample); } xfree(data_cur); H5Tclose(dtyp_memory); xfree(ops); return data;}
开发者ID:FredHutch,项目名称:slurm,代码行数:84,
示例12: phdf5read1/* Example of using the hio HDF5 library to read a dataset */voidphdf5read1(char *filename, hio_context_t context){ hid_t fid1; /* HDF5 file IDs */ hid_t acc_tpl1; /* File access templates */ hid_t file_dataspace; /* File dataspace ID */ hid_t mem_dataspace; /* memory dataspace ID */ hid_t dataset1, dataset2; /* Dataset ID */ DATATYPE data_array1[SPACE1_DIM1][SPACE1_DIM2]; /* data buffer */ DATATYPE data_origin1[SPACE1_DIM1][SPACE1_DIM2]; /* expected data buffer */ hsize_t start[SPACE1_RANK]; /* for hyperslab setting */ hsize_t count[SPACE1_RANK], stride[SPACE1_RANK]; /* for hyperslab setting */ herr_t ret; /* Generic return value */ if (verbose) printf("Independent read test on file %s/n", filename); /* setup file access template */ acc_tpl1 = H5Pcreate (H5P_FILE_ACCESS); assert(acc_tpl1 != FAIL); /* set Hio access with communicator */ H5FD_hio_set_read_io(&settings, H5FD_HIO_CONTIGUOUS); ret = H5Pset_fapl_hio(acc_tpl1, &settings); assert(ret != FAIL); /* open the file collectively */ fid1=H5Fopen(filename,H5F_ACC_RDONLY,acc_tpl1); assert(fid1 != FAIL); /* Release file-access template */ ret=H5Pclose(acc_tpl1); assert(ret != FAIL); /* open the dataset1 collectively */ dataset1 = H5Dopen2(fid1, DATASETNAME1, H5P_DEFAULT); assert(dataset1 != FAIL); /* open another dataset collectively */ dataset2 = H5Dopen2(fid1, DATASETNAME1, H5P_DEFAULT); assert(dataset2 != FAIL); /* set up dimensions of the slab this process accesses */ start[0] = mpi_rank*SPACE1_DIM1/mpi_size; start[1] = 0; count[0] = SPACE1_DIM1/mpi_size; count[1] = SPACE1_DIM2; stride[0] = 1; stride[1] =1;if (verbose) printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu/n", (unsigned long)start[0], (unsigned long)start[1], (unsigned long)count[0], (unsigned long)count[1], (unsigned long)(count[0]*count[1])); /* create a file dataspace independently */ file_dataspace = H5Dget_space (dataset1); assert(file_dataspace != FAIL); ret=H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride, count, NULL); assert(ret != FAIL); /* create a memory dataspace independently */ mem_dataspace = H5Screate_simple (SPACE1_RANK, count, NULL); assert (mem_dataspace != FAIL); /* fill dataset with test data */ dataset_fill(start, count, stride, &data_origin1[0][0]); /* read data blocking and contiguous */ ret = H5Dread(dataset1, H5T_NATIVE_INT, mem_dataspace, file_dataspace, H5P_DEFAULT, data_array1); assert(ret != FAIL); /* verify the read data with original expected data */ ret = dataset_vrfy(start, count, stride, &data_array1[0][0], &data_origin1[0][0]); assert(ret != FAIL); ret = H5Dread(dataset2, H5T_NATIVE_INT, mem_dataspace, file_dataspace, H5P_DEFAULT, data_array1); assert(ret != FAIL); /* verify the read data with original expected data */ ret = dataset_vrfy(start, count, stride, &data_array1[0][0], &data_origin1[0][0]); assert(ret == 0); /* close dataset collectively */ ret=H5Dclose(dataset1); assert(ret != FAIL); ret=H5Dclose(dataset2); assert(ret != FAIL); /* release all IDs created */ H5Sclose(file_dataspace); /* close the file collectively *///.........这里部分代码省略.........
开发者ID:hugegreenbug,项目名称:libhio,代码行数:101,
示例13: ReadHDF5filebool ReadHDF5file(char* filename, char* fieldname, dtype** outArray, int* dims){#ifdef _HDF5_H // Open the file hid_t file_id; file_id = H5Fopen(filename,H5F_ACC_RDONLY,H5P_DEFAULT);//? file_id = H5Fopen(filename,H5F_ACC_RDONLY,faplist_id); if(file_id < 0){ printf("ERROR: Could not open file %s/n",filename); return false; } // Open the dataset hid_t dataset_id; hid_t dataspace_id; dataset_id = H5Dopen1(file_id, fieldname); if(dataset_id < 0){ printf("ERROR: Could not open the data field %s/n",fieldname); return false; } dataspace_id = H5Dget_space(dataset_id); // Test if 2D data int ndims; ndims = H5Sget_simple_extent_ndims(dataspace_id); // Get dimensions of data set (nx, ny, nn) hsize_t* dimsl = new hsize_t[ndims]; H5Sget_simple_extent_dims(dataspace_id,dimsl,NULL); for(int i = 0;(i<ndims&&i<3);i++) dims[i] = dimsl[ndims-1-i]; //!!!!!!!! NOT SURE size_t nn = 1; for(int i = 0;i<ndims;i++) nn *= dimsl[i]; // Create space for the new data dtype* data = *outArray; if (data!=NULL) delete data;//free(data); *outArray = new dtype[nn]; data = *outArray; hid_t datatype_id; H5T_class_t dataclass; size_t size; datatype_id = H5Dget_type(dataset_id); dataclass = H5Tget_class(datatype_id); size = H5Tget_size(datatype_id); int rrr = sizeof(int); if(dataclass == H5T_FLOAT){ if (size == sizeof(float)) { float* buffer = (float *) calloc(nn, sizeof(float)); H5Dread(dataset_id, datatype_id, H5S_ALL,H5S_ALL, H5P_DEFAULT, buffer); for(long i=0; i<nn; i++) data[i] = buffer[i]; free(buffer); } else if (size == sizeof(double)) { double* buffer = (double *) calloc(nn, sizeof(double)); H5Dread(dataset_id, datatype_id, H5S_ALL,H5S_ALL, H5P_DEFAULT, buffer); for(long i=0; i<nn; i++) data[i] = buffer[i]; free(buffer); } else { printf("2dData::readHDF5: unknown floating point type, size=%i/n",(int) size); return false; } } else if(dataclass == H5T_INTEGER){ if (size == sizeof(short)) { short* buffer = (short*) calloc(nn, sizeof(short)); H5Dread(dataset_id, datatype_id, H5S_ALL,H5S_ALL, H5P_DEFAULT, buffer); for(long i=0; i<nn; i++) data[i] = buffer[i]; free(buffer); } else if (size == sizeof(int)) { int* buffer = (int *) calloc(nn, sizeof(int)); H5Dread(dataset_id, datatype_id, H5S_ALL,H5S_ALL, H5P_DEFAULT, buffer); for(long i=0; i<nn; i++) data[i] = buffer[i]; free(buffer); } else if (size == sizeof(long)) { long* buffer = (long *) calloc(nn, sizeof(long)); H5Dread(dataset_id, datatype_id, H5S_ALL,H5S_ALL, H5P_DEFAULT, buffer); for(long i=0; i<nn; i++) data[i] = buffer[i]; free(buffer); } else { printf("2dData::readHDF5: unknown integer type, size=%i/n",(int) size); return false; } } else { printf("2dData::readHDF5: unknown HDF5 data type/n"); return false; }//.........这里部分代码省略.........
开发者ID:shibom,项目名称:scripts_sls,代码行数:101,
示例14: H5Fopenvoid cData2d::readHDF5(char* filename, char* fieldname){ // Open the file hid_t file_id; file_id = H5Fopen(filename,H5F_ACC_RDONLY,H5P_DEFAULT); if(file_id < 0){ printf("ERROR: Could not open file %s/n",filename); return; } // Open the dataset hid_t dataset_id; hid_t dataspace_id; dataset_id = H5Dopen1(file_id, fieldname); dataspace_id = H5Dget_space(dataset_id); // Test if 2D data int ndims; ndims = H5Sget_simple_extent_ndims(dataspace_id); if(ndims != 2) { printf("2dData::readHDF5: Not 2D data set, ndims=%i/n",ndims); exit(0); } // Get dimensions of data set (nx, ny, nn) hsize_t dims[ndims]; H5Sget_simple_extent_dims(dataspace_id,dims,NULL); ny = dims[0]; nx = dims[1]; nn = 1; for(int i = 0;i<ndims;i++) nn *= dims[i]; // Create space for the new data free(data); data = NULL; data = (tData2d *) calloc(nn, sizeof(tData2d)); // Read in data after setting up a temporary buffer of the appropriate variable type // Somehow this works best when split out accordint to different data types // Fix into general form later hid_t datatype_id; H5T_class_t dataclass; size_t size; datatype_id = H5Dget_type(dataset_id); dataclass = H5Tget_class(datatype_id); size = H5Tget_size(datatype_id); if(dataclass == H5T_FLOAT){ if (size == sizeof(float)) { float* buffer = (float *) calloc(nn, sizeof(float)); H5Dread(dataset_id, datatype_id, H5S_ALL,H5S_ALL, H5P_DEFAULT, buffer); for(long i=0; i<nn; i++) data[i] = buffer[i]; free(buffer); } else if (size == sizeof(double)) { double* buffer = (double *) calloc(nn, sizeof(double)); H5Dread(dataset_id, datatype_id, H5S_ALL,H5S_ALL, H5P_DEFAULT, buffer); for(long i=0; i<nn; i++) data[i] = buffer[i]; free(buffer); } else { printf("2dData::readHDF5: unknown floating point type, size=%i/n",(int) size); return; } } else if(dataclass == H5T_INTEGER){ if (size == sizeof(char)) { char* buffer = (char*) calloc(nn, sizeof(char)); H5Dread(dataset_id, datatype_id, H5S_ALL,H5S_ALL, H5P_DEFAULT, buffer); for(long i=0; i<nn; i++) data[i] = buffer[i]; free(buffer); } else if (size == sizeof(short)) { short* buffer = (short*) calloc(nn, sizeof(short)); H5Dread(dataset_id, datatype_id, H5S_ALL,H5S_ALL, H5P_DEFAULT, buffer); for(long i=0; i<nn; i++) data[i] = buffer[i]; free(buffer); } else if (size == sizeof(int)) { int* buffer = (int *) calloc(nn, sizeof(int)); H5Dread(dataset_id, datatype_id, H5S_ALL,H5S_ALL, H5P_DEFAULT, buffer); for(long i=0; i<nn; i++) data[i] = buffer[i]; free(buffer); } else if (size == sizeof(long)) { long* buffer = (long *) calloc(nn, sizeof(long)); H5Dread(dataset_id, datatype_id, H5S_ALL,H5S_ALL, H5P_DEFAULT, buffer); for(long i=0; i<nn; i++) data[i] = buffer[i]; free(buffer); }//.........这里部分代码省略.........
开发者ID:antonbarty,项目名称:cheetah-old,代码行数:101,
示例15: main//.........这里部分代码省略......... memspace = H5Screate_simple(rank,count,NULL); float totalsizegb=mpi_size * rankmemsize *size / 1024.0 / 1024.0 / 1024.0; if(mpi_rank==0) printf("rankmemsize:%d, %dBytes/n",rankmemsize, rankmemsize*sizeof(double)); double * data_t=(double *)malloc( rankmemsize * sizeof(double)); if(data_t == NULL){ printf("Memory allocation fails mpi_rank = %d",mpi_rank); for (i=0; i< rank; i++){ printf("Dim %d: %d, ",i,count[i]); } return -1; } MPI_Barrier(comm); double tr0 = MPI_Wtime(); if(mpi_rank == 0){ if(col==1) printf("IO: Collective Read/n"); else printf("IO: Independent Read/n"); } hid_t plist=H5P_DEFAULT; if(col==1){ plist = H5Pcreate(H5P_DATASET_XFER); H5Pset_dxpl_mpio(plist, H5FD_MPIO_COLLECTIVE); } else { plist = H5Pcreate(H5P_DATASET_XFER); H5Pset_dxpl_mpio(plist,H5FD_MPIO_INDEPENDENT); } H5Dread(dataset, H5T_NATIVE_DOUBLE, memspace,dataspace, plist, data_t); printf("rank %d,start0 %lld count0 %lld,start1 %lld count1 %lld/n",mpi_rank,offset[0],count[0],offset[1],count[1]); H5Pclose(plist); MPI_Barrier(comm); double tr1 = MPI_Wtime()-tr0; if(mpi_rank==0){ printf("/nRank %d, read time %.2fs/n",mpi_rank,tr1); for(i=0; i<rank; i++){ printf("Start_%d:%d Count_%d:%d/n",i,offset[i],i,count[i]); } printf("/n"); printf("Total Loading %f GB with %d mpi processes/n",totalsizegb,mpi_size); } //close object handle of file 1 //H5Tclose(datatype); H5Sclose(dataspace); H5Sclose(memspace); H5Dclose(dataset); //H5Fclose(file); MPI_Barrier(comm); if(mpi_rank==0) printf("Closing File %s ok,/nOpening File %s /n",filename,output); //start to write to new places //printf("%d:%d,%d/n",mpi_rank,offset[0],count[0]); hid_t plist_id2, file_id2,dataspace_id2, dataset_id2; //new file access property plist_id2 = H5Pcreate(H5P_FILE_ACCESS); //mpiio H5Pset_fapl_mpio(plist_id2, comm, info); //create new file
开发者ID:SharpLu,项目名称:h5spark,代码行数:67,
示例16: main//.........这里部分代码省略......... /* * Create the compound datatype for memory. */ memtype = H5Tcreate (H5T_COMPOUND, sizeof (sensor_t)); status = H5Tinsert (memtype, "Serial number", HOFFSET (sensor_t, serial_no), H5T_NATIVE_INT); status = H5Tinsert (memtype, "Location", HOFFSET (sensor_t, location), strtype); status = H5Tinsert (memtype, "Temperature (F)", HOFFSET (sensor_t, temperature), H5T_NATIVE_DOUBLE); status = H5Tinsert (memtype, "Pressure (inHg)", HOFFSET (sensor_t, pressure), H5T_NATIVE_DOUBLE); /* * Create the compound datatype for the file. Because the standard * types we are using for the file may have different sizes than * the corresponding native types, we must manually calculate the * offset of each member. */ filetype = H5Tcreate (H5T_COMPOUND, 8 + sizeof (hvl_t) + 8 + 8); status = H5Tinsert (filetype, "Serial number", 0, H5T_STD_I64BE); status = H5Tinsert (filetype, "Location", 8, strtype); status = H5Tinsert (filetype, "Temperature (F)", 8 + sizeof (hvl_t), H5T_IEEE_F64BE); status = H5Tinsert (filetype, "Pressure (inHg)", 8 + sizeof (hvl_t) + 8, H5T_IEEE_F64BE); /* * 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 compound data to it. */ dset = H5Dcreate (file, DATASET, filetype, space, H5P_DEFAULT); status = H5Dwrite (dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata); /* * 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); /* * Get dataspace and allocate memory for read buffer. */ space = H5Dget_space (dset); ndims = H5Sget_simple_extent_dims (space, dims, NULL); rdata = (sensor_t *) malloc (dims[0] * sizeof (sensor_t)); /* * Read the data. */ status = H5Dread (dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata); /* * Output the data to the screen. */ for (i=0; i<dims[0]; i++) { printf ("%s[%d]:/n", DATASET, i); printf ("Serial number : %d/n", rdata[i].serial_no); printf ("Location : %s/n", rdata[i].location); printf ("Temperature (F) : %f/n", rdata[i].temperature); printf ("Pressure (inHg) : %f/n/n", rdata[i].pressure); } /* * Close and release resources. H5Dvlen_reclaim will automatically * traverse the structure and free any vlen data (strings in this * case). */ status = H5Dvlen_reclaim (memtype, space, H5P_DEFAULT, rdata); free (rdata); status = H5Dclose (dset); status = H5Sclose (space); status = H5Tclose (memtype); status = H5Tclose (strtype); status = H5Fclose (file); return 0;}
开发者ID:FrankLIKE,项目名称:d_hdf5,代码行数:101,
示例17: mainintmain(void){ /* First structure and dataset*/ typedef struct s1_t { int a; float b; double c; } s1_t; s1_t s1[LENGTH]; hid_t s1_tid; /* File datatype identifier */ /* Second structure (subset of s1_t) and dataset*/ typedef struct s2_t { double c; int a; } s2_t; s2_t s2[LENGTH]; hid_t s2_tid; /* Memory datatype handle */ /* Third "structure" ( will be used to read float field of s1) */ hid_t s3_tid; /* Memory datatype handle */ float s3[LENGTH]; int i; hid_t file, dataset, space; /* Handles */ herr_t status; hsize_t dim[] = {LENGTH}; /* Dataspace dimensions */ /* * Initialize the data */ for (i = 0; i< LENGTH; i++) { s1[i].a = i; s1[i].b = i*i; s1[i].c = 1./(i+1); } /* * Create the data space. */ space = H5Screate_simple(RANK, dim, NULL); /* * Create the file. */ file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Create the memory data type. */ s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t)); H5Tinsert(s1_tid, "a_name", HOFFSET(s1_t, a), H5T_NATIVE_INT); H5Tinsert(s1_tid, "c_name", HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE); H5Tinsert(s1_tid, "b_name", HOFFSET(s1_t, b), H5T_NATIVE_FLOAT); /* * Create the dataset. */ dataset = H5Dcreate(file, DATASETNAME, s1_tid, space, H5P_DEFAULT); /* * Wtite data to the dataset; */ status = H5Dwrite(dataset, s1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s1); /* * Release resources */ H5Tclose(s1_tid); H5Sclose(space); H5Dclose(dataset); H5Fclose(file); /* * Open the file and the dataset. */ file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT); dataset = H5Dopen(file, DATASETNAME); /* * Create a data type for s2 */ s2_tid = H5Tcreate(H5T_COMPOUND, sizeof(s2_t)); H5Tinsert(s2_tid, "c_name", HOFFSET(s2_t, c), H5T_NATIVE_DOUBLE); H5Tinsert(s2_tid, "a_name", HOFFSET(s2_t, a), H5T_NATIVE_INT); /* * Read two fields c and a from s1 dataset. Fields in the file * are found by their names "c_name" and "a_name". */ status = H5Dread(dataset, s2_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s2); /* * Display the fields *///.........这里部分代码省略.........
开发者ID:MattNapsAlot,项目名称:rHDF5,代码行数:101,
示例18: verify_data/* * This routine verifies the data written in the dataset. It does one of the * three cases according to the value of parameter `write_pattern'. * 1. it returns correct fill values though the dataset has not been written; * 2. it still returns correct fill values though only a small part is written; * 3. it returns correct values when the whole dataset has been written in an * interleaved pattern. */static voidverify_data(const char *filename, int chunk_factor, write_type write_pattern, int close, hid_t *file_id, hid_t *dataset){ /* HDF5 gubbins */ hid_t dataspace, memspace; /* HDF5 file identifier */ hid_t access_plist; /* HDF5 ID for file access property list */ herr_t hrc; /* HDF5 return code */ hsize_t chunk_dims[1] ={CHUNK_SIZE}; hsize_t count[1]; hsize_t stride[1]; hsize_t block[1]; hsize_t offset[1]; /* Selection offset within dataspace */ /* Variables used in reading data back */ char buffer[CHUNK_SIZE]; int value, i; int index; long nchunks; /* Initialize MPI */ MPI_Comm_size(MPI_COMM_WORLD,&mpi_size); MPI_Comm_rank(MPI_COMM_WORLD,&mpi_rank); nchunks=chunk_factor*mpi_size; /* Set up MPIO file access property lists */ access_plist = H5Pcreate(H5P_FILE_ACCESS); VRFY((access_plist >= 0), ""); hrc = H5Pset_fapl_mpio(access_plist, MPI_COMM_WORLD, MPI_INFO_NULL); VRFY((hrc >= 0), ""); /* Open the file */ if (*file_id<0){ *file_id = H5Fopen(filename, H5F_ACC_RDWR, access_plist); VRFY((*file_id >= 0), ""); } /* Open dataset*/ if (*dataset<0){ *dataset = H5Dopen2(*file_id, DSET_NAME, H5P_DEFAULT); VRFY((*dataset >= 0), ""); } memspace = H5Screate_simple(1, chunk_dims, NULL); VRFY((memspace >= 0), ""); dataspace = H5Dget_space(*dataset); VRFY((dataspace >= 0), ""); /* all processes check all chunks. */ count[0] = 1; stride[0] = 1; block[0] = chunk_dims[0]; for (i=0; i<nchunks; i++){ /* reset buffer values */ memset(buffer, -1, CHUNK_SIZE); offset[0] = i*chunk_dims[0]; hrc = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, stride, count, block); VRFY((hrc >= 0), ""); /* Read the chunk */ hrc = H5Dread(*dataset, H5T_NATIVE_UCHAR, memspace, dataspace, H5P_DEFAULT, buffer); VRFY((hrc >= 0), "H5Dread"); /* set expected value according the write pattern */ switch (write_pattern) { case all: value = i%mpi_size + 1; break; case none: value = 0; break; case sec_last: if (i==nchunks-2) value = 100; else value = 0; } /* verify content of the chunk */ for (index = 0; index < CHUNK_SIZE; index++) VRFY((buffer[index] == value), "data verification"); } hrc = H5Sclose (dataspace); VRFY((hrc >= 0), ""); hrc = H5Sclose (memspace); VRFY((hrc >= 0), "");//.........这里部分代码省略.........
开发者ID:ArielleBassanelli,项目名称:gempak,代码行数:101,
示例19: H5Dopenvoid BAGDataset::LoadMetadata(){ // Load the metadata from the file. const hid_t hMDDS = H5Dopen(hHDF5, "/BAG_root/metadata"); const hid_t datatype = H5Dget_type(hMDDS); const hid_t dataspace = H5Dget_space(hMDDS); const hid_t native = H5Tget_native_type(datatype, H5T_DIR_ASCEND); hsize_t dims[3] = { static_cast<hsize_t>(0), static_cast<hsize_t>(0), static_cast<hsize_t>(0) }; hsize_t maxdims[3] = { static_cast<hsize_t>(0), static_cast<hsize_t>(0), static_cast<hsize_t>(0) }; H5Sget_simple_extent_dims(dataspace, dims, maxdims); pszXMLMetadata = static_cast<char *>(CPLCalloc(static_cast<int>(dims[0] + 1), 1)); H5Dread(hMDDS, native, H5S_ALL, dataspace, H5P_DEFAULT, pszXMLMetadata); H5Tclose(native); H5Sclose(dataspace); H5Tclose(datatype); H5Dclose(hMDDS); if( strlen(pszXMLMetadata) == 0 ) return; // Try to get the geotransform. CPLXMLNode *psRoot = CPLParseXMLString(pszXMLMetadata); if( psRoot == nullptr ) return; CPLStripXMLNamespace(psRoot, nullptr, TRUE); CPLXMLNode *const psGeo = CPLSearchXMLNode(psRoot, "=MD_Georectified"); if( psGeo != nullptr ) { char **papszCornerTokens = CSLTokenizeStringComplex( CPLGetXMLValue(psGeo, "cornerPoints.Point.coordinates", ""), " ,", FALSE, FALSE); if( CSLCount(papszCornerTokens) == 4 ) { const double dfLLX = CPLAtof(papszCornerTokens[0]); const double dfLLY = CPLAtof(papszCornerTokens[1]); const double dfURX = CPLAtof(papszCornerTokens[2]); const double dfURY = CPLAtof(papszCornerTokens[3]); adfGeoTransform[0] = dfLLX; adfGeoTransform[1] = (dfURX - dfLLX) / (GetRasterXSize() - 1); adfGeoTransform[3] = dfURY; adfGeoTransform[5] = (dfLLY - dfURY) / (GetRasterYSize() - 1); adfGeoTransform[0] -= adfGeoTransform[1] * 0.5; adfGeoTransform[3] -= adfGeoTransform[5] * 0.5; } CSLDestroy(papszCornerTokens); } // Try to get the coordinate system. OGRSpatialReference oSRS; if( OGR_SRS_ImportFromISO19115(&oSRS, pszXMLMetadata) == OGRERR_NONE ) { oSRS.exportToWkt(&pszProjection); } else { ParseWKTFromXML(pszXMLMetadata); } // Fetch acquisition date. CPLXMLNode *const psDateTime = CPLSearchXMLNode(psRoot, "=dateTime"); if( psDateTime != nullptr ) { const char *pszDateTimeValue = CPLGetXMLValue(psDateTime, nullptr, ""); if( pszDateTimeValue ) SetMetadataItem("BAG_DATETIME", pszDateTimeValue); } CPLDestroyXMLNode(psRoot);}
开发者ID:ksshannon,项目名称:gdal,代码行数:91,
示例20: main//.........这里部分代码省略......... dims_pad[2] = 2 * (dims[2] / 2 + 1); hsize_t n_x = dims_pad[0] * dims_pad[1] * dims_pad[2]; x1 = malloc(n_x * sizeof(double)); x2 = malloc(n_x * sizeof(double)); x3 = malloc(n_x * sizeof(double)); double *x[] = {x1, x2, x3}; if (!x1 || !x2 || !x3) { printf("Error: Could not allocate memory for the Levy basis./n"); err = -1; goto cleanup; }#pragma omp parallel for for (ptrdiff_t i = 0; i < n_x; i++) { x1[i] = 0.0; x2[i] = 0.0; x3[i] = 0.0; } /* Define memory dataspace */ memspace = H5Screate_simple(3, dims_pad, NULL); offset[0] = offset[1] = offset[2] = 0; count[0] = dims[0]; count[1] = dims[1]; count[2] = dims[2]; /* Define hyperslab in the memory dataspace */ err = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset, NULL, count, NULL); for (int j = 0; j < 3; j++) { /* Define hyperslap in the file dataspace */ offset[3] = j; count[3] = 1; err = H5Sselect_hyperslab(levy_basis_dataspace_id, H5S_SELECT_SET, offset, NULL, count, NULL); /* Read data from hyperslab */ err = H5Dread(levy_basis_dataset_id, H5T_NATIVE_DOUBLE, memspace, levy_basis_dataspace_id, H5P_DEFAULT, x[j]); if (err < 0) { printf("Error: Could not read hyperslab./n"); err = -1; goto cleanup; } } DEBUGPRINT("### Convolving"); double delta = 2.0 * M_PI / dims[0]; err = ambit_symmetric_odd_isotropic_circular_convolution_inplace( n_threads, n_k, k_abscissa, k_ordinate, dims[0], delta, x1, x2, x3); if (err) { printf("Error in ambit_symmetric_odd_isotropic_circular_convolution_inplace./n"); goto cleanup; } DEBUGPRINT("### Writing output"); output_file_id = H5Fcreate(args.output_file, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); if (output_file_id < 0) { printf("Error: Could not open /"%s/"./n", args.output_file); err = -1; goto cleanup; } output_dataspace_id = H5Screate_simple(4, dims, NULL); output_dataset_id = H5Dcreate(output_file_id, "/simulation", H5T_NATIVE_DOUBLE, output_dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); for (int j = 0; j < 3; j++) { printf("j = %i/n", j); /* Define hyperslap in the file dataspace */ offset[3] = j; count[3] = 1; err = H5Sselect_hyperslab(output_dataspace_id, H5S_SELECT_SET, offset, NULL, count, NULL); /* Write data to hyperslab */ err = H5Dwrite(output_dataset_id, H5T_NATIVE_DOUBLE, memspace, output_dataspace_id, H5P_DEFAULT, x[j]); if (err < 0) { printf("Error: Could not write hyperslab./n"); err = -1; goto cleanup; } } cleanup: if (memspace > 0) H5Sclose(memspace); if (output_dataspace_id > 0) H5Sclose(output_dataspace_id); if (output_dataset_id > 0) H5Dclose(output_dataset_id); if (output_file_id > 0) H5Fclose(output_file_id); if (levy_basis_dataspace_id > 0) H5Sclose(levy_basis_dataspace_id); if (levy_basis_dataset_id > 0) H5Dclose(levy_basis_dataset_id); if (levy_basis_file_id > 0) H5Fclose(levy_basis_file_id); if (kernel_file_id > 0) H5Fclose(kernel_file_id); free(tmp); free(k_abscissa); free(k_ordinate); free(x1); free(x2); free(x3); return err;}
开发者ID:emilhedevang,项目名称:ambit-stochastics,代码行数:101,
示例21: H5IMget_paletteherr_t H5IMget_palette( hid_t loc_id, const char *image_name, int pal_number, unsigned char *pal_data ){ hid_t did; int has_pal; hid_t atid=-1; hid_t aid; hid_t asid=-1; hssize_t n_refs; hsize_t dim_ref; hobj_ref_t *refbuf; /* buffer to read references */ hid_t pal_id; /* check the arguments */ if (image_name == NULL) return -1; if (pal_data == NULL) return -1; /* Open the dataset. */ if((did = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0) return -1; /* Try to find the attribute "PALETTE" on the >>image<< dataset */ has_pal = H5IM_find_palette(did); if(has_pal == 1 ) { if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0) goto out; if((atid = H5Aget_type(aid)) < 0) goto out; if(H5Tget_class(atid) < 0) goto out; /* Get the reference(s) */ if((asid = H5Aget_space(aid)) < 0) goto out; n_refs = H5Sget_simple_extent_npoints(asid); dim_ref = (hsize_t)n_refs; refbuf = (hobj_ref_t*)HDmalloc( sizeof(hobj_ref_t) * (size_t)dim_ref ); if ( H5Aread( aid, atid, refbuf ) < 0) goto out; /* Get the palette id */ if ( (pal_id = H5Rdereference( did, H5R_OBJECT, &refbuf[pal_number] )) < 0) goto out; /* Read the palette dataset */ if ( H5Dread( pal_id, H5Dget_type(pal_id), H5S_ALL, H5S_ALL, H5P_DEFAULT, pal_data ) < 0) goto out; /* close */ if (H5Dclose(pal_id)<0) goto out; if ( H5Sclose( asid ) < 0) goto out; if ( H5Tclose( atid ) < 0) goto out; if ( H5Aclose( aid ) < 0) goto out; HDfree( refbuf ); } /* Close the image dataset. */ if ( H5Dclose( did ) < 0) return -1; return 0;out: H5Dclose( did ); H5Sclose( asid ); H5Tclose( atid ); H5Aclose( aid ); return -1;}
开发者ID:AndyHuang7601,项目名称:EpicGames-UnrealEngine,代码行数:87,
示例22: main//.........这里部分代码省略......... time_count++; } fclose(fp); #if PIDX_IO PIDX_create_access(&access); PIDX_set_mpi_access(access, 1, 1, 1, comm); PIDX_set_process_extent(access, sub_div[0], sub_div[1], sub_div[2]);#endif if (rank == 0) printf("Number of timesteps = %d/n", time_count); for (t = 0; t < time_count; t++) {#if HDF_IO file_id = H5Fopen(file_name[t], H5F_ACC_RDONLY, plist_id);#endif #if PIDX_IO PIDX_file_create(output_file_name, PIDX_file_trunc, access, &file); PIDX_set_dims(file, global_bounding_box); PIDX_set_current_time_step(file, t); PIDX_set_block_size(file, bits_per_block); PIDX_set_aggregation_factor(file, 1); PIDX_set_block_count(file, blocks_per_file); PIDX_set_variable_count(file, 1); PIDX_debug_rst(file, 0); PIDX_debug_hz(file, 0); PIDX_dump_agg_info(file, 0); PIDX_enable_hz(file, 1); PIDX_enable_agg(file, 1); PIDX_enable_io(file, 1);#endif #if HDF_IO group_id = H5Gopen(file_id, "/data", H5P_DEFAULT); dataset_id = H5Dopen2(group_id, "P", H5P_DEFAULT); mem_dataspace = H5Screate_simple (3, count, NULL); file_dataspace = H5Dget_space (dataset_id); H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, offset, NULL, count, NULL);#endif buffer = malloc(sizeof(double) * count_local[0] * count_local[1] * count_local[2]); memset(buffer, 0, sizeof(double) * count_local[0] * count_local[1] * count_local[2]); #if HDF_IO H5Dread(dataset_id, H5T_NATIVE_DOUBLE, mem_dataspace, file_dataspace, H5P_DEFAULT, buffer); H5Sclose(mem_dataspace); H5Sclose(file_dataspace); H5Dclose(dataset_id); H5Gclose(group_id); H5Fclose(file_id); if (rank == 0) printf("Finished reading HDF files/n");#else int64_t i1, j1, k1; for (k1 = 0; k1 < count_local[2]; k1++) for (j1 = 0; j1 < count_local[1]; j1++) for (i1 = 0; i1 < count_local[0]; i1++) { int64_t index = (int64_t) (count_local[0] * count_local[1] * k1) + (count_local[0] * j1) + i1; buffer[index] = (256 * rank) / nprocs; }#endif #if PIDX_IO PIDX_variable_create(file, "P", sizeof(double) * 8, "1*float64", &variable); PIDX_append_and_write_variable(variable, local_offset_point, local_box_count_point, buffer, PIDX_column_major); if (rank == 0) printf("Starting to Write IDX %s Time Step %d/n", output_file_name, t); PIDX_close(file);#endif free(buffer); buffer = 0; } //////////#if HDF_IO H5Pclose(plist_id);#endif #if PIDX_IO PIDX_close_access(access);#endif free(output_file_name); output_file_name = 0; MPI_Finalize(); return 0;}
开发者ID:gmarkomanolis,项目名称:PIDX,代码行数:101,
示例23: do_copy_refobjs//.........这里部分代码省略......... * 1) the external filters GZIP and SZIP might not be available * 2) the internal filters might be turned off *------------------------------------------------------------------------- */ if(h5tools_canreadf(NULL, dcpl_id) == 1) { /*------------------------------------------------------------------------- * test for a valid output dataset *------------------------------------------------------------------------- */ dset_out = FAIL; /*------------------------------------------------------------------------- * object references are a special case * we cannot just copy the buffers, but instead we recreate the reference *------------------------------------------------------------------------- */ if(H5Tequal(mtype_id, H5T_STD_REF_OBJ)) { hid_t refobj_id; hobj_ref_t *refbuf = NULL; /* buffer for object references */ hobj_ref_t *buf = NULL; const char* refname; unsigned u; /*------------------------------------------------------------------------- * read to memory *------------------------------------------------------------------------- */ if(nelmts) { buf = (hobj_ref_t *)HDmalloc((unsigned)(nelmts * msize)); if(buf==NULL) { printf("cannot read into memory/n" ); goto error; } /* end if */ if(H5Dread(dset_in, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) goto error; refbuf = (hobj_ref_t*) HDcalloc((unsigned)nelmts, msize); if(refbuf == NULL){ printf("cannot allocate memory/n" ); goto error; } /* end if */ for(u = 0; u < nelmts; u++) { H5E_BEGIN_TRY { if((refobj_id = H5Rdereference(dset_in, H5R_OBJECT, &buf[u])) < 0) continue; } H5E_END_TRY; /* get the name. a valid name could only occur * in the second traversal of the file */ if((refname = MapIdToName(refobj_id, travt)) != NULL) { /* create the reference, -1 parameter for objects */ if(H5Rcreate(&refbuf[u], fidout, refname, H5R_OBJECT, -1) < 0) goto error; if(options->verbose) { printf(FORMAT_OBJ,"dset",travt->objs[i].name ); printf("object <%s> object reference created to <%s>/n", travt->objs[i].name, refname); } } /*refname*/ H5Oclose(refobj_id); } /* u */
开发者ID:polyactis,项目名称:test,代码行数:67,
示例24: H5Dreadvoid hdf5dataset::read(void* data){ herr_t status = H5Dread(_dataset_id, _type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, data); if(status < 0) throw std::runtime_error("Failed to read dataset (" + _hfile.filename() + ") in file (" + _name + ")");}
开发者ID:klindworth,项目名称:cvwidgets,代码行数:6,
示例25: read_hdf5_bufferedint read_hdf5_buffered(char *file_name, int buffer_size) { double sum = 0.0; double *buffer; long i; hid_t file_id, dataset_id, dataspace_id, memspace_id; hsize_t dataspace_dims[1], offset[1], count[0], mem_offset[1], mem_count[1], remainder; size_t buffer_bytes = (buffer_size/sizeof(double))*sizeof(double); if (buffer_size % sizeof(double) != 0) { warnx("buffer size is not a multiple of double precsion type size"); } buffer_size = buffer_bytes/sizeof(double); if ((buffer = (double *) malloc(buffer_bytes)) == NULL) { errx(EXIT_FAILURE, "can't allocate buffer of size %d", buffer_bytes); } printf("%d, %d/n", buffer_size, buffer_bytes); file_id = H5Fopen(file_name, H5F_ACC_RDONLY, H5P_DEFAULT); dataset_id = H5Dopen(file_id, "/values", H5P_DEFAULT); dataspace_id = H5Dget_space(dataset_id); H5Sget_simple_extent_dims(dataspace_id, dataspace_dims, NULL); mem_count[0] = buffer_size; memspace_id = H5Screate_simple(1, mem_count, NULL); mem_offset[0] = 0; H5Sselect_hyperslab(memspace_id, H5S_SELECT_SET, mem_offset, NULL, mem_count, NULL); count[0] = buffer_size; for (offset[0] = 0; offset[0] < dataspace_dims[0] - buffer_size; offset[0] += buffer_size) { H5Sselect_hyperslab(dataspace_id, H5S_SELECT_SET, offset, NULL, count, NULL); H5Dread(dataset_id, H5T_NATIVE_DOUBLE, memspace_id, dataspace_id, H5P_DEFAULT, buffer); for (i = 0; i < buffer_size; i++) { sum += buffer[i]; } } remainder = dataspace_dims[0] % buffer_size; if (remainder != 0) { mem_count[0] = remainder; H5Sselect_hyperslab(memspace_id, H5S_SELECT_SET, mem_offset, NULL, mem_count, NULL); offset[0] = dataspace_dims[0] - remainder; count[0] = remainder; H5Sselect_hyperslab(dataspace_id, H5S_SELECT_SET, offset, NULL, count, NULL); H5Dread(dataset_id, H5T_NATIVE_DOUBLE, memspace_id, dataspace_id, H5P_DEFAULT, buffer); for (i = 0; i < remainder; i++) { sum += buffer[i]; } } H5Dclose(dataset_id); H5Sclose(dataspace_id); H5Sclose(memspace_id); H5Fclose(file_id); fprintf(stderr, "%lu double precision numbers read, sum = %le/n", (long unsigned) dataspace_dims[0], sum); free(buffer); return EXIT_SUCCESS;}
开发者ID:vsb1357,项目名称:IoTests,代码行数:61,
示例26: memsetCPLErr HDF5ImageRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage ){ herr_t status; hsize_t count[3]; H5OFFSET_TYPE offset[3]; int nSizeOfData; hid_t memspace; hsize_t col_dims[3]; hsize_t rank; HDF5ImageDataset *poGDS = ( HDF5ImageDataset * ) poDS; if( poGDS->eAccess == GA_Update ) { memset( pImage, 0, nBlockXSize * nBlockYSize * GDALGetDataTypeSize( eDataType )/8 ); return CE_None; } rank=2; if( poGDS->ndims == 3 ){ rank=3; offset[0] = nBand-1; count[0] = 1; col_dims[0] = 1; } offset[poGDS->ndims - 2] = nBlockYOff*nBlockYSize; offset[poGDS->ndims - 1] = nBlockXOff*nBlockXSize; count[poGDS->ndims - 2] = nBlockYSize; count[poGDS->ndims - 1] = nBlockXSize; nSizeOfData = H5Tget_size( poGDS->native ); memset( pImage,0,nBlockXSize*nBlockYSize*nSizeOfData ); /* blocksize may not be a multiple of imagesize */ count[poGDS->ndims - 2] = MIN( size_t(nBlockYSize), poDS->GetRasterYSize() - offset[poGDS->ndims - 2]); count[poGDS->ndims - 1] = MIN( size_t(nBlockXSize), poDS->GetRasterXSize()- offset[poGDS->ndims - 1]);/* -------------------------------------------------------------------- *//* Select block from file space *//* -------------------------------------------------------------------- */ status = H5Sselect_hyperslab( poGDS->dataspace_id, H5S_SELECT_SET, offset, NULL, count, NULL );/* -------------------------------------------------------------------- *//* Create memory space to receive the data *//* -------------------------------------------------------------------- */ col_dims[poGDS->ndims-2]=nBlockYSize; col_dims[poGDS->ndims-1]=nBlockXSize; memspace = H5Screate_simple( (int) rank, col_dims, NULL ); H5OFFSET_TYPE mem_offset[3] = {0, 0, 0}; status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, mem_offset, NULL, count, NULL); status = H5Dread ( poGDS->dataset_id, poGDS->native, memspace, poGDS->dataspace_id, H5P_DEFAULT, pImage ); H5Sclose( memspace ); if( status < 0 ) { CPLError( CE_Failure, CPLE_AppDefined, "H5Dread() failed for block." ); return CE_Failure; } else return CE_None;}
开发者ID:imincik,项目名称:pkg-gdal,代码行数:83,
示例27: dimsint VsReader::getData( VsDataset* dataSet, void* data, // Use these variables for adjusting // the read memory space. std::string indexOrder, // Index ordering int components, // Index for a component int* srcMins, // start locations int* srcCounts, // number of entries int* srcStrides, // stride in memory // Use these variables for adjusting // the write memory space. int mdims, // spatial dims (rank) int* destSizes, // overall memory size int* destMins, // start locations int* destCounts, // number of entries int* destStrides ) const // stride in memory{ // components = -2 No component array (i.e. scalar variable) // components = -1 Component array present but read all values. // (i.e. vector variable or point coordinates) // component >= 0 Component array present read single value at that index. if (dataSet == NULL) { VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " " << "Requested dataset is null?" << std::endl; return -1; } if (data == NULL) { VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " " << "Data storage is null?" << std::endl; return -1; } int err = 0; // No index ordering info so read all data. if (indexOrder.length() == 0) { err = H5Dread(dataSet->getId(), dataSet->getType(), H5S_ALL, H5S_ALL, H5P_DEFAULT, data); if (err < 0) { VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " " << "Error " << err << " in reading variable " << dataSet->getFullName() << "." << std::endl; return err; } } // mins, counts, and/or strides so hyperslab. else { hid_t dataspace = H5Dget_space(dataSet->getId()); int ndims = H5Sget_simple_extent_ndims(dataspace); if (ndims == 0) { VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " " << "Unable to load dimensions for variable." << "Returning -1." << std::endl; return -1; } std::vector<hsize_t> dims(ndims); int ndim = H5Sget_simple_extent_dims(dataspace, &(dims[0]), NULL); if( ndim != ndims ) { VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " " << "Data dimensions not match. " << std::endl; return -1; } VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " " << "about to set up arguments." << std::endl; std::vector<hsize_t> count(ndims); std::vector<hsize_t> start(ndims); std::vector<hsize_t> stride(ndims); // FORTRAN ordering. if((indexOrder == VsSchema::compMinorFKey) || (indexOrder == VsSchema::compMajorFKey)) { // No components - [iz][iy][ix] if( components == -2 ) { for (unsigned int i = 0; i< (unsigned int)ndims; i++) { // Flip the ordering of the input. int base = ndims - 1; start[1] = (hsize_t) srcMins[base-i]; count[1] = (hsize_t) srcCounts[base-i]; stride[1] = (hsize_t) srcStrides[base-i]; VsLog::debugLog()//.........这里部分代码省略.........
开发者ID:HarinarayanKrishnan,项目名称:VisIt28RC_Trunk,代码行数:101,
示例28: main//.........这里部分代码省略.........#ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_stop, NULL);#else#ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); t_start.tv_sec = tbstart->time; t_start.tv_usec = tbstart->millitm; t_stop.tv_sec = tbstop->time; t_stop.tv_usec = tbstop->millitm;#endif#endif putc ('/n', stderr); print_stats ("fill raw", &r_start, &r_stop, &t_start, &t_stop, (size_t)(nread*size[0]*size[1])); /* Fill hdf5 */ synchronize ();#ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_start);#endif#ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_start, NULL);#else#ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart);#endif#endif fprintf (stderr, HEADING, "fill hdf5"); for(u = 0; u < nread; u++) { putc (PROGRESS, stderr); HDfflush(stderr); status = H5Dread (dset, H5T_NATIVE_UCHAR, file_space, file_space, H5P_DEFAULT, the_data); assert (status>=0); }#ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_stop);#endif#ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_stop, NULL);#else#ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); t_start.tv_sec = tbstart->time; t_start.tv_usec = tbstart->millitm; t_stop.tv_sec = tbstop->time; t_stop.tv_usec = tbstop->millitm;#endif#endif putc ('/n', stderr); print_stats ("fill hdf5", &r_start, &r_stop, &t_start, &t_stop, (size_t)(nread*size[0]*size[1])); /* Write the raw dataset */ synchronize ();#ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_start);#endif#ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_start, NULL);#else#ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart);
开发者ID:ElaraFX,项目名称:hdf5,代码行数:67,
示例29: test_core//.........这里部分代码省略......... /* Allocate memory for data set. */ if(NULL == (points = (int *)HDmalloc(DSET1_DIM1 * DSET1_DIM2 * sizeof(int)))) TEST_ERROR; if(NULL == (check = (int *)HDmalloc(DSET1_DIM1 * DSET1_DIM2 * sizeof(int)))) TEST_ERROR; /* 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 */ if((dset1 = H5Dcreate2(file, DSET1_NAME, H5T_NATIVE_INT, space1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; /* Write the data to the dset1 */ if(H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) TEST_ERROR; if(H5Dclose(dset1) < 0) TEST_ERROR; if((dset1 = H5Dopen2(file, DSET1_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; /* Read the data back from dset1 */ if(H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ p1 = points; p2 = check; for(i = 0; i < DSET1_DIM1; i++) for(j = 0; j < DSET1_DIM2; j++) if(*p1++ != *p2++) { H5_FAILED(); printf(" Read different values than written in data set 1./n"); printf(" At index %d,%d/n", i, j); TEST_ERROR; } /* end if */ if(H5Dclose(dset1) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Open the file with backing store on for read and write. * Changes will be saved in file. */ if(H5Pset_fapl_core(fapl, (size_t)CORE_INCREMENT, TRUE) < 0) TEST_ERROR; if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; /* Create the dset1 */ if((dset1 = H5Dcreate2(file, DSET1_NAME, H5T_NATIVE_INT, space1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
开发者ID:FilipeMaia,项目名称:hdf5,代码行数:66,
注:本文中的H5Dread函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ H5Dwrite函数代码示例 C++ H5Dopen2函数代码示例 |