Esempio n. 1
0
        public bool TestTypes() {
            for(int i=1;i<13;i++) {
                NcType t = new NcType(i);
                Assert.Equals(t.GetId(), i);
                if(i==1) { // byte
                    Assert.Equals(t.GetName(), "byte");
                    Assert.Equals(t.GetSize(), 1); // A byte should be just one byte right?
                } else {
                    Assert.NotNull(t.GetName());
                    Assert.True(t.GetSize() > 0);
                }
            }

            return true;
        }
Esempio n. 2
0
        public Dictionary<string, NcType> GetTypes(Location location=Location.Current) {
            CheckNull();
            Dictionary<string, NcType> ncTypes = new Dictionary<string, NcType>();

            // search in current group
            if(location == Location.Current || location == Location.ParentsAndCurrent 
                                                        || location == Location.ChildrenAndCurrent
                                                        || location == Location.All) {
                Int32 typeCount = GetTypeCount();
                Int32[] typeIds = new Int32[typeCount];
                NcCheck.Check(NetCDF.nc_inq_typeids(myId, ref typeCount, typeIds));

                foreach(Int32 i in typeIds) {
                    NcType tmpType = new NcType(this, i);
                    ncTypes.Add(tmpType.GetName(), tmpType);
                }
            }

            // search in parent groups
            if(location == Location.Parents || location == Location.ParentsAndCurrent 
                                                        || location == Location.All) {
                Dictionary<string, NcGroup> groups = GetGroups(GroupLocation.ParentsGrps);
                foreach(KeyValuePair<string, NcGroup> k in groups) {
                    k.Value.GetTypes().ToList().ForEach(x => ncTypes[x.Key] = x.Value);
                }
            }

            // search in child groups
            if(location == Location.Children || location == Location.ChildrenAndCurrent
                                                        || location == Location.All) {
                Dictionary<string, NcGroup> groups = GetGroups(GroupLocation.AllChildrenGrps);
                foreach(KeyValuePair<string, NcGroup> k in groups) {
                    k.Value.GetTypes().ToList().ForEach(x => ncTypes[x.Key] = x.Value);
                }
            }
            return ncTypes;
        }
Esempio n. 3
0
        public NcVar AddVar(string name, NcType ncType, List<NcDim> ncDimVector) {
            CheckNull();
            CheckDefine();
            NcType tmpType=null;
            Int32 varId=0;
            Int32[] dimIds = new Int32[ncDimVector.Count];
            if(ncType.IsNull())
                throw new exceptions.NcNullType("Attempt to invoke NcGroup.AddVar with a Null NcType object");
            tmpType = GetType(ncType.GetName(), Location.ParentsAndCurrent);
            if(tmpType.IsNull())
                throw new exceptions.NcNullType("Attempt to invoke NcGroup.AddVar failed: NcType must be defined in either the current group or a parent group");
            for(int i=0;i<ncDimVector.Count;i++) {
                if(ncDimVector[i].IsNull())
                    throw new exceptions.NcNullDim("Attempt to invoke NcGroup.AddVar failed: NcType must be defined in either the current group or a parent group");
                NcDim tmpDim = GetDim(ncDimVector[i].GetName(), Location.ParentsAndCurrent);
                if(tmpDim.IsNull())
                    throw new exceptions.NcNullDim("Attempt to invoke NcGroup::addVar failed: NcDim must be defined in either the current group or a parent group");
                dimIds[i] = ncDimVector[i].GetId();
            }
            NcCheck.Check(NetCDF.nc_def_var(myId, name, tmpType.GetId(), ncDimVector.Count, dimIds, ref varId));

            return new NcVar(this, varId);
        }
Esempio n. 4
0
        public NcVar AddVar(string name, NcType ncType, NcDim ncDim) {
            CheckNull();
            CheckDefine();
            if(ncType.IsNull())
                throw new exceptions.NcNullType("Attempt to invoke NcGroup.AddVar failed: NcType must be defined in either the current group or a parent group");
            NcType tmpType = GetType(ncType.GetName(), Location.ParentsAndCurrent);
            if(tmpType.IsNull())
                throw new exceptions.NcNullType("Attempt to invoke NcGroup.AddVar failed: NcType must be defined in either the current group or a parent group");

            if(ncDim.IsNull())
                throw new exceptions.NcNullDim("Attempt to invoke NcGroup.AddVar failed: NcDim must be defined in either the current group or a parent group");
            NcDim tmpDim = GetDim(ncDim.GetName(), Location.ParentsAndCurrent);
            if(tmpDim.IsNull())
                throw new exceptions.NcNullDim("Attempt to invoke NcGroup.AddVar failed: NcDim must be defined in either the current group or a parent group");

            Int32 varId=0;
            Int32[] dimId = {tmpDim.GetId()};
            NcCheck.Check(NetCDF.nc_def_var(myId, name, tmpType.GetId(), 1, dimId, ref varId));
            return new NcVar(this, varId);
        }