Exemplo n.º 1
0
CPLErr HDF5Dataset::CreateMetadata( HDF5GroupObjects *poH5Object, int nType)
{
    hid_t	hGroupID;		/* identifier of group */
    hid_t       hDatasetID;
    int         nbAttrs;
    herr_t      ret;

    HDF5Dataset *poDS;

    if( !poH5Object->pszPath )
        return CE_None;

    poDS = this;

    poH5CurrentObject = poH5Object;
    nbAttrs = poH5Object->nbAttrs;

    if( poH5Object->pszPath == NULL || EQUAL(poH5Object->pszPath, "" ) )
	return CE_None;

    switch( nType ) {

    case H5G_GROUP:

	hGroupID = H5Gopen( hHDF5, poH5Object->pszPath );
	if( nbAttrs > 0 ) { 
	    ret = H5Aiterate( hGroupID, NULL, 
			      HDF5AttrIterate, (void *)poDS  );
	    ret = H5Gclose( hGroupID );
	}

	break;

    case H5G_DATASET:

	hDatasetID =  H5Dopen(hHDF5, poH5Object->pszPath );

	if( nbAttrs > 0 ) { 
	    ret = H5Aiterate( hDatasetID, NULL, 
			      HDF5AttrIterate, (void *)poDS );
	    ret = H5Dclose( hDatasetID );
	}
	break;

    default:
	break;
    }

    return CE_None;
}
Exemplo n.º 2
0
static int find_objs(hid_t group, const char *name, void *op_data)
{
  hid_t obj;
  H5G_stat_t statbuf;
  unsigned int idx = 0;
  int status;
  h5item *parent = (h5item *)op_data;
  h5item *item = (h5item *)malloc(sizeof(h5item));
  h5item *itm;
  item->item_type = 0;
  item->name=strcpy(malloc(strlen(name)+1),name);
  item->child = 0;
  item->brother = 0;
  item->parent = parent;
  item->obj = 0;
  item->attribute = 0;
  if (parent->child == NULL)
  {
    parent->child = item;
  }
  else
  {
    for (itm = parent->child; itm->brother; itm = itm->brother);
    itm->brother = item;
  }
  if (parent->child == item)
/*     H5Aiterate(group,&idx,find_attr,(void *)item); */
    H5Aiterate(group,NULL,find_attr,(void *)item);
  //    H5Aiterate(group,&idx,find_attr,(void *)0);
  H5Gget_objinfo(group, name, 1, &statbuf);
  item->item_type = statbuf.type;
  switch (statbuf.type) {
  case H5G_GROUP:
    if ((obj = H5Gopen(group, name)) >= 0) {
      H5Giterate(obj, ".", NULL, find_objs, (void *)item);
      H5Gclose (obj);
    }
    break;
  case H5G_DATASET:
    if ((obj = H5Dopen (group, name)) >= 0) {
      item->obj = obj;
/*       H5Aiterate(obj,&idx,find_attr,(void *)item); */
      H5Aiterate(obj,&idx,find_attr,(void *)item);
    }
    break;
  }
  return 0;
}
int VsFilter::visitDataset(hid_t locId, const char* name, void* opdata) {
  RECURSION_DATA* data = static_cast< RECURSION_DATA* >(opdata);
  VsGroup* parent = static_cast< VsGroup*>(data->parent);
  VsRegistry* registry = data->registry;

  VsLog::debugLog() << "VsFilter::visitDataset: node '" << name
    <<"' is a dataset." << std::endl;

  hid_t datasetId = H5Dopen(locId, name, H5P_DEFAULT);

  VsDataset* newDataset = new VsDataset(registry, parent, name, datasetId);
  
  //If unable to get a handle to the hdf5 object, we just drop the object
  //But return 0 to continue iterating over objects
  if (datasetId < 0) {
    VsLog::errorLog() <<"VsFilter::visitDataset() - Unable to open dataset with name " <<name <<std::endl;
    VsLog::errorLog() <<"VsFilter::visitDataset() - This object and all children will be dropped." <<std::endl;
    return 0;
  }

  RECURSION_DATA nextLevelData;
  nextLevelData.registry = registry;
  nextLevelData.parent = newDataset;
  
  // Recurse over attributes
  H5Aiterate(datasetId, H5_INDEX_NAME, H5_ITER_INC, NULL, visitAttrib, &nextLevelData);

  VsLog::debugLog() <<"VsFilter::visitDataset: Returning." <<std::endl;
  return 0;
}
Exemplo n.º 4
0
static int readIntAttribute_v1(int _iDatasetId, const char *_pstName)
{
    hid_t iAttributeId;
    herr_t status;
    hsize_t n = 0;
    int iVal = -1;

    if (H5Aiterate(_iDatasetId, H5_INDEX_NAME, H5_ITER_NATIVE, &n, find_attr_by_name_v1, (void *)_pstName) > 0)
    {
        iAttributeId = H5Aopen_by_name(_iDatasetId, ".", _pstName, H5P_DEFAULT, H5P_DEFAULT);
        if (iAttributeId < 0)
        {
            return -1;
        }

        status = H5Aread(iAttributeId, H5T_NATIVE_INT, &iVal);
        if (status < 0)
        {
            return -1;
        }

        status = H5Aclose(iAttributeId);
        if (status < 0)
        {
            return -1;
        }
    }
    return iVal;
}
Exemplo n.º 5
0
/****************************************************************
**
**  Aiterate(): Attribute set iteration routine.
**
****************************************************************/
PyObject *Aiterate(hid_t loc_id) {
  hsize_t i = 0;
  PyObject *attrlist;                  /* List where the attrnames are put */

  attrlist = PyList_New(0);
  H5Aiterate(loc_id, H5_INDEX_CRT_ORDER, H5_ITER_NATIVE, &i,
             (H5A_operator_t)aitercb, (void *)attrlist);

  return attrlist;
}
Exemplo n.º 6
0
Arquivo: Common.cpp Projeto: zjnny/hdf
int _CheckAttrFC(int loc_id, const char *name, void *strname)
{
	int iTempValue;
	H5G_stat_t statbuf;
	hid_t hDatasetID;

	H5Gget_objinfo((hid_t)loc_id, name, 0, &statbuf);
	hDatasetID = H5Dopen(loc_id, name);
	iTempValue=H5Aiterate(hDatasetID,NULL, _GetValue, strname );
	H5Dclose(hDatasetID);
	return iTempValue;
}
Exemplo n.º 7
0
void H5Dataset::ls(std::vector<std::string> & name, std::vector<std::string> & type) const
{
    herr_t err;
    OpDataGetLs opdata(const_cast<H5Dataset *>(this), &name, &type);
    hsize_t idx = 0;

    err = H5Aiterate(dataset, H5_INDEX_NAME, H5_ITER_INC, &idx, H5Object::getLsAttributes, &opdata);
    if (err < 0)
    {
        throw H5Exception(__LINE__, __FILE__, _("Cannot list dataset attributes."));
    }
}
Exemplo n.º 8
0
CPLErr HDF5Dataset::CreateMetadata( HDF5GroupObjects *poH5Object, int nType)
{

    if( !poH5Object->pszPath )
        return CE_None;

    poH5CurrentObject = poH5Object;

    if( poH5Object->pszPath == nullptr || EQUAL(poH5Object->pszPath, "") )
        return CE_None;

    HDF5Dataset *const poDS = this;
    const int nbAttrs = poH5Object->nbAttrs;

    switch( nType )
    {
    case H5G_GROUP:
        if( nbAttrs > 0 )
        {
            // Identifier of group.
            const hid_t l_hGroupID = H5Gopen(hHDF5, poH5Object->pszPath);
            H5Aiterate(l_hGroupID, nullptr, HDF5AttrIterate, poDS);
            H5Gclose(l_hGroupID);
        }
        break;
    case H5G_DATASET:
        if( nbAttrs > 0 )
        {
            const hid_t hDatasetID = H5Dopen(hHDF5, poH5Object->pszPath);
            H5Aiterate(hDatasetID, nullptr, HDF5AttrIterate, poDS);
            H5Dclose(hDatasetID);
        }
        break;

    default:
        break;
    }

    return CE_None;
}
int VsFilter::visitGroup(hid_t locId, const char* name, void* opdata) {
  RECURSION_DATA* data = static_cast< RECURSION_DATA* >(opdata);
  VsGroup* parent = static_cast< VsGroup*> (data->parent);
  VsRegistry* registry = data->registry;
  
  VsLog::debugLog() << "VsFilter::visitGroup: node '" << name
    << "' is a group." << std::endl;

  if (std::string(name) == "..")
  {
    VsLog::debugLog() << "VsFilter::visitGroup: skipping group '..'" << std::endl;
    return 0;
  }

  hid_t groupId = H5Gopen(locId, name, H5P_DEFAULT);
  
  //If unable to get a handle to the hdf5 object, we just drop the object
  //But return 0 to continue iterating over objects
  if (groupId < 0) {
    VsLog::errorLog() <<"VsFilter::visitGroup() - Unable to open group with name " <<name <<std::endl;
    VsLog::errorLog() <<"VsFilter::visitGroup() - This object and all children will be dropped." <<std::endl;
    return 0;
  }
  
  VsGroup* newGroup = new VsGroup(registry, parent, name, groupId);
  
  RECURSION_DATA nextLevelData;
  nextLevelData.registry = registry;
  nextLevelData.parent = newGroup;
  
  // Recurse over all attributes of the group
  VsLog::debugLog() <<"VsFilter::visitGroup(): Recursing on attributes of group " <<newGroup->getFullName() <<std::endl;
  H5Aiterate(groupId, H5_INDEX_NAME, H5_ITER_INC, NULL, visitAttrib, &nextLevelData);

  // Recurse to examine child groups
  VsLog::debugLog() <<"VsFilter::visitGroup(): Recursing on children of group " <<newGroup->getFullName() <<std::endl;
  H5Literate(groupId, H5_INDEX_NAME, H5_ITER_INC, NULL, visitLinks, &nextLevelData);

  // Not needed because the newly declared VsGroup takes ownership of the id
  // And will do the H5GClose when it is deleted
  // H5Gclose(groupId);

  VsLog::debugLog() <<"VsFilter::visitGroup(): Returning." <<std::endl;
  return 0;
}
Exemplo n.º 10
0
/*
** WARNING : this function returns an allocated value that must be freed.
*/
static char* readAttribute_v1(int _iDatasetId, const char *_pstName)
{
    hid_t iAttributeId;
    hid_t iFileType, memtype, iSpace;
    herr_t status;
    hsize_t dims[1];
    hsize_t n = 0;
    size_t iDim;

    char *pstValue = NULL;

    if (H5Aiterate(_iDatasetId, H5_INDEX_NAME, H5_ITER_NATIVE, &n, find_attr_by_name_v1, (void *)_pstName) > 0)
    {
        iAttributeId = H5Aopen_by_name(_iDatasetId, ".", _pstName, H5P_DEFAULT, H5P_DEFAULT);
        if (iAttributeId < 0)
        {
            return NULL;
        }
        /*
        * Get the datatype and its size.
        */
        iFileType = H5Aget_type(iAttributeId);
        iDim = H5Tget_size(iFileType);
        iDim++;                 /* Make room for null terminator */

        /*
        * Get dataspace and allocate memory for read buffer.  This is a
        * two dimensional attribute so the dynamic allocation must be done
        * in steps.
        */
        iSpace = H5Aget_space(iAttributeId);
        if (iSpace < 0)
        {
            return NULL;
        }

        status = H5Sget_simple_extent_dims(iSpace, dims, NULL);
        if (status < 0)
        {
            return NULL;
        }

        /*
        * Allocate space for string data.
        */
        pstValue = (char *)MALLOC((size_t) ((dims[0] * iDim + 1) * sizeof(char)));

        /*
        * Create the memory datatype.
        */
        memtype = H5Tcopy(H5T_C_S1);
        status = H5Tset_size(memtype, iDim);
        if (status < 0)
        {
            FREE(pstValue);
            return NULL;
        }

        /*
        * Read the data.
        */
        status = H5Aread(iAttributeId, memtype, pstValue);
        if (status < 0)
        {
            FREE(pstValue);
            return NULL;
        }

        status = H5Tclose(memtype);
        if (status < 0)
        {
            FREE(pstValue);
            return NULL;
        }

        status = H5Sclose(iSpace);
        if (status < 0)
        {
            FREE(pstValue);
            return NULL;
        }

        status = H5Tclose(iFileType);
        if (status < 0)
        {
            FREE(pstValue);
            return NULL;
        }

        status = H5Aclose(iAttributeId);
        if (status < 0)
        {
            FREE(pstValue);
            return NULL;
        }
    }
    return pstValue;

}