public NcVarAtt(NcGroup grp, NcVar var, Int32 index) : base(false) { ASCIIEncoding encoder = new ASCIIEncoding(); groupId = grp.GetId(); varId = var.GetId(); byte[] buffer = new byte[(int)NetCDF.netCDF_limits.NC_MAX_NAME]; NcCheck.Check(NetCDF.nc_inq_attname(groupId, varId, index, buffer)); string sbuffer = encoder.GetString(buffer); myName = sbuffer.Substring(0, sbuffer.IndexOf('\0')); // A null-terminated C-string }
public bool TestNestedGroups() { NcFile file = null; NcDim dim; Dictionary <string, NcGroup> groups; try { file = TestHelper.NewFile(filePath); NcGroup a = file.AddGroup("a"); Assert.False(a.IsNull()); NcGroup b = file.AddGroup("b"); Assert.False(b.IsNull()); NcGroup a1 = a.AddGroup("a1"); Assert.False(a1.IsNull()); NcGroup a2 = a.AddGroup("a2"); Assert.False(a2.IsNull()); NcGroup b1 = b.AddGroup("b1"); Assert.False(b1.IsNull()); NcGroup b2 = b.AddGroup("b2"); Assert.False(b2.IsNull()); Assert.Equals(file.GetGroupCount(GroupLocation.AllGrps), 7); Assert.Equals(file.GetGroupCount(GroupLocation.AllChildrenGrps), 6); Assert.Equals(b2.GetGroupCount(GroupLocation.ParentsGrps), 2); Assert.Equals(a2.GetGroupCount(GroupLocation.ParentsGrps), 2); Assert.True(file.GetGroups(GroupLocation.AllChildrenGrps).ContainsKey("b1")); groups = a1.GetGroups(GroupLocation.ParentsGrps); Assert.True(groups.ContainsKey("/") && groups["/"].GetId() == file.GetId()); Assert.Equals(file.GetGroups("b1", GroupLocation.AllChildrenGrps).Count, 1); Assert.True(file.GetGroup("a2", GroupLocation.ChildrenGrps).IsNull()); Assert.Equals(file.GetGroup("a2", GroupLocation.AllChildrenGrps).GetId(), a2.GetId()); Assert.True(file.IsRootGroup()); Assert.False(a.IsRootGroup()); foreach (KeyValuePair <string, NcGroup> group in file.GetGroups(GroupLocation.AllGrps)) { dim = group.Value.AddDim("time" + (group.Value.IsRootGroup() ? "Root" : group.Key), 20); NcVar v = group.Value.AddVar("time" + (group.Value.IsRootGroup() ? "Root" : group.Key), NcUint64.Instance, dim); NcAtt att = group.Value.PutAtt("Attr" + (group.Value.IsRootGroup() ? "Root" : group.Key), "Value"); Assert.False(v.IsNull()); Assert.Equals(file.GetVar(v.GetName(), Location.All).GetId(), v.GetId()); } Assert.Equals(file.GetVarCount(Location.All), 7); Assert.Equals(file.GetVars(Location.All).Count, 7); foreach (KeyValuePair <string, NcVar> gvar in file.GetVars(Location.All)) { Assert.Equals(gvar.Key, gvar.Value.GetName()); NcGroup g = gvar.Value.GetParentGroup(); Assert.Equals(gvar.Key, "time" + (g.IsRootGroup() ? "Root" : g.GetName())); } Assert.Equals(file.GetVars("timeRoot", Location.All).Count, 1); Assert.Equals(file.GetAttCount(Location.All), 7); Assert.Equals(file.GetAtts(Location.All).Count, 7); foreach (KeyValuePair <string, NcGroupAtt> k in file.GetAtts(Location.All)) { Assert.Equals(k.Value.GetValues(), "Value"); } } finally { file.Close(); } CheckDelete(filePath); return(true); }