本文整理汇总了C++中H5Gopen2函数的典型用法代码示例。如果您正苦于以下问题:C++ H5Gopen2函数的具体用法?C++ H5Gopen2怎么用?C++ H5Gopen2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了H5Gopen2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: check_file
/*-------------------------------------------------------------------------
* Function: check_file
*
* Purpose: Part 2 of a two-part H5Fflush() test.
*
* Return: Success: 0
*
* Failure: 1
*
* Programmer: Leon Arber
* Sept. 26, 2006.
*
*-------------------------------------------------------------------------
*/
static int
check_file(char* filename, hid_t fapl, int flag)
{
hid_t file, groups, grp;
char name[1024];
int i;
if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) goto error;
if(check_dset(file, "dset")) goto error;
/* Open some groups */
if((groups = H5Gopen2(file, "some_groups", H5P_DEFAULT)) < 0) goto error;
for(i = 0; i < 100; i++) {
sprintf(name, "grp%02u", (unsigned)i);
if((grp = H5Gopen2(groups, name, H5P_DEFAULT)) < 0) goto error;
if(H5Gclose(grp) < 0) goto error;
} /* end for */
/* Check to see if that last added dataset in the third file is accessible
* (it shouldn't be...but it might. Flag an error in case it is for now */
if(flag && check_dset(file, "dset2")) goto error;
if(H5Gclose(groups) < 0) goto error;
if(H5Fclose(file) < 0) goto error;
return 0;
error:
return 1;
} /* end check_file() */
示例2: test_groups_with_filters
/*-------------------------------------------------------------------------
* Function: test_groups_with_filters
*
* Purpose: Tests opening group with dynamically loaded filters
*
* Return: Success: 0
* Failure: -1
*
* Programmer: Raymond Lu
* 1 April 2013
*
*-------------------------------------------------------------------------
*/
static herr_t
test_groups_with_filters(hid_t file)
{
hid_t gid, group;
int i;
char gname[256];
TESTING("Testing opening groups with DYNLIB3 filter");
/* Open the top group */
if((gid = H5Gopen2(file, "group1", H5P_DEFAULT)) < 0) goto error;
/* Create multiple groups under "group1" */
for (i=0; i < GROUP_ITERATION; i++) {
sprintf(gname, "group_%d", i);
if((group = H5Gopen2(gid, gname, H5P_DEFAULT)) < 0) goto error;
if(H5Gclose(group) < 0) goto error;
}
/* Close the group */
if(H5Gclose(gid) < 0) goto error;
PASSED();
return 0;
error:
return -1;
}
示例3: main
int main(){
hid_t fprop;
hid_t fid;
hid_t vol_id = H5VL_memvol_init();
herr_t status;
hid_t g1, g2;
hid_t plist;
char name[1024];
fprop = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_vol(fprop, vol_id, &fprop);
fid = H5Fcreate("test", H5F_ACC_TRUNC, H5P_DEFAULT, fprop);
H5VLget_plugin_name(fid, name, 1024);
printf ("Using VOL %s\n", name);
g1 = H5Gcreate2(fid, "g1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Gclose(g1);
g2 = H5Gcreate2(fid, "g2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
g1 = H5Gcreate2(g2, "g1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Gclose(g1);
H5Gclose(g2);
// is this allowed?
//g3 = H5Gcreate2(fid, "g1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
//H5Gclose(g3);
printf("Testing additional functions\n");
g1 = H5Gopen2(fid, "g1", H5P_DEFAULT );
plist = H5Gget_create_plist(g1);
H5G_info_t group_info;
H5Gget_info(g1, & group_info );
H5Gget_info_by_idx(fid, "g1", H5_INDEX_CRT_ORDER, H5_ITER_NATIVE, 0, & group_info, H5P_DEFAULT ) ;
H5Gget_info_by_idx(fid, "g1", H5_INDEX_NAME, H5_ITER_NATIVE, 0, & group_info, H5P_DEFAULT ) ;
H5Gget_info_by_name(fid, "g1", & group_info, H5P_DEFAULT);
H5Pclose(plist);
status = H5Gclose(g1);
g1 = H5Gopen2(fid, "g2", H5P_DEFAULT );
H5Gclose(g1);
//g1 = H5Gopen2(fid, "INVALID", H5P_DEFAULT );
//H5Gclose(g1);
g1 = H5Gcreate_anon( fid, H5P_DEFAULT, H5P_DEFAULT );
H5Gclose(g1);
H5Fclose(fid);
H5VL_memvol_finalize();
printf("Status: %d\n", status);
return 0;
}
示例4: H5Gopen2
void pyne::Material::_load_comp_protocol0(hid_t db, std::string datapath, int row) {
hid_t matgroup = H5Gopen2(db, datapath.c_str(), H5P_DEFAULT);
hid_t nucset;
double nucvalue;
ssize_t nuckeylen;
std::string nuckey;
// get the number of members in the material group
H5G_info_t group_info;
H5Gget_info(matgroup, &group_info);
hsize_t matG = group_info.nlinks;
// Iterate over datasets in the group.
for (int matg = 0; matg < matG; matg++) {
nuckeylen = 1 + H5Lget_name_by_idx(matgroup, ".", H5_INDEX_NAME, H5_ITER_INC, matg,
NULL, 0, H5P_DEFAULT);
char * nkey = new char[nuckeylen];
nuckeylen = H5Lget_name_by_idx(matgroup, ".", H5_INDEX_NAME, H5_ITER_INC, matg,
nkey, nuckeylen, H5P_DEFAULT);
nuckey = nkey;
nucset = H5Dopen2(matgroup, nkey, H5P_DEFAULT);
nucvalue = h5wrap::get_array_index<double>(nucset, row);
if (nuckey == "Mass" || nuckey == "MASS" || nuckey == "mass")
mass = nucvalue;
else
comp[pyne::nucname::id(nuckey)] = nucvalue;
H5Dclose(nucset);
delete[] nkey;
};
// Set meta data
atoms_per_molecule = -1.0;
};
示例5: scan_for_max_id
static int
scan_for_max_id( FileHandle* file_ptr, mhdf_Status* status )
{
hid_t group_id;
herr_t rval;
/* Check for new format, with max_id as attrib of root group */
#if defined(H5Gopen_vers) && H5Gopen_vers > 1
group_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT );
#else
group_id = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP );
#endif
if (group_id < 0)
{
mhdf_setFail( status, "Internal error - invalid file.");
return 0;
}
if (mhdf_read_scalar_attrib( group_id, MAX_ID_ATTRIB,
H5T_NATIVE_ULONG, &file_ptr->max_id,
status ))
{
H5Gclose( group_id );
return 1;
}
/* Didn't find it, scan the elements group */
rval = H5Giterate( group_id, ELEMENT_GROUP_NAME, 0, &max_id_iter, &file_ptr->max_id );
if (rval)
{
H5Gclose( group_id );
mhdf_setFail( status, "Internal error -- invalid file." );
return 0;
}
/* Check node table too */
rval = get_max_id( group_id, NODE_GROUP_NAME, "coordinates", (unsigned long*)(&file_ptr->max_id) );
if (rval)
{
H5Gclose( group_id );
mhdf_setFail( status, "Internal error -- invalid file." );
return 0;
}
/* Check set table, if it exists */
rval = mhdf_is_in_group( group_id, SET_GROUP_NAME, status );
if (rval < 1)
{
H5Gclose( group_id );
return !rval;
}
rval = get_max_id( group_id, SET_GROUP_NAME, SET_META_NAME, (unsigned long*)(&file_ptr->max_id) );
H5Gclose( group_id );
if (rval)
{
mhdf_setFail( status, "Internal error -- invalid file." );
return 0;
}
return 1;
}
示例6: PetscViewerHDF5OpenGroup
PetscErrorCode PetscViewerHDF5OpenGroup(PetscViewer viewer, hid_t *fileId, hid_t *groupId)
{
hid_t file_id, group;
const char *groupName = NULL;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscViewerHDF5GetFileId(viewer, &file_id);CHKERRQ(ierr);
ierr = PetscViewerHDF5GetGroup(viewer, &groupName);CHKERRQ(ierr);
/* Open group */
if (groupName) {
PetscBool root;
ierr = PetscStrcmp(groupName, "/", &root);CHKERRQ(ierr);
if (!root && !H5Lexists(file_id, groupName, H5P_DEFAULT)) {
#if (H5_VERS_MAJOR * 10000 + H5_VERS_MINOR * 100 + H5_VERS_RELEASE >= 10800)
group = H5Gcreate2(file_id, groupName, 0, H5P_DEFAULT, H5P_DEFAULT);
#else /* deprecated HDF5 1.6 API */
group = H5Gcreate(file_id, groupName, 0);
#endif
if (group < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_LIB, "Could not create group %s", groupName);
ierr = H5Gclose(group);CHKERRQ(ierr);
}
#if (H5_VERS_MAJOR * 10000 + H5_VERS_MINOR * 100 + H5_VERS_RELEASE >= 10800)
group = H5Gopen2(file_id, groupName, H5P_DEFAULT);
#else
group = H5Gopen(file_id, groupName);
#endif
if (group < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_LIB, "Could not open group %s", groupName);
} else group = file_id;
*fileId = file_id;
*groupId = group;
PetscFunctionReturn(0);
}
示例7: soft_link_example
static void soft_link_example(void)
{
hid_t file_id;
hid_t group_id;
/* Define the link class that we'll use to register "user-defined soft
* links" using the callbacks we defined above.
* A link class can have NULL for any callback except its traverse
* callback.
*/
const H5L_class_t UD_soft_class[1] = {{
H5L_LINK_CLASS_T_VERS, /* Version number for this struct.
* This field is always H5L_LINK_CLASS_T_VERS */
(H5L_type_t)UD_SOFT_CLASS, /* Link class id number. This can be any
* value between H5L_TYPE_UD_MIN (64) and
* H5L_TYPE_MAX (255). It should be a
* value that isn't already being used by
* another kind of link. We'll use 65. */
"UD_soft_link", /* Link class name for debugging */
NULL, /* Creation callback */
NULL, /* Move callback */
NULL, /* Copy callback */
UD_soft_traverse, /* The actual traversal function */
NULL, /* Deletion callback */
NULL /* Query callback */
}};
/* First, create a file and an object within the file for the link to
* point to.
*/
file_id = H5Fcreate(SOFT_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
group_id = H5Gcreate2(file_id, TARGET_GROUP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Gclose(group_id);
/* This is how we create a normal soft link to the group.
*/
H5Lcreate_soft(TARGET_GROUP, file_id, SOFT_LINK_NAME, H5P_DEFAULT, H5P_DEFAULT);
/* To do the same thing using a user-defined link, we first have to
* register the link class we defined.
*/
H5Lregister(UD_soft_class);
/* Now create a user-defined link. We give it the path to the group
* as its udata.1
*/
H5Lcreate_ud(file_id, UD_SOFT_LINK_NAME, (H5L_type_t)UD_SOFT_CLASS, TARGET_GROUP,
strlen(TARGET_GROUP) + 1, H5P_DEFAULT, H5P_DEFAULT);
/* We can access the group through the UD soft link like we would through
* a normal soft link. This link will still dangle if the object's
* original name is changed or unlinked.
*/
group_id = H5Gopen2(file_id, UD_SOFT_LINK_NAME, H5P_DEFAULT);
/* The group is now open normally. Don't forget to close it! */
H5Gclose(group_id);
H5Fclose(file_id);
}
示例8: H5Fopen
void SGDSolver<Dtype>::RestoreSolverStateFromHDF5(const string& state_file) {
#ifdef USE_HDF5
hid_t file_hid = H5Fopen(state_file.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK_GE(file_hid, 0) << "Couldn't open solver state file " << state_file;
this->iter_ = hdf5_load_int(file_hid, "iter");
if (H5LTfind_dataset(file_hid, "learned_net")) {
string learned_net = hdf5_load_string(file_hid, "learned_net");
this->net_->CopyTrainedLayersFrom(learned_net);
}
this->current_step_ = hdf5_load_int(file_hid, "current_step");
hid_t history_hid = H5Gopen2(file_hid, "history", H5P_DEFAULT);
CHECK_GE(history_hid, 0) << "Error reading history from " << state_file;
int state_history_size = hdf5_get_num_links(history_hid);
CHECK_EQ(state_history_size, history_.size())
<< "Incorrect length of history blobs.";
for (int i = 0; i < history_.size(); ++i) {
ostringstream oss;
oss << i;
hdf5_load_nd_dataset<Dtype>(history_hid, oss.str().c_str(), 0,
kMaxBlobAxes, history_[i].get());
}
H5Gclose(history_hid);
H5Fclose(file_hid);
#else
LOG(FATAL) << "RestoreSolverStateFromHDF5 requires hdf5;"
<< " compile with USE_HDF5.";
#endif // USE_HDF5
}
示例9: OpenGroup
//-*****************************************************************************
H5Node OpenGroup( H5Node& iParent, const std::string& iName )
{
ABCA_ASSERT( iParent.isValidObject(),
"Invalid parent group passed into HDF5Util OpenGroup: "
<< iName << std::endl );
HDF5Hierarchy* h5HPtr = iParent.getH5HPtr();
if ( h5HPtr )
{
hobj_ref_t childRef = h5HPtr->getChildRef( iParent.getRef(), iName );
hid_t childId = H5Rdereference( iParent.getObject(),
H5R_OBJECT,
&childRef );
return H5Node( childId, childRef, h5HPtr );
}
else
{
hid_t childId = H5Gopen2( iParent.getObject(),
iName.c_str(),
H5P_DEFAULT );
return H5Node( childId, 0, NULL );
}
}
示例10: H5Fopen
int64_t GWriteHDFFile::WriteBlock(std::string BlockName, int type, void *data, int partlen, uint32_t np_write, uint32_t begin)
{
herr_t herr;
hid_t handle = H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
hid_t group = H5Gopen2(handle, g_name[type], H5P_DEFAULT);
if(group < 0)
return group;
hsize_t size[2];
int rank=1;
//Get type
char b_type = get_block_type(BlockName);
hid_t dtype;
if(b_type == 'f') {
size[1] = partlen/sizeof(float);
dtype=H5T_NATIVE_FLOAT;
}else if (b_type == 'i') {
size[1] = partlen/sizeof(int64_t);
//Hopefully this is 64 bits; the HDF5 manual is not clear.
dtype = H5T_NATIVE_LLONG;
}
else{
return -1000;
}
if (size[1] > 1) {
rank = 2;
}
/* I don't totally understand why the below works (it is not clear to me from the documentation).
* I gleaned it from a posting to the HDF5 mailing list and a related stack overflow thread here:
* http://stackoverflow.com/questions/24883461/hdf5-updating-a-cell-in-a-table-of-integers
* http://lists.hdfgroup.org/pipermail/hdf-forum_lists.hdfgroup.org/2014-July/007966.html
* The important thing seems to be that we have a dataspace for the whole array and create a hyperslab on that dataspace.
* Then we need another dataspace with the size of the stuff we want to write.*/
//Make space in memory for the whole array
//Create a hyperslab that we will write to
size[0] = npart[type];
hid_t full_space_id = H5Screate_simple(rank, size, NULL);
//If this is the first write, create the dataset
if (begin==0) {
H5Dcreate2(group,BlockName.c_str(),dtype, full_space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
}
hid_t dset = H5Dopen2(group,BlockName.c_str(),H5P_DEFAULT);
if (dset < 0)
return dset;
size[0] = np_write;
hid_t space_id = H5Screate_simple(rank, size, NULL);
hsize_t begins[2]={begin,0};
//Select the hyperslab of elements we are about to write to
H5Sselect_hyperslab(full_space_id, H5S_SELECT_SET, begins, NULL, size, NULL);
/* Write to the dataset */
herr = H5Dwrite(dset, dtype, space_id, full_space_id, H5P_DEFAULT, data);
H5Dclose(dset);
H5Sclose(space_id);
H5Sclose(full_space_id);
H5Gclose(group);
H5Fclose(handle);
if (herr < 0)
return herr;
return np_write;
}
示例11: test_opening_groups_using_plugins
/*-------------------------------------------------------------------------
* Function: test_opening_groups_using_plugins
*
* Purpose: Tests opening group with dynamically loaded filters
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
test_opening_groups_using_plugins(hid_t fid)
{
hid_t gid = -1;
hid_t sub_gid = -1;
int i;
char subgroup_name[256];
TESTING("opening groups with filter plugin 4");
/* Open the top group */
if ((gid = H5Gopen2(fid, TOP_LEVEL_GROUP_NAME, H5P_DEFAULT)) < 0)
TEST_ERROR;
/* Open all the sub-groups under the top-level group */
for (i = 0; i < N_SUBGROUPS; i++) {
char *sp = subgroup_name;
sp += HDsprintf(subgroup_name, SUBGROUP_PREFIX);
HDsprintf(sp, "%d", i);
if ((sub_gid = H5Gopen2(gid, subgroup_name, H5P_DEFAULT)) < 0)
TEST_ERROR;
if (H5Gclose(sub_gid) < 0)
TEST_ERROR;
}
/* Close the top-level group */
if (H5Gclose(gid) < 0)
TEST_ERROR;
PASSED();
return SUCCEED;
error:
/* Clean up objects used for this test */
H5E_BEGIN_TRY {
H5Gclose(gid);
H5Gclose(sub_gid);
} H5E_END_TRY
return FAIL;
} /* end test_opening_groups_using_plugins() */
示例12: H5Eset_auto2
/**
Traverse the path of an object in HDF5 file, checking existence of
groups in the path and creating them if required. */
hid_t HDF5DataWriter::getDataset(string path)
{
if (filehandle_ < 0){
return -1;
}
herr_t status = H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
// Create the groups corresponding to this path
string::size_type lastslash = path.find_last_of("/");
vector<string> pathTokens;
moose::tokenize(path, "/", pathTokens);
hid_t prev_id = filehandle_;
hid_t id = -1;
for ( unsigned int ii = 0; ii < pathTokens.size()-1; ++ii ){
// check if object exists
htri_t exists = H5Lexists(prev_id, pathTokens[ii].c_str(),
H5P_DEFAULT);
if (exists > 0){
// try to open existing group
id = H5Gopen2(prev_id, pathTokens[ii].c_str(), H5P_DEFAULT);
} else if (exists == 0) {
// If that fails, try to create a group
id = H5Gcreate2(prev_id, pathTokens[ii].c_str(),
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
}
if ((exists < 0) || (id < 0)){
// Failed to open/create a group, print the
// offending path (for debugging; the error is
// perhaps at the level of hdf5 or file system).
cerr << "Error: failed to open/create group: ";
for (unsigned int jj = 0; jj <= ii; ++jj){
cerr << "/" << pathTokens[jj];
}
cerr << endl;
prev_id = -1;
}
if (prev_id >= 0 && prev_id != filehandle_){
// Successfully opened/created new group, close the old group
status = H5Gclose(prev_id);
assert( status >= 0 );
}
prev_id = id;
}
string name = pathTokens[pathTokens.size()-1];
htri_t exists = H5Lexists(prev_id, name.c_str(), H5P_DEFAULT);
hid_t dataset_id = -1;
if (exists > 0){
dataset_id = H5Dopen2(prev_id, name.c_str(), H5P_DEFAULT);
} else if (exists == 0){
dataset_id = createDoubleDataset(prev_id, name);
} else {
cerr << "Error: H5Lexists returned "
<< exists << " for path \""
<< path << "\"" << endl;
}
return dataset_id;
}
示例13: main
int
main()
{
printf("\n*** Checking many attributes in HDF5 file.\n");
printf("*** Checking some more simple atts...\n");
{
#define NUM_ATTS 10000
hid_t fcpl_id, hdfid, grpid;
hid_t spaceid, attid1;
int one = 1;
hsize_t dims[1] = {1};
int i;
char name[NC_MAX_NAME];
struct timeval start_time, end_time, diff_time;
double sec;
/* Create a HDF5 file. */
if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR;
if (H5Pset_link_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED |
H5P_CRT_ORDER_INDEXED)) < 0) ERR;
if (H5Pset_attr_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED |
H5P_CRT_ORDER_INDEXED)) < 0) ERR;
if ((hdfid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT)) < 0) ERR;
if (H5Pclose(fcpl_id) < 0) ERR;
/* Open the root group. */
if ((grpid = H5Gopen2(hdfid, "/", H5P_DEFAULT)) < 0) ERR;
if (gettimeofday(&start_time, NULL)) ERR;
/* Write an attribute. */
if ((spaceid = H5Screate_simple(1, dims, NULL)) < 0) ERR;
for (i = 0; i < NUM_ATTS; i++)
{
sprintf(name, "att_%d", i);
if ((attid1 = H5Acreate2(grpid, name, H5T_NATIVE_INT, spaceid,
H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
if (H5Awrite(attid1, H5T_NATIVE_INT, &one) < 0) ERR;
/* if (H5Aclose(attid1) < 0) ERR;*/
if((i + 1) % 1000 == 0)
{ /* only print every 1000th attribute name */
if (gettimeofday(&end_time, NULL)) ERR;
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
sec = diff_time.tv_sec + 1.0e-6 * diff_time.tv_usec;
printf("%i\t%.3g sec\n", i + 1, sec);
}
}
/* Close everything. */
if (H5Sclose(spaceid) < 0) ERR;
if (H5Gclose(grpid) < 0) ERR;
if (H5Fclose(hdfid) < 0) ERR;
}
SUMMARIZE_ERR;
FINAL_RESULTS;
}
示例14: loadHdf5Input
/* Read and load coefficients Knlm and scale radius a */
int loadHdf5Input(char *filename, struct Indata *var){
hid_t hdf_file,hdf_group,hdf_data;
herr_t status;
double temp[NMAX][LMAX][LMAX][2];
fprintf(stdout,"Reading file %s ...",filename);
hdf_file = H5Fopen(filename,H5F_ACC_RDONLY,H5P_DEFAULT);
if (hdf_file < 0){
return -1;
}
if ( (hdf_group=H5Gopen2(hdf_file,"/",H5P_DEFAULT)) < 0){
H5Gclose(hdf_file);
return -1;
}
if ( (hdf_data=H5Dopen2(hdf_file,"/Knlm",H5P_DEFAULT)) < 0){
H5Dclose(hdf_data);
return -1;
}
//status=H5Dread(hdf_data, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, var->Knlm);
status=H5Dread(hdf_data, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, temp);
for (int n=0; n<NMAX; n++){
for (int l=0; l<LMAX; l++){
for (int m=0; m<LMAX; m++){
var->Knlm[l][m][n][0]=temp[n][l][m][0]; // I reorder the matrix since the summation
var->Knlm[l][m][n][1]=temp[n][l][m][1]; // over n is done first
// [0]/[1] -> cosine/sine terms
}
}
}
/* Read virial radius (not really needed) */
if ( (hdf_data=H5Dopen2(hdf_file,"/Rvir",H5P_DEFAULT)) < 0){
H5Dclose(hdf_data);
return -1;
}
status=H5Dread(hdf_data, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &var->virialrad);
/* Read Hernquist scale radius needed to normalize positions */
if ( (hdf_data=H5Dopen2(hdf_file,"/a",H5P_DEFAULT)) < 0){
H5Dclose(hdf_data);
return -1;
}
status=H5Dread(hdf_data, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &var->scalerad);
//H5Gclose(hdf_group);
H5Fclose(hdf_file);
H5Dclose(hdf_data);
fprintf(stdout," file read successfully!\n");
return 0;
}
示例15: H5CreateOrOpenGroup
hid_t H5CreateOrOpenGroup(hid_t &file_id, string &group_name) {
hid_t group_id;
if(group_name == "/") {
group_id = H5Gopen2(file_id, group_name.c_str(), H5P_DEFAULT);
} else {
// first make sure the base group exists
string delim = "/";
int pos = group_name.rfind(delim);
if((pos != (int) std::string::npos) && (pos != 0)) {
string subgroup = group_name.substr(0,pos);
group_id = H5CreateOrOpenGroup(file_id, subgroup);
H5Gclose (group_id);
}
// then open or create the group we want
if(H5Lexists(file_id, group_name.c_str(), H5P_DEFAULT)) {
group_id = H5Gopen2(file_id, group_name.c_str(), H5P_DEFAULT);
} else {
group_id = H5Gcreate2(file_id, group_name.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
}
}
return(group_id);
}