Ejemplo n.º 1
0
        public bool TestVarGeneric()
        {
            NcFile file = null;

            try {
                file = TestHelper.NewFile(filePath);
                NcDim dim1    = file.AddDim("dim1", 5);
                NcVar testVar = file.AddVar("var1", "double", "dim1");
                Assert.False(testVar.IsNull());
                testVar = file.AddVar("var2", NcDouble.Instance, dim1);
                Assert.False(testVar.IsNull());
                testVar = file.AddVar("var3", "double", new List <string>()
                {
                    "dim1"
                });
                Assert.False(testVar.IsNull());
                testVar = file.AddVar("var4", NcDouble.Instance, new List <NcDim>()
                {
                    dim1
                });
                Assert.False(testVar.IsNull());
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Ejemplo n.º 2
0
        public bool TestGetCoordVars()
        {
            NcFile file = null;

            try {
                file = TestHelper.NewFile(filePath);
                NcDim dim1 = file.AddDim("time", 20);
                NcDim dim2 = file.AddDim("hdg", 20);

                NcVar var1 = file.AddVar("time", NcDouble.Instance, dim1);
                Assert.False(var1.IsNull());
                NcVar var2 = file.AddVar("hdg", NcDouble.Instance, dim2);
                Assert.False(var2.IsNull());
                NcVar var3 = file.AddVar("alt", NcDouble.Instance, new List <NcDim>()
                {
                    dim1, dim2
                });
                Assert.False(var3.IsNull());

                Dictionary <string, NcGroup> coordVars = file.GetCoordVars();
                Assert.True(coordVars.ContainsKey("time") && coordVars["time"].GetId() == file.GetId());
                Assert.True(coordVars.ContainsKey("hdg") && coordVars["hdg"].GetId() == file.GetId());
                Assert.False(coordVars.ContainsKey("alt"));
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Ejemplo n.º 3
0
        public bool TestPut()
        {
            NcFile file = null;

            try {
                file = TestHelper.NewFile(filePath);
                NcDim time = file.AddDim("time", 2);
                NcDim x    = file.AddDim("x", 2);
                NcDim y    = file.AddDim("y", 2);
                NcDim z    = file.AddDim("z", 4);
                NcVar u    = file.AddVar("u", NcFloat.Instance, new List <NcDim>()
                {
                    time, x, y, z
                });
                NcVar v = file.AddVar("v", NcFloat.Instance, new List <NcDim>()
                {
                    time, x, y, z
                });

                NcArray uArray = new NcArray(NcFloat.Instance, u.Shape);
                uArray.Fill(1);
                uArray.FillSlice(20, new int[] { 0, 0, 0, 3 }, new int[] { 2, 2, 2, 4 });
                NcArray vArray = new NcArray(NcFloat.Instance, v.Shape);
                vArray.Fill(100);

                u.PutVar(uArray);

                v.PutVar(vArray);

                NcArray outArray = u.GetVar();
                Assert.True(uArray.Equals(outArray));

                outArray = v.GetVar();
                Assert.True(vArray.Equals(outArray));
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Ejemplo n.º 4
0
        public bool TestGet()
        {
            NcFile file = null;

            try {
                file = TestHelper.NewFile(filePath);
                NcDim time = file.AddDim("time", 10);
                NcDim x    = file.AddDim("x", 20);
                NcDim y    = file.AddDim("y", 20);
                NcVar u    = file.AddVar("u", NcFloat.Instance, new List <NcDim>()
                {
                    time, x, y
                });
                NcVar v = file.AddVar("v", NcFloat.Instance, new List <NcDim>()
                {
                    time, x, y
                });

                float[] uBuf = new float[10 * 20 * 20];
                for (int i = 0; i < uBuf.Length; i++)
                {
                    uBuf[i] = (float)i;
                }
                float[] vBuf = new float[10 * 20 * 20];
                for (int i = 0; i < vBuf.Length; i++)
                {
                    vBuf[i] = (float)i;
                }

                u.PutVar(uBuf);
                v.PutVar(vBuf);

                NcArray uArray = u.GetVar();
                Assert.Equals(uArray.Array, uBuf);
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Ejemplo n.º 5
0
        public bool TestDefine()
        {
            NcFile file = null;

            try {
                file = new NcFile(filePath, NcFileMode.replace, NcFileFormat.classic);
                NcDim timeDim = file.AddDim("time", 20);
                NcVar timeVar = file.AddVar("time", NcDouble.Instance, timeDim);
                timeVar.PutAtt("units", "minutes since 2000-01-01 00:00:00");
                timeVar.PutAtt("long_name", "Time");
                timeVar.CheckData();
                NcArray vals = NcArray.Arange(NcDouble.Instance, 20);
                timeVar.PutVar(vals);
                Assert.Equals(timeVar.GetAtt("long_name"), "Time");

                NcVar data = file.AddVar("data", NcDouble.Instance, timeDim);
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Ejemplo n.º 6
0
        public bool TestScalar()
        {
            NcFile file = null;

            float[] buffer = new float[] { 1.0f };
            try {
                file = TestHelper.NewFile(filePath);
                NcVar var = file.AddVar("scalar", NcFloat.Instance);

                var.PutAtt("long_name", "A scalar variable");
                var.PutVar(new float[] { 1.0f });
                buffer[0] = 90.0f;
                Assert.Equals(buffer[0], 90.0f);
                var.GetVar(buffer);
                Assert.Equals(buffer[0], 1.0f);
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Ejemplo n.º 7
0
        public bool TestOpaque()
        {
            NcFile       file       = null;
            NcVar        var        = null;
            NcDim        dim        = null;
            NcType       type       = null;
            NcOpaqueType opaqueType = null;

            byte[] opaqueBuffer = new byte[32];
            byte[] readBuffer   = new byte[32];
            for (int i = 0; i < 32; i++)
            {
                opaqueBuffer[i] = (byte)i;
            }

            try {
                file       = TestHelper.NewFile(filePath);
                type       = file.AddOpaqueType("opaque", 32);
                opaqueType = new NcOpaqueType(type);

                Assert.Equals(type.GetTypeClass(), NcTypeEnum.NC_OPAQUE);
                Assert.Equals(opaqueType.GetTypeSize(), 32);

                dim = file.AddDim("time", 1);
                var = file.AddVar("opaqueVar", opaqueType, dim);
                int iLen = 0;
                var.PutVar(new Int32[] { 0 }, opaqueBuffer);
                iLen = var.GetVar(new Int32[] { 0 }, readBuffer);
                Assert.Equals(iLen, 32);
                for (int i = 0; i < 32; i++)
                {
                    Assert.Equals(readBuffer[i], opaqueBuffer[i]);
                }
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Ejemplo n.º 8
0
        public bool TestShape()
        {
            NcFile file = null;

            try {
                file = TestHelper.NewFile(filePath);
                NcDim dim  = file.AddDim("time", 4);
                NcDim node = file.AddDim("node", 5);
                NcDim egg  = file.AddDim("egg", 6);

                NcVar var = file.AddVar("var", NcFloat.Instance, new List <NcDim>()
                {
                    dim, node, egg
                });
                List <int> shape = var.GetShape();
                Assert.Equals(shape.ToArray(), new int[] { 4, 5, 6 });
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Ejemplo n.º 9
0
        public bool TestGroupDefine()
        {
            NcFile file = null;
            NcDim  dim;
            NcVar  var;

            try {
                file = new NcFile(filePath, NcFileMode.replace, NcFileFormat.classic);
                file.CheckData();
                dim = file.AddDim("dim1", 1);
                file.CheckData();
                var = file.AddVar("var1", NcInt.Instance, dim);
                file.CheckData();
                var.PutAtt("blah", "blah");
                file.CheckDefine();
                NcArray array = NcArray.Arange(NcInt.Instance, 1);
                var.PutVar(array);
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Ejemplo n.º 10
0
        public bool TestUnlimitedDim()
        {
            NcFile file    = null;
            NcDim  time    = null;
            NcVar  timeVar = null;

            Int32[] readBuffer  = new Int32[11];
            Int32[] writeBuffer = new Int32[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            try {
                file    = TestHelper.NewFile(filePath);
                time    = file.AddDim("time");
                timeVar = file.AddVar("t", NcInt64.Instance, time);
                timeVar.PutVar(new Int32[] { 0 }, new Int32[] { 11 }, writeBuffer);
                timeVar.GetVar(readBuffer);
                for (int i = 0; i < 11; i++)
                {
                    Assert.Equals(readBuffer[i], (Int32)i);
                }
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Ejemplo n.º 11
0
        public bool TestEnum()
        {
            NcFile     file     = null;
            NcType     type     = null;
            NcEnumType enumType = null;
            NcDim      dim      = null;
            NcVar      var      = null;

            sbyte[]  sbyteBuffer  = new sbyte[1];
            byte[]   byteBuffer   = new byte[1];
            Int16[]  Int16Buffer  = new Int16[1];
            UInt16[] UInt16Buffer = new UInt16[1];
            Int32[]  Int32Buffer  = new Int32[1];
            UInt32[] UInt32Buffer = new UInt32[1];
            Int64[]  Int64Buffer  = new Int64[1];
            UInt64[] UInt64Buffer = new UInt64[1];

            try {
                file = TestHelper.NewFile(filePath);
                dim  = file.AddDim("time", 1);

                type     = file.AddEnumType("sbyteenum", NcEnumType.Types.NC_BYTE);
                enumType = new NcEnumType(type);
                Assert.Equals(enumType.GetName(), "sbyteenum");
                Assert.Equals(enumType.GetMemberCount(), 0);
                Assert.True(NcByte.Instance.Equals(enumType.GetBaseType()));
                enumType.AddMember("BASE", 0);
                enumType.AddMember("VOR", 1);
                enumType.AddMember("DME", 2);
                enumType.AddMember("TAC", 3);

                var = file.AddVar("enumsbyteVar", enumType, dim);
                var.PutVar(new sbyte[] { 3 });
                var.GetVar(sbyteBuffer);
                Assert.Equals(sbyteBuffer[0], (sbyte)3);

                type     = file.AddEnumType("byteenum", NcEnumType.Types.NC_UBYTE);
                enumType = new NcEnumType(type);
                Assert.Equals(enumType.GetName(), "byteenum");
                Assert.Equals(enumType.GetMemberCount(), 0);
                Assert.True(NcUbyte.Instance.Equals(enumType.GetBaseType()));
                enumType.AddMember("BASE", 0);
                enumType.AddMember("VOR", 1);
                enumType.AddMember("DME", 2);
                enumType.AddMember("TAC", 3);

                var = file.AddVar("enumbyteVar", enumType, dim);
                var.PutVar(new byte[] { 3 });
                var.GetVar(byteBuffer);
                Assert.Equals(byteBuffer[0], (byte)3);

                type     = file.AddEnumType("Int16enum", NcEnumType.Types.NC_SHORT);
                enumType = new NcEnumType(type);
                Assert.Equals(enumType.GetName(), "Int16enum");
                Assert.Equals(enumType.GetMemberCount(), 0);
                Assert.True(NcShort.Instance.Equals(enumType.GetBaseType()));
                enumType.AddMember("BASE", 0);
                enumType.AddMember("VOR", 1);
                enumType.AddMember("DME", 2);
                enumType.AddMember("TAC", 3);

                var = file.AddVar("enumInt16Var", enumType, dim);
                var.PutVar(new Int16[] { 3 });
                var.GetVar(Int16Buffer);
                Assert.Equals(Int16Buffer[0], (Int16)3);

                type     = file.AddEnumType("UInt16enum", NcEnumType.Types.NC_USHORT);
                enumType = new NcEnumType(type);
                Assert.Equals(enumType.GetName(), "UInt16enum");
                Assert.Equals(enumType.GetMemberCount(), 0);
                Assert.True(NcUshort.Instance.Equals(enumType.GetBaseType()));
                enumType.AddMember("BASE", 0);
                enumType.AddMember("VOR", 1);
                enumType.AddMember("DME", 2);
                enumType.AddMember("TAC", 3);

                var = file.AddVar("enumUInt16Var", enumType, dim);
                var.PutVar(new UInt16[] { 3 });
                var.GetVar(UInt16Buffer);
                Assert.Equals(UInt16Buffer[0], (UInt16)3);

                type     = file.AddEnumType("Int32enum", NcEnumType.Types.NC_INT);
                enumType = new NcEnumType(type);
                Assert.Equals(enumType.GetName(), "Int32enum");
                Assert.Equals(enumType.GetMemberCount(), 0);
                Assert.True(NcInt.Instance.Equals(enumType.GetBaseType()));
                enumType.AddMember("BASE", 0);
                enumType.AddMember("VOR", 1);
                enumType.AddMember("DME", 2);
                enumType.AddMember("TAC", 3);

                var = file.AddVar("enumInt32Var", enumType, dim);
                var.PutVar(new Int32[] { 3 });
                var.GetVar(Int32Buffer);
                Assert.Equals(Int32Buffer[0], (Int32)3);

                type     = file.AddEnumType("UInt32enum", NcEnumType.Types.NC_UINT);
                enumType = new NcEnumType(type);
                Assert.Equals(enumType.GetName(), "UInt32enum");
                Assert.Equals(enumType.GetMemberCount(), 0);
                Assert.True(NcUint.Instance.Equals(enumType.GetBaseType()));
                enumType.AddMember("BASE", 0);
                enumType.AddMember("VOR", 1);
                enumType.AddMember("DME", 2);
                enumType.AddMember("TAC", 3);

                var = file.AddVar("enumUInt32Var", enumType, dim);
                var.PutVar(new UInt32[] { 3 });
                var.GetVar(UInt32Buffer);
                Assert.Equals(UInt32Buffer[0], (UInt32)3);

                type     = file.AddEnumType("Int64enum", NcEnumType.Types.NC_INT64);
                enumType = new NcEnumType(type);
                Assert.Equals(enumType.GetName(), "Int64enum");
                Assert.Equals(enumType.GetMemberCount(), 0);
                Assert.True(NcInt64.Instance.Equals(enumType.GetBaseType()));
                enumType.AddMember("BASE", (Int64)0);
                enumType.AddMember("VOR", (Int64)1);
                enumType.AddMember("DME", (Int64)2);
                enumType.AddMember("TAC", (Int64)3);
                Assert.Equals(enumType.GetMemberCount(), 4);
                Assert.Equals(enumType.GetMemberNameFromValue((sbyte)1), "VOR");
                Assert.Equals(enumType.GetMemberNameFromValue((byte)1), "VOR");
                Assert.Equals(enumType.GetMemberNameFromValue((Int16)1), "VOR");
                Assert.Equals(enumType.GetMemberNameFromValue((UInt16)1), "VOR");
                Assert.Equals(enumType.GetMemberNameFromValue((Int32)1), "VOR");
                Assert.Equals(enumType.GetMemberNameFromValue((UInt32)1), "VOR");
                Assert.Equals(enumType.GetMemberNameFromValue((Int64)1), "VOR");
                Assert.Equals(enumType.GetMemberNameFromValue((UInt64)1), "VOR");

                var = file.AddVar("enumInt64Var", enumType, dim);
                var.PutVar(new Int64[] { 3 });
                var.GetVar(Int64Buffer);
                Assert.Equals(Int64Buffer[0], (Int64)3);

                type     = file.AddEnumType("UInt64enum", NcEnumType.Types.NC_UINT64);
                enumType = new NcEnumType(type);
                Assert.Equals(enumType.GetName(), "UInt64enum");
                Assert.Equals(enumType.GetMemberCount(), 0);
                Assert.True(NcUint64.Instance.Equals(enumType.GetBaseType()));
                enumType.AddMember("BASE", 0);
                enumType.AddMember("VOR", 1);
                enumType.AddMember("DME", 2);
                enumType.AddMember("TAC", 3);

                var = file.AddVar("enumUInt64Var", enumType, dim);
                var.PutVar(new UInt64[] { 3 });
                var.GetVar(UInt64Buffer);
                Assert.Equals(UInt64Buffer[0], (UInt64)3);
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Ejemplo n.º 12
0
        public bool TestVlen()
        {
            NcFile     file             = null;
            NcVlenType vlen             = null;
            NcDim      dim              = null;
            NcVar      var              = null;
            string     stringVlenBuffer = "hi there";
            string     stringReadBuffer;

            int iLen = 0;

            sbyte[] sbyteVlenBuffer = new sbyte[] { 0, -12, -4 };
            sbyte[] sbyteReadBuffer = new sbyte[8];

            byte[] byteVlenBuffer = new byte[] { 0, 12, 4 };
            byte[] byteReadBuffer = new byte[8];

            Int16[] Int16VlenBuffer = new Int16[] { 0, -12, -4 };
            Int16[] Int16ReadBuffer = new Int16[8];

            UInt16[] UInt16VlenBuffer = new UInt16[] { 0, 12, 4 };
            UInt16[] UInt16ReadBuffer = new UInt16[8];

            Int32[] Int32VlenBuffer = new Int32[] { 0, -12, -4 };
            Int32[] Int32ReadBuffer = new Int32[8];

            UInt32[] UInt32VlenBuffer = new UInt32[] { 0, 12, 4 };
            UInt32[] UInt32ReadBuffer = new UInt32[8];

            Int64[] Int64VlenBuffer = new Int64[] { 0, -12, -4 };
            Int64[] Int64ReadBuffer = new Int64[8];

            UInt64[] UInt64VlenBuffer = new UInt64[] { 0, 12, 4 };
            UInt64[] UInt64ReadBuffer = new UInt64[8];

            float[] floatVlenBuffer = new float[] { 0, 12, 4 };
            float[] floatReadBuffer = new float[8];

            double[] doubleVlenBuffer = new double[] { 0, 12, 4 };
            double[] doubleReadBuffer = new double[8];

            try {
                file = TestHelper.NewFile(filePath);
                dim  = file.AddDim("time", 1);

                // string
                vlen = file.AddVlenType("vlenstring", NcChar.Instance);
                var  = file.AddVar("string", vlen, dim);
                var.PutVar(new Int32[] { 0 }, stringVlenBuffer);
                var.GetVar(new Int32[] { 0 }, out stringReadBuffer);
                Assert.Equals(stringVlenBuffer, stringReadBuffer);

                // sbyte
                vlen = file.AddVlenType("vlensbyte", NcByte.Instance);
                var  = file.AddVar("sbyte", vlen, dim);
                var.PutVar(new Int32[] { 0 }, sbyteVlenBuffer);
                iLen = var.GetVar(new Int32[] { 0 }, sbyteReadBuffer);
                for (int i = 0; i < iLen; i++)
                {
                    Assert.Equals(sbyteVlenBuffer[i], sbyteReadBuffer[i]);
                }

                // byte
                vlen = file.AddVlenType("vlenbyte", NcByte.Instance);
                var  = file.AddVar("byte", vlen, dim);
                var.PutVar(new Int32[] { 0 }, byteVlenBuffer);
                iLen = var.GetVar(new Int32[] { 0 }, byteReadBuffer);
                for (int i = 0; i < iLen; i++)
                {
                    Assert.Equals(byteVlenBuffer[i], byteReadBuffer[i]);
                }

                // Int16
                vlen = file.AddVlenType("vlenInt16", NcShort.Instance);
                var  = file.AddVar("Int16", vlen, dim);
                var.PutVar(new Int32[] { 0 }, Int16VlenBuffer);
                iLen = var.GetVar(new Int32[] { 0 }, Int16ReadBuffer);
                for (int i = 0; i < iLen; i++)
                {
                    Assert.Equals(Int16VlenBuffer[i], Int16ReadBuffer[i]);
                }

                // UInt16
                vlen = file.AddVlenType("vlenUInt16", NcUshort.Instance);
                var  = file.AddVar("UInt16", vlen, dim);
                var.PutVar(new Int32[] { 0 }, UInt16VlenBuffer);
                iLen = var.GetVar(new Int32[] { 0 }, UInt16ReadBuffer);
                for (int i = 0; i < iLen; i++)
                {
                    Assert.Equals(UInt16VlenBuffer[i], UInt16ReadBuffer[i]);
                }

                // Int32
                vlen = file.AddVlenType("vlenInt32", NcInt.Instance);
                var  = file.AddVar("Int32", vlen, dim);
                var.PutVar(new Int32[] { 0 }, Int32VlenBuffer);
                iLen = var.GetVar(new Int32[] { 0 }, Int32ReadBuffer);
                for (int i = 0; i < iLen; i++)
                {
                    Assert.Equals(Int32VlenBuffer[i], Int32ReadBuffer[i]);
                }

                // UInt32
                vlen = file.AddVlenType("vlenUInt32", NcUint.Instance);
                var  = file.AddVar("UInt32", vlen, dim);
                var.PutVar(new Int32[] { 0 }, UInt32VlenBuffer);
                iLen = var.GetVar(new Int32[] { 0 }, UInt32ReadBuffer);
                for (int i = 0; i < iLen; i++)
                {
                    Assert.Equals(UInt32VlenBuffer[i], UInt32ReadBuffer[i]);
                }

                // Int64
                vlen = file.AddVlenType("vlenInt64", NcInt64.Instance);
                var  = file.AddVar("Int64", vlen, dim);
                var.PutVar(new Int32[] { 0 }, Int64VlenBuffer);
                iLen = var.GetVar(new Int32[] { 0 }, Int64ReadBuffer);
                for (int i = 0; i < iLen; i++)
                {
                    Assert.Equals(Int64VlenBuffer[i], Int64ReadBuffer[i]);
                }

                // UInt64
                vlen = file.AddVlenType("vlenUInt64", NcUint64.Instance);
                var  = file.AddVar("UInt64", vlen, dim);
                var.PutVar(new Int32[] { 0 }, UInt64VlenBuffer);
                iLen = var.GetVar(new Int32[] { 0 }, UInt64ReadBuffer);
                for (int i = 0; i < iLen; i++)
                {
                    Assert.Equals(UInt64VlenBuffer[i], UInt64ReadBuffer[i]);
                }

                // float
                vlen = file.AddVlenType("vlenfloat", NcFloat.Instance);
                var  = file.AddVar("float", vlen, dim);
                var.PutVar(new Int32[] { 0 }, floatVlenBuffer);
                iLen = var.GetVar(new Int32[] { 0 }, floatReadBuffer);
                for (int i = 0; i < iLen; i++)
                {
                    Assert.Equals(floatVlenBuffer[i], floatReadBuffer[i]);
                }

                // double
                vlen = file.AddVlenType("vlendouble", NcDouble.Instance);
                var  = file.AddVar("double", vlen, dim);
                var.PutVar(new Int32[] { 0 }, doubleVlenBuffer);
                iLen = var.GetVar(new Int32[] { 0 }, doubleReadBuffer);
                for (int i = 0; i < iLen; i++)
                {
                    Assert.Equals(doubleVlenBuffer[i], doubleReadBuffer[i]);
                }
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Ejemplo n.º 13
0
        public bool TestVarAttributes()
        {
            NcFile file = null;
            NcAtt  att  = null;
            NcVar  var  = null;
            NcDim  dim  = null;

            sbyte[]  sbyteBuf  = new sbyte[2];
            byte[]   byteBuf   = new byte[2];
            short[]  shortBuf  = new short[2];
            ushort[] ushortBuf = new ushort[2];
            int[]    intBuf    = new int[2];
            uint[]   uintBuf   = new uint[2];
            long[]   longBuf   = new long[2];
            ulong[]  ulongBuf  = new ulong[2];
            float[]  floatBuf  = new float[2];
            double[] doubleBuf = new double[2];
            try {
                file = TestHelper.NewFile(filePath);
                dim  = file.AddDim("time", 5);
                var  = file.AddVar("time", NcUint.Instance, dim);


                // Test global attributes
                att = var.PutAtt("string", "test");
                Assert.Equals(att.GetName(), "string");
                Assert.Equals(att.GetValues(), "test");


                att = var.PutAtt("sbyte", NcByte.Instance, (sbyte)-1);
                Assert.Equals(att.GetName(), "sbyte");
                att.GetValues(sbyteBuf);
                Assert.Equals(sbyteBuf[0], (sbyte)(-1));
                att = var.PutAtt("sbyteA", NcByte.Instance, new sbyte[] { -1, 1 });
                Assert.Equals(att.GetName(), "sbyteA");
                att.GetValues(sbyteBuf);
                Assert.Equals(sbyteBuf[1], (sbyte)1);

                att = var.PutAtt("byte", NcByte.Instance, (byte)2);
                Assert.Equals(att.GetName(), "byte");
                att.GetValues(byteBuf);
                Assert.Equals(byteBuf[0], (byte)2);
                att = var.PutAtt("byteA", NcByte.Instance, new byte[] { 2, 1 });
                Assert.Equals(att.GetName(), "byteA");
                att.GetValues(byteBuf);
                Assert.Equals(byteBuf[1], (byte)1);

                att = var.PutAtt("short", NcShort.Instance, (short)-1);
                Assert.Equals(att.GetName(), "short");
                att.GetValues(shortBuf);
                Assert.Equals(shortBuf[0], (short)(-1));
                att = var.PutAtt("shortA", NcShort.Instance, new short[] { -1, 1 });
                Assert.Equals(att.GetName(), "shortA");
                att.GetValues(shortBuf);
                Assert.Equals(shortBuf[1], (short)1);

                att = var.PutAtt("ushort", NcUshort.Instance, (ushort)2);
                Assert.Equals(att.GetName(), "ushort");
                att.GetValues(ushortBuf);
                Assert.Equals(ushortBuf[0], (ushort)2);
                att = var.PutAtt("ushortA", NcUshort.Instance, new ushort[] { 2, 1 });
                Assert.Equals(att.GetName(), "ushortA");
                att.GetValues(ushortBuf);
                Assert.Equals(ushortBuf[1], (ushort)1);

                att = var.PutAtt("int", NcInt.Instance, (int)-1);
                Assert.Equals(att.GetName(), "int");
                att.GetValues(intBuf);
                Assert.Equals(intBuf[0], (int)(-1));
                att = var.PutAtt("intA", NcInt.Instance, new int[] { -1, 1 });
                Assert.Equals(att.GetName(), "intA");
                att.GetValues(intBuf);
                Assert.Equals(intBuf[1], (int)1);

                att = var.PutAtt("uint", NcUint.Instance, (uint)2);
                att.GetValues(uintBuf);
                Assert.Equals(uintBuf[0], (uint)2);
                att = var.PutAtt("uintA", NcUint.Instance, new uint[] { 2, 1 });
                att.GetValues(uintBuf);
                Assert.Equals(uintBuf[1], (uint)1);

                att = var.PutAtt("long", NcInt64.Instance, (long)-1);
                att.GetValues(longBuf);
                Assert.Equals(longBuf[0], (long)(-1));
                att = var.PutAtt("longA", NcInt64.Instance, new long[] { -1, 1 });
                att.GetValues(longBuf);
                Assert.Equals(longBuf[1], (long)1);

                att = var.PutAtt("ulong", NcUint64.Instance, (ulong)2);
                att.GetValues(ulongBuf);
                Assert.Equals(ulongBuf[0], (ulong)2);
                att = var.PutAtt("ulongA", NcUint64.Instance, new ulong[] { 2, 1 });
                att.GetValues(ulongBuf);
                Assert.Equals(ulongBuf[1], (ulong)1);

                att = var.PutAtt("float", NcFloat.Instance, (float)-1);
                att.GetValues(floatBuf);
                Assert.Equals(floatBuf[0], (float)(-1));
                att = var.PutAtt("floatA", NcFloat.Instance, new float[] { -1, 1 });
                att.GetValues(floatBuf);
                Assert.Equals(floatBuf[1], (float)1);

                att = var.PutAtt("double", NcDouble.Instance, (double)2);
                att.GetValues(doubleBuf);
                Assert.Equals(doubleBuf[0], (double)2);
                att = var.PutAtt("doubleA", NcDouble.Instance, new double[] { 2, 1 });
                att.GetValues(doubleBuf);
                Assert.Equals(doubleBuf[1], (double)1);
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Ejemplo n.º 14
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);
 }
Ejemplo n.º 15
0
 private void FileSetup(ref NcFile file, ref NcDim dim1, ref NcVar var1, string type = "int")
 {
     file = TestHelper.NewFile(filePath);
     dim1 = file.AddDim("time", 20);
     var1 = file.AddVar("temp", type, "time");
 }