Ejemplo n.º 1
0
        public Int32 GetAttLength()
        {
            Int32 lenp = 0;

            NcCheck.Check(NetCDF.nc_inq_attlen(groupId, varId, myName, ref lenp));
            return(lenp);
        }
Ejemplo n.º 2
0
        public Int32 GetSize()
        {
            CheckNull();
            Int32 dimSize = 0;

            NcCheck.Check(NetCDF.nc_inq_dimlen(groupId, myId, ref dimSize));
            return(dimSize);
        }
Ejemplo n.º 3
0
        public Int32 GetTypeSize()
        {
            byte[] buffer = null;
            Int32  sizep  = 0;

            NcCheck.Check(NetCDF.nc_inq_opaque(groupId, myId, buffer, ref sizep));
            return(sizep);
        }
Ejemplo n.º 4
0
        public string GetName()
        {
            CheckNull();
            StringBuilder dimName = new StringBuilder((int)NetCDF.netCDF_limits.NC_MAX_NAME);

            NcCheck.Check(NetCDF.nc_inq_dimname(groupId, myId, dimName));
            return(dimName.ToString());
        }
Ejemplo n.º 5
0
        public string GetName()
        {
            StringBuilder charName = new StringBuilder((int)NetCDF.netCDF_limits.NC_MAX_NAME);
            Int32         sizep    = 0;

            NcCheck.Check(NetCDF.nc_inq_type(groupId, myId, charName, ref sizep));
            return(charName.ToString());
        }
Ejemplo n.º 6
0
        public string GetValues()
        {
            CheckNull();
            ASCIIEncoding encoder = new ASCIIEncoding();
            int           attLen  = GetAttLength();

            byte[] buffer = new byte[attLen];
            NcCheck.Check(NetCDF.nc_get_att_text(groupId, varId, myName, buffer));
            return(encoder.GetString(buffer));
        }
Ejemplo n.º 7
0
        public string GetMemberNameFromValue(sbyte memberValue)
        {
            byte[]        nameBuffer = new byte[(int)NetCDF.netCDF_limits.NC_MAX_NAME + 1];
            ASCIIEncoding encoder    = new ASCIIEncoding();

            NcCheck.Check(NetCDF.nc_inq_enum_ident(groupId, myId, (Int64)memberValue, nameBuffer));
            string buf = encoder.GetString(nameBuffer);

            return(buf.Substring(0, buf.IndexOf('\0')));
        }
Ejemplo n.º 8
0
 public void GetValues(double[] dataValues, bool strictChecking = true)
 {
     CheckNull();
     if (strictChecking)
     {
         CheckAttLen(dataValues.Length);
     }
     CheckFixedType();
     NcCheck.Check(NetCDF.nc_get_att_double(groupId, varId, myName, dataValues));
 }
Ejemplo n.º 9
0
        public Int32 GetMemberCount()
        {
            byte[] buffer        = null;
            Int32  base_nc_typep = 0;
            Int32  base_sizep    = 0;
            Int32  num_membersp  = 0;

            NcCheck.Check(NetCDF.nc_inq_enum(groupId, myId, buffer, ref base_nc_typep, ref base_sizep, ref num_membersp));
            return(num_membersp);
        }
Ejemplo n.º 10
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
        }
Ejemplo n.º 11
0
        public NcVarAtt(Int32 groupId, Int32 varId, Int32 index) : base(false)
        {
            ASCIIEncoding encoder = new ASCIIEncoding();

            this.groupId = groupId;
            this.varId   = varId;
            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
        }
Ejemplo n.º 12
0
        public NcTypeEnum GetTypeClass()
        {
            switch (myId)
            {
            case (int)NcTypeEnum.NC_BYTE: return(NcTypeEnum.NC_BYTE);

            case (int)NcTypeEnum.NC_UBYTE: return(NcTypeEnum.NC_UBYTE);

            case (int)NcTypeEnum.NC_CHAR: return(NcTypeEnum.NC_CHAR);

            case (int)NcTypeEnum.NC_SHORT: return(NcTypeEnum.NC_SHORT);

            case (int)NcTypeEnum.NC_USHORT: return(NcTypeEnum.NC_USHORT);

            case (int)NcTypeEnum.NC_INT: return(NcTypeEnum.NC_INT);

            case (int)NcTypeEnum.NC_UINT: return(NcTypeEnum.NC_UINT);

            case (int)NcTypeEnum.NC_INT64: return(NcTypeEnum.NC_INT64);

            case (int)NcTypeEnum.NC_UINT64: return(NcTypeEnum.NC_UINT64);

            case (int)NcTypeEnum.NC_FLOAT: return(NcTypeEnum.NC_FLOAT);

            case (int)NcTypeEnum.NC_DOUBLE: return(NcTypeEnum.NC_DOUBLE);

            case (int)NcTypeEnum.NC_STRING: return(NcTypeEnum.NC_STRING);

            case (int)NcTypeEnum.NC_VLEN: return(NcTypeEnum.NC_VLEN);

            case (int)NcTypeEnum.NC_OPAQUE: return(NcTypeEnum.NC_OPAQUE);

            case (int)NcTypeEnum.NC_ENUM: return(NcTypeEnum.NC_ENUM);

            case (int)NcTypeEnum.NC_COMPOUND: return(NcTypeEnum.NC_COMPOUND);

            default: break;
            }
            byte[] readBuffer    = null;
            Int32  sizep         = 0;
            Int32  base_nc_typep = 0;
            Int32  nfieldsp      = 0;
            Int32  classp        = 0;

            NcCheck.Check(NetCDF.nc_inq_user_type(groupId, myId, readBuffer, ref sizep, ref base_nc_typep, ref nfieldsp, ref classp));
            return((NcTypeEnum)classp);
        }
Ejemplo n.º 13
0
        public bool IsUnlimited()
        {
            CheckNull();
            Int32 numlimdims = 0;

            Int32[] unlimdimidsp = null;
            NcCheck.Check(NetCDF.nc_inq_unlimdims(groupId, ref numlimdims, unlimdimidsp));
            unlimdimidsp = new Int32[numlimdims];
            NcCheck.Check(NetCDF.nc_inq_unlimdims(groupId, ref numlimdims, unlimdimidsp));
            for (int i = 0; i < numlimdims; i++)
            {
                if (unlimdimidsp[i] == myId)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 14
0
        public NcFile(string filePath, NcFileMode fMode, NcFileFormat fFormat)
        {
            Int32 format = 0;

            switch (fFormat)
            {
            case NcFileFormat.classic:
                format = 0;
                break;

            case NcFileFormat.classic64:
                format = NC_64BIT_OFFSET;
                break;

            case NcFileFormat.nc4:
                format = NC_NETCDF4;
                break;

            case NcFileFormat.nc4classic:
                format = NC_NETCDF4 | NC_CLASSIC_MODEL;
                break;
            }
            switch (fMode)
            {
            case NcFileMode.write:
                NcCheck.Check(NcCheck.NC_EINVAL);
                break;

            case NcFileMode.read:
                NcCheck.Check(NcCheck.NC_EINVAL);
                break;

            case NcFileMode.newFile:
                NcCheck.Check(NetCDF.nc_create(filePath, format | NC_NOCLOBBER, ref myId));
                break;

            case NcFileMode.replace:
                NcCheck.Check(NetCDF.nc_create(filePath, format | NC_CLOBBER, ref myId));
                break;
            }
            this.filePath = filePath;
            nullObject    = false;
        }
Ejemplo n.º 15
0
        public NcType GetBaseType()
        {
            byte[] buffer       = null;
            Int32  base_type    = 0;
            Int32  base_sizep   = 0;
            Int32  num_membersp = 0;

            NcCheck.Check(NetCDF.nc_inq_enum(groupId, myId, buffer, ref base_type, ref base_sizep, ref num_membersp));
            switch ((NcTypeEnum)base_type)
            {
            case NcTypeEnum.NC_BYTE:   return(NcByte.Instance);

            case NcTypeEnum.NC_UBYTE:  return(NcUbyte.Instance);

            case NcTypeEnum.NC_CHAR:   return(NcChar.Instance);

            case NcTypeEnum.NC_SHORT:  return(NcShort.Instance);

            case NcTypeEnum.NC_USHORT: return(NcUshort.Instance);

            case NcTypeEnum.NC_INT:    return(NcInt.Instance);

            case NcTypeEnum.NC_UINT:   return(NcUint.Instance);

            case NcTypeEnum.NC_INT64:  return(NcInt64.Instance);

            case NcTypeEnum.NC_UINT64: return(NcUint64.Instance);

            case NcTypeEnum.NC_FLOAT:  return(NcFloat.Instance);

            case NcTypeEnum.NC_DOUBLE: return(NcDouble.Instance);

            case NcTypeEnum.NC_STRING: return(NcString.Instance);

            default:
                return(new NcType(GetParentGroup(), (int)base_type));
            }

            return(new NcType()); // Null
        }
Ejemplo n.º 16
0
        public NcType GetBaseType()
        {
            byte[] buffer        = new byte[(int)NetCDF.netCDF_limits.NC_MAX_NAME + 1];
            Int32  base_nc_typep = 0;
            Int32  datum_sizep   = 0;

            NcCheck.Check(NetCDF.nc_inq_vlen(groupId, myId, buffer, ref datum_sizep, ref base_nc_typep));
            switch ((NcTypeEnum)base_nc_typep)
            {
            case NcTypeEnum.NC_BYTE:   return(NcByte.Instance);

            case NcTypeEnum.NC_UBYTE:  return(NcUbyte.Instance);

            case NcTypeEnum.NC_CHAR:   return(NcChar.Instance);

            case NcTypeEnum.NC_SHORT:  return(NcShort.Instance);

            case NcTypeEnum.NC_USHORT: return(NcUshort.Instance);

            case NcTypeEnum.NC_INT:    return(NcInt.Instance);

            case NcTypeEnum.NC_UINT:   return(NcUint.Instance);

            case NcTypeEnum.NC_INT64:  return(NcInt64.Instance);

            case NcTypeEnum.NC_UINT64: return(NcUint64.Instance);

            case NcTypeEnum.NC_FLOAT:  return(NcFloat.Instance);

            case NcTypeEnum.NC_DOUBLE: return(NcDouble.Instance);

            case NcTypeEnum.NC_STRING: return(NcString.Instance);

            default:
                return(new NcType(GetParentGroup(), base_nc_typep));
            }
            return(new NcType()); // null
        }
Ejemplo n.º 17
0
        public NcFile(string filePath, NcFileMode fMode)
        {
            switch (fMode)
            {
            case NcFileMode.write:
                NcCheck.Check(NetCDF.nc_open(filePath, NC_WRITE, ref myId));
                break;

            case NcFileMode.read:
                NcCheck.Check(NetCDF.nc_open(filePath, NC_NOWRITE, ref myId));
                break;

            case NcFileMode.newFile:
                NcCheck.Check(NetCDF.nc_create(filePath, NC_NETCDF4 | NC_NOCLOBBER, ref myId));
                break;

            case NcFileMode.replace:
                NcCheck.Check(NetCDF.nc_create(filePath, NC_NETCDF4 | NC_CLOBBER, ref myId));
                break;
            }
            this.filePath = filePath;
            nullObject    = false;
        }
Ejemplo n.º 18
0
        public NcType GetNcType()
        {
            int xtypep = 0;

            NcCheck.Check(NetCDF.nc_inq_atttype(groupId, varId, myName, ref xtypep));

            if (xtypep <= 12)
            {
                // This is an atomic type
                return(new NcType(xtypep));
            }
            else
            {
                Dictionary <string, NcType> typeMap = GetParentGroup().GetTypes(Location.ParentsAndCurrent);
                foreach (KeyValuePair <string, NcType> k in typeMap)
                {
                    if (k.Value.GetId() == xtypep)
                    {
                        return(k.Value);
                    }
                }
            }
            return(new NcType());
        }
Ejemplo n.º 19
0
 public void Close()
 {
     NcCheck.Check(NetCDF.nc_close(myId));
     nullObject = true;
     myId       = 0;
 }
Ejemplo n.º 20
0
 public void AddMember(string name, UInt64 memberValue)
 {
     NcCheck.Check(NetCDF.nc_insert_enum(groupId, myId, name, ref memberValue));
 }
Ejemplo n.º 21
0
 public void Rename(string newName)
 {
     CheckNull();
     NcCheck.Check(NetCDF.nc_rename_dim(groupId, myId, newName));
 }