public void GetTree(HDFObjectInfo parent, H5LocId id, string name, string path) { try { H5GroupId root_id = H5G.open(id, name); parent.NItems = H5G.getNumObjects(root_id); for (ulong i = 0; i < (ulong)parent.NItems; i++) { HDFObjectInfo info = new HDFObjectInfo(); info.Index = i; info.Name = H5G.getObjectNameByIndex(root_id, (ulong)i); ObjectInfo h5oi = H5G.getObjectInfo(root_id, info.Name, false); info.Type = h5oi.objectType; info.Path = path; if (info.Type == H5GType.GROUP) { info.Path += info.Name + "/"; info.Parent = parent; GetTree(info, root_id, info.Name, info.Path); info.IsProperty = true; foreach (HDFObjectInfo obj in info.Children) { obj.Parent = info; if (obj.Type != H5GType.DATASET) { info.IsProperty = false; break; } } } else { info.Path += info.Name; info.Parent = parent; if (info.Type == H5GType.DATASET) { H5DataSetId dsid = H5D.open(root_id, info.Name); H5DataSpaceId dspid = H5D.getSpace(dsid); info.DataTypeId = H5D.getType(dsid); info.Size = H5T.getSize(info.DataTypeId); info.Class = H5T.getClass(info.DataTypeId); info.NativeType = H5T.getNativeType(info.DataTypeId, H5T.Direction.DESCEND); info.Dims = H5S.getSimpleExtentDims(dspid); info.NDims = H5S.getSimpleExtentNDims(dspid); info.MaxDims = H5S.getSimpleExtentMaxDims(dspid); info.Parent.HasDatasets = true; H5S.close(dspid); H5D.close(dsid); } } parent.Children.Add(info); } H5G.close(root_id); } catch (Exception ex) { last_exception = ex; } }
public bool CheckMeteoHDF(FileName file, int number_of_instants, bool exception_warn = false) { try { HDFObjectInfo group, dataset; HDF.HDF input = new HDF.HDF(); HDFObjectInfo input_root = new HDFObjectInfo(); input.InitializeLibrary(); input.OpenHDF(file, H5F.OpenMode.ACC_RDONLY); input.GetTree(input_root, input.FileID, "/", "/"); input.CloseHDF(); HDFObjectInfo time = input_root.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "Time"; }); if (time == null) throw new Exception("Missing 'time' group."); if (time.Children == null) throw new Exception("Missing 'time' datasets."); if (time.Children.Count != number_of_instants) throw new Exception("Wrong number of 'time' datasets"); HDFObjectInfo results = input_root.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "Results"; }); if (results == null) throw new Exception("Missing 'results' group."); if (results.Children == null) throw new Exception("Missing 'results' datasets."); if (results.Children.Count < 5) throw new Exception("Wrong number of 'results' datasets"); group = results.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "air temperature"; }); if (group == null) throw new Exception("Missing 'air temperature' group."); if (group.Children == null) return false; if (group.Children.Count != number_of_instants) return false; group = results.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "precipitation"; }); if (group == null) throw new Exception("Missing 'precipitation' group."); if (group.Children == null) return false; if (group.Children.Count != number_of_instants) return false; group = results.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "relative humidity"; }); if (group == null) throw new Exception("Missing 'relative humidity' group."); if (group.Children == null) return false; if (group.Children.Count != number_of_instants) return false; group = results.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "solar radiation"; }); if (group == null) throw new Exception("Missing 'solar radiation' group."); if (group.Children == null) return false; if (group.Children.Count != number_of_instants) return false; group = results.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "wind modulus"; }); if (group == null) throw new Exception("Missing 'wind modulus' group."); if (group.Children == null) return false; if (group.Children.Count != number_of_instants) return false; HDFObjectInfo grid = input_root.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "Grid"; }); if (grid == null) return false; if (grid.Children == null) return false; dataset = grid.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "Bathymetry"; }); if (dataset == null) throw new Exception("Missing 'Bathymetry' dataset."); dataset = grid.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "ConnectionX"; }); if (dataset == null) throw new Exception("Missing 'ConnectionX' dataset."); dataset = grid.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "ConnectionY"; }); if (dataset == null) throw new Exception("Missing 'ConnectionY' dataset."); dataset = grid.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "Define Cells"; }); if (dataset == null) throw new Exception("Missing 'Define Cells' dataset."); //dataset = grid.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "LandUse"; }); //if (dataset == null) throw new Exception("Missing 'LandUse' dataset."); dataset = grid.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "Latitude"; }); if (dataset == null) throw new Exception("Missing 'Latitude' dataset."); dataset = grid.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "Longitude"; }); if (dataset == null) throw new Exception("Missing Longitude' dataset."); dataset = grid.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "WaterPoints2D"; }); if (dataset == null) throw new Exception("Missing 'WaterPoints2D' dataset."); dataset = grid.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "WaterPoints3D"; }); if (dataset == null) throw new Exception("Missing 'WaterPoints3D' dataset."); //group = grid.Children.Find(delegate(HDFObjectInfo node) { return node.Name == "VerticalZ"; }); //if (group == null) throw new Exception("Missing 'VerticalZ' group."); //if (group.Children == null) throw new Exception("Missing 'VerticalZ' datasets."); //if (group.Children.Count != number_of_instants) throw new Exception("Wrong number of 'VerticalZ' datasets."); return true; } catch (Exception ex) { if (exception_warn) { Console.WriteLine(""); Console.WriteLine(ex.Message); Console.WriteLine(""); } return false; } }
public List<HDFObjectInfo> GetRootObjects() { try { List<HDFObjectInfo> list = new List<HDFObjectInfo>(); H5GroupId root_id = H5G.open(file_id, "/"); long n_objs = H5G.getNumObjects(root_id); for (ulong i = 0; i < (ulong)n_objs; i++) { HDFObjectInfo info = new HDFObjectInfo(); info.Index = i; info.Name = H5G.getObjectNameByIndex(root_id, i); ObjectInfo h5oi = H5G.getObjectInfo(root_id, info.Name, false); info.Type = h5oi.objectType; list.Add(info); } H5G.close(root_id); return list; } catch (Exception ex) { last_exception = ex; return null; } }