本文整理汇总了C++中H5Dcreate2函数的典型用法代码示例。如果您正苦于以下问题:C++ H5Dcreate2函数的具体用法?C++ H5Dcreate2怎么用?C++ H5Dcreate2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了H5Dcreate2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_dangle_dataset
/*-------------------------------------------------------------------------
* Function: test_dangle_dataset
*
* Purpose: Check for dangling dataset IDs causing problems on library
* shutdown
*
* Return: Success: zero
* Failure: non-zero
*
* Programmer: Quincey Koziol
* Tuesday, May 13, 2003
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
test_dangle_dataset(H5F_close_degree_t degree)
{
char filename[1024];
hid_t fid; /* File ID */
hid_t fapl; /* File access property list */
hid_t dsid; /* Dataset ID */
hid_t sid; /* Dataspace ID */
unsigned u; /* Local index variable */
TESTING(" dangling dataset IDs");
if(H5open() < 0)
TEST_ERROR;
/* Create file access property list */
if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
TEST_ERROR;
/* Set file close degree */
if(H5Pset_fclose_degree(fapl, degree) < 0)
TEST_ERROR;
h5_fixname(FILENAME[0], H5P_DEFAULT, filename, sizeof filename);
if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
TEST_ERROR;
if((sid = H5Screate(H5S_SCALAR)) < 0)
TEST_ERROR;
if((dsid = H5Dcreate2(fid, DSETNAME, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
TEST_ERROR;
if(H5Dclose(dsid) < 0)
TEST_ERROR;
/* Try creating duplicate dataset */
H5E_BEGIN_TRY {
if((dsid = H5Dcreate2(fid, DSETNAME, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) >= 0)
TEST_ERROR;
} H5E_END_TRY;
if(H5Sclose(sid) < 0)
TEST_ERROR;
/* Leave open a _lot_ of objects */
for(u = 0; u < MAX_DANGLE; u++)
if((dsid = H5Dopen2(fid, DSETNAME, H5P_DEFAULT)) < 0)
TEST_ERROR;
if(degree == H5F_CLOSE_SEMI) {
H5E_BEGIN_TRY {
if(H5Fclose(fid) >= 0)
TEST_ERROR;
} H5E_END_TRY;
} /* end if */
示例2: main
int
main(void)
{
hid_t file=-1, dcpl=-1, space=-1, dset1=-1, dset2=-1;
hsize_t cur_size[2]= {8, 8};
H5D_space_status_t allocation;
int fill_val1 = 4444, fill_val2=5555;
if((file=H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) <0) goto error;
if((space=H5Screate_simple(2, cur_size, cur_size)) < 0) goto error;
if((dcpl=H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error;
/* Create a dataset with space being allocated and fill value written */
if(H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) goto error;
if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) goto error;
if(H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fill_val1) < 0) goto error;
if((dset1 = H5Dcreate2(file, "dset1", H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
goto error;
if(H5Dget_space_status(dset1, &allocation) < 0) goto error;
if(allocation == H5D_SPACE_STATUS_NOT_ALLOCATED) {
puts(" Got unallocated space instead of allocated.");
printf(" Got %d\n", allocation);
goto error;
}
if(H5Dclose(dset1) < 0) goto error;
/* Create a dataset with space allocation being delayed */
if(H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_LATE) < 0) goto error;
if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) goto error;
if(H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fill_val2) < 0) goto error;
if((dset2 = H5Dcreate2(file, "dset2", H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
goto error;
if(H5Dget_space_status(dset2, &allocation) < 0) goto error;
if(allocation != H5D_SPACE_STATUS_NOT_ALLOCATED) {
puts(" Got allocated space instead of unallocated.");
printf(" Got %d\n", allocation);
goto error;
}
if(H5Dclose(dset2) < 0) goto error;
if(H5Sclose(space) < 0) goto error;
if(H5Pclose(dcpl) < 0) goto error;
if(H5Fclose(file) < 0) goto error;
return 0;
error:
H5E_BEGIN_TRY {
H5Pclose(dcpl);
H5Sclose(space);
H5Dclose(dset1);
H5Dclose(dset2);
H5Fclose(file);
} H5E_END_TRY;
return 1;
}
示例3: saveHdf5
int saveHdf5(state_type &OUT, state_type &TIME){
hid_t hdf_file,hdf_group,hdf_data,dataspace_id;
herr_t status;
fprintf(stdout,"Writing file %s ...",allparams.outfilename);
hdf_file = H5Fcreate(allparams.outfilename,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
if (hdf_file < 0){
return -1;
}
/*
if ( (hdf_group=H5Gopen2(hdf_file,"/",H5P_DEFAULT)) < 0){
H5Fclose(hdf_file);
return -1;
}*/
/* Write particle positions and velocities.
* Ordered in chunk where first Nstep+1 lines correspond to particle 1,
* step Nstep+1 chunk correspond to particle 2 etc. */
std::cout << "Writing positions and velocities\n";
hsize_t dims[1]={OUT.size()};
dataspace_id=H5Screate_simple(1,dims,NULL);
if ( (hdf_data=H5Dcreate2(hdf_file,"x",H5T_NATIVE_DOUBLE,dataspace_id,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT)) < 0){
H5Dclose(hdf_data);
return -1;
}
status=H5Dwrite(hdf_data, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &OUT[0]);
/*Write times*/
std::cout << "Writing times\n";
hsize_t dims2[1]={TIME.size()};
dataspace_id=H5Screate_simple(1,dims2,NULL);
if ( (hdf_data=H5Dcreate2(hdf_file,"t",H5T_NATIVE_DOUBLE,dataspace_id,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT)) < 0){
H5Dclose(hdf_data);
return -1;
}
status=H5Dwrite(hdf_data, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &TIME[0]);
/*Write no. of components*/
dims2[0]={1};
dataspace_id=H5Screate_simple(1,dims2,NULL);
if ( (hdf_data=H5Dcreate2(hdf_file,"NumComponents",H5T_NATIVE_INT,dataspace_id,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT)) < 0){
H5Dclose(hdf_data);
return -1;
}
status=H5Dwrite(hdf_data, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &allparams.NumComponents);
H5Fclose(hdf_file);
H5Dclose(hdf_data);
H5Sclose(dataspace_id);
fprintf(stdout," file written successfully!\n");
return 0;
}
示例4: assertSuccess
void Dataset::createAndInitialize(
Location const& location
, Datatype const& datatype
, Dataspace const& dataspace
, optional<void const*> const& optional_data
, optional<DatasetCreationProperties const&> const& optional_creation_properties
, optional<DatasetAccessProperties const&> const& optional_access_properties
, optional<LinkCreationProperties const&> const& optional_link_creation_properties
) { // {{{
identity =
make_shared<Identity>(
assertSuccess(
"creating dataset",
H5Dcreate2(
location.getParentId(),
location.getNameAsCStr(),
datatype.getDatatypeId(),
dataspace.getId(),
getOptionalPropertiesId(optional_link_creation_properties),
getOptionalPropertiesId(optional_creation_properties),
getOptionalPropertiesId(optional_access_properties)
)
),
H5Dclose
);
if(optional_data) write(*optional_data,datatype);
} // }}}
示例5: H5Dcreate2
int H5mdfile::H5_Dcreate2(int argc, char **argv, Tcl_Interp *interp)
{
/* Create the dataset */
dataset_id = H5Dcreate2(file_id, argv[2], dataset_type_id, dataspace_simple_id, H5P_DEFAULT, prop_id, H5P_DEFAULT);
dataspace_id = H5Dget_space (dataset_id);
return TCL_OK;
}
示例6: gent_compressed
/*-------------------------------------------------------------------------
* Function: gent_compressed
*
* Purpose: Generate a compressed dataset in LOC_ID
*
*-------------------------------------------------------------------------
*/
static void gent_compressed(hid_t loc_id)
{
hid_t sid, did, pid;
hsize_t dims[1] = {6};
hsize_t chunk_dims[1] = {2};
int buf[6] = {1,2,3,4,5,6};
/* create dataspace */
sid = H5Screate_simple(1, dims, NULL);
/* create property plist for chunk*/
pid = H5Pcreate(H5P_DATASET_CREATE);
H5Pset_chunk(pid, 1, chunk_dims);
/* set the deflate filter */
#if defined (H5_HAVE_FILTER_DEFLATE)
H5Pset_deflate(pid, 1);
#endif
/* create dataset */
did = H5Dcreate2(loc_id, DATASET_COMPRESSED, H5T_NATIVE_INT, sid, H5P_DEFAULT, pid, H5P_DEFAULT);
/* write */
H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
/* close */
H5Sclose(sid);
H5Dclose(did);
H5Pclose(pid);
}
示例7: new_object
/*-------------------------------------------------------------------------
* Function: new_object
*
* Purpose: Creates a new object that refers to a indexed storage of raw
* data. No raw data is stored.
*
* Return: Success: ID of dataset
*
* Failure: -1
*
* Programmer: Robb Matzke
* Wednesday, October 15, 1997
*
* Modifications:
* Converted to use datasets instead of directly messing with
* the istore routines, etc. since the new raw data architecture
* performs hyperslab operations at a higher level than the
* istore routines did and the new istore routines can't handle
* I/O on more than one chunk at a time. QAK - 2003/04/16
*
*-------------------------------------------------------------------------
*/
static hid_t
new_object(hid_t f, const char *name, int ndims, hsize_t dims[], hsize_t cdims[])
{
hid_t dataset; /* Dataset ID */
hid_t space; /* Dataspace ID */
hid_t dcpl; /* Dataset creation property list ID */
/* Create the dataset creation property list */
if ((dcpl=H5Pcreate(H5P_DATASET_CREATE)) < 0) TEST_ERROR;
/* Set the chunk dimensions */
if(H5Pset_chunk(dcpl, ndims, cdims) < 0) TEST_ERROR;
/* Create the dataspace */
if((space = H5Screate_simple(ndims, dims, NULL)) < 0) TEST_ERROR;
/* Create the dataset */
if((dataset = H5Dcreate2(f, name, TEST_DATATYPE, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) TEST_ERROR;
/* Clean up */
/* Close property lists */
if(H5Pclose(dcpl) < 0) TEST_ERROR;
/* Close dataspace */
if(H5Sclose(space) < 0) TEST_ERROR;
return dataset;
error:
return -1;
}
示例8: create_dsets
/*-------------------------------------------------------------------------
* Function: create_dsets
*
* Purpose: Attempts to create some datasets.
*
* Return: Success: 0
*
* Failure: -1
*
* Programmer: Raymond Lu
* Friday, Oct 3, 2003
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
create_dsets(hid_t file)
{
hid_t dataset;
char dset_name[32];
int i;
/*
* Create a dataset using the default dataset creation properties.
*/
for(i = 0; i < NUM_DSETS; i++) {
sprintf(dset_name, "dataset %d", i);
if((dataset = H5Dcreate2(file, dset_name, H5T_NATIVE_DOUBLE, space,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto error;
if(H5Dclose(dataset) < 0)
goto error;
} /* end for */
return 0;
error:
return -1;
}
示例9: memcpy
void *tts_dcreate_creator(void *_thread_data)
{
hid_t dataspace, dataset;
herr_t ret;
hsize_t dimsf[1]; /* dataset dimensions */
struct thread_info thread_data;
memcpy(&thread_data, _thread_data, sizeof(struct thread_info));
/* define dataspace for dataset */
dimsf[0] = 1;
dataspace = H5Screate_simple(1, dimsf, NULL);
assert(dataspace >= 0);
/* create a new dataset within the file */
dataset = H5Dcreate2(thread_data.file, thread_data.dsetname,
H5T_NATIVE_INT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
assert(dataset >= 0);
/* initialize data for dataset and write value to dataset */
ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, &thread_data.id);
assert(ret >= 0);
/* close dataset and dataspace resources */
ret = H5Dclose(dataset);
assert(ret >= 0);
ret = H5Sclose(dataspace);
assert(ret >= 0);
return NULL;
}
示例10: h5dcreate_c
/****if* H5Df/h5dcreate_c
* NAME
* h5dcreate_c
* PURPOSE
* Call H5Dcreate2 to create a dataset
* INPUTS
* loc_id - file or group identifier
* name - name of the dataset
* namelen - name length
* type_id - datatype identifier
* space_id - dataspace identifier
* crt_pr - identifier of creation property list
* OUTPUTS
* dset_id - dataset identifier
* RETURNS
* 0 on success, -1 on failure
* AUTHOR
* Elena Pourmal
* Wednesday, August 4, 1999
* HISTORY
* - Added optional parameters introduced in version 1.8
* February, 2008
* SOURCE
*/
int_f
h5dcreate_c (hid_t_f *loc_id, _fcd name, int_f *namelen, hid_t_f *type_id, hid_t_f *space_id,
hid_t_f *lcpl_id, hid_t_f *dcpl_id, hid_t_f *dapl_id, hid_t_f *dset_id)
/******/
{
char *c_name = NULL;
hid_t c_dset_id;
int ret_value = -1;
/*
* Convert FORTRAN name to C name
*/
if(NULL == ( c_name = (char *)HD5f2cstring(name, (size_t)*namelen)))
goto DONE;
/*
* Call H5Dcreate2 function.
*/
if((c_dset_id = H5Dcreate2((hid_t)*loc_id, c_name, (hid_t)*type_id, (hid_t)*space_id,
(hid_t)*lcpl_id, (hid_t)*dcpl_id, (hid_t)*dapl_id)) < 0)
goto DONE;
*dset_id = (hid_t_f)c_dset_id;
ret_value = 0;
DONE:
if(c_name)
HDfree(c_name);
return ret_value;
}
示例11: test_1c
/*-------------------------------------------------------------------------
* Function: test_1c
*
* Purpose: Test a single external file which is large enough to
* represent the current data and large enough to represent the
* eventual size of the data.
*
* Return: Success: 0
*
* Failure: number of errors
*
* Programmer: Robb Matzke
* Monday, November 23, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
test_1c(hid_t file)
{
hid_t dcpl=-1; /*dataset creation properties */
hid_t space=-1; /*data space */
hid_t dset=-1; /*dataset */
hsize_t cur_size[1]; /*current data space size */
hsize_t max_size[1]; /*maximum data space size */
TESTING("extendible dataspace, exact external size");
if((dcpl = H5Pcreate (H5P_DATASET_CREATE)) < 0) goto error;
cur_size[0] = 100;
max_size[0] = 200;
if(H5Pset_external(dcpl, "ext1.data", (off_t)0,
(hsize_t)(max_size[0] * sizeof(int))) < 0) goto error;
if((space = H5Screate_simple(1, cur_size, max_size)) < 0) goto error;
if((dset = H5Dcreate2(file, "dset3", H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
goto error;
if(H5Dclose(dset) < 0) goto error;
if(H5Sclose(space) < 0) goto error;
if(H5Pclose(dcpl) < 0) goto error;
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
H5Dclose(dset);
H5Pclose(dcpl);
H5Sclose(space);
} H5E_END_TRY;
return 1;
}
示例12: gent_compound
/*-------------------------------------------------------------------------
* Function: gent_compound
*
* Purpose: Generate a compound dataset in LOC_ID
*
*-------------------------------------------------------------------------
*/
static void gent_compound(hid_t loc_id)
{
typedef struct s_t
{
char str1[20];
char str2[20];
} s_t;
hid_t sid, did, tid_c, tid_s;
hsize_t dims[1] = {2};
s_t buf[2] = {{"str1", "str2"}, {"str3", "str4"}};
/* create dataspace */
sid = H5Screate_simple(1, dims, NULL);
/* create a compound type */
tid_c = H5Tcreate(H5T_COMPOUND, sizeof(s_t));
tid_s = H5Tcopy(H5T_C_S1);
H5Tset_size(tid_s, 20);
H5Tinsert(tid_c, "str1", HOFFSET(s_t,str1), tid_s);
H5Tinsert(tid_c, "str2", HOFFSET(s_t,str2), tid_s);
/* create dataset */
did = H5Dcreate2(loc_id, DATASET_COMPOUND, tid_c, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* write */
H5Dwrite(did, tid_c, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
/* close */
H5Sclose(sid);
H5Dclose(did);
H5Tclose(tid_c);
H5Tclose(tid_s);
}
示例13: H5Pcreate
asynStatus NDFileHDF5AttributeDataset::createHDF5Dataset()
{
asynStatus status = asynSuccess;
cparm_ = H5Pcreate(H5P_DATASET_CREATE);
H5Pset_fill_value(cparm_, datatype_, ptrFillValue_);
H5Pset_chunk(cparm_, rank_, chunk_);
dataspace_ = H5Screate_simple(rank_, dims_, maxdims_);
// Open the group by its name
hid_t dsetgroup;
if (groupName_ != ""){
dsetgroup = H5Gopen(file_, groupName_.c_str(), H5P_DEFAULT);
} else {
dsetgroup = file_;
}
// Now create the dataset
dataset_ = H5Dcreate2(dsetgroup, dsetName_.c_str(),
datatype_, dataspace_,
H5P_DEFAULT, cparm_, H5P_DEFAULT);
if (groupName_ != ""){
H5Gclose(dsetgroup);
}
memspace_ = H5Screate_simple(rank_, elementSize_, NULL);
return status;
}
示例14: gent_chunked
/*-------------------------------------------------------------------------
* Function: gent_chunked
*
* Purpose: Generate a chunked dataset in LOC_ID
*
*-------------------------------------------------------------------------
*/
static void gent_chunked(hid_t loc_id)
{
hid_t sid, did, pid;
hsize_t dims[1] = {6};
hsize_t chunk_dims[1] = {2};
int buf[6] = {1,2,3,4,5,6};
/* create dataspace */
sid = H5Screate_simple(1, dims, NULL);
/* create property plist */
pid = H5Pcreate(H5P_DATASET_CREATE);
H5Pset_chunk(pid, 1, chunk_dims);
/* create dataset */
did = H5Dcreate2(loc_id, DATASET_CHUNK, H5T_NATIVE_INT, sid, H5P_DEFAULT, pid, H5P_DEFAULT);
/* write */
H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
/* close */
H5Sclose(sid);
H5Dclose(did);
H5Pclose(pid);
}
示例15: WriteNoiseCorrelations
/*
Write an existing noise correlation object to disk.
If filename is already a file, fail.
*/
void WriteNoiseCorrelations(std::string filename, const NoiseCorrelations& noise)
{
hid_t fileID = H5Fcreate(filename.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
// Write a version number of 1.
{
unsigned char version = 1;
hid_t scalarID = H5Screate(H5S_SCALAR);
hid_t attID = H5Acreate2(fileID, "version", H5T_STD_U8LE, scalarID, H5P_DEFAULT, H5P_DEFAULT);
H5Awrite(attID, H5T_NATIVE_UCHAR, reinterpret_cast<void*>(&version));
H5Aclose(attID);
H5Sclose(scalarID);
}
// Write the channel index as an ordered list of included channels.
HDF5Helper::WriteMapAsAttribute(noise.GetNoiseBlockIndex().MinorIndex(),
fileID,
"channel_list");
// Write the actual noise information.
// We choose to write one dataset per frequency, since those are stored in memory as separate arrays.
// However, we need to manually pick out only the entries which contain non-redundant information.
std::vector<double> PackedArray; // Reuse rather than re-allocating each time.
for(size_t f = 0; f < 1024; f++) {
const NoiseMatrix& mat = noise.GetMatrixForIndex(f);
const NoiseCorrelations::NoiseBlockIndexT& NoiseBlockIndex = noise.GetNoiseBlockIndex();
assert(NoiseBlockIndex.MaxIndex() % 2 == 0 and NoiseBlockIndex.MaxIndex() > 0);
// Create the name for this dataset.
std::ostringstream strstream;
strstream << "/noise_corr_" << std::setfill('0') << std::setw(4) << f;
std::string dataset_name = strstream.str();
// Allocate space in the temporary vector.
hsize_t ExpectedSize = ExpectedPackedSize(f, NoiseBlockIndex.MaxIndex());
PackedArray.resize(0);
PackedArray.reserve(NoiseBlockIndex.MaxIndex()*NoiseBlockIndex.MaxIndex()/4);
// Fill PackedArray. Take into account all appropriate symmetries.
for(size_t i = 0; i < NoiseBlockIndex.MaxIndex(); i++) {
for(size_t j = i; j < NoiseBlockIndex.MaxIndex(); j++) {
if(not IncludeEntryInPackedArray(f, i, j, NoiseBlockIndex)) continue;
PackedArray.push_back(mat.GetCorrByIndex(i, j));
}
}
assert(PackedArray.size() == ExpectedSize);
// Write the array to file.
hid_t vectorID = H5Screate_simple(1, &ExpectedSize, NULL);
hid_t datasetID = H5Dcreate2(fileID, dataset_name.c_str(), H5T_IEEE_F64LE, vectorID, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(datasetID, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
reinterpret_cast<void*>(&PackedArray[0]));
H5Dclose(datasetID);
H5Sclose(vectorID);
}
assert(H5Fget_obj_count(fileID, H5F_OBJ_ALL) == 1); // The file should be the only object left.
H5Fclose(fileID);
}