/**
	 * TODO
	 * Retrieves the number of global attributes in the selected file.  This is useful for iterating over all
	 * available global attributes.
	 * @return The number of global attributes stored in the selected file.
	 */
	int HDF5FileReader::getNumberOfGlobalAttributes()
	{
		long num_attributes;
		H5::Group group = this->current_file->openGroup("/");
		num_attributes = group.getNumAttrs();
		return (int)num_attributes;
	}
Example #2
0
static void attributes_append_group(Attributes &attrs, H5::Group &g, cpath basename, cpath group_path)
{     
  for(uint i=0;i<g.getNumObjs();i++) {
    
    char g_name[1024];
    g.getObjnameByIdx(hsize_t(i), g_name, 1024);
    cpath name = group_path / g_name;
    
    H5G_stat_t stat;
    g.getObjinfo(g_name, false, stat);
    
    if (stat.type == H5G_GROUP) {
      H5::Group sub = g.openGroup(g_name);
      attributes_append_group(attrs, sub, basename, name);
    }
    else if (stat.type == H5G_LINK)
    {
      //FIXME we assume soft link!
      Attribute attr;
      char attr_name[1024];
      char link[1024];
      
      attr.setName(remove_prefix(name, basename));
      
      H5L_info_t info;
      H5Lget_val(g.getId(), g_name, link, 1024, H5P_DEFAULT);
      attr.setLink(remove_prefix(link, basename));
      
      attrs.append(attr);
    }
  }
  
  
  for(int i=0;i<g.getNumAttrs();i++) {
    H5::Attribute h5attr = g.openAttribute(i);
    Attribute attr;
    BaseType type;
    char name[1024];
    
    H5Aget_name(h5attr.getId(), 1024, name);
    read_attr(&attr, g, basename, group_path, name, type);
    
    attrs.append(attr);
  }
}
Example #3
0
/*********************************************************
FunctionName:RecursiveVisitNode
FunctionDesc:递归创建Group
InputParam:
OutputParam:
Return:
Author:xiaowei.han
*********************************************************/
void RecursiveVisitNode(H5::Group& Node, Hdf5_Wrapper::LP_HDF5_DATA pData)
{
	using namespace H5;
	if (nullptr == pData)
	{
		return;
	}
	//获取节点名称
	pData->strKeyName = Utility::UTF8ToGB2312(Node.getObjName());
	//获取属性个数
	int nAttrNum = static_cast<int>(Node.getNumAttrs());
	for (int i = 0; i < nAttrNum; ++i)
	{
		auto childAttr = Node.openAttribute(i);

		//解析读取属性数据
		//获取数据类型
		auto AttrDataType = childAttr.getDataType();
		//获取数据类型大小
		unsigned int nDataByte = (unsigned int)AttrDataType.getSize();

		boost::scoped_ptr<CAbstractAttrHanlder> pHandler(CreateAttrHandler(childAttr.getTypeClass(), nDataByte));

		if (pHandler)
		{
			pHandler->ReadAttr(childAttr, AttrDataType, pData->AttributeArray);
		}
		childAttr.close();
	}

	//获取节点对象个数
	int nObjNum = static_cast<int>(Node.getNumObjs());

	//遍历子节点信息
	for (int i = 0; i < nObjNum; ++i)
	{
		//NECESSARY_LOG("the node name is [%s],the type is [%d].", Node.getObjnameByIdx(i).c_str(), Node.getObjTypeByIdx(i));
		auto SubNodeType = Node.getObjTypeByIdx(i);
		switch (SubNodeType)
		{
		case H5G_GROUP:
		{
			Hdf5_Wrapper::LP_HDF5_DATA pSubData = new Hdf5_Wrapper::HDF5_DATA;
			if (nullptr != pSubData)
			{
				//添加进去
				pData->SubDataArray.push_back(pSubData);
				auto ChildGroupNode = Node.openGroup(Node.getObjnameByIdx(i));
				RecursiveVisitNode(ChildGroupNode,pSubData);
				ChildGroupNode.close();
			}
		}
		break;
		case H5G_DATASET:
		{
			auto childDataset = Node.openDataSet(Node.getObjnameByIdx(i));

			Hdf5_Wrapper::LP_HDF5_DATA pSubData = new Hdf5_Wrapper::HDF5_DATA;
			if (nullptr != pSubData)
			{
				pSubData->strKeyName = childDataset.getObjName();
				//添加进去
				pData->SubDataArray.push_back(pSubData);
				//获取数据类型
				auto ChildDataSetDataType = childDataset.getDataType();
				//获取类型占用字节数
				unsigned int nDataByte = (unsigned int)ChildDataSetDataType.getSize();
				//判断数据类型
				boost::scoped_ptr<CAbstractDataTypeHandler> pHandlder(CDataTypeHandlerFactory::CreateDataTypeHandler(childDataset.getTypeClass(),nDataByte));
				if (pHandlder)
				{
					pHandlder->ReadDataSet(childDataset, pSubData);
				}
			}
		}
		break;
		default:
			break;
		}	
	}
}
Example #4
0
void ossim_hdf5::printIterative( H5::H5File* file,
                                 const std::string& groupName,
                                 const std::string& prefix,
                                 ossim_uint32& recursedCount,
                                 std::ostream& out )
{
   if ( file && groupName.size() )
   {
      ++recursedCount;
      
      H5::Group* group = new H5::Group( file->openGroup(groupName) );

      // Print attributes:
      const ossim_uint32 ATTRS_COUNT = group->getNumAttrs();
      for ( ossim_uint32 aIdx = 0; aIdx < ATTRS_COUNT; ++aIdx )
      {
         H5::Attribute attr( group->openAttribute( aIdx ) );
         ossim_hdf5::printAttribute( attr, prefix, out );
         attr.close();
      }
      
      const hsize_t OBJ_COUNT = group->getNumObjs();
      for ( hsize_t i = 0; i < OBJ_COUNT; ++i )
      {
         std::string objName = group->getObjnameByIdx(i);

         if ( objName.size() )
         {
            char separator = '/';
            std::string combinedName;
            combine( groupName, objName, separator, combinedName );
            
            separator = '.';
            std::string combinedPrefix;
            combine( prefix, objName, separator, combinedPrefix );
            
            H5G_obj_t objType   = group->getObjTypeByIdx(i);

#if 0
            std::cout << "combinedName: " << combinedName
                      << "\ncombinedPrefix: " << combinedPrefix
                      << "\ngetObjnameByIdx[" << i << "]: " << objName
                      << "\ngetObjTypeByIdx[" << i << "]: " << objType
                      << std::endl;
#endif
            
            if ( objType == H5G_GROUP )
            {
               // Recursive call:
               if ( recursedCount < ossim_hdf5::MAX_RECURSION_LEVEL )
               {
                  ossim_hdf5::printIterative(
                     file, combinedName, combinedPrefix, recursedCount, out );
               }
               else
               {
                  ossimNotify(ossimNotifyLevel_WARN)
                     << "ossim_hdf5::printIterative WARNING!"
                     << "\nMax iterations reached!" << std::endl;
               }
            }
            else if ( objType == H5G_DATASET )
            {
               printObject( file, combinedName, combinedPrefix, out );
            }
            else
            {
               ossimNotify(ossimNotifyLevel_WARN)
                  << "ossim_hdf5::printIterative WARNING!"
                  << "\nUnhandled object type: " << objType << std::endl;
            }
         }
      }
      
      group->close();
      delete group;
      group = 0;
      --recursedCount;
      
   } // Matches: if ( file )
   
} // End: void ossim_hdf5::printIterative method.