Beispiel #1
0
 public NcVlenType(NcType ncType) : base(ncType)
 {
     if (GetTypeClass() != NcTypeEnum.NC_VLEN)
     {
         throw new exceptions.NcException("The NcType object must be the base of a Vlen type");
     }
 }
Beispiel #2
0
 public NcOpaqueType(NcType ncType) : base(ncType)
 {
     if (GetTypeClass() != NcTypeEnum.NC_OPAQUE)
     {
         throw new exceptions.NcBadType("The NcType object must have a base type of NC_OPAQUE");
     }
 }
Beispiel #3
0
 public NcEnumType(NcType ncType) : base(ncType)
 {
     if (GetTypeClass() != NcTypeEnum.NC_ENUM)
     {
         throw new exceptions.NcBadType("The NcType object must be of type NC_ENUM");
     }
 }
Beispiel #4
0
        // Constructor
        public NcType(NcGroup grp, string name)
        {
            nullObject = false;
            groupId    = grp.GetId();
            NcType typeTmp = grp.GetType(name, Location.ParentsAndCurrent);

            myId = typeTmp.GetId();
        }
Beispiel #5
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;
        }
Beispiel #6
0
 // Compares global types
 public virtual bool Equals(NcType other) {
     return myId == other.myId;
 }
Beispiel #7
0
 // Copy constructor
 public NcType(NcType rhs)
 {
     nullObject = rhs.nullObject;
     myId       = rhs.myId;
     groupId    = rhs.groupId;
 }
Beispiel #8
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;
        }
Beispiel #9
0
 // Compares global types
 public virtual bool Equals(NcType other)
 {
     return(myId == other.myId);
 }
Beispiel #10
0
 private void FileSetup(ref NcFile file, ref NcDim dim1, ref NcVar var1, NcType type, int len=20) {
     file = TestHelper.NewFile(filePath);
     dim1 = file.AddDim("time", len);
     var1 = file.AddVar("temp", type, dim1);
 }
Beispiel #11
0
        public int GetTypeCount(NcTypeEnum enumType, Location location=Location.Current) {
            CheckNull();
            Int32 ntypes=0;
            // search in current group
            if(location == Location.Current || location == Location.ParentsAndCurrent 
                                                        || location == Location.ChildrenAndCurrent
                                                        || location == Location.All) {
                Int32 ntypesp=0;
                Int32[] typeidsp = null;
                NcCheck.Check(NetCDF.nc_inq_typeids(myId, ref ntypesp, typeidsp));
                typeidsp = new Int32[ntypesp];
                NcCheck.Check(NetCDF.nc_inq_typeids(myId, ref ntypesp, typeidsp));

                foreach(Int32 i in typeidsp) {
                    NcType typeTmp = new NcType(this,i);
                    if(typeTmp.GetTypeClass() == enumType)
                        ntypes++;
                }
            }

            // 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) {
                    ntypes += k.Value.GetTypeCount(enumType);
                }
            }

            // search in children 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) {
                    ntypes += k.Value.GetTypeCount(enumType);
                }
            }
            return ntypes;
        }
Beispiel #12
0
 // Copy constructor
 public NcType(NcType rhs) {
     nullObject = rhs.nullObject;
     myId = rhs.myId;
     groupId = rhs.groupId;
 }
Beispiel #13
0
 public NcVarAtt PutAtt(string name, NcType type, double[] dataValues) {
     CheckNull();
     CheckDefine();
     if(!type.IsFixedType())
         throw new NotImplementedException("PutAtt() not implemented for non-fixed types");
     NcCheck.Check(NetCDF.nc_put_att_double(groupId, myId, name, type.GetId(), dataValues.Length, dataValues));
     return GetAtt(name);
 }
Beispiel #14
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);
        }
Beispiel #15
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);
        }
Beispiel #16
0
        // Add a scalar variable
        public NcVar AddVar(string name, NcType type) 
        {
            CheckNull();
            CheckDefine();
            if(type.IsNull())
                throw new exceptions.NcNullType("Attempt to invoke NcGroup.AddVar failed: typeName must be defined in either the current group or a parent group");

            Int32 varId = 0;
            Int32[] dimIds = null;
            NcCheck.Check(NetCDF.nc_def_var(myId, name,  type.GetId(), 0, dimIds, ref varId));
            return new NcVar(this, varId);
        }
Beispiel #17
0
 public NcVlenType AddVlenType(string name, NcType baseType) {
     CheckNull();
     CheckDefine();
     Int32 typeId=0;
     NcCheck.Check(NetCDF.nc_def_vlen(myId, name, baseType.GetId(), ref typeId));
     NcVlenType ncTypeTmp = new NcVlenType(this, name);
     return ncTypeTmp;
 }
Beispiel #18
0
 public NcEnumType(NcType ncType ) : base(ncType) {
     if(GetTypeClass() != NcTypeEnum.NC_ENUM) 
         throw new exceptions.NcBadType("The NcType object must be of type NC_ENUM");
 }
Beispiel #19
0
 public NcOpaqueType(NcType ncType) : base(ncType) {
     if(GetTypeClass() != NcTypeEnum.NC_OPAQUE)
         throw new exceptions.NcBadType("The NcType object must have a base type of NC_OPAQUE");
 }
Beispiel #20
0
 public NcGroupAtt PutAtt(string name, NcType type, Int16[] dataValues) {
     CheckNull();
     CheckDefine();
     //TODO: Support for VLEN | OPAQUE | ENUM | COMPOUND
     if(!type.IsFixedType())
         throw new NotImplementedException("PutAtt() not implemented for non-fixed types");
     NcCheck.Check(NetCDF.nc_put_att_short(myId, NcAtt.NC_GLOBAL, name, type.GetId(), dataValues.Length, dataValues ));
     return GetAtt(name);
 }
Beispiel #21
0
 public NcVarAtt PutAtt(string name, NcType type, float datumValue) {
     CheckNull();
     CheckDefine();
     if(!type.IsFixedType())
         throw new NotImplementedException("PutAtt() not implemented for non-fixed types");
     NcCheck.Check(NetCDF.nc_put_att_float(groupId, myId, name, type.GetId(), 1, new float[] { datumValue }));
     return GetAtt(name);
 }
Beispiel #22
0
 public NcGroupAtt PutAtt(string name, NcType type, float[] dataValues) {
     CheckNull();
     CheckDefine();
     if(!type.IsFixedType())
         throw new NotImplementedException("PutAtt() not implemented for non-fixed types");
     NcCheck.Check(NetCDF.nc_put_att_float(myId, NcAtt.NC_GLOBAL, name, type.GetId(), dataValues.Length, dataValues ));
     return GetAtt(name);
 }
Beispiel #23
0
 public NcGroupAtt PutAtt(string name, NcType type, double datumValue) {
     CheckNull();
     CheckDefine();
     if(!type.IsFixedType())
         throw new NotImplementedException("PutAtt() not implemented for non-fixed types");
     NcCheck.Check(NetCDF.nc_put_att_double(myId, NcAtt.NC_GLOBAL, name, type.GetId(), 1, new double[] { datumValue }));
     return GetAtt(name);
 }
Beispiel #24
0
 public NcVlenType(NcType ncType) : base(ncType) {
     if(GetTypeClass() != NcTypeEnum.NC_VLEN)
         throw new exceptions.NcException("The NcType object must be the base of a Vlen type");
 }