本文整理汇总了C++中H5Dwrite函数的典型用法代码示例。如果您正苦于以下问题:C++ H5Dwrite函数的具体用法?C++ H5Dwrite怎么用?C++ H5Dwrite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了H5Dwrite函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: H5Dget_space
/**
* Write a hyperslab into the dataset.
*
* @param [in] HDF5_Dataset_id - Dataset id
* @param [in] Position - Position in the dataset
* @param [in] Size - Size of the hyperslab
* @param [in] Data
* @throw ios::failure
*
*/
void THDF5_File::WriteHyperSlab(const hid_t HDF5_Dataset_id, const TDimensionSizes & Position , const TDimensionSizes & Size, const float * Data){
// Select hyperslab
const int MatrixRank = 3;
hsize_t ElementCount[MatrixRank] = {Size.Z, Size.Y, Size.X};
hsize_t Offset[MatrixRank] = {Position.Z,Position.Y,Position.X};
herr_t status;
hid_t HDF5_Filespace,HDF5_Memspace;
// Select hyperslab in the file.
HDF5_Filespace = H5Dget_space(HDF5_Dataset_id);
status = H5Sselect_hyperslab(HDF5_Filespace, H5S_SELECT_SET, Offset, 0, ElementCount, NULL);
if (status < 0) {
char ErrorMessage[256];
sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
throw ios::failure(ErrorMessage);
}
// assign memspace
HDF5_Memspace = H5Screate_simple(MatrixRank, ElementCount, NULL);
status = H5Dwrite(HDF5_Dataset_id, H5T_NATIVE_FLOAT, HDF5_Memspace, HDF5_Filespace, H5P_DEFAULT, Data);
if (status < 0) {
char ErrorMessage[256];
sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
throw ios::failure(ErrorMessage);
}
H5Sclose(HDF5_Memspace);
H5Sclose(HDF5_Filespace);
}// end of WriteHyperSlab
示例2: save_quad_bc
bool save_quad_bc(hid_t parent_group_id, JudyArray<Boundary *> &bcs) {
herr_t status;
// create main group
hid_t group_id = H5Gcreate(parent_group_id, "quad", 0);
// count
hid_t dataspace_id = H5Screate(H5S_SCALAR);
hid_t attr_count = H5Acreate(group_id, "count", H5T_NATIVE_UINT32, dataspace_id, H5P_DEFAULT);
uint count = bcs.count();
status = H5Awrite(attr_count, H5T_NATIVE_UINT32, &count);
H5Aclose(attr_count);
///
hsize_t dims = Quad::NUM_VERTICES;
hid_t elem_dataspace_id = H5Screate_simple(1, &dims, NULL);
hid_t merker_dataspace_id = H5Screate(H5S_SCALAR);
// dump vertices
for (int i = 0; i < count; i++) {
char name[256];
sprintf(name, "%d", i);
// the dataset
hid_t dataset_id = H5Dcreate(group_id, name, H5T_NATIVE_UINT32, elem_dataspace_id, H5P_DEFAULT);
status = H5Dwrite(dataset_id, H5T_NATIVE_UINT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, bcs[i]->get_vertices());
// marker
hid_t attr_marker = H5Acreate(dataset_id, "marker", H5T_NATIVE_UINT32, dataspace_id, H5P_DEFAULT);
uint marker = bcs[i]->get_marker();
status = H5Awrite(attr_marker, H5T_NATIVE_UINT32, &marker);
H5Aclose(attr_marker);
status = H5Dclose(dataset_id);
}
H5Sclose(elem_dataspace_id);
H5Sclose(dataspace_id);
status = H5Gclose(group_id); // close the group
}
示例3: EPIK_TRACER
void seissol::checkpoint::h5::Fault::write(int timestepFault)
{
EPIK_TRACER("CheckPointFault_write");
SCOREP_USER_REGION("CheckPointFault_write", SCOREP_USER_REGION_TYPE_FUNCTION);
if (numSides() == 0)
return;
logInfo(rank()) << "Writing fault check point.";
// Create array with all pointers
EPIK_USER_REG(r_write_fault, "checkpoint_write_fault");
SCOREP_USER_REGION_DEFINE(r_write_fault);
EPIK_USER_START(r_write_fault);
SCOREP_USER_REGION_BEGIN(r_write_fault, "checkpoint_write_fault", SCOREP_USER_REGION_TYPE_COMMON);
// Attributes
checkH5Err(H5Awrite(m_h5timestepFault[odd()], H5T_NATIVE_INT, ×tepFault));
// Set memory and file space
hsize_t fStart[2] = {fileOffset(), 0};
hsize_t count[2] = {numSides(), numBndGP()};
hid_t h5memSpace = H5Screate_simple(2, count, 0L);
checkH5Err(h5memSpace);
checkH5Err(H5Sselect_all(h5memSpace));
checkH5Err(H5Sselect_hyperslab(m_h5fSpaceData, H5S_SELECT_SET, fStart, 0L, count, 0L));
for (unsigned int i = 0; i < NUM_VARIABLES; i++) {
checkH5Err(H5Dwrite(m_h5data[odd()][i], H5T_NATIVE_DOUBLE, h5memSpace, m_h5fSpaceData,
h5XferList(), data(i)));
}
checkH5Err(H5Sclose(h5memSpace));
EPIK_USER_END(r_write_fault);
SCOREP_USER_REGION_END(r_write_fault);
// Finalize the checkpoint
finalizeCheckpoint();
logInfo(rank()) << "Writing fault check point. Done.";
}
示例4: H5TBOwrite_elements
herr_t H5TBOwrite_elements( hid_t dataset_id,
hid_t mem_type_id,
hsize_t nrecords,
const void *coords,
const void *data )
{
hsize_t count[1];
hid_t space_id;
hid_t mem_space_id;
/* Get the dataspace handle */
if ( (space_id = H5Dget_space( dataset_id )) < 0 )
goto out;
/* Define a selection of points in the dataset */
if ( H5Sselect_elements(space_id, H5S_SELECT_SET, (size_t)nrecords, (const hsize_t *)coords) < 0 )
goto out;
/* Create a memory dataspace handle */
count[0] = nrecords;
if ( (mem_space_id = H5Screate_simple( 1, count, NULL )) < 0 )
goto out;
if ( H5Dwrite( dataset_id, mem_type_id, mem_space_id, space_id, H5P_DEFAULT, data ) < 0 )
goto out;
/* Terminate access to the memory dataspace */
if ( H5Sclose( mem_space_id ) < 0 )
goto out;
/* Terminate access to the dataspace */
if ( H5Sclose( space_id ) < 0 )
goto out;
return 0;
out:
return -1;
}
示例5: writeMPI_p
/* ------- begin -------------------------- writeMPI_p.c ----- */
void writeMPI_p(int task) {
/* Writes output on indata file, MPI group, one task at once */
const char routineName[] = "writeMPI_p";
hsize_t offset[] = {0, 0, 0, 0};
hsize_t count[] = {1, 1, 1, 1};
hsize_t dims[4];
hid_t file_dspace, mem_dspace;
dims[0] = 1;
if (( mem_dspace = H5Screate_simple(1, dims, NULL) ) < 0) HERR(routineName);
offset[0] = mpi.ix;
offset[1] = mpi.iy;
if (( file_dspace = H5Dget_space(io.in_mpi_tm) ) < 0) HERR(routineName);
if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset,
NULL, count, NULL) ) < 0) HERR(routineName);
if (( H5Dwrite(io.in_mpi_tm, H5T_NATIVE_INT, mem_dspace, file_dspace,
H5P_DEFAULT, &mpi.rank) ) < 0) HERR(routineName);
if (( H5Dwrite(io.in_mpi_tn, H5T_NATIVE_INT, mem_dspace, file_dspace,
H5P_DEFAULT, &task) ) < 0) HERR(routineName);
if (( H5Dwrite(io.in_mpi_it, H5T_NATIVE_INT, mem_dspace, file_dspace,
H5P_DEFAULT, &mpi.niter[0]) ) < 0) HERR(routineName);
if (( H5Dwrite(io.in_mpi_conv, H5T_NATIVE_INT, mem_dspace, file_dspace,
H5P_DEFAULT, &mpi.convergence[0]) ) < 0) HERR(routineName);
if (( H5Dwrite(io.in_mpi_zc, H5T_NATIVE_INT, mem_dspace, file_dspace,
H5P_DEFAULT, &mpi.zcut_hist[0]) ) < 0) HERR(routineName);
if (( H5Dwrite(io.in_mpi_dm, H5T_NATIVE_DOUBLE, mem_dspace, file_dspace,
H5P_DEFAULT, &mpi.dpopsmax[0]) ) < 0) HERR(routineName);
if (( H5Sclose(file_dspace) ) < 0) HERR(routineName);
if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName);
dims[0] = mpi.niter[0];
if (( mem_dspace = H5Screate_simple(1, dims, NULL) ) < 0) HERR(routineName);
offset[0] = mpi.ix;
offset[1] = mpi.iy;
count[2] = mpi.niter[0];
if (( file_dspace = H5Dget_space(io.in_mpi_dmh) ) < 0) HERR(routineName);
if (( H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, offset,
NULL, count, NULL) ) < 0) HERR(routineName);
if (( H5Dwrite(io.in_mpi_dmh, H5T_NATIVE_DOUBLE, mem_dspace, file_dspace,
H5P_DEFAULT, mpi.dpopsmax_hist[0]) ) < 0) HERR(routineName);
if (( H5Sclose(file_dspace) ) < 0) HERR(routineName);
if (( H5Sclose(mem_dspace) ) < 0) HERR(routineName);
return;
}
示例6: H5Dwrite
void hdf5_dataset::write(hdf5_datatype const& type, void const* buffer)
{
herr_t status =
H5Dwrite(
get_id(),
type.get_id(),
H5S_ALL,
H5S_ALL,
H5P_DEFAULT,
buffer
);
if(status < 0) {
boost::serialization::throw_exception(
hdf5_archive_exception(
hdf5_archive_exception::hdf5_archive_dataset_write_error
)
);
}
}
示例7: Write_hdf5
static int Write_hdf5(void *buf, size_t nbytes)
{
hid_t dsid;
herr_t n1, n2;
char dsname[256];
static int n = 0;
if (dspc == -1)
{
hsize_t dims = nbytes;
dspc = H5Screate_simple(1, &dims, &dims);
}
sprintf(dsname, "data_%07d", n++);
dsid = H5Dcreate(fid, dsname, H5T_NATIVE_UCHAR, dspc, H5P_DEFAULT);
if (dsid < 0) return 0;
n1 = H5Dwrite(dsid, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
n2 = H5Dclose(dsid);
if (n1 < 0 || n2 < 0) return 0;
return nbytes;
}
示例8: create_new_dataset
int create_new_dataset(H5block *d){
hid_t file_id, dataset_id, dataspace_id, status, dcpl, datatype;
file_id = H5Fopen(d->name, H5F_ACC_RDWR, H5P_DEFAULT);
hsize_t dims[2];
dims[0] = d->x_index_dim;
dims[1] = d->y_index_dim;
dataspace_id = H5Screate_simple(2, dims, NULL);
datatype = H5Tcopy(H5T_NATIVE_FLOAT);
status = H5Tset_order(datatype, H5T_ORDER_LE);
char buffer[50];
sprintf(buffer, "/dset%ld", d->ticks);
dataset_id = H5Dcreate(file_id, buffer, datatype, dataspace_id, H5P_DEFAULT);
status = H5Dwrite(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
d->field);
status = H5Dclose(dataset_id);
status = H5Tclose(datatype);
status = H5Sclose(dataspace_id);
status = H5Fclose(file_id);
}
示例9: testCreateStringDataset
void testCreateStringDataset()
{
const char * data[STR_DSET_LEN] = {"You have to", "live", "life", "to the limit"};
hid_t file, memtype, dset;
hsize_t size = STR_DSET_LEN;
herr_t status;
HDF5WriterBase writer;
string h5Filename = moose::random_string( 10 );
file = H5Fcreate(h5Filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
dset = writer.createStringDataset(file, STR_DSET_NAME, size, size);
assert(dset >= 0);
memtype = H5Tcopy(H5T_C_S1);
status = H5Tset_size(memtype, H5T_VARIABLE);
assert(status >= 0);
status = H5Dwrite(dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
assert(status >= 0);
status = H5Dclose(dset);
H5Tclose(memtype);
H5Fclose(file);
}
示例10: ASDF_write_quakeml
herr_t ASDF_write_quakeml(hid_t loc_id, const char *quakeml_string) {
hsize_t dims[1] = {strlen(quakeml_string)};
hsize_t maxdims[1] = {H5S_UNLIMITED};
hid_t space_id, dcpl_id, array_id;
CHK_H5(space_id = H5Screate_simple(1, dims, maxdims));
CHK_H5(dcpl_id = H5Pcreate(H5P_DATASET_CREATE));
CHK_H5(H5Pset_chunk(dcpl_id, 1, dims));
CHK_H5(array_id = H5Dcreate(loc_id, "/QuakeML", H5T_STD_I8LE, space_id,
H5P_DEFAULT, dcpl_id, H5P_DEFAULT));
CHK_H5(H5Dwrite(array_id, H5T_STD_I8LE, H5S_ALL, H5S_ALL,
H5P_DEFAULT, quakeml_string));
CHK_H5(H5Dclose(array_id));
CHK_H5(H5Sclose(space_id));
return 0; // Success
}
示例11: writeDouble2d
herr_t writeDouble2d(hid_t file_id,const char *dsName, void * matrix, int DIM_X, int DIM_Y) {
hid_t dataset_id,dataspace_id;
hsize_t dims[] = {DIM_Y,DIM_X}; /*DIM_Y corresponds to number of rows, DIM_X to columns*/
herr_t status;
/* Create the data space for the dataset. */
dataspace_id = H5Screate_simple(2, dims, NULL);
/* Create the dataset. */
dataset_id = H5Dcreate(file_id, dsName, H5T_IEEE_F64LE, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Sclose(dataspace_id);
/*Write the dataset*/
status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
matrix);
/* End access to the dataset and release resources used by it. */
status = H5Dclose(dataset_id);
return status;
}
示例12: extendDataSet
asynStatus NDFileHDF5AttributeDataset::writeAttributeDataset(hdf5::When_t whenToSave, hsize_t *offsets, NDAttribute *ndAttr, int flush, int indexed)
{
asynStatus status = asynSuccess;
char * stackbuf[MAX_ATTRIBUTE_STRING_SIZE];
void* pDatavalue = stackbuf;
int ret;
//check if the attribute is meant to be saved at this time
if (whenToSave_ == whenToSave) {
// Extend the dataset as required to store the data
if (indexed == -1){
extendDataSet(offsets);
} else {
extendIndexDataSet(offsets[indexed]);
}
// find the data based on datatype
ret = ndAttr->getValue(ndAttr->getDataType(), pDatavalue, MAX_ATTRIBUTE_STRING_SIZE);
if (ret == ND_ERROR) {
memset(pDatavalue, 0, MAX_ATTRIBUTE_STRING_SIZE);
}
// Work with HDF5 library to select a suitable hyperslab (one element) and write the new data to it
H5Dset_extent(dataset_, dims_);
filespace_ = H5Dget_space(dataset_);
// Select the hyperslab
H5Sselect_hyperslab(filespace_, H5S_SELECT_SET, offset_, NULL, elementSize_, NULL);
// Write the data to the hyperslab.
H5Dwrite(dataset_, datatype_, memspace_, filespace_, H5P_DEFAULT, pDatavalue);
// Check if we are being asked to flush
if (flush == 1){
status = this->flushDataset();
}
H5Sclose(filespace_);
nextRecord_++;
}
return status;
}
示例13: saveParticleComp_Int
void saveParticleComp_Int(int *data,char *fileName,char *dataName,int totalCnt,int cnt,int offSet)
{
int i,j,k;
int myrank, nTasks;
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Comm_size(MPI_COMM_WORLD, &nTasks);
hid_t file_id,dset_id,plist_id,tic_id;
herr_t status;
hid_t total_file_space,subfilespace,filespace,memspace,ticspace;
hsize_t dimsf[1],count[1],offset[1];
plist_id=H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_mpio(plist_id,MPI_COMM_WORLD,MPI_INFO_NULL);
// H5Pset_fclose_degree(plist_id,H5F_CLOSE_SEMI);
// MPI_Barrier(MPI_COMM_WORLD);
file_id=H5Fopen(fileName,H5F_ACC_RDWR,plist_id);
H5Pclose(plist_id);
dimsf[0]=totalCnt;
filespace=H5Screate_simple(1,dimsf,NULL);
count[0]=cnt;
offset[0]=offSet;
memspace=H5Screate_simple(1,count,NULL);
dset_id=H5Dcreate2(file_id,dataName,H5T_NATIVE_INT,filespace,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
subfilespace=H5Dget_space(dset_id);
H5Sselect_hyperslab(subfilespace,H5S_SELECT_SET,offset,NULL,count,NULL);
plist_id=H5Pcreate(H5P_DATASET_XFER);
H5Pset_dxpl_mpio(plist_id,H5FD_MPIO_INDEPENDENT);
status = H5Dwrite(dset_id, H5T_NATIVE_INT,memspace,subfilespace,plist_id,data);
H5Pclose(plist_id);
H5Sclose(subfilespace);
H5Dclose(dset_id);
H5Sclose(memspace);
H5Sclose(filespace);
H5Fclose(file_id);
}
示例14: F77_FUNC_
void F77_FUNC_(pwhdf_open_file,PWHDF_OPEN_FILE)(const char* fname, const int* length)
{
char * hfname = ( char * ) malloc( (*length) + 1 ) ;
memcpy( hfname , fname , *length ) ;
hfname[*length] = '\0' ;
if(h_file>=0) H5Fclose(h_file);
h_file = H5Fcreate(hfname,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
/* impelements version 1.00 hdf5 format */
int version[]={1,10};
hsize_t dim=2;
hid_t dataspace= H5Screate_simple(1, &dim, NULL);
hid_t dataset= H5Dcreate(h_file, "version", H5T_NATIVE_INT, dataspace, H5P_DEFAULT);
hid_t ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,version);
H5Sclose(dataspace);
H5Dclose(dataset);
free(hfname);
}
示例15: dumpToH5
void dumpToH5(int Ni, int Nj, int Nk, int is, int js, int ks, int ie, int je, int ke, float ***f, char *format, ...) {
char filename[1024];
va_list ap;
va_start(ap, format);
vsprintf(filename, format, ap);
hid_t file, dataset, filespace, memspace;
hsize_t dimsm[3] = { Ni, Nj, Nk };
hsize_t start[3] = { is, js, ks };
hsize_t count[3] = { 1-is+ie, 1-js+je, 1-ks+ke };
memspace = H5Screate_simple(3, dimsm, 0);
filespace = H5Screate_simple(3, count, 0);
file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
dataset = H5Dcreate(file, "Data", H5T_NATIVE_FLOAT, filespace, H5P_DEFAULT);
H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, 0, count, 0);
H5Dwrite(dataset, H5T_NATIVE_FLOAT, memspace, filespace, H5P_DEFAULT, f[0][0]);
H5Dclose(dataset);
H5Sclose(filespace);
H5Sclose(memspace);
H5Fclose(file);
}