// Constructor for an existing global attr public NcGroupAtt(NcGroup grp, int index) : base(false) { ASCIIEncoding encoder = new ASCIIEncoding(); groupId = grp.GetId(); varId = NC_GLOBAL; 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 NcGroup GetParentGroup() { if(IsNull()) throw new exceptions.NcNullGrp("Attempt to invoke NcGroup.GetParentGroup on a Null group"); try { int parentId=0; NcCheck.Check(NetCDF.nc_inq_grp_parent(myId, ref parentId)); NcGroup ncGroupParent = new NcGroup(parentId); return ncGroupParent; } catch (exceptions.NcEnoGrp) { return new NcGroup(); } }
public bool TestGetParentGroup() { NcGroup group; NcGroup grpTest; NcFile file=null; group = new NcGroup(); try { grpTest = group.GetParentGroup(); Assert.True(grpTest.IsNull()); throw new AssertFailedException("NcNullGrp not thrown"); } catch (exceptions.NcNullGrp) { } try { file = newFile(filePath); group = file.GetParentGroup(); Assert.True(group.IsNull()); } finally { file.Close(); } return true; }
public NcFile(NcGroup rhs) : base(rhs) { }
public NcType GetNcType() { if(nullObject) return new NcType(); // Return null-type int xtypep=0; NcCheck.Check(NetCDF.nc_inq_vartype(groupId, myId, ref xtypep)); switch(xtypep) { case (int)NcTypeEnum.NC_BYTE: return NcByte.Instance; case (int)NcTypeEnum.NC_UBYTE: return NcUbyte.Instance; case (int)NcTypeEnum.NC_CHAR: return NcChar.Instance; case (int)NcTypeEnum.NC_SHORT: return NcShort.Instance; case (int)NcTypeEnum.NC_USHORT: return NcUshort.Instance; case (int)NcTypeEnum.NC_INT: return NcInt.Instance; case (int)NcTypeEnum.NC_UINT: return NcUint.Instance; case (int)NcTypeEnum.NC_INT64: return NcInt64.Instance; case (int)NcTypeEnum.NC_UINT64: return NcUint64.Instance; case (int)NcTypeEnum.NC_FLOAT: return NcFloat.Instance; case(int)NcTypeEnum.NC_DOUBLE: return NcDouble.Instance; default: break; } NcGroup group = new NcGroup(groupId); Dictionary<string, NcType> types = group.GetTypes(Location.ParentsAndCurrent); foreach(KeyValuePair<string, NcType> k in types) { if(k.Value.GetId() == xtypep) return k.Value; } // Should never get to here throw new exceptions.NcException("Type could not be identified"); return null; }
public NcVar(NcGroup grp, Int32 varId) { nullObject = false; myId = varId; groupId = grp.GetId(); }
public NcOpaqueType(NcGroup grp, string name) : base(grp, name) { }
public NcGroup(NcGroup rhs) { nullObject = rhs.nullObject; myId = rhs.myId; }
public Dictionary<string, NcGroup> GetGroups(GroupLocation location=GroupLocation.ChildrenGrps) { CheckNull(); Dictionary<string, NcGroup> ncGroups = new Dictionary<string, NcGroup>(); // Record this group if(location == GroupLocation.ParentsAndCurrentGrps || location == GroupLocation.AllGrps) { ncGroups.Add(GetName(), this); } // the child groups of the current group if(location == GroupLocation.ChildrenGrps || location == GroupLocation.AllChildrenGrps || location == GroupLocation.AllGrps ) { int groupCount = GetGroupCount(); int[] ncids = new int[groupCount]; int numgrps=0; NcCheck.Check(NetCDF.nc_inq_grps(myId, ref numgrps, ncids)); for(int i=0; i<groupCount; i++) { NcGroup tmpGroup = new NcGroup(ncids[i]); ncGroups.Add(tmpGroup.GetName(), tmpGroup); } } // search in parent groups. if(location == GroupLocation.ParentsGrps || location == GroupLocation.ParentsAndCurrentGrps || location == GroupLocation.AllGrps) { NcGroup tmpGroup = GetParentGroup(); while(tmpGroup != null && !tmpGroup.IsNull()) { ncGroups.Add(tmpGroup.GetName(), tmpGroup); tmpGroup = tmpGroup.GetParentGroup(); } } // search in child groups of the children if(location == GroupLocation.ChildrenOfChildrenGrps || location == GroupLocation.AllChildrenGrps || location == GroupLocation.AllGrps) { Dictionary<string, NcGroup> groups = GetGroups(GroupLocation.ChildrenGrps); foreach(KeyValuePair<string, NcGroup> k in groups) { foreach(KeyValuePair<string, NcGroup> kchild in k.Value.GetGroups(GroupLocation.AllChildrenGrps)) { ncGroups.Add(kchild.Key, kchild.Value); } } } return ncGroups; }
public NcEnumType(NcGroup grp, string name) : base(grp,name) { }
public NcDim(NcGroup grp, Int32 dimId) { nullObject = false; groupId = grp.GetId(); myId = dimId; }
public NcVlenType(NcGroup grp, string name) : base(grp,name) { }
// Constructor for a non-global type public NcType(NcGroup grp, int id) { nullObject = false; myId = id; groupId = grp.GetId(); }
// Constructor public NcType(NcGroup grp, string name) { nullObject = false; groupId = grp.GetId(); NcType typeTmp = grp.GetType(name, Location.ParentsAndCurrent); myId = typeTmp.GetId(); }