Recursively reading file information from some file get infinite recycling

Hi, Rob:
    Thanks for you efficient reply. My code is almost like this:

//TreeNOde is an XMLWrapper and its structure is like a tree
//m_hdfID = H5Fopen(lpcszFileName, H5F_ACC_RDONLY, H5P_DEFAULT);
//called like constructDatasetFromGroup(m_hdfID, m_trRoot, -1);
HDFstatus constructDatasetFromGroup(hid_t groupID, TreeNode& trParent, int nSubIndex)
{
string strGroup;
if ( nSubIndex < 0 ) //when groupID is file ID
  strGroup = STR_GROUP;
else
  strGroup.Format(STR_TAGNAME_FORMAT, STR_GROUP, nSubIndex);

TreeNode trGroup = trParent.AddSubNode(strGroup); //add subtreenode named strGroup

string strName;
int nLength = H5Iget_name(groupID, NULL, 0);
LPSTR lpName = strName.GetBuffer(nLength + 1);
H5Iget_name(groupID, lpName, nLength + 1);
strName.ReleaseBuffer();

trGroup.SetAttribute(STR_NAME, strName);

hsize_t dObjs;
HDFstatus status = H5Gget_num_objs(groupID, &dObjs);
int nSubGroup = 0;
int nSubDataset = 0;
int nDataType = 0, nLink = 0;
for ( uint ii = 0; ii < dObjs; ii++ )
{
  nLength = H5Gget_objname_by_idx(groupID, ii, NULL, 0);
  
  strName.Empty();
  lpName = strName.GetBuffer(nLength + 1);
  nLength = H5Gget_objname_by_idx(groupID, ii, lpName, nLength + 1);
  strName.ReleaseBuffer();
  
  H5G_obj_t objtype = H5Gget_objtype_by_idx(groupID, ii);
  if ( H5G_GROUP == objtype )
  {
   hid_t gID = H5Gopen1(groupID, strName);
   status = constructDatasetFromGroup(gID, trGroup, nSubGroup++); //recursively call, and recursively get into subgroup link here.
   H5Gclose(gID);
   
   ASSERT(status == HDF_SUCCESS);
  }
  else if ( H5G_DATASET == objtype )
  {
   hid_t dID = H5Dopen1(groupID, strName);
   status = addOneDataset(dID, trGroup, nSubDataset++);
   H5Dclose(dID);
  }
  else if ( H5G_TYPE == objtype ) //I don't need this kind of information, so ignore it.
  {
   ASSERT(FALSE);
  }
  else if ( H5G_LINK == objtype ) //it is strange that though "link_to_group" under "subgroup" is a link, but it never come here.
  {
   ASSERT(FALSE);
  }
  else if ( H5G_UDLINK == objtype ) //never come here either
  {
   ASSERT(FALSE);
  }
}
return HDF_SUCCESS;
}

textlinktar.h5 (6.59 KB)

···

--