Esempio n. 1
0
        public bool TestStrictChecking()
        {
            NcFile file = null;
            NcDim  dim1 = null;
            NcVar  var1 = null;

            Int32[] buffer = new Int32[20];
            for (int i = 0; i < 20; i++)
            {
                buffer[i] = i;
            }
            try {
                FileSetup(ref file, ref dim1, ref var1);
                var1.PutVar(buffer);
                buffer = new Int32[15]; // Squeeze it
                try {
                    var1.GetVar(buffer);
                    // If it gets to here the program will crash hard anyway
                    throw new AssertFailedException("BufferOverflow exception not raised");
                } catch (NcBufferOverflow) {
                    // yay it worked
                }
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        /// <summary>
        /// 取得 Variables 中指定 ComponentName 的 Attributes 值
        /// </summary>
        /// <param name="curVar"></param>
        /// <param name="componentName"></param>
        /// <returns></returns>
        public object GetNcAttValueByVariables(NcVar curVar, string componentName)
        {
            object returnValue = null;

            foreach (NcAtt curAtt in curVar.Attributes)
            {
                if (curAtt.ComponentName.Equals(componentName))
                {
                    switch (curAtt.GetType().ToString())
                    {
                    case "NetCDF.NcAttString":
                        returnValue = ((NcAttString)curAtt).Value;
                        break;

                    case "NetCDF.NcAttDouble":
                        returnValue = ((NcAttDouble)curAtt).Value;
                        break;

                    case "NetCDF.NcAttInt":
                        returnValue = ((NcAttInt)curAtt).Value;
                        break;

                    case "NetCDF.NcAttFloat":
                        returnValue = ((NcAttFloat)curAtt).Value;
                        break;
                    }
                }
            }
            return(returnValue);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public bool TestUInt64Var()
        {
            NcFile file = null;
            NcDim  dim1 = null;
            NcVar  var1 = null;

            UInt64[] buffer     = new UInt64[20];
            UInt64[] readBuffer = new UInt64[20];
            for (int i = 0; i < 20; i++)
            {
                buffer[i] = (UInt64)i;
            }
            try {
                FileSetup(ref file, ref dim1, ref var1, NcUint64.Instance);
                // Test the basic get/put
                var1.PutVar(buffer);
                var1.GetVar(readBuffer);
                for (int i = 0; i < 20; i++)
                {
                    Assert.Equals(readBuffer[i], buffer[i]);
                }
                // test get and put scalars
                var1.PutVar(new Int32[] { 5 }, new UInt64[] { 30 });
                var1.GetVar(new Int32[] { 5 }, readBuffer);
                Assert.Equals(readBuffer[0], (UInt64)30);
                // test get and put 1d arrays
                var1.PutVar(new Int32[] { 2 }, new Int32[] { 4 }, new UInt64[] { 20, 20, 20, 20 });
                var1.GetVar(new Int32[] { 2 }, new Int32[] { 4 }, readBuffer);
                Assert.Equals(readBuffer[0], (UInt64)20);
                Assert.Equals(readBuffer[3], (UInt64)20);
                var1.GetVar(readBuffer);
                Assert.Equals(readBuffer[0], (UInt64)0);
                Assert.Equals(readBuffer[2], (UInt64)20);
                Assert.Equals(readBuffer[5], (UInt64)20);
                Assert.Equals(readBuffer[6], (UInt64)6);

                // test striding
                var1.PutVar(new Int32[] { 10 }, new Int32[] { 5 }, new Int32[] { 2 }, new UInt64[] { 40, 40, 40 });
                var1.GetVar(new Int32[] { 10 }, new Int32[] { 5 }, new Int32[] { 2 }, readBuffer);
                Assert.Equals(readBuffer[0], (UInt64)40);
                Assert.Equals(readBuffer[2], (UInt64)40);
                var1.GetVar(readBuffer);
                Assert.Equals(readBuffer[10], (UInt64)40);
                Assert.Equals(readBuffer[12], (UInt64)40);
                Assert.Equals(readBuffer[14], (UInt64)40);
                Assert.Equals(readBuffer[15], (UInt64)15);
                // Test ranges
                var1.PutVar(new Int32[] { 0 }, new ulong[] { 18446744073709551615L });
                try {
                    var1.PutVar(new Int32[] { 0 }, new long[] { -1 });
                    throw new AssertFailedException("Failed to raise NcRange exception.");
                } catch (NcRange) {
                }
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Esempio n. 6
0
        public NcVarAtt(NcGroup grp, NcVar var, Int32 index) : base(false)
        {
            ASCIIEncoding encoder = new ASCIIEncoding();

            groupId = grp.GetId();
            varId   = var.GetId();
            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
        }
Esempio n. 7
0
        public bool TestDoubleVar()
        {
            NcFile file = null;
            NcDim  dim1 = null;
            NcVar  var1 = null;

            double[] buffer     = new double[20];
            double[] readBuffer = new double[20];
            for (int i = 0; i < 20; i++)
            {
                buffer[i] = (double)i;
            }
            try {
                FileSetup(ref file, ref dim1, ref var1, NcDouble.Instance);
                // Test the basic get/put
                var1.PutVar(buffer);
                var1.GetVar(readBuffer);
                for (int i = 0; i < 20; i++)
                {
                    Assert.Equals(readBuffer[i], buffer[i]);
                }
                // test get and put scalars
                var1.PutVar(new Int32[] { 5 }, new double[] { 30.0 });
                var1.GetVar(new Int32[] { 5 }, readBuffer);
                Assert.Equals(readBuffer[0], 30.0);
                // test get and put 1d arrays
                var1.PutVar(new Int32[] { 2 }, new Int32[] { 4 }, new double[] { 20.0, 20.0, 20.0, 20.0 });
                var1.GetVar(new Int32[] { 2 }, new Int32[] { 4 }, readBuffer);
                Assert.Equals(readBuffer[0], (double)20.0);
                Assert.Equals(readBuffer[3], (double)20.0);
                var1.GetVar(readBuffer);
                Assert.Equals(readBuffer[0], (double)0.0);
                Assert.Equals(readBuffer[2], (double)20.0);
                Assert.Equals(readBuffer[5], (double)20.0);
                Assert.Equals(readBuffer[6], (double)6.0);
                // test striding
                var1.PutVar(new Int32[] { 10 }, new Int32[] { 5 }, new Int32[] { 2 }, new double[] { 40, 40, 40 });
                var1.GetVar(new Int32[] { 10 }, new Int32[] { 5 }, new Int32[] { 2 }, readBuffer);
                Assert.Equals(readBuffer[0], (double)40);
                Assert.Equals(readBuffer[2], (double)40);
                var1.GetVar(readBuffer);
                Assert.Equals(readBuffer[10], (double)40);
                Assert.Equals(readBuffer[12], (double)40);
                Assert.Equals(readBuffer[14], (double)40);
                Assert.Equals(readBuffer[15], (double)15);
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Esempio n. 8
0
        public bool TestSByteVar()
        {
            NcFile file = null;
            NcDim  dim1 = null;
            NcVar  var1 = null;

            sbyte[] buffer     = new sbyte[4];
            sbyte[] readBuffer = new sbyte[4];
            for (int i = 0; i < 4; i++)
            {
                buffer[i] = (sbyte)(i - 1);
            }
            try {
                FileSetup(ref file, ref dim1, ref var1, NcByte.Instance, 4);
                // Test the array get/put
                var1.PutVar(buffer);
                var1.GetVar(readBuffer);
                for (int i = 0; i < 4; i++)
                {
                    Assert.Equals(readBuffer[i], buffer[i]);
                }

                // Test get and put for scalars
                var1.PutVar(new Int32[] { 1 }, new sbyte[] { -2 });
                var1.GetVar(new Int32[] { 1 }, readBuffer);
                Assert.Equals(readBuffer[0], (sbyte)-2);

                // Test get and put subsets
                var1.PutVar(new Int32[] { 2 }, new Int32[] { 2 }, new sbyte[] { -2, -2 });
                var1.GetVar(new Int32[] { 2 }, new Int32[] { 2 }, readBuffer);
                Assert.Equals(readBuffer[0], (sbyte)-2);
                Assert.Equals(readBuffer[1], (sbyte)-2);
                // Test ranges
                var1.PutVar(new Int32[] { 0 }, new int[] { 127 });
                try {
                    var1.PutVar(new Int32[] { 0 }, new int[] { 128 });
                    throw new AssertFailedException("Failed to raise NcRange exception.");
                } catch (NcRange) {
                }
                var1.PutVar(new Int32[] { 0 }, new int[] { -128 });
                try {
                    var1.PutVar(new Int32[] { 0 }, new int[] { -129 });
                    throw new AssertFailedException("Failed to raise NcRange exception.");
                } catch (NcRange) {
                }
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Esempio n. 9
0
        public bool TestVarPutGet()
        {
            NcFile file = null;
            NcDim  dim1 = null;
            NcVar  var1 = null;

            Int32[] vals = new Int32[20];
            for (int i = 0; i < 20; i++)
            {
                vals[i] = i;
            }
            try {
                FileSetup(ref file, ref dim1, ref var1);
                var1.PutVar(vals);
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
        public bool TestStringVar()
        {
            NcFile        file    = null;
            NcDim         dim1    = null;
            NcVar         var1    = null;
            ASCIIEncoding encoder = new ASCIIEncoding();

            string buffer = String.Format("{0,20}", "hi there"); // need exactly 20 chars

            byte[] readBuffer = new byte[20];
            try {
                FileSetup(ref file, ref dim1, ref var1, NcChar.Instance);
                var1.PutVar(encoder.GetBytes(buffer));
                var1.GetVar(readBuffer);
                Assert.Equals(encoder.GetString(readBuffer), buffer);
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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);
        }
Esempio n. 14
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);
        }
Esempio n. 15
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);
        }
Esempio n. 16
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);
        }
Esempio n. 17
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);
        }
Esempio n. 18
0
        public bool TestExtensive()
        {
            NcFile  file    = null;
            NcGroup east    = null;
            NcGroup west    = null;
            NcDim   timeDim = null;
            NcDim   latDim  = null;
            NcDim   lonDim  = null;
            NcVar   timeVar = null;
            NcVar   latVar  = null;
            NcVar   lonVar  = null;
            NcVar   temp    = null;

            float[] buffer;

            double[] timeArray = new double[] { 0, 1, 2, 3, 4, 5, 6 };
            double[] latArray  = new double[] { 40.1, 40.2, 40.3, 40.4, 40.5 };
            double[] lonArray  = new double[] { -73.5, -73.4, -73.3, -73.2 };
            float[]  sstArray  = new float[140];

            double[] readBuffer = new double[140];
            for (int i = 0; i < 140; i++)
            {
                sstArray[i] = (float)i;
            }

            try {
                file = TestHelper.NewFile(filePath);
                east = file.AddGroup("east");
                west = file.AddGroup("west");

                // Fill out east first
                timeDim = east.AddDim("time");   // UNLIMITED
                latDim  = east.AddDim("lat", 5); // 5 lats
                lonDim  = east.AddDim("lon", 4); // 4 lons
                timeVar = east.AddVar("time", NcDouble.Instance, timeDim);
                latVar  = east.AddVar("lat", NcDouble.Instance, latDim);
                lonVar  = east.AddVar("lon", NcDouble.Instance, lonDim);
                temp    = east.AddVar("sst", NcFloat.Instance, (List <NcDim>) new[] { timeDim, latDim, lonDim }.ToList());

                timeVar.PutVar(new Int32[] { 0 }, new Int32[] { timeArray.Length }, timeArray);
                latVar.PutVar(latArray);
                lonVar.PutVar(lonArray);
                temp.PutVar(new Int32[] { 0, 0, 0 }, new Int32[] { 7, 5, 4 }, sstArray);

                // Now check that the writes were successful and that
                // the read buffer matches the writes

                timeVar.GetVar(readBuffer);
                for (int i = 0; i < 7; i++)
                {
                    Assert.Equals(readBuffer[i], timeArray[i]);
                }
                latVar.GetVar(readBuffer);
                for (int i = 0; i < 5; i++)
                {
                    Assert.Equals(readBuffer[i], latArray[i]);
                }
                lonVar.GetVar(readBuffer);
                for (int i = 0; i < 4; i++)
                {
                    Assert.Equals(readBuffer[i], lonArray[i]);
                }
                temp.GetVar(readBuffer);
                for (int i = 0; i < 140; i++)
                {
                    Assert.Equals((float)readBuffer[i], sstArray[i]);
                }
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Esempio n. 19
0
        public bool TestNestedGroups()
        {
            NcFile file = null;
            NcDim  dim;
            Dictionary <string, NcGroup> groups;

            try {
                file = TestHelper.NewFile(filePath);
                NcGroup a = file.AddGroup("a");
                Assert.False(a.IsNull());
                NcGroup b = file.AddGroup("b");
                Assert.False(b.IsNull());
                NcGroup a1 = a.AddGroup("a1");
                Assert.False(a1.IsNull());
                NcGroup a2 = a.AddGroup("a2");
                Assert.False(a2.IsNull());
                NcGroup b1 = b.AddGroup("b1");
                Assert.False(b1.IsNull());
                NcGroup b2 = b.AddGroup("b2");
                Assert.False(b2.IsNull());

                Assert.Equals(file.GetGroupCount(GroupLocation.AllGrps), 7);
                Assert.Equals(file.GetGroupCount(GroupLocation.AllChildrenGrps), 6);
                Assert.Equals(b2.GetGroupCount(GroupLocation.ParentsGrps), 2);
                Assert.Equals(a2.GetGroupCount(GroupLocation.ParentsGrps), 2);
                Assert.True(file.GetGroups(GroupLocation.AllChildrenGrps).ContainsKey("b1"));
                groups = a1.GetGroups(GroupLocation.ParentsGrps);
                Assert.True(groups.ContainsKey("/") && groups["/"].GetId() == file.GetId());
                Assert.Equals(file.GetGroups("b1", GroupLocation.AllChildrenGrps).Count, 1);
                Assert.True(file.GetGroup("a2", GroupLocation.ChildrenGrps).IsNull());
                Assert.Equals(file.GetGroup("a2", GroupLocation.AllChildrenGrps).GetId(), a2.GetId());
                Assert.True(file.IsRootGroup());
                Assert.False(a.IsRootGroup());

                foreach (KeyValuePair <string, NcGroup> group in file.GetGroups(GroupLocation.AllGrps))
                {
                    dim = group.Value.AddDim("time" + (group.Value.IsRootGroup() ? "Root" : group.Key), 20);
                    NcVar v   = group.Value.AddVar("time" + (group.Value.IsRootGroup() ? "Root" : group.Key), NcUint64.Instance, dim);
                    NcAtt att = group.Value.PutAtt("Attr" + (group.Value.IsRootGroup() ? "Root" : group.Key), "Value");
                    Assert.False(v.IsNull());
                    Assert.Equals(file.GetVar(v.GetName(), Location.All).GetId(), v.GetId());
                }


                Assert.Equals(file.GetVarCount(Location.All), 7);
                Assert.Equals(file.GetVars(Location.All).Count, 7);
                foreach (KeyValuePair <string, NcVar> gvar in file.GetVars(Location.All))
                {
                    Assert.Equals(gvar.Key, gvar.Value.GetName());
                    NcGroup g = gvar.Value.GetParentGroup();
                    Assert.Equals(gvar.Key, "time" + (g.IsRootGroup() ? "Root" : g.GetName()));
                }
                Assert.Equals(file.GetVars("timeRoot", Location.All).Count, 1);

                Assert.Equals(file.GetAttCount(Location.All), 7);
                Assert.Equals(file.GetAtts(Location.All).Count, 7);
                foreach (KeyValuePair <string, NcGroupAtt> k in file.GetAtts(Location.All))
                {
                    Assert.Equals(k.Value.GetValues(), "Value");
                }
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Esempio n. 20
0
        public bool TestByteVar()
        {
            NcFile file = null;
            NcDim  dim1 = null;
            NcVar  var1 = null;

            byte[] buffer     = new byte[20];
            byte[] readBuffer = new byte[20];
            for (int i = 0; i < 20; i++)
            {
                buffer[i] = (byte)i;
            }
            try {
                FileSetup(ref file, ref dim1, ref var1, NcByte.Instance);
                // Test the basic get/put
                var1.PutVar(buffer);
                var1.GetVar(readBuffer);
                for (int i = 0; i < 20; i++)
                {
                    Assert.Equals(readBuffer[i], buffer[i]);
                }
                // test get and put scalars
                var1.PutVar(new Int32[] { 5 }, new byte[] { 30 });
                var1.GetVar(new Int32[] { 5 }, readBuffer);
                Assert.Equals(readBuffer[0], (byte)30);

                // test get and put 1d arrays
                var1.PutVar(new Int32[] { 2 }, new Int32[] { 4 }, new byte[] { 20, 20, 20, 20 });
                var1.GetVar(new Int32[] { 2 }, new Int32[] { 4 }, readBuffer);
                Assert.Equals(readBuffer[0], (byte)20);
                Assert.Equals(readBuffer[3], (byte)20);
                var1.GetVar(readBuffer);
                Assert.Equals(readBuffer[0], (byte)0);
                Assert.Equals(readBuffer[2], (byte)20);
                Assert.Equals(readBuffer[5], (byte)20);
                Assert.Equals(readBuffer[6], (byte)6);

                // test striding
                var1.PutVar(new Int32[] { 10 }, new Int32[] { 5 }, new Int32[] { 2 }, new byte[] { 40, 40, 40, 40 });
                var1.GetVar(new Int32[] { 10 }, new Int32[] { 5 }, new Int32[] { 2 }, readBuffer);
                Assert.Equals(readBuffer[0], (byte)40);
                Assert.Equals(readBuffer[2], (byte)40);
                var1.GetVar(readBuffer);
                Assert.Equals(readBuffer[10], (byte)40);
                Assert.Equals(readBuffer[12], (byte)40);
                Assert.Equals(readBuffer[14], (byte)40);
                Assert.Equals(readBuffer[15], (byte)15);
                // Test ranges
                // Note: NC_BYTE is a SIGNED 8-bit integer, no getting around that.
                var1.PutVar(new Int32[] { 0 }, new int[] { 127 });
                try {
                    var1.PutVar(new Int32[] { 0 }, new int[] { 128 });
                    throw new AssertFailedException("Failed to raise NcRange exception.");
                } catch (NcRange) {
                }
                var1.PutVar(new Int32[] { 0 }, new int[] { -128 });
                try {
                    var1.PutVar(new Int32[] { 0 }, new int[] { -129 });
                    throw new AssertFailedException("Failed to raise NcRange exception.");
                } catch (NcRange) {
                }
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Esempio n. 21
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);
        }
Esempio n. 22
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);
        }
Esempio n. 23
0
        public bool TestInt32Var()
        {
            NcFile file = null;
            NcDim  dim1 = null;
            NcVar  var1 = null;

            Int32[] buffer     = new Int32[20];
            Int32[] readBuffer = new Int32[20];
            for (int i = 0; i < 20; i++)
            {
                buffer[i] = (Int32)(i - 10);
            }
            try {
                FileSetup(ref file, ref dim1, ref var1, NcInt.Instance);
                // Test the basic get/put
                var1.PutVar(buffer);
                var1.GetVar(readBuffer);
                for (int i = 0; i < 20; i++)
                {
                    Assert.Equals(readBuffer[i], buffer[i]);
                }
                // test get and put scalars
                var1.PutVar(new Int32[] { 5 }, new Int32[] { -30 });
                var1.GetVar(new Int32[] { 5 }, readBuffer);
                Assert.Equals(readBuffer[0], (Int32)(-30));
                // test get and put 1d arrays
                var1.PutVar(new Int32[] { 2 }, new Int32[] { 4 }, new Int32[] { -20, -20, -20, -20 });
                var1.GetVar(new Int32[] { 2 }, new Int32[] { 4 }, readBuffer);
                Assert.Equals(readBuffer[0], (Int32)(-20));
                Assert.Equals(readBuffer[3], (Int32)(-20));
                var1.GetVar(readBuffer);
                Assert.Equals(readBuffer[0], (Int32)(-10));
                Assert.Equals(readBuffer[2], (Int32)(-20));
                Assert.Equals(readBuffer[5], (Int32)(-20));
                Assert.Equals(readBuffer[6], (Int32)(-4));

                // test striding
                var1.PutVar(new Int32[] { 10 }, new Int32[] { 5 }, new Int32[] { 2 }, new Int32[] { -40, -40, -40 });
                var1.GetVar(new Int32[] { 10 }, new Int32[] { 5 }, new Int32[] { 2 }, readBuffer);
                Assert.Equals(readBuffer[0], (Int32)(-40));
                Assert.Equals(readBuffer[2], (Int32)(-40));
                var1.GetVar(readBuffer);
                Assert.Equals(readBuffer[10], (Int32)(-40));
                Assert.Equals(readBuffer[12], (Int32)(-40));
                Assert.Equals(readBuffer[14], (Int32)(-40));
                Assert.Equals(readBuffer[15], (Int32)5);
                // Test ranges
                var1.PutVar(new Int32[] { 0 }, new long[] { 2147483647 });
                try {
                    var1.PutVar(new Int32[] { 0 }, new long[] { 2147483648 });
                    throw new AssertFailedException("Failed to raise NcRange exception.");
                } catch (NcRange) {
                }
                var1.PutVar(new Int32[] { 0 }, new long[] { -2147483648 });
                try {
                    var1.PutVar(new Int32[] { 0 }, new long[] { -2147483649 });
                    throw new AssertFailedException("Failed to raise NcRange exception.");
                } catch (NcRange) {
                }
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Esempio n. 24
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);
        }
Esempio n. 25
0
        public bool TestInt64Var()
        {
            NcFile file = null;
            NcDim  dim1 = null;
            NcVar  var1 = null;

            Int64[] buffer     = new Int64[20];
            Int64[] readBuffer = new Int64[20];
            for (int i = 0; i < 20; i++)
            {
                buffer[i] = (Int64)(i - 10);
            }
            try {
                FileSetup(ref file, ref dim1, ref var1, NcInt64.Instance);
                // Test the basic get/put
                var1.PutVar(buffer);
                var1.GetVar(readBuffer);
                for (int i = 0; i < 20; i++)
                {
                    Assert.Equals(readBuffer[i], buffer[i]);
                }
                // test get and put scalars
                var1.PutVar(new Int32[] { 5 }, new Int64[] { -30 });
                var1.GetVar(new Int32[] { 5 }, readBuffer);
                Assert.Equals(readBuffer[0], (Int64)(-30));
                // test get and put 1d arrays
                var1.PutVar(new Int32[] { 2 }, new Int32[] { 4 }, new Int64[] { -20, -20, -20, -20 });
                var1.GetVar(new Int32[] { 2 }, new Int32[] { 4 }, readBuffer);
                Assert.Equals(readBuffer[0], (Int64)(-20));
                Assert.Equals(readBuffer[3], (Int64)(-20));
                var1.GetVar(readBuffer);
                Assert.Equals(readBuffer[0], (Int64)(-10));
                Assert.Equals(readBuffer[2], (Int64)(-20));
                Assert.Equals(readBuffer[5], (Int64)(-20));
                Assert.Equals(readBuffer[6], (Int64)(-4));

                // test striding
                var1.PutVar(new Int32[] { 10 }, new Int32[] { 5 }, new Int32[] { 2 }, new Int64[] { -40, -40, -40 });
                var1.GetVar(new Int32[] { 10 }, new Int32[] { 5 }, new Int32[] { 2 }, readBuffer);
                Assert.Equals(readBuffer[0], (Int64)(-40));
                Assert.Equals(readBuffer[2], (Int64)(-40));
                var1.GetVar(readBuffer);
                Assert.Equals(readBuffer[10], (Int64)(-40));
                Assert.Equals(readBuffer[12], (Int64)(-40));
                Assert.Equals(readBuffer[14], (Int64)(-40));
                Assert.Equals(readBuffer[15], (Int64)5);
                // Test ranges
                var1.PutVar(new Int32[] { 0 }, new ulong[] { 9223372036854775807L });
                try {
                    var1.PutVar(new Int32[] { 0 }, new ulong[] { 9223372036854775808L });
                    throw new AssertFailedException("Failed to raise NcRange exception.");
                } catch (NcRange) {
                }
                var1.PutVar(new Int32[] { 0 }, new long[] { -9223372036854775808L });
                // Can't actually show the negative... how would you represent the overflow?
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Esempio n. 26
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");
 }
Esempio n. 27
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);
 }