Hello everyone,
After talking with the help desk it was found that the H5G functions have
been deprecated and replaced by functions in the H5O and H5L classes. So a
big thank you goes out to the Help Desk.
So the code to get the groups in the data set are:
public void getGroups(StreamWriter sw)
{
//open the HDF5 library
int x = H5.Open();
//open the file
H5FileId gh5file = H5F.open(fname, H5F.OpenMode.ACC_RDONLY);
//read in the root group
H5GroupId rootGroup = H5G.open(gh5file, "/");
//find out how many objects are under the root group
long count = H5G.getNumObjects(rootGroup);
//store the names at this level
//ObjectInfo info = H5G.getObjectInfo(rootGroup, "/DYNAMIC
DATA", false);
H5ObjectInfo info = H5O.getInfoByName(rootGroup, "/DYNAMIC
DATA");
groups.Add(new Group("/DYNAMIC DATA", info.objectType));
H5G.close(rootGroup);
//find all children of roots children recursively
for (int i = 0; i < groups.Count; i++)
{
findChildren(groups[i], gh5file, sw);
}
H5F.close(gh5file);
H5.Close();
}
public static void findChildren(Group s, H5FileId ghfile, StreamWriter sw)
{
//Get the number of children that belong to current group
H5GroupId curr_group = H5G.open(ghfile, s.name);
try
{
long count = H5G.getNumObjects(curr_group);
//for each of the children add them to the parent list
for (ulong j = 0; j < (ulong)count; j++)
{
//read it by index
string obj_name = H5L.getNameByIndex(curr_group,
s.name, H5IndexType.NAME, H5IterationOrder.NATIVE, j);
//string obj_name =
H5G.getObjectNameByIndex(curr_group, j);
H5ObjectInfo objinfo = H5O.getInfoByIndex(curr_group,
s.name, H5IndexType.NAME, H5IterationOrder.NATIVE, j);
s.children.Add(new Group(s.name + "/" + obj_name,
objinfo.objectType));
//ObjectInfo info = H5G.getObjectInfo(curr_group,
obj_name, false);
//s.children.Add(new Group(s.name + "/" + obj_name,
info.objectType));
}
//H5G.close(curr_group);
//H5F.close(gh5file);
}
catch (Exception ex)
{
sw.WriteLine("FindChildren Error: {0}", ex.Message);
sw.WriteLine("CurrGroup: {0}", s.name);
throw ex;
}
//For each child we are going to recurse down
for (int i = 0; i < s.children.Count; i++)
{
//in the GH5 file format there is nothing below dataset
//if it is not a dataset, recurse on its children
if (s.children[i].type != H5ObjectType.DATASET)
//H5GType.DATASET)
{
findChildren(s.children[i], ghfile, sw);
}
else //it is a dataset so log the enformation
{
s.children[i].dsetID = H5D.open(ghfile,
s.children[i].name);
H5DataTypeId dID = H5D.getType(s.children[i].dsetID);
s.children[i].dtypeID = dID;
s.children[i].dtype = H5T.getClass(dID);
s.children[i].dtype_size = H5T.getSize(dID);
s.children[i].numPoints = H5S.getSimpleExtentNPoints(
H5D.getSpace(s.children[i].dsetID));
s.children[i].order = H5T.get_order(dID);
s.children[i].unit = Helpers
.ReadAttributeString(s.children[i].dsetID, s.children[i].name, "UNITS");
H5T.close(dID);
H5D.close(s.children[i].dsetID);
}
}
H5G.close(curr_group);
}
In the findChildren function I'm now using the H5O.getInfoByIndex and the
H5L.getNameByIndex functions. They seem to work well and don't have the
same issue as the H5G function. This code could probably be made more
compact once I figure out how to use the iteration functions inside C#._______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org