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"); } }
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"); } }
public NcEnumType(NcType ncType) : base(ncType) { if (GetTypeClass() != NcTypeEnum.NC_ENUM) { throw new exceptions.NcBadType("The NcType object must be of type NC_ENUM"); } }
// Constructor public NcType(NcGroup grp, string name) { nullObject = false; groupId = grp.GetId(); NcType typeTmp = grp.GetType(name, Location.ParentsAndCurrent); myId = typeTmp.GetId(); }
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; }
// Compares global types public virtual bool Equals(NcType other) { return myId == other.myId; }
// Copy constructor public NcType(NcType rhs) { nullObject = rhs.nullObject; myId = rhs.myId; groupId = rhs.groupId; }
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; }
// Compares global types public virtual bool Equals(NcType other) { return(myId == other.myId); }
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); }
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; }
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); }
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); }
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); }
// 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); }
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; }
public NcEnumType(NcType ncType ) : base(ncType) { if(GetTypeClass() != NcTypeEnum.NC_ENUM) throw new exceptions.NcBadType("The NcType object must be of type NC_ENUM"); }
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"); }
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); }
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); }
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); }
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); }
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"); }