Exemplo n.º 1
0
/****if* H5Of/H5Oget_info_by_name_c
 * NAME
 *  H5Oget_info_by_name_c
 * PURPOSE
 *  Calls H5Oget_info_by_name
 * INPUTS
 *  loc_id       - File or group identifier specifying location of group in which object is located.
 *  name         - Name of group, relative to loc_id.
 *  namelen      - Name length.
 *  lapl_id      - Link access property list.
 * OUTPUTS
 *  object_info  - Buffer in which to return object information.
 *
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  M. Scot Breitenfeld
 *  December 1, 2008
 * SOURCE
*/
int_f
h5oget_info_by_name_c (hid_t_f *loc_id, _fcd name, size_t_f *namelen, hid_t_f *lapl_id,
			H5O_info_t_f *object_info)
/******/
{
  char *c_name = NULL;          /* Buffer to hold C string */
  int_f ret_value = 0;          /* Return value */
  H5O_info_t Oinfo;
  
  /*
   * Convert FORTRAN name to C name
   */
  if((c_name = HD5f2cstring(name, (size_t)*namelen)) == NULL)
    HGOTO_DONE(FAIL);

  /*
   * Call H5Oinfo_by_name function.
   */
  if(H5Oget_info_by_name((hid_t)*loc_id, c_name,
			 &Oinfo, (hid_t)*lapl_id) < 0)
    HGOTO_DONE(FAIL);

  ret_value = fill_h5o_info_t_f(Oinfo,object_info);

 done:
  if(c_name)
    HDfree(c_name);
  return ret_value;
}
Exemplo n.º 2
0
//-*****************************************************************************
bool DatasetExists( hid_t iParent, const std::string &iName )
{
    ABCA_ASSERT( iParent >= 0, "Invalid Parent in DatasetExists" );
    
    // First, check to make sure the link exists.
    htri_t exi = H5Lexists( iParent, iName.c_str(), H5P_DEFAULT );
    if ( exi < 1 )
    {
        return false;
    }
    
    // Now make sure it is a group.
    H5O_info_t oinfo;
    herr_t status = H5Oget_info_by_name( iParent,
                                         iName.c_str(), &oinfo,
                                         H5P_DEFAULT );
    if ( status < 0 )
    {
        return false;
    }
    
    if ( oinfo.type != H5O_TYPE_DATASET )
    {
        return false;
    }

    return true;
}
Exemplo n.º 3
0
/*-------------------------------------------------------------------------
 * Function:    ref_path_table_lookup
 *
 * Purpose:     Looks up a table entry given a path name.
 *              Used during construction of the table.
 *
 * Return:      The table entre (pte) or NULL if not in the
 *              table.
 *
 * Programmer:  REMcG
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
haddr_t
ref_path_table_lookup(const char *thepath)
{
    H5O_info_t  oi;

    /* Allow lookups on the root group, even though it doesn't have any link info */
    if(HDstrcmp(thepath, "/")) {
        H5L_info_t  li;

        /* Check for external link first, so we don't return the OID of an object in another file */
        if(H5Lget_info(thefile, thepath, &li, H5P_DEFAULT) < 0)
            return HADDR_UNDEF;

        /* UD links can't be followed, so they always "dangle" like soft links.  */
        if(li.type >= H5L_TYPE_UD_MIN)
            return HADDR_UNDEF;
    } /* end if */

    /* Get the object info now */
    /* (returns failure for dangling soft links) */
    if(H5Oget_info_by_name(thefile, thepath, &oi, H5P_DEFAULT) < 0)
        return HADDR_UNDEF;

    /* Return OID */
    return(oi.addr);
}
Exemplo n.º 4
0
/****************************************************************
**
**  liter_cb2(): Custom link iteration callback routine.
**
****************************************************************/
static herr_t
liter_cb2(hid_t loc_id, const char *name, const H5L_info_t H5_ATTR_UNUSED *link_info,
    void *opdata)
{
    const iter_info *test_info = (const iter_info *)opdata;
    H5O_info_t oinfo;
    herr_t ret;		/* Generic return value		*/

    if(HDstrcmp(name, test_info->name)) {
        TestErrPrintf("name = '%s', test_info = '%s'\n", name, test_info->name);
        return(H5_ITER_ERROR);
    } /* end if */

    /*
     * Get type of the object and check it.
     */
    ret = H5Oget_info_by_name(loc_id, name, &oinfo, H5P_DEFAULT);
    CHECK(ret, FAIL, "H5Oget_info_by_name");

    if(test_info->type != oinfo.type) {
        TestErrPrintf("test_info->type = %d, oinfo.type = %d\n", test_info->type, (int)oinfo.type);
        return(H5_ITER_ERROR);
    } /* end if */

    return(H5_ITER_STOP);
} /* liter_cb2() */
Exemplo n.º 5
0
/*--------------------------------------------------------------*/
static int FindByClassIterator(hid_t groupID,
	const char *name,
	const H5L_info_t *info, void *op_data)
{
	findByClassData *fbcb = (findByClassData *)op_data;
	H5O_info_t obj_info;
	hid_t attrID;
	char nxClass[132];

	memset(nxClass,0,sizeof(nxClass));
	H5Oget_info_by_name(groupID, name, &obj_info,H5P_DEFAULT);
	if(obj_info.type == H5O_TYPE_GROUP){
			/*
				work the NX_class attribute
			*/
			attrID = H5NXget_attribute_string(groupID,name,
				"NX_class", nxClass);
			if(attrID >= 0){
				if(strcmp(nxClass,fbcb->nxClass) == 0){
					fbcb->name = strdup(name);
					return 1;
				}
			}
  }
	return 0;
}
Exemplo n.º 6
0
/*-------------------------------------------------------------------------
 * Function: traverse
 *
 * Purpose: Iterate over all the objects/links in a file.  Conforms to the
 *      "visitor" pattern.
 *
 * Return: 0 on success, -1 on failure
 *
 * Programmer: Quincey Koziol, [email protected]
 *
 * Date: September 1, 2007
 *
 *-------------------------------------------------------------------------
 */
static int
traverse(hid_t file_id, const char *grp_name, hbool_t visit_start,
    hbool_t recurse, const trav_visitor_t *visitor)
{
    H5O_info_t  oinfo;          /* Object info for starting group */

    /* Get info for starting object */
    if(H5Oget_info_by_name(file_id, grp_name, &oinfo, H5P_DEFAULT) < 0)
        return -1;

    /* Visit the starting object */
    if(visit_start && visitor->visit_obj)
        (*visitor->visit_obj)(grp_name, &oinfo, NULL, visitor->udata);

    /* Go visiting, if the object is a group */
    if(oinfo.type == H5O_TYPE_GROUP) {
        trav_addr_t seen;           /* List of addresses seen */
        trav_ud_traverse_t udata;   /* User data for iteration callback */

        /* Init addresses seen */
        seen.nused = seen.nalloc = 0;
        seen.objs = NULL;

        /* Check for multiple links to top group */
        if(oinfo.rc > 1)
            trav_addr_add(&seen, oinfo.addr, grp_name);

        /* Set up user data structure */
        udata.seen = &seen;
        udata.visitor = visitor;
        udata.is_absolute = (*grp_name == '/');
        udata.base_grp_name = grp_name;

        /* Check for iteration of links vs. visiting all links recursively */
        if(recurse) {
            /* Visit all links in group, recursively */
            if(H5Lvisit_by_name(file_id, grp_name, trav_index_by, trav_index_order, traverse_cb, &udata, H5P_DEFAULT) < 0)
                return -1;
        } /* end if */
        else {
            /* Iterate over links in group */
            if(H5Literate_by_name(file_id, grp_name, trav_index_by, trav_index_order, NULL, traverse_cb, &udata, H5P_DEFAULT) < 0)
                return -1;
        } /* end else */

        /* Free visited addresses table */
        if(seen.objs) {
            size_t u;       /* Local index variable */

            /* Free paths to objects */
            for(u = 0; u < seen.nused; u++)
                HDfree(seen.objs[u].path);
            HDfree(seen.objs);
        } /* end if */
    } /* end if */

    return 0;
}
Exemplo n.º 7
0
med_err _MEDdatagroupExist(const med_idt        gid,
			   const char * const   datagroupname,
			   med_bool *   const   datagroupexist,
			   med_bool *   const   isasoftlink )
/*Pour l'instant, dans le modèle interne les liens sont uniquement des liens vers
  des datasets*/

{
  med_err        _ret=-1;
  H5L_info_t     _linkinfo;
  H5O_info_t     _oinfo;

  if ( H5Lget_info( gid, datagroupname,  &_linkinfo, H5P_DEFAULT ) >= 0 ) {

    switch ( _linkinfo.type ) {

    case H5L_TYPE_SOFT:
      *isasoftlink=MED_TRUE;
      _oinfo.type=H5G_LINK;
      break;

    case H5L_TYPE_HARD:
      *isasoftlink  = MED_FALSE;
      if ( H5Oget_info_by_name( gid, datagroupname, &_oinfo, H5P_DEFAULT ) <0) {
	MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"H5Oget_info_by_name");
	SSCRUTE( datagroupname);
      }
      break;

    case H5L_TYPE_EXTERNAL:
    case H5L_TYPE_ERROR:
    default:
      MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_HDFTYPE, datagroupname);
      ISCRUTE( _linkinfo.type);
      goto ERROR;
      break;
    }

    /*TODO : A vérifier sur un lien de datagroup, à mon avis ne fonctionne pas */
    switch ( _oinfo.type ) {
    case H5G_GROUP:
    case H5G_LINK:
      *datagroupexist = MED_TRUE;
      break;
    default:
      *datagroupexist = MED_FALSE;
    }

  } else {
      *datagroupexist = MED_FALSE;
      *isasoftlink    = MED_FALSE;
  }

  _ret = 0;
 ERROR:

  return _ret;
}
/**
 * \param[in,out]   data    pointer to a a string pointer.
 */
static herr_t query_first_name(hid_t id,const char *name,const H5L_info_t *i, void *data)
{ H5O_info_t info;
  HTRY(H5Oget_info_by_name(id,name,&info,H5P_DEFAULT));
  if(info.type==H5O_TYPE_DATASET)
  { TRY(*(char**)data=(char*)malloc(1+strlen(name)));
    strcpy(*(char**)data,name);
  }
  return 1; // imediately terminate iteration
Error:
  return 0;
}
Exemplo n.º 9
0
/****************************************************************
**
**  get_objinfo(): Get information about the type of a child.
**
****************************************************************/
int get_objinfo(hid_t loc_id, const char *name) {
  herr_t     ret;            /* Generic return value         */
  H5O_info_t oinfo;

  /* Get type of the object, without emiting an error in case the
     node does not exist. */
  H5E_BEGIN_TRY {
    ret = H5Oget_info_by_name(loc_id, name, &oinfo, H5P_DEFAULT);
  } H5E_END_TRY;
  if (ret < 0)
    return -2;
  return oinfo.type;
}
Exemplo n.º 10
0
/*
 * HDF5 Operator function.
 *
 * Puts the name of the objects (in this case 'datasets')
 * in an HDF5 file into a std::vector for us to use for
 * iterating over the file.
 *
 * This was based on a couple of HDF5 example files.
 */
herr_t op_func (hid_t loc_id, const char *name,
#if H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >=8
                const H5L_info_t *info,
#endif
                void *operator_data)
{
    std::vector<std::string>* p_dataset_names = static_cast<std::vector< std::string > * >(operator_data);

    /*
     * Get type of the object and display its name and type.
     * The name of the object is passed to this function by
     * the Library.
     */
#if H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >=8
    H5O_info_t infobuf;
    H5Oget_info_by_name (loc_id, name, &infobuf, H5P_DEFAULT);
    switch (infobuf.type)
    {
//          case H5O_TYPE_GROUP:
//              printf ("  Group: %s\n", name);
//              break;
        case H5O_TYPE_DATASET:
            p_dataset_names->push_back(name);
            break;
//          case H5O_TYPE_NAMED_DATATYPE:
//              printf ("  Datatype: %s\n", name);
//              break;
#else // HDF5 1.6.x
    H5G_stat_t statbuf;
    H5Gget_objinfo (loc_id, name, 0, &statbuf);
    switch (statbuf.type)
    {
//        case H5G_GROUP:
//            printf ("  Group: %s\n", name);
//            break;
        case H5G_DATASET:
            //printf ("  Dataset: %s\n", name);
            p_dataset_names->push_back(name);
            break;
//        case H5G_TYPE:
//            printf ("  Datatype: %s\n", name);
//            break;
#endif
        default:
            NEVER_REACHED;
            // If you ever do reach here, it means that an HDF5 file you are trying to convert contains
            // something other than a 'Dataset', which is the usual data structure we write out in Chaste.
            // The above commented out lines should help you figure out what it is, and how it got there.
    }
    return 0;
}
Exemplo n.º 11
0
/*-------------------------------------------------------------------------
 * Function: trav_fileinfo_add
 *
 * Purpose: Add a file addr & fileno to info struct
 *
 * Return: void
 *
 *-------------------------------------------------------------------------
 */
void
trav_fileinfo_add(trav_info_t *info, hid_t loc_id)
{
    H5O_info_t oinfo;
    size_t idx = info->nused - 1;

    if ( info->paths[idx].path && HDstrcmp(info->paths[idx].path, "."))
      H5Oget_info_by_name(loc_id, info->paths[idx].path, &oinfo, H5P_DEFAULT);
    else
      H5Oget_info(loc_id, &oinfo);

    info->paths[idx].objno = oinfo.addr;
    info->paths[idx].fileno = oinfo.fileno;
} /* end trav_fileinfo_add() */
Exemplo n.º 12
0
/****************************************************************
**
**  litercb(): Custom link iteration callback routine.
**
****************************************************************/
herr_t litercb(hid_t loc_id, const char *name, const H5L_info_t *info,
               void *data) {
  PyObject   **out_info=(PyObject **)data;
  PyObject   *strname;
  herr_t     ret;
  H5O_info_t oinfo;
  int        namedtypes = 0;

  strname = PyString_FromString(name);

  switch(info->type) {
    case H5L_TYPE_SOFT:
    case H5L_TYPE_EXTERNAL:
      PyList_Append(out_info[2], strname);
      break;
    case H5L_TYPE_ERROR:  /* XXX: check */
      PyList_Append(out_info[3], strname);
      break;
    case H5L_TYPE_HARD:
      /* Get type of the object and check it */
      ret = H5Oget_info_by_name(loc_id, name, &oinfo, H5P_DEFAULT);
      if (ret < 0)
          return -1;

      switch(oinfo.type) {
        case H5O_TYPE_GROUP:
          PyList_Append(out_info[0], strname);
          break;
        case H5O_TYPE_DATASET:
          PyList_Append(out_info[1], strname);
          break;
        case H5O_TYPE_NAMED_DATATYPE:
          ++namedtypes;
          break;
        case H5O_TYPE_UNKNOWN:
          PyList_Append(out_info[3], strname);
          break;
        default:
          /* should not happen */
          PyList_Append(out_info[3], strname);
      }
      break;
    default:
      /* should not happen */
      PyList_Append(out_info[3], strname);
  }
  Py_DECREF(strname);

  return 0 ;  /* Loop until no more objects remain in directory */
}
Exemplo n.º 13
0
int getDataSetIdFromName(int _iFile, const char *_pstName)
{
    H5O_info_t info;
    htri_t ret = H5Lexists(_iFile, _pstName, H5P_DEFAULT);
    if (ret == 1)
    {
        H5Oget_info_by_name(_iFile, _pstName, &info, H5P_DEFAULT);
        if (info.type == H5O_TYPE_GROUP)
        {
            return H5Gopen(_iFile, _pstName, H5P_DEFAULT);
        }

        return H5Dopen(_iFile, _pstName, H5P_DEFAULT);
    }

    return -1;
}
Exemplo n.º 14
0
void h5_att_str(hid_t file_id, char *group, char *name, char *value)
{
  int ii, kk;
  void *buf = NULL;
  hid_t attr_id;
  H5O_info_t object_info;
  char *attr_name = (char *) MALLOC(sizeof(char)*50);

  H5Oget_info_by_name(file_id, group, &object_info, H5P_DEFAULT);
  for (ii=0; ii<object_info.num_attrs; ii++) {
    attr_id = H5Aopen_by_idx(file_id, group, H5_INDEX_NAME, H5_ITER_NATIVE, ii,
      H5P_DEFAULT, H5P_DEFAULT);
    H5Aget_name(attr_id, 50, attr_name);
    if (strcmp_case(name, attr_name) == 0) {
      hid_t attr_type = H5Aget_type(attr_id);
      H5T_class_t data_type = H5Tget_native_type(attr_type, H5T_DIR_DEFAULT);
      size_t data_size = H5Tget_size(data_type);
      hid_t attr_space = H5Aget_space(attr_id);
      hsize_t dims[H5S_MAX_RANK];
      int rank = H5Sget_simple_extent_dims(attr_space, dims, NULL);
      hsize_t elements = 1;
      for (kk=0; kk<rank; kk++)
        elements *= dims[kk];
      buf = (void *) MALLOC((unsigned)(elements*data_size));
      H5Aread(attr_id, attr_type, buf);
      H5Tclose(attr_type);
      H5Tclose(data_type);
      H5Sclose(attr_space);
    }
    else {
      H5Aclose(attr_id);
      continue;
    }
    H5Aclose(attr_id);
  }
  if (buf) {
    strcpy(value, buf);
    FREE(buf);
  }
  else
    strcpy(value, "???");
  FREE(attr_name);
}
Exemplo n.º 15
0
//-*****************************************************************************
bool DatasetExists( H5Node& iParent, const std::string &iName )
{
    ABCA_ASSERT( iParent.isValidObject(),
                 "Invalid parent group passed into HDF5Util DatasetExists: "
                 << iName << std::endl );

    HDF5Hierarchy* h5HPtr = iParent.getH5HPtr();

    if ( h5HPtr )
    {
        return h5HPtr->childExists( iParent.getRef(), iName );
    }
    else
    {
        hid_t iParentObject = iParent.getObject();

        // First, check to make sure the link exists.
        htri_t exi = H5Lexists( iParentObject, iName.c_str(), H5P_DEFAULT );
        if ( exi < 1 )
        {
            return false;
        }

        // Now make sure it is a group.
        H5O_info_t oinfo;
        herr_t status = H5Oget_info_by_name( iParentObject,
                                             iName.c_str(), &oinfo,
                                             H5P_DEFAULT );
        if ( status < 0 )
        {
            return false;
        }

        if ( oinfo.type != H5O_TYPE_DATASET )
        {
            return false;
        }

        return true;
    }
}
med_err _MEDconvertStringDatasets(med_idt id, const char *lname, const H5L_info_t *linfo, visitordatas *data) {

  med_err  _ret=-1,_err=-1;
  med_idt  _gid=0;
  H5O_info_t oinfo;
  char     _tmpbuff[MAX_LEN_PATH+1]="";
  int      _tmpbuffsize=0;
  med_int  _nbratt=0;

#ifdef _DEBUG_
  SSCRUTE(lname);
#endif

  if (!strcmp(lname,".")) return 0;

  switch ( (*linfo).type ) {

  case H5L_TYPE_SOFT:
    oinfo.type=(H5O_type_t) H5G_LINK;
    break;
  case H5L_TYPE_HARD:
    if ( H5Oget_info_by_name( id, lname, &oinfo, H5P_DEFAULT ) <0) {
      MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"H5Oget_info_by_name");
      SSCRUTE(lname);
    }
    break;
  case H5L_TYPE_EXTERNAL:
  case H5L_TYPE_ERROR:
  default:
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_HDFTYPE,lname);
    ISCRUTE_int((*linfo).type);
    goto ERROR;
    break;
 }

  switch ( oinfo.type ) {

  case H5G_GROUP:
  case H5G_LINK:
    break;

  case H5G_DATASET:

    strcat(_tmpbuff,lname);
    _tmpbuffsize=strlen(_tmpbuff);

    /*
      Ce traitement est spécifique aux datatsets présents dans les familles
    */
/*     SSCRUTE(_tmpbuff); */
/*     SSCRUTE(&_tmpbuff[_tmpbuffsize-3]); */
    if ( strcmp(&_tmpbuff[_tmpbuffsize-3],MED_NOM_NOM) ) break;

    _tmpbuff[_tmpbuffsize-4]='\0';
/*     SSCRUTE(_tmpbuff); */

    /*
     * Lecture de l'attribut MED_NOM_NBR sur le dataset
     */
    if ( _MEDattributeNumRdByName(id,_tmpbuff,MED_NOM_NBR,MED_INTERNAL_INT,
				  ( unsigned char * const) &_nbratt ) < 0 ) {
      MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_NBR);
      goto ERROR;
    }

/*     ISCRUTE(_nbratt); */
    _err=MAJ_236_300_string_datasets( data->gid2, _tmpbuff, MED_NOM_NOM, MED_TAILLE_LNOM,
				      MED_LNAME_SIZE,_nbratt);

    MED_ERR_EXIT_IF( _err < 0, MED_ERR_CALL, MED_ERR_API, "MAJ_236_300_string_datasets");

    _tmpbuff[_tmpbuffsize-4]='/';
    _err = H5Adelete_by_name( data->gid2, _tmpbuff, MED_NOM_NBR, H5P_DEFAULT  );

    MED_ERR_EXIT_IF( _err < 0, MED_ERR_DELETE, MED_ERR_ATTRIBUTE, "MED_NOM_NBR");


  break;

  case H5G_TYPE:
  default:
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_HDFTYPE,lname);
    goto ERROR;
  }
  _ret = 0;

 ERROR:
  return _ret;
}
Exemplo n.º 17
0
/*-------------------------------------------------------------------------
 * Function: traverse_cb
 *
 * Purpose: Iterator callback for traversing objects in file
 *
 * Programmer: Quincey Koziol, [email protected]
 *
 * Date: September 1, 2007
 *
 *-------------------------------------------------------------------------
 */
static herr_t
traverse_cb(hid_t loc_id, const char *path, const H5L_info_t *linfo,
    void *_udata)
{
    trav_ud_traverse_t *udata = (trav_ud_traverse_t *)_udata;     /* User data */
    char *new_name = NULL;
    const char *full_name;
    const char *already_visited = NULL; /* Whether the link/object was already visited */

    /* Create the full path name for the link */
    if(udata->is_absolute) {
        size_t base_len = HDstrlen(udata->base_grp_name);
        size_t add_slash = base_len ? ((udata->base_grp_name)[base_len-1] != '/') : 1;

        if(NULL == (new_name = (char*)HDmalloc(base_len + add_slash + HDstrlen(path) + 1)))
            return(H5_ITER_ERROR);
        HDstrcpy(new_name, udata->base_grp_name);
        if (add_slash)
            new_name[base_len] = '/';
        HDstrcpy(new_name + base_len + add_slash, path);
        full_name = new_name;
    } /* end if */
    else
        full_name = path;

    /* Perform the correct action for different types of links */
    if(linfo->type == H5L_TYPE_HARD) {
        H5O_info_t oinfo;

        /* Get information about the object */
        if(H5Oget_info_by_name(loc_id, path, &oinfo, H5P_DEFAULT) < 0) {
            if(new_name)
                HDfree(new_name);
            return(H5_ITER_ERROR);
        }

        /* If the object has multiple links, add it to the list of addresses
         *  already visited, if it isn't there already
         */
        if(oinfo.rc > 1)
            if(NULL == (already_visited = trav_addr_visited(udata->seen, oinfo.addr)))
                trav_addr_add(udata->seen, oinfo.addr, full_name);

        /* Make 'visit object' callback */
        if(udata->visitor->visit_obj)
            if((*udata->visitor->visit_obj)(full_name, &oinfo, already_visited, udata->visitor->udata) < 0) {
                if(new_name)
                    HDfree(new_name);
                return(H5_ITER_ERROR);
            }
    } /* end if */
    else {
        /* Make 'visit link' callback */
        if(udata->visitor->visit_lnk)
            if((*udata->visitor->visit_lnk)(full_name, linfo, udata->visitor->udata) < 0) {
                if(new_name)
                    HDfree(new_name);
                return(H5_ITER_ERROR);
            }
    } /* end else */

    if(new_name)
        HDfree(new_name);

    return(H5_ITER_CONT);
} /* end traverse_cb() */
Exemplo n.º 18
0
herr_t op_func (hid_t loc_id, const char *name, const H5L_info_t *info,
            void *operator_data)
{
    herr_t          status, return_val = 0;
    H5O_info_t      infobuf;
    struct opdata   *od = (struct opdata *) operator_data;
    unsigned        spaces = 2*(od->recurs+1);
    FILE* pfile;
    pfile = fopen(filePathJson.toStdString().c_str(), "a");
    if (!pfile)
    {
       throw GenericExc(QObject::tr("Ошибка открытия json файла"));

    }
    status = H5Oget_info_by_name (loc_id, name, &infobuf, H5P_DEFAULT);
    if (status < 0)
    {
        throw GenericExc(QObject::tr("Ошибка получения информации о файле"));
    }
    switch (infobuf.type) {
        case H5O_TYPE_GROUP: {
            if (countGroup != 0) {
                fprintf (pfile, "{\n");
                fprintf (pfile, "%*s", spaces, "");
            }
            fprintf (pfile, "\"%s\" : ", name);
            countGroup++;
            if ( group_check (od, infobuf.addr) ) {
            }
            else {
                struct opdata nextod;
                nextod.recurs = od->recurs + 1;
                nextod.prev = od;
                nextod.addr = infobuf.addr;
                fclose(pfile);
                return_val = H5Literate_by_name (loc_id, name, H5_INDEX_NAME,
                            H5_ITER_NATIVE, NULL, op_func, (void *) &nextod,
                            H5P_DEFAULT);
            }
            pfile = fopen(filePathJson.toStdString().c_str(), "a");
            if (!pfile)
            {
               throw GenericExc(QObject::tr("Ошибка открытия json файла"));

            }
            if (count == 0) {
                fprintf (pfile, "%*s}\n", spaces, "");
            } else {
                fprintf (pfile, "\n%*s]\n", spaces, "");
                count = 0;
            }
            break;
        }
        case H5O_TYPE_DATASET:
            if (count == 0)
            {
                fprintf (pfile, "[\n");
            } else
            {
                fprintf(pfile, ",\n");
            }
            fprintf (pfile, "%*s", spaces, "");
            fprintf (pfile, "\"%s\"", name);
            count++;
            countGroup = 0;
            break;
        default:
            break;
    }
    fclose(pfile);
    return return_val;
}
Exemplo n.º 19
0
/* ***if* H5Of/H5Oget_info_by_name_c
 * NAME
 *  H5Oget_info_by_name_c
 * PURPOSE
 *  Calls H5Oget_info_by_name
 * INPUTS
 *  loc_id       - File or group identifier specifying location of group in which object is located.
 *  name         - Name of group, relative to loc_id.
 *  namelen      - Name length.
 *  lapl_id      - Link access property list.
 * OUTPUTS
 *  corder_valid - Indicates whether the the creation order data is valid for this attribute.
 *  corder       - Is a positive integer containing the creation order of the attribute.
 *  cset         - Indicates the character set used for the attribute’s name.
 *  data_size    - indicates the size, in the number of characters, of the attribute.
 *
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  M. Scot Breitenfeld
 *  December 1, 2008
 * SOURCE
*/
int_f
nh5oget_info_by_name_c (hid_t_f *loc_id, _fcd name, size_t_f *namelen, hid_t_f *lapl_id,
			H5O_info_t_f *object_info)
/******/
{
  char *c_name = NULL;          /* Buffer to hold C string */
  int_f ret_value = 0;          /* Return value */
  H5O_info_t Oinfo;
  struct tm *ts;
  
  /*
   * Convert FORTRAN name to C name
   */
  if((c_name = HD5f2cstring(name, (size_t)*namelen)) == NULL)
    HGOTO_DONE(FAIL);

  /*
   * Call H5Oinfo_by_name function.
   */
  if(H5Oget_info_by_name((hid_t)*loc_id, c_name,
			 &Oinfo, (hid_t)*lapl_id) < 0)
    HGOTO_DONE(FAIL);

  object_info->fileno    = Oinfo.fileno;
  object_info->addr      = (haddr_t_f)Oinfo.addr;
 

  object_info->type      = (int_f)Oinfo.type;
  object_info->rc        = (int_f)Oinfo.rc;

  ts = gmtime(&Oinfo.atime);

  object_info->atime[0]     = (int_f)ts->tm_year+1900; /* year starts at 1900 */
  object_info->atime[1]     = (int_f)ts->tm_mon+1; /* month starts at 0 in C */
  object_info->atime[2]     = (int_f)ts->tm_mday;
/*   object_info->atime[3]     = (int_f)ts->tm_gmtoff; /\* convert from seconds to minutes *\/ */
  object_info->atime[4]     = (int_f)ts->tm_hour;
  object_info->atime[5]     = (int_f)ts->tm_min;
  object_info->atime[6]     = (int_f)ts->tm_sec;
  object_info->atime[7]     = -32767; /* millisecond is not available, assign it -HUGE(0) */

  ts = gmtime(&Oinfo.btime);

  object_info->btime[0]     = (int_f)ts->tm_year+1900; /* year starts at 1900 */
  object_info->btime[1]     = (int_f)ts->tm_mon+1; /* month starts at 0 in C */
  object_info->btime[2]     = (int_f)ts->tm_mday;
/*   object_info->btime[3]     = (int_f)ts->tm_gmtoff/60; /\* convert from seconds to minutes *\/ */
  object_info->btime[4]     = (int_f)ts->tm_hour;
  object_info->btime[5]     = (int_f)ts->tm_min;
  object_info->btime[6]     = (int_f)ts->tm_sec;
  object_info->btime[7]     = -32767; /* millisecond is not available, assign it -HUGE(0) */

  ts = gmtime(&Oinfo.ctime);

  object_info->ctime[0]     = (int_f)ts->tm_year+1900; /* year starts at 1900 */
  object_info->ctime[1]     = (int_f)ts->tm_mon+1; /* month starts at 0 in C */
  object_info->ctime[2]     = (int_f)ts->tm_mday;
/*   object_info->ctime[3]     = (int_f)ts->tm_gmtoff/60; /\* convert from seconds to minutes *\/ */
  object_info->ctime[4]     = (int_f)ts->tm_hour;
  object_info->ctime[5]     = (int_f)ts->tm_min;
  object_info->ctime[6]     = (int_f)ts->tm_sec;
  object_info->ctime[7]     = -32767; /* millisecond is not available, assign it -HUGE(0) */

  ts = gmtime(&Oinfo.mtime);

  object_info->mtime[0]     = (int_f)ts->tm_year+1900; /* year starts at 1900 */
  object_info->mtime[1]     = (int_f)ts->tm_mon+1; /* month starts at 0 in C */
  object_info->mtime[2]     = (int_f)ts->tm_mday;
/*   object_info->mtime[3]     = (int_f)ts->tm_gmtoff/60; /\* convert from seconds to minutes *\/ */
  object_info->mtime[4]     = (int_f)ts->tm_hour;
  object_info->mtime[5]     = (int_f)ts->tm_min;
  object_info->mtime[6]     = (int_f)ts->tm_sec;
  object_info->mtime[7]     = -32767; /* millisecond is not available, assign it -HUGE(0) */

  object_info->num_attrs = (hsize_t_f)Oinfo.num_attrs;

  object_info->hdr.version = (int_f)Oinfo.hdr.version;
  object_info->hdr.nmesgs  = (int_f)Oinfo.hdr.nmesgs;
  object_info->hdr.nchunks = (int_f)Oinfo.hdr.nchunks;
  object_info->hdr.flags   = (int_f)Oinfo.hdr.flags;

  object_info->hdr.space.total = (hsize_t_f)Oinfo.hdr.space.total;
  object_info->hdr.space.meta  = (hsize_t_f)Oinfo.hdr.space.meta;
  object_info->hdr.space.mesg  = (hsize_t_f)Oinfo.hdr.space.mesg;
  object_info->hdr.space.free  = (hsize_t_f)Oinfo.hdr.space.free;

  object_info->hdr.mesg.present = Oinfo.hdr.mesg.present;
  object_info->hdr.mesg.shared  = Oinfo.hdr.mesg.shared;

  object_info->meta_size.obj.index_size = (hsize_t_f)Oinfo.meta_size.obj.index_size;
  object_info->meta_size.obj.heap_size  = (hsize_t_f)Oinfo.meta_size.obj.heap_size;

 done:
  return ret_value;
}
Exemplo n.º 20
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	H5O_mtime_decode() test.
 *
 * Return:	Success:
 *
 *		Failure:
 *
 * Programmer:	Robb Matzke
 *              Thursday, July 30, 1998
 *
 * Modifications:
 *              Added checks for old and new modification time messages
 *              in pre-created datafiles (generated with gen_old_mtime.c and
 *              gen_new_mtime.c).
 *              Quincey Koziol
 *              Friday, January  3, 2003
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    hid_t	fapl, file, space, dset;
    hsize_t	size[1] = {2};
    time_t	now;
    struct tm	*tm;
    H5O_info_t	oi1, oi2;
    signed char	buf1[32], buf2[32];
    char	filename[1024];

    h5_reset();
    fapl = h5_fileaccess();

    TESTING("modification time messages");

    /* Create the file, create a dataset, then close the file */
    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR;
    if((space = H5Screate_simple(1, size, NULL)) < 0) TEST_ERROR;
    if((dset = H5Dcreate2(file, "dset", H5T_NATIVE_SCHAR, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        TEST_ERROR;
    now = HDtime(NULL);
    if(H5Dclose(dset) < 0) TEST_ERROR;
    if(H5Sclose(space) < 0) TEST_ERROR;
    if(H5Fclose(file) < 0) TEST_ERROR;

    /*
     * Open the file and get the modification time. We'll test the
     * H5Oget_info() arguments too: being able to stat something without
     * knowing its name.
     */
    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
    if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR;
    if(H5Oget_info_by_name(file, "dset", &oi1, H5P_DEFAULT) < 0) TEST_ERROR;
    if((dset = H5Dopen2(file, "dset", H5P_DEFAULT)) < 0) TEST_ERROR;
    if(H5Oget_info(dset, &oi2) < 0) TEST_ERROR;
    if(H5Dclose(dset) < 0) TEST_ERROR;
    if(H5Fclose(file) < 0) TEST_ERROR;

    /* Compare addresses & times from the two ways of calling H5Oget_info() */
    if(oi1.addr != oi2.addr || oi1.mtime != oi2.mtime) {
        H5_FAILED();
        puts("    Calling H5Oget_info() with the dataset ID returned");
        puts("    different values than calling it with a file and dataset");
        puts("    name.");
        goto error;
    }

    /* Compare times -- they must be within 60 seconds of one another */
    if(0 == oi1.mtime) {
        SKIPPED();
        puts("    The modification time could not be decoded on this OS.");
        puts("    Modification times will be mantained in the file but");
        puts("    cannot be queried on this system.  See H5O_mtime_decode().");
        return 0;
    } else if(HDfabs(HDdifftime(now, oi1.mtime)) > 60.0) {
        H5_FAILED();
        tm = HDlocaltime(&(oi1.mtime));
        HDstrftime((char*)buf1, sizeof buf1, "%Y-%m-%d %H:%M:%S", tm);
        tm = HDlocaltime(&now);
        HDstrftime((char*)buf2, sizeof buf2, "%Y-%m-%d %H:%M:%S", tm);
        printf("    got: %s\n    ans: %s\n", buf1, buf2);
        goto error;
    }
    PASSED();


    /* Check opening existing file with old-style modification time information
     * and make certain that the time is correct
     */
    TESTING("accessing old modification time messages");

    {
        char testfile[512]="";
        char *srcdir = HDgetenv("srcdir");

        if(srcdir && ((HDstrlen(srcdir) + strlen(TESTFILE1) + 1) < sizeof(testfile))){
            HDstrcpy(testfile, srcdir);
            HDstrcat(testfile, "/");
        }
        HDstrcat(testfile, TESTFILE1);
        file = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT);
        if(file >= 0){
            if(H5Oget_info_by_name(file, "/Dataset1", &oi1, H5P_DEFAULT) < 0)
                TEST_ERROR;
            if(oi1.mtime != MTIME1) {
                H5_FAILED();
                   /* If this fails, examine H5Omtime.c.  Modification time is very
                    * system dependant (e.g., on Windows DST must be hardcoded). */
                puts("    Old modification time incorrect");
                goto error;
            }
            if(H5Fclose(file) < 0) TEST_ERROR;
        }
        else {
            H5_FAILED();
            printf("***cannot open the pre-created old modification test file (%s)\n",
                testfile);
            goto error;
        } /* end else */
    }
    PASSED();

    /* Check opening existing file with new-style modification time information
     * and make certain that the time is correct
     */
    TESTING("accessing new modification time messages");

    {
        char testfile[512]="";
        char *srcdir = HDgetenv("srcdir");

        if(srcdir && ((HDstrlen(srcdir) + strlen(TESTFILE2) + 1) < sizeof(testfile))){
            HDstrcpy(testfile, srcdir);
            HDstrcat(testfile, "/");
        }
        HDstrcat(testfile, TESTFILE2);
        file = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT);
        if(file >= 0){
            if(H5Oget_info_by_name(file, "/Dataset1", &oi2, H5P_DEFAULT) < 0)
                TEST_ERROR;
            if(oi2.mtime != MTIME2) {
               H5_FAILED();
               puts("    Modification time incorrect.");
               goto error;
            }
            if(H5Fclose(file) < 0) TEST_ERROR;
        }
        else {
            H5_FAILED();
            printf("***cannot open the pre-created old modification test file (%s)\n",
                testfile);
            goto error;
        } /* end else */
    }
    PASSED();

    /* All looks good */
    puts("All modification time tests passed.");
    h5_cleanup(FILENAME, fapl);
    return 0;

    /* Something broke */
error:
    return 1;
}
Exemplo n.º 21
0
med_err _MEDchecknSublinkFunc(med_idt id,const char *lname, const H5L_info_t *linfo, med_bool  *data) {

  med_err  _ret=-1;
  H5O_info_t oinfo;
  H5G_info_t _group_info;


#ifdef _DEBUG_
  SSCRUTE(lname);
#endif

  if (!strcmp(lname,".")) return 0;

  switch ( (*linfo).type ) {

  case H5L_TYPE_SOFT:
    oinfo.type=H5G_LINK;
    break;
  case H5L_TYPE_HARD:
    if ( H5Oget_info_by_name( id, lname, &oinfo, H5P_DEFAULT ) <0) {
      MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"H5Oget_info_by_name");
      SSCRUTE(lname);
    }
    break;
  case H5L_TYPE_EXTERNAL:
  case H5L_TYPE_ERROR:
  default:
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_HDFTYPE,lname);
    ISCRUTE_int((*linfo).type);
    goto ERROR;
    break;
 }

  switch ( oinfo.type ) {

  case H5G_GROUP:

    if ( H5Gget_info_by_name(id, lname, &_group_info, H5P_DEFAULT  ) < 0 ){
      MED_ERR_(_ret,MED_ERR_ACCESS,MED_ERR_GROUP, MED_ERR_NAME_MSG );
      SSCRUTE(lname);goto ERROR;
    }

    if ( _group_info.nlinks > 1 ) {
      *data=MED_TRUE;
      MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_GROUP,lname);
      ISCRUTE_size(_group_info.nlinks);goto ERROR;
    }

  /*   SSCRUTE(lname); */
/*     ISCRUTE(*data); */
/*     ISCRUTE(_group_info.nlinks); */

    break;

  case H5G_DATASET:
  case H5G_LINK:
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_HDFTYPE,lname);
    goto ERROR;

    break;
  case H5G_TYPE:
  default:
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_HDFTYPE,lname);
    goto ERROR;
  }
  _ret = 0;

 ERROR:
  return _ret;
}
Exemplo n.º 22
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Oget_info_by_name
 * Signature: (JLjava/lang/String;J)Lhdf/hdf5lib/structs/H5O_info_t;
 */
JNIEXPORT jobject JNICALL
Java_hdf_hdf5lib_H5_H5Oget_1info_1by_1name
    (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_id)
{
    const char *lName;
    herr_t      status = -1;
    H5O_info_t  infobuf;
    jvalue      args[12];
    jobject     hdrinfobuf;
    jobject     ihinfobuf1;
    jobject     ihinfobuf2;
    jobject     ret_obj = NULL;

    PIN_JAVA_STRING(name, lName);
    if (lName != NULL) {
        status = H5Oget_info_by_name((hid_t)loc_id, lName, &infobuf, (hid_t)access_id);

        UNPIN_JAVA_STRING(name, lName);

        if (status < 0) {
            h5libraryError(env);
        } /* end if */
        else {
            args[0].i = (jint)infobuf.hdr.version;
            args[1].i = (jint)infobuf.hdr.nmesgs;
            args[2].i = (jint)infobuf.hdr.nchunks;
            args[3].i = (jint)infobuf.hdr.flags;
            args[4].j = (jlong)infobuf.hdr.space.total;
            args[5].j = (jlong)infobuf.hdr.space.meta;
            args[6].j = (jlong)infobuf.hdr.space.mesg;
            args[7].j = (jlong)infobuf.hdr.space.free;
            args[8].j = (jlong)infobuf.hdr.mesg.present;
            args[9].j = (jlong)infobuf.hdr.mesg.shared;
            CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_hdr_info_t", "(IIIIJJJJJJ)V", args);
            hdrinfobuf = ret_obj;

            args[0].j = (jlong)infobuf.meta_size.obj.index_size;
            args[1].j = (jlong)infobuf.meta_size.obj.heap_size;
            CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args);
            ihinfobuf1 = ret_obj;
            args[0].j = (jlong)infobuf.meta_size.attr.index_size;
            args[1].j = (jlong)infobuf.meta_size.attr.heap_size;
            CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args);
            ihinfobuf2 = ret_obj;

            args[0].j = (jlong)infobuf.fileno;
            args[1].j = (jlong)infobuf.addr;
            args[2].i = infobuf.type;
            args[3].i = (jint)infobuf.rc;
            args[4].j = (jlong)infobuf.num_attrs;
            args[5].j = infobuf.atime;
            args[6].j = infobuf.mtime;
            args[7].j = infobuf.ctime;
            args[8].j = infobuf.btime;
            args[9].l = hdrinfobuf;
            args[10].l = ihinfobuf1;
            args[11].l = ihinfobuf2;
            CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_info_t", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V", args);
        }
    }

    return ret_obj;
} /* end Java_hdf_hdf5lib_H5_H5Oget_1info_1by_1name */
Exemplo n.º 23
0
/*--------------------------------------------------------------*/
static herr_t SecondPassIterator(hid_t g_id,
		const char *name,
		const H5L_info_t *info, void *op_data)
{
	SecondPassData *spd = (SecondPassData *)op_data;
  H5O_info_t obj_info;
	hid_t attID, groupID, dataID;
	char nxClass[512], fname[512];

	/*
		have we seen that yet?
	*/
	if(hash_lookup((char *)name,spd->namesSeen) != NULL){
		return 0;
	}

	/*
		Nope, we will have to warn...
	*/
	H5Oget_info_by_name(g_id, name, &obj_info,H5P_DEFAULT);
	if(obj_info.type == H5O_TYPE_GROUP){
		groupID = H5Gopen(g_id,name,H5P_DEFAULT);
		H5Iget_name(groupID, fname,sizeof(fname));
		NXVsetLog(spd->self,"dataPath",fname);
		if(H5LTfind_attribute(groupID,"NX_class") == 1){
			memset(nxClass,0,sizeof(nxClass));
			H5NXget_attribute_string(g_id,name,
			"NX_class", nxClass);
			if(hash_lookup(nxClass,spd->baseNames) == NULL){
				NXVsetLog(spd->self,"sev","warnundef");
				NXVprintLog(spd->self,"message","Unknown group %s of class %s found",
					name, nxClass);
				NXVlog(spd->self);
				spd->self->warnCount++;
			} else {
				NXVsetLog(spd->self,"sev","warnbase");
				NXVprintLog(spd->self,"message",
					"Additional base class group %s of type %s found",
					name, nxClass);
				NXVlog(spd->self);
				spd->self->warnCount++;
			}
		} else {
			NXVsetLog(spd->self,"sev","warnundef");
			NXVprintLog(spd->self,"message",
				"Additional non NeXus group %s found",
				name);
			NXVlog(spd->self);
			spd->self->warnCount++;
    }
		H5Gclose(groupID);
	} else if (obj_info.type == H5O_TYPE_DATASET) {
		dataID = H5Dopen(g_id,name,H5P_DEFAULT);
		H5Iget_name(dataID, fname,sizeof(fname));
		H5Dclose(dataID);
		NXVsetLog(spd->self,"dataPath",fname);
		if(hash_lookup((char *)name,spd->baseNames) == NULL){
			NXVsetLog(spd->self,"sev","warnundef");
			NXVprintLog(spd->self,"message","Unknown dataset %s found",
			name);
			NXVlog(spd->self);
			spd->self->warnCount++;
		} else {
			NXVsetLog(spd->self,"sev","warnbase");
			NXVprintLog(spd->self,"message","Additional base class dataset %s found",
			name);
			NXVlog(spd->self);
			spd->self->warnCount++;
		}
	}

	return 0;
}
Exemplo n.º 24
0
int VsFilter::visitLinks(hid_t locId, const char* name,
    const H5L_info_t *linfo, void* opdata) {
  VsLog::debugLog() <<"VsFilter::visitLinks() - looking at object " <<name <<std::endl;
  
  switch (linfo->type) {
    case H5L_TYPE_HARD: {

      H5O_info_t objinfo;

      /* Stat the object */
      if(H5Oget_info_by_name(locId, name, &objinfo, H5P_DEFAULT) < 0) {
        VsLog::errorLog() <<"VsFilter::visitLinks() - unable to open object with name " <<name <<std::endl;
        VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl;
        return 0;
      }

      switch(objinfo.type)
      {
        case H5O_TYPE_GROUP:
        return visitGroup( locId, name, opdata );
        break;
        case H5O_TYPE_DATASET:
        return visitDataset( locId, name, opdata );
        break;

        default:
        VsLog::debugLog() << "VsFilter::visitLinks: node '" << name <<
        "' has an unknown type " << objinfo.type << std::endl;
        break;
      }
    }
    break;
    //end of case H5L_TYPE_HARD
    case H5L_TYPE_EXTERNAL: {

      char *targbuf = (char*) malloc( linfo->u.val_size );

      if (H5Lget_val(locId, name, targbuf, linfo->u.val_size, H5P_DEFAULT) < 0) {
        VsLog::errorLog() <<"VsFilter::visitLinks() - unable to open external link with name " <<targbuf <<std::endl;
        VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl;
        return 0;
      }
      
      const char *filename;
      const char *targname;

      if (H5Lunpack_elink_val(targbuf, linfo->u.val_size, 0, &filename, &targname) < 0) {
        VsLog::errorLog() <<"VsFilter::visitLinks() - unable to open external file with name " <<filename <<std::endl;
        VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl;
        return 0;
      }
      
      VsLog::debugLog() << "VsFilter::visitLinks(): node '" << name << "' is an external link." << std::endl;
      VsLog::debugLog() << "VsFilter::visitLinks(): node '" << targname << "' is an external target group." << std::endl;

      free(targbuf);
      targbuf = NULL;
      
      // Get info of the linked object.
      H5O_info_t objinfo;
#ifndef H5_USE_16_API
      hid_t obj_id = H5Oopen(locId, name, H5P_DEFAULT);
#else
      hid_t obj_id = H5Oopen(locId, name);        
#endif
      
      if (obj_id < 0) {
        VsLog::errorLog() <<"VsFilter::visitLinks() - unable to get id for external object " <<name <<std::endl;
        VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl;
        return 0;
      }

      //Test-open the linked object
      if (H5Oget_info (obj_id, &objinfo) < 0) {
        VsLog::errorLog() <<"VsFilter::visitLinks() - unable to open external object " <<name <<std::endl;
        VsLog::errorLog() <<"VsFilter::visitLinks() - this object and all children will be dropped." <<std::endl;
        return 0;
      }
      
      //Close the linked object to release hdf5 id
      H5Oclose( obj_id );

      //Finally, decide what to do depending on what type of object this is
      switch(objinfo.type)
      {
        case H5O_TYPE_GROUP:
        return visitGroup( locId, name, opdata );
        break;
        case H5O_TYPE_DATASET:
        return visitDataset( locId, name, opdata );
        break;

        default:
          VsLog::debugLog() << "VsFilter::visitLinks: node '" << name <<
        "' has an unknown type " << objinfo.type << std::endl;
        break;
      }
    }
    break;
      //END OF CASE H5L_TYPE_EXTERNAL
    
    default:
    VsLog::debugLog() << "VsFilter::visitLinks: node '" << name <<
    "' has an unknown object type " << linfo->type << std::endl;
    break;
  }

  return 0;
}
Exemplo n.º 25
0
// Read all optional attributes
char AH5_read_opt_attrs(hid_t loc_id, const char *path, AH5_opt_attrs_t *opt_attrs, char mandatory_attrs[][AH5_ATTR_LENGTH], size_t nb_mandatory_attrs)
{
    char success = AH5_FALSE, is_mandatory;
    H5O_info_t object_info;
    hsize_t i, j, k = 0;
    hid_t attr_id, type_id, memtype;
    float buf[2];
    hsize_t nb_present_mandatory_attrs = 0;
    char temp_name[AH5_ATTR_LENGTH];

    if (AH5_path_valid(loc_id, path))
    {
        // Check presence of all mandatory attributes
        for (i = 0; i < (hsize_t) nb_mandatory_attrs; i++)
            if (H5Aexists_by_name(loc_id, path, mandatory_attrs[i], H5P_DEFAULT) > 0)
                nb_present_mandatory_attrs++;
        H5Oget_info_by_name(loc_id, path, &object_info, H5P_DEFAULT);
        opt_attrs->nb_instances = object_info.num_attrs - nb_present_mandatory_attrs;
        if (opt_attrs->nb_instances > 0)
            opt_attrs->instances = (AH5_attr_instance_t *) malloc ((size_t) opt_attrs->nb_instances * sizeof(AH5_attr_instance_t));
        for (i = 0; i < object_info.num_attrs; i++)
        {
            is_mandatory = AH5_FALSE;
            attr_id = H5Aopen_by_idx(loc_id, path, H5_INDEX_CRT_ORDER, H5_ITER_NATIVE, i, H5P_DEFAULT, H5P_DEFAULT);
            H5Aget_name(attr_id, AH5_ATTR_LENGTH, temp_name);
            for (j = 0; j < nb_mandatory_attrs; j++)
                if (strcmp(temp_name, mandatory_attrs[j]) == 0)
                    is_mandatory = AH5_TRUE;
            if (!is_mandatory)
            {
                opt_attrs->instances[k].name = strdup(temp_name);
                type_id = H5Aget_type(attr_id);
                opt_attrs->instances[k].type = H5Tget_class(type_id);
                H5Tclose(type_id);
                switch (opt_attrs->instances[k].type)
                {
                case H5T_INTEGER:
                    opt_attrs->instances[k].value.i = 0;
                    if (H5Aread(attr_id, H5T_NATIVE_INT, &(opt_attrs->instances[k].value.i)) >= 0)
                        success = AH5_TRUE;
                    break;
                case H5T_FLOAT:
                    opt_attrs->instances[k].value.f = 0;
                    if (H5Aread(attr_id, H5T_NATIVE_FLOAT, &(opt_attrs->instances[k].value.f)) >= 0)
                        success = AH5_TRUE;
                    break;
                case H5T_COMPOUND:
                    opt_attrs->instances[k].value.c = AH5_set_complex(0, 0);
                    type_id = AH5_H5Tcreate_cpx_memtype();
                    if (H5Aread(attr_id, type_id, buf) >= 0)
                    {
                        opt_attrs->instances[k].value.c = AH5_set_complex(buf[0], buf[1]);
                        success = AH5_TRUE;
                    }
                    H5Tclose(type_id);
                    break;
                case H5T_STRING:
                    opt_attrs->instances[k].value.s = NULL;
                    memtype = H5Tcopy(H5T_C_S1);
                    H5Tset_size(memtype, AH5_ATTR_LENGTH);
                    opt_attrs->instances[k].value.s = (char *) malloc(AH5_ATTR_LENGTH * sizeof(char));
                    if (H5Aread(attr_id, memtype, opt_attrs->instances[k].value.s) >= 0)
                        success = AH5_TRUE;
                    H5Tclose(memtype);
                    break;
                default:
                    opt_attrs->instances[k].type = H5T_NO_CLASS;
                    printf("***** WARNING: Unsupported type of attribute \"%s@%s\". *****\n\n", path, opt_attrs->instances[k].name);
                    break;
                }
                k++;
            }
            H5Aclose(attr_id);
        }
    }
    if (!success)
    {
        opt_attrs->instances = NULL;
        opt_attrs->nb_instances = 0;
    }
    return success;
}
Exemplo n.º 26
0
/*-------------------------------------------------------------------------
 * Function: H5tools_get_symlink_info
 *
 * Purpose: Get symbolic link (soft, external) info and its target object type 
            (dataset, group, named datatype) and path, if exist
 *
 * Patameters:
 *  - [IN]  fileid : link file id
 *  - [IN]  linkpath : link path
 *  - [OUT] link_info: returning target object info (h5tool_link_info_t)
 *
 * Return: 
 *   2 : given pathname is object 
 *   1 : Succed to get link info.  
 *   0 : Detected as a dangling link
 *  -1 : H5 API failed.
 *
 * NOTE:
 *  link_info->trg_path must be freed out of this function
 *
 * Programmer: Jonathan Kim
 *
 * Date: Feb 8, 2010
 *-------------------------------------------------------------------------*/
int
H5tools_get_symlink_info(hid_t file_id, const char * linkpath, h5tool_link_info_t *link_info,
    hbool_t get_obj_type)
{
    htri_t l_ret;
    H5O_info_t trg_oinfo;
    hid_t fapl = H5P_DEFAULT;
    hid_t lapl = H5P_DEFAULT;
    int ret = -1; /* init to fail */

    /* init */
    link_info->trg_type = H5O_TYPE_UNKNOWN;

    /* if path is root, return group type */
    if(!HDstrcmp(linkpath,"/"))
    {
        link_info->trg_type = H5O_TYPE_GROUP;
        ret = 2;
        goto out;
    }

    /* check if link itself exist */
    if(H5Lexists(file_id, linkpath, H5P_DEFAULT) <= 0) {
        if(link_info->opt.msg_mode == 1)
            parallel_print("Warning: link <%s> doesn't exist \n",linkpath);
        goto out;
    } /* end if */

    /* get info from link */
    if(H5Lget_info(file_id, linkpath, &(link_info->linfo), H5P_DEFAULT) < 0) {
        if(link_info->opt.msg_mode == 1)
            parallel_print("Warning: unable to get link info from <%s>\n",linkpath);
        goto out;
    } /* end if */

    /* given path is hard link (object) */
    if(link_info->linfo.type == H5L_TYPE_HARD) {
        ret = 2;
        goto out;
    } /* end if */

    /* trg_path must be freed out of this function when finished using */
    link_info->trg_path = (char*)HDcalloc(link_info->linfo.u.val_size, sizeof(char));
    HDassert(link_info->trg_path);

    /* get link value */
    if(H5Lget_val(file_id, linkpath, (void *)link_info->trg_path, link_info->linfo.u.val_size, H5P_DEFAULT) < 0) {
        if(link_info->opt.msg_mode == 1)
            parallel_print("Warning: unable to get link value from <%s>\n",linkpath);
        goto out;
    } /* end if */

    /*-----------------------------------------------------
     * if link type is external link use different lapl to 
     * follow object in other file
     */
    if(link_info->linfo.type == H5L_TYPE_EXTERNAL) {
        if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
            goto out;
        if(H5Pset_fapl_sec2(fapl) < 0)
            goto out;
        if((lapl = H5Pcreate(H5P_LINK_ACCESS)) < 0)
            goto out;
        if(H5Pset_elink_fapl(lapl, fapl) < 0)
            goto out;
    } /* end if */

    /* Check for retrieving object info */
    if(get_obj_type) {
        /*--------------------------------------------------------------
         * if link's target object exist, get type
         */
         /* check if target object exist */
        l_ret = H5Oexists_by_name(file_id, linkpath, lapl);
        
        /* detect dangling link */
        if(l_ret == FALSE) {
            ret = 0;
            goto out;
        } /* end if */
        /* function failed */
        else if(l_ret < 0)
            goto out;    

        /* get target object info */
        if(H5Oget_info_by_name(file_id, linkpath, &trg_oinfo, lapl) < 0) {
            if(link_info->opt.msg_mode == 1)
                parallel_print("Warning: unable to get object information for <%s>\n", linkpath);
            goto out;
        } /* end if */

        /* check unknown type */
        if(trg_oinfo.type < H5O_TYPE_GROUP || trg_oinfo.type >=H5O_TYPE_NTYPES) {
            if(link_info->opt.msg_mode == 1)
                parallel_print("Warning: target object of <%s> is unknown type\n", linkpath);
            goto out;
        }  /* end if */

        /* set target obj type to return */
        link_info->trg_type = trg_oinfo.type;
        link_info->objno = trg_oinfo.addr;
        link_info->fileno = trg_oinfo.fileno;
    } /* end if */
    else
        link_info->trg_type = H5O_TYPE_UNKNOWN;

    /* succeed */
    ret = 1;

out:
    if(fapl != H5P_DEFAULT)
        H5Pclose(fapl);
    if(lapl != H5P_DEFAULT)
        H5Pclose(lapl);

    return ret;
} /* end H5tools_get_symlink_info() */