コード例 #1
0
ファイル: flush2.c プロジェクト: CommonLibrary/hdf5
/*-------------------------------------------------------------------------
 * 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
0
ファイル: plugin.c プロジェクト: schwehr/hdf5
/*-------------------------------------------------------------------------
 * 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
0
ファイル: direct-group.c プロジェクト: ESiWACE/ESD-Middleware
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
0
ファイル: material.cpp プロジェクト: crbates/pyne
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
0
ファイル: file.c プロジェクト: chrismullins/moab
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
0
ファイル: vecio.c プロジェクト: feelpp/debian-petsc
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
0
ファイル: h5_extlink.c プロジェクト: ngcurrier/ProteusCFD
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
0
ファイル: sgd_solver.cpp プロジェクト: fossabot/caffe
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
0
ファイル: HDF5Util.cpp プロジェクト: AWhetter/alembic
//-*****************************************************************************
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
0
ファイル: gadgetwritehdf.cpp プロジェクト: sbird/GadgetReader
 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
0
ファイル: filter_plugin.c プロジェクト: Starlink/hdf5
/*-------------------------------------------------------------------------
 * 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
0
ファイル: HDF5DataWriter.cpp プロジェクト: hrani/moose-core
/**
   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
0
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
0
ファイル: readfile.cpp プロジェクト: edjocute/Orbit
/* 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
0
ファイル: ionstats_data.cpp プロジェクト: Brainiarc7/TS
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);
}
コード例 #16
0
/* The example function.
 * Creates a file named "unix2win.h5" with an external link pointing to
 * the file "u2w/u2w_target.h5".
 *
 * Registers a new traversal function for external links and then
 * follows the external link to open the target file.
 */
static int
unix2win_example(void)
{
    hid_t  fid = (-1);         /* File ID */
    hid_t  gid = (-1);         /* Group ID */

    /* Create the target file. */
#ifdef H5_HAVE_WIN32_API
    if((fid=H5Fcreate("u2w\\u2w_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) goto error;
#else
    if((fid=H5Fcreate("u2w/u2w_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) goto error;
#endif
    if(H5Fclose(fid) < 0) goto error;

    /* Create the source file with an external link in Windows format */
    if((fid=H5Fcreate("unix2win.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) goto error;

    /* Create the external link */
    if(H5Lcreate_external("u2w/../u2w/u2w_target.h5", "/", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) goto error;

    /* If we are not on Windows, assume we are on a Unix-y filesystem and
     * follow the external link normally.
     * If we are on Windows, register the unix2win traversal function so
     * that external links can be traversed.
     */

#ifdef H5_HAVE_WIN32_API
    /* Register the elink_unix2win class defined above to replace default
     * external links
     */
    if(H5Lregister(elink_unix2win_class) < 0) goto error;
#endif

    /* Now follow the link */
    if((gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT)) < 0) goto error;
    printf("Successfully followed external link.\n");

    /* Close the group and the file */
    if(H5Gclose(gid) <0) goto error;
    if(H5Fclose(fid) <0) goto error;

    return 0;

 error:
    printf("Error!\n");
    H5E_BEGIN_TRY {
      H5Gclose (gid);
      H5Fclose (fid);
    } H5E_END_TRY;
    return -1;
}
コード例 #17
0
ファイル: tst_h_ints.c プロジェクト: U-238/gempak
int
main()
{
   printf("\n*** Checking HDF5 integer dataset with extension.\n");
   printf("*** checking 1D int dataset with extend...");
   {

/* Misspelling is deliberite. Please dont correct. */
#define INTERGERS "Intergers"      
#define NUM_STR 1
#define NDIMS 1
      hid_t fileid, grpid, spaceid;
      hid_t datasetid, plistid;
      hsize_t dims[NDIMS] = {NUM_STR}, max_dims[NDIMS] = {H5S_UNLIMITED};
      hsize_t chunk_dims[NDIMS] = {1};
      hsize_t xtend_size[NDIMS] = {2};
      int data[NUM_STR] = {42};
      int empty = -42;

      /* Create the file, open root group. */
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, 
			      H5P_DEFAULT)) < 0) ERR;
      if ((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) ERR;
      
      /* Create a space for the dataset. */
      if ((spaceid = H5Screate_simple(1, dims, max_dims)) < 0) ERR;

      /* Create the dataset. */
      if ((plistid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;
      if (H5Pset_chunk(plistid, 1, chunk_dims) < 0) ERR;
      if (H5Pset_fill_value(plistid, H5T_NATIVE_INT32, &empty) < 0) ERR;
      if ((datasetid = H5Dcreate1(grpid, INTERGERS, H5T_NATIVE_INT32, 
				  spaceid, plistid)) < 0) ERR;

      /* Now extend the dataset. */
      if (H5Dextend(datasetid, xtend_size) < 0) ERR;

      if (H5Dwrite(datasetid, H5T_NATIVE_INT, spaceid, spaceid, 
		   H5P_DEFAULT, &data) < 0) ERR;

      /* Close up. */
      if (H5Dclose(datasetid) < 0) ERR;
      if (H5Pclose(plistid) < 0) ERR;
      if (H5Sclose(spaceid) < 0) ERR;
      if (H5Gclose(grpid) < 0) ERR;
      if (H5Fclose(fileid) < 0) ERR;
   }
   SUMMARIZE_ERR;
   FINAL_RESULTS;
}
コード例 #18
0
ファイル: stab.c プロジェクト: FilipeMaia/hdf5
/*-------------------------------------------------------------------------
 * Function:	test_misc
 *
 * Purpose:	Test miscellaneous group stuff.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Tuesday, November 24, 1998
 *
 *-------------------------------------------------------------------------
 */
static int
test_misc(hid_t fapl, hbool_t new_format)
{
    hid_t	fid = (-1);             /* File ID */
    hid_t	g1 = (-1), g2 = (-1), g3 = (-1);
    char	filename[NAME_BUF_SIZE];
    char	comment[64];

    if(new_format)
        TESTING("miscellaneous group tests (w/new group format)")
    else
        TESTING("miscellaneous group tests")

    /* Create file */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
    if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR

    /* Create initial groups for testing, then close */
    if((g1 = H5Gcreate2(fid, "test_1a", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR
    if((g2 = H5Gcreate2(g1, "sub_1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR
    if((g3 = H5Gcreate2(fid, "test_1b", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR
    if(H5Oset_comment(g3, "hello world") < 0) TEST_ERROR
    if(H5Gclose(g1) < 0) TEST_ERROR
    if(H5Gclose(g2) < 0) TEST_ERROR
    if(H5Gclose(g3) < 0) TEST_ERROR

    /* Open all groups with absolute names to check for exsistence */
    if((g1 = H5Gopen2(fid, "/test_1a", H5P_DEFAULT)) < 0) TEST_ERROR
    if((g2 = H5Gopen2(fid, "/test_1a/sub_1", H5P_DEFAULT)) < 0) TEST_ERROR
    if((g3 = H5Gopen2(fid, "/test_1b", H5P_DEFAULT)) < 0) TEST_ERROR
    if(H5Oget_comment_by_name(g3, "././.", comment, sizeof comment, H5P_DEFAULT) < 0) TEST_ERROR
    if(HDstrcmp(comment, "hello world")) {
	H5_FAILED();
	puts("    Read the wrong comment string from the group.");
	printf("    got: \"%s\"\n    ans: \"hello world\"\n", comment);
	TEST_ERROR
    }
コード例 #19
0
ファイル: file.c プロジェクト: chrismullins/moab
static herr_t get_max_id( hid_t group_id, 
                          const char* subgroup, 
                          const char* datatable,
                          unsigned long* data )
{
  unsigned long id;
  hid_t elem_id, conn_id, attr_id, space_id;
  herr_t rval;
  int rank;
  hsize_t dims[2];
  
#if defined(H5Gopen_vers) && H5Gopen_vers > 1  
  elem_id = H5Gopen2( group_id, subgroup, H5P_DEFAULT );
#else
  elem_id = H5Gopen( group_id, subgroup );
#endif
  if (elem_id < 0) return (herr_t)-1;
  
#if defined(H5Dopen_vers) && H5Dopen_vers > 1  
  conn_id = H5Dopen2( elem_id, datatable, H5P_DEFAULT );
#else
  conn_id = H5Dopen( elem_id, datatable );
#endif
  H5Gclose( elem_id );
  if (conn_id < 0) return (herr_t)-1;
  
  space_id = H5Dget_space( conn_id );
  if (space_id < 0) { H5Dclose( conn_id ); return -1; }
  
  rank = H5Sget_simple_extent_ndims( space_id );
  if (rank <= 0 || rank > 2) { H5Dclose(conn_id); H5Sclose(space_id); return -1; }
  
  rval = H5Sget_simple_extent_dims( space_id, dims, NULL );
  H5Sclose( space_id );
  if (rval < 0) { H5Dclose( conn_id ); return -1; }
  
  attr_id = H5Aopen_name( conn_id, START_ID_ATTRIB );
  H5Dclose( conn_id );
  if (attr_id < 0) return (herr_t)-1;
  
  rval = H5Aread( attr_id, H5T_NATIVE_ULONG, &id );
  H5Aclose( attr_id );
  if (rval < 0) return rval;
  
  id += dims[0];
  if (id > *data)
    *data = id;
  return 0;
}
コード例 #20
0
    void Foam::hdf5SurfaceWriter::writeData
    (
        const hid_t& file_id,
        const word& surfaceName,
        const word& fieldName,
        const word& time,
        const Field<scalar>& values
    )
    {

        ioScalar* scalarData;
        scalarData = new ioScalar[values.size()];

        // Loop through the field and construct the array
        forAll(values, iter)
        {
            scalarData[iter] = values[iter];
        }


    hid_t group = H5Gopen2(file_id, time.c_str(), H5P_DEFAULT);
    hsize_t dimsf[1];
    dimsf[0] = values.size();
    hid_t dataspace = H5Screate_simple(1, dimsf, NULL);

    hid_t datatype = H5Tcopy(H5T_SCALAR);

    char datasetName[80];
    sprintf
    (
        datasetName,
        "%s/%s",
        time.c_str(),
        fieldName.c_str()
    );

    hid_t  dataset = H5Dcreate2(file_id, datasetName, datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    H5Dwrite(dataset, H5T_SCALAR, H5S_ALL, 
          H5S_ALL, H5P_DEFAULT, scalarData);
    H5Dclose(dataset);
    H5Sclose(dataspace);
    H5Tclose(datatype);
    H5Gclose(group);
    

    delete [] scalarData;

    }
コード例 #21
0
ファイル: group.cpp プロジェクト: gcross/HDF
Group::Group(
    Location const& location
)
  : Object(
        location.getFile(),
        assertSuccess(
            "opening group",
            H5Gopen2(
                location.getParentId(),
                location.getNameAsCStr(),
                H5P_DEFAULT
            )
        ),
        H5Gclose
    )
{}
コード例 #22
0
//--------------------------------------------------------------------------
// Function:	CommonFG::openGroup
///\brief	Opens an existing group in a location which can be a file
///		or another group.
///\param	name  - IN: Name of the group to open
///\return	Group instance
///\exception	H5::FileIException or H5::GroupIException
// Programmer	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
Group CommonFG::openGroup( const char* name ) const
{
   // Call C routine H5Gopen2 to open the named group, giving the
   // location id which can be a file id or a group id
   hid_t group_id = H5Gopen2( getLocId(), name, H5P_DEFAULT );

   // If the opening of the group failed, throw an exception
   if( group_id < 0 )
   {
      throwException("openGroup", "H5Gopen2 failed");
   }

   // No failure, create and return the Group object
   Group group( group_id );
   return( group );
}
コード例 #23
0
ファイル: h5_extlink.c プロジェクト: ngcurrier/ProteusCFD
/* Basic external link example
 *
 * Creates two files and uses an external link to access an object in the
 * second file from the first file.
 */
static void extlink_example(void)
{
    hid_t source_file_id, targ_file_id;
    hid_t group_id, group2_id;

    /* Create two files, a source and a target */
    source_file_id = H5Fcreate(SOURCE_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    targ_file_id = H5Fcreate(TARGET_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /* Create a group in the target file for the external link to point to. */
    group_id = H5Gcreate2(targ_file_id, "target_group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    /* Close the group and the target file */
    H5Gclose(group_id);

    /* Create an external link in the source file pointing to the target group.
     * We could instead have created the external link first, then created the
     * group it points to; the order doesn't matter.
     */
    H5Lcreate_external(TARGET_FILE, "target_group", source_file_id, "ext_link", H5P_DEFAULT, H5P_DEFAULT);

    /* Now we can use the external link to create a new group inside the
     * target group (even though the target file is closed!).  The external
     * link works just like a soft link.
     */
    group_id = H5Gcreate2(source_file_id, "ext_link/new_group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    /* The group is inside the target file and we can access it normally.
     * Here, group_id and group2_id point to the same group inside the
     * target file.
     */
    group2_id = H5Gopen2(targ_file_id, "target_group/new_group", H5P_DEFAULT);

    /* Don't forget to close the IDs we opened. */
    H5Gclose(group2_id);
    H5Gclose(group_id);

    H5Fclose(targ_file_id);
    H5Fclose(source_file_id);

    /* The link from the source file to the target file will work as long as
     * the target file can be found.  If the target file is moved, renamed,
     * or deleted in the filesystem, HDF5 won't be able to find it and the
     * external link will "dangle."
     */
}
コード例 #24
0
ファイル: h5gImp.c プロジェクト: fengbingchun/Caffe_Test
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    _H5Gopen2
 * Signature: (JLjava/lang/String;J)J
 */
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Gopen2(JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_plist_id)
{
    hid_t group_id = -1;
    const char *gName;

    PIN_JAVA_STRING(name, gName, -1);

    group_id = H5Gopen2((hid_t)loc_id, gName, (hid_t)access_plist_id );

    UNPIN_JAVA_STRING(name, gName);

    if (group_id < 0)
        h5libraryError(env);

    return (jlong)group_id;
} /* end Java_hdf_hdf5lib_H5__1H5Gopen2 */
コード例 #25
0
ファイル: NSDFWriter.cpp プロジェクト: asiaszmek/moose-core
void NSDFWriter::writeModelTree()
{
    vector< string > tokens;
    ObjId mRoot(modelRoot_);
    string rootPath = MODELTREEPATH + string("/") + mRoot.element()->getName();
    hid_t rootGroup = require_group(filehandle_, rootPath);
    hid_t tmp;
    htri_t exists;
    herr_t status;
    deque<Id> nodeQueue;
    deque<hid_t> h5nodeQueue;
    nodeQueue.push_back(mRoot);
    h5nodeQueue.push_back(rootGroup);
    // TODO: need to clarify what happens with array elements. We can
    // have one node per vec and set a count field for the number of
    // elements
    while (nodeQueue.size() > 0){
        ObjId node = nodeQueue.front();
        nodeQueue.pop_front();
        hid_t prev = h5nodeQueue.front();;
        h5nodeQueue.pop_front();
        vector < Id > children;
        Neutral::children(node.eref(), children);
        for ( unsigned int ii = 0; ii < children.size(); ++ii){
            string name = children[ii].element()->getName();
            // skip the system elements
            if (children[ii].path() == "/Msgs"
                || children[ii].path() == "/clock"
                || children[ii].path() == "/classes"
                || children[ii].path() == "/postmaster"){
                continue;
            }
            exists = H5Lexists(prev, name.c_str(), H5P_DEFAULT);
            if (exists > 0){
                tmp = H5Gopen2(prev, name.c_str(), H5P_DEFAULT);
            } else {
                tmp = H5Gcreate2(prev, name.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
            }
            writeScalarAttr< string >(tmp, "uid", children[ii].path());
            nodeQueue.push_back(children[ii]);
            h5nodeQueue.push_back(tmp);
        }
        status = H5Gclose(prev);
    }
}
コード例 #26
0
ファイル: tst_attsperf.c プロジェクト: dschwen/libmesh
/* Open/close the file with HDF5. */
int
readfile_hdf5(char *file_name, long long *delta, int do_inq, int num_vars)
{
   hid_t hdfid, hdf_grpid;
   hid_t fapl_id;
   struct timeval starttime, endtime;
   long long startt, endt;

   /* Start the clock. */
   gettimeofday(&starttime, NULL);

   /* Open and close the root group. */
   if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
   if (H5Pset_fclose_degree(fapl_id, H5F_CLOSE_SEMI)) ERR;
   if ((hdfid = H5Fopen(file_name, H5F_ACC_RDONLY, fapl_id)) < 0) ERR;
   if ((hdf_grpid = H5Gopen2(hdfid, "/", H5P_DEFAULT)) < 0) ERR;

   /* Do we want to do an inq? */
   if (do_inq)
   {
      if (num_vars)
      {
      }
      else /* global atts */
      {
         hsize_t num_obj;

         /* Find out how many attributes. */
         if ((num_obj = H5Aget_num_attrs(hdf_grpid)) < 0) ERR;
      }
   }

   if (H5Gclose(hdf_grpid) < 0) ERR;
   if (H5Fclose(hdfid) < 0) ERR;

   gettimeofday(&endtime, NULL);

   /* Compute the time delta */
   startt = (1000000 * starttime.tv_sec) + starttime.tv_usec;
   endt = (1000000 * endtime.tv_sec) + endtime.tv_usec;
   *delta = endt - startt;

   return 0;
}
コード例 #27
0
ファイル: readfile.cpp プロジェクト: edjocute/Orbit
/* Load and read file with initial positions and velocites */
int loadHdf5Init(char *filename, std::vector<array6> &init){
    hid_t   hdf_file,hdf_group,hdf_data,hdf_dspace;
    herr_t  status;
    //state_type x(6);
    array6 x;

    fprintf(stdout,"Reading file %s ...\n",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){
        H5Fclose(hdf_file);
        return -1;
    }

    if ( (hdf_data=H5Dopen2(hdf_file,"/x",H5P_DEFAULT)) < 0){
        H5Dclose(hdf_data);
        return -1;
    }
    hdf_dspace = H5Dget_space(hdf_data);
    hsize_t dims[2];
    H5Sget_simple_extent_dims(hdf_dspace,dims,NULL);
    std::cout << "No. of test particles read = " << dims[0] << "\n";
    double *temp = new double[dims[0]*dims[1]];
    status=H5Dread(hdf_data, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, temp);
    for (int i=0; i<dims[0]; i++){
        for (int j=0; j<dims[1]; j++){
            x[j]=temp[i*dims[1]+j];
        }
        init.push_back(x);
    }

    delete [] temp;
    H5Gclose(hdf_group);
    H5Fclose(hdf_file);
    H5Dclose(hdf_data);
    fprintf(stdout," file read successfully!\n");
    return 0;
}
コード例 #28
0
ファイル: TestH5.cpp プロジェクト: asobolev/nix
void TestH5::setUp() {
    unsigned int &openMode = open_mode();

    if (openMode == H5F_ACC_TRUNC) {
        h5file = H5Fcreate("test_h5.h5", openMode, H5P_DEFAULT, H5P_DEFAULT);
    } else {
        h5file = H5Fopen("test_h5.h5", openMode, H5P_DEFAULT);
    }

    CPPUNIT_ASSERT(H5Iis_valid(h5file));

    hid_t g;
    if (openMode == H5F_ACC_TRUNC) {
        g = H5Gcreate2(h5file, "h5", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    } else {
        g = H5Gopen2(h5file, "h5", H5P_DEFAULT);
    }

    CPPUNIT_ASSERT(H5Iis_valid(g));
    h5group = nix::hdf5::Group(g);

    openMode = H5F_ACC_RDWR;
}
コード例 #29
0
//-*****************************************************************************
ProtoObjectReader::ProtoObjectReader( hid_t iParent,
                                      const std::string &iParentFullPathName,
                                      const std::string &iName )
{
    // Validate.
    ABCA_ASSERT( iParent >= 0,
                 "Invalid group passed into ProtoObjectReader ctor" );

    // Open the HDF5 group corresponding to this object.
    m_group = H5Gopen2( iParent, iName.c_str(), H5P_DEFAULT );
    ABCA_ASSERT( m_group >= 0,
                 "Could not open object group named: "
                 << iName << " in parent: " << iParentFullPathName );

    // Read the meta data.
    // Metadata is always named ".prop.meta" for objects,
    // as it is shared with the underlying property.
    AbcA::MetaData mdata;
    ReadMetaData( m_group, ".prop.meta", mdata );

    std::string fullChildName;

    if ( iParentFullPathName == "/" )
    {
        fullChildName = "/" + iName;
    }
    else
    {
        fullChildName = iParentFullPathName + "/" + iName;
    }

    if ( fullChildName == "/ABC" ) { fullChildName = "/"; }

    m_header = AbcA::ObjectHeader( iName,
                                   fullChildName,
                                   mdata );
}
コード例 #30
0
int h5repack_cmp_pl(const char *fname1,
                     const char *fname2)
{
    int           ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
    hid_t         fid1=-1;         /* file ID */
    hid_t         fid2=-1;         /* file ID */
    hid_t         dset1=-1;        /* dataset ID */
    hid_t         dset2=-1;        /* dataset ID */
    hid_t         gid=-1;          /* group ID */
    hid_t         dcpl1=-1;        /* dataset creation property list ID */
    hid_t         dcpl2=-1;        /* dataset creation property list ID */
    hid_t         gcplid=-1;       /* group creation property list */
    unsigned      crt_order_flag1; /* group creation order flag */
    unsigned      crt_order_flag2; /* group creation order flag */
    trav_table_t  *trav=NULL;
    int           ret=1;
    unsigned int  i;

   /*-------------------------------------------------------------------------
    * open the files
    *-------------------------------------------------------------------------
    */

    /* disable error reporting */
    H5E_BEGIN_TRY
    {

        /* Open the files */
        if ((fid1 = H5Fopen(fname1,H5F_ACC_RDONLY,H5P_DEFAULT)) < 0 )
        {
            error_msg("<%s>: %s\n", fname1, H5FOPENERROR );
            return -1;
        }
        if ((fid2 = H5Fopen(fname2,H5F_ACC_RDONLY,H5P_DEFAULT)) < 0 )
        {
            error_msg("<%s>: %s\n", fname2, H5FOPENERROR );
            H5Fclose(fid1);
            return -1;
        }
        /* enable error reporting */
    } H5E_END_TRY;

   /*-------------------------------------------------------------------------
    * get file table list of objects
    *-------------------------------------------------------------------------
    */
    trav_table_init(&trav);
    if(h5trav_gettable(fid1, trav) < 0)
        HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5trav_gettable failed");

   /*-------------------------------------------------------------------------
    * traverse the suppplied object list
    *-------------------------------------------------------------------------
    */
    for(i = 0; i < trav->nobjs; i++)
    {

        if(trav->objs[i].type == H5TRAV_TYPE_GROUP)
        {

            if ((gid = H5Gopen2(fid1, trav->objs[i].name, H5P_DEFAULT)) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed");
            if ((gcplid = H5Gget_create_plist(gid)) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gget_create_plist failed");
            if (H5Pget_link_creation_order(gcplid, &crt_order_flag1) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pget_link_creation_order failed");
            if (H5Pclose(gcplid) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
            if (H5Gclose(gid) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed");

            if ((gid = H5Gopen2(fid2, trav->objs[i].name, H5P_DEFAULT)) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed");
            if ((gcplid = H5Gget_create_plist(gid)) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gget_create_plist failed");
            if (H5Pget_link_creation_order(gcplid, &crt_order_flag2) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pget_link_creation_order failed");
            if (H5Pclose(gcplid) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
            if (H5Gclose(gid) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed");

            if (crt_order_flag1 != crt_order_flag2) {
                error_msg("property lists for <%s> are different\n",trav->objs[i].name);
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "property lists failed");
            }

        }



        else if(trav->objs[i].type == H5TRAV_TYPE_DATASET)
        {
            if((dset1 = H5Dopen2(fid1, trav->objs[i].name, H5P_DEFAULT)) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
            if((dset2 = H5Dopen2(fid2, trav->objs[i].name, H5P_DEFAULT)) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
            if((dcpl1 = H5Dget_create_plist(dset1)) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed");
            if((dcpl2 = H5Dget_create_plist(dset2)) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed");

           /*-------------------------------------------------------------------------
            * compare the property lists
            *-------------------------------------------------------------------------
            */
            if((ret = H5Pequal(dcpl1, dcpl2)) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pequal failed");

            if(ret == 0) {
                error_msg("property lists for <%s> are different\n",trav->objs[i].name);
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "property lists failed");
            }

           /*-------------------------------------------------------------------------
            * close
            *-------------------------------------------------------------------------
            */
            if(H5Pclose(dcpl1) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
            if(H5Pclose(dcpl2) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
            if(H5Dclose(dset1) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed");
            if(H5Dclose(dset2) < 0)
                HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed");
        } /*if*/
    } /*i*/

   /*-------------------------------------------------------------------------
    * free
    *-------------------------------------------------------------------------
    */

    trav_table_free(trav);

   /*-------------------------------------------------------------------------
    * close
    *-------------------------------------------------------------------------
    */

    H5Fclose(fid1);
    H5Fclose(fid2);

    return ret;

/*-------------------------------------------------------------------------
* error
*-------------------------------------------------------------------------
*/
done:
    H5E_BEGIN_TRY
    {
        H5Pclose(dcpl1);
        H5Pclose(dcpl2);
        H5Dclose(dset1);
        H5Dclose(dset2);
        H5Fclose(fid1);
        H5Fclose(fid2);
        H5Pclose(gcplid);
        H5Gclose(gid);
        trav_table_free(trav);
    } H5E_END_TRY;

    return ret_value;
}