示例#1
0
 // 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
 }
示例#2
0
 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();
     }
 }
示例#3
0
        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;
        }
示例#4
0
 public NcFile(NcGroup rhs) : base(rhs) {
     
 }
示例#5
0
        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;
        }
示例#6
0
 public NcVar(NcGroup grp, Int32 varId) {
     nullObject = false;
     myId = varId;
     groupId = grp.GetId();
 }
示例#7
0
 public NcOpaqueType(NcGroup grp, string name) : base(grp, name) {
 }
示例#8
0
 public NcGroup(NcGroup rhs) {
     nullObject = rhs.nullObject;
     myId = rhs.myId;
 }
示例#9
0
        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;
        }
示例#10
0
 public NcEnumType(NcGroup grp, string name) : base(grp,name) {
 }
示例#11
0
 public NcDim(NcGroup grp, Int32 dimId) {
     nullObject = false;
     groupId = grp.GetId();
     myId = dimId;
 }
示例#12
0
 public NcVlenType(NcGroup grp, string name) : base(grp,name) {
 }
示例#13
0
 // Constructor for a non-global type
 public NcType(NcGroup grp, int id) {
     nullObject = false;
     myId = id;
     groupId = grp.GetId();
 }
示例#14
0
 // Constructor
 public NcType(NcGroup grp, string name) {
     nullObject = false;
     groupId = grp.GetId();
     NcType typeTmp = grp.GetType(name, Location.ParentsAndCurrent);
     myId = typeTmp.GetId();
 }