예제 #1
0
        public bool TestAddSub()
        {
            NcArray ones   = new NcArray(NcInt.Instance, new int[] { 10 }).Fill(1);
            NcArray twos   = ones + 1;
            NcArray threes = ones + 2;
            NcArray fours  = twos + 2;

            Assert.True(threes.Equals(ones + twos));
            Assert.False(fours.Equals(ones + twos));
            Assert.True(fours.Equals(twos + twos));
            Assert.True(ones.Equals(threes - twos));
            Assert.True(twos.Equals(fours - twos));
            Assert.False(ones.Equals(fours - ones));


            double[] buf = new double[100];
            for (int i = 0; i < 100; i++)
            {
                buf[i] = (double)i;
            }
            NcArray wrapper = new NcArray(buf, NcDouble.Instance, new int[] { 100 });

            wrapper.Add(20.0);
            Assert.Equals(buf[0], 20.0);
            return(true);
        }
예제 #2
0
        public bool TestMultDiv()
        {
            NcArray ones   = new NcArray(NcInt.Instance, new int[] { 10 }).Fill(1);
            NcArray twos   = ones * 2;
            NcArray threes = twos + 1;
            NcArray fours  = twos * 2;
            NcArray zeros  = ones * 0;


            Assert.True(threes.Equals(ones * threes));
            Assert.True(twos.Equals(fours / twos));
            Assert.True(twos.Equals(fours / 2));
            try {
                fours.Div(0);
                throw new AssertFailedException("Failed to throw DivideByZeroException");
            } catch (DivideByZeroException) {
            }

            NcArray buf = NcArray.Arange(NcDouble.Instance, 5);

            buf = buf * 10.0;
            int[]   shape   = new int[] { 1, 3, 5, 7 };
            NcArray uVector = NcArray.Arange(NcShort.Instance, 1 * 3 * 5 * 7).Reshape(shape);

            return(true);
        }
예제 #3
0
        public bool TestCasting()
        {
            NcArray a = NcArray.Arange(NcInt.Instance, 2);
            double  b = a.GetDoubleAt(0);

            Assert.Equals(b, 0.0);
            return(true);
        }
예제 #4
0
        public bool TestSlicing() {

            int[] basicArray = new int[64];
            for(int i=0;i<64;i++) basicArray[i] = i;

            NcArray ncArray = new NcArray(basicArray, new int[] { 4,4,4});
            NcArray outArray = ncArray.Slice(new int[] { 2, 2, 2}, new int[] {4, 4, 4});
            Assert.Equals(outArray.Array, new int[] { 42, 43, 46, 47, 58, 59, 62, 63 });

            return true;
        }
예제 #5
0
        public bool TestSlicing()
        {
            int[] basicArray = new int[64];
            for (int i = 0; i < 64; i++)
            {
                basicArray[i] = i;
            }

            NcArray ncArray  = new NcArray(basicArray, new int[] { 4, 4, 4 });
            NcArray outArray = ncArray.Slice(new int[] { 2, 2, 2 }, new int[] { 4, 4, 4 });

            Assert.Equals(outArray.Array, new int[] { 42, 43, 46, 47, 58, 59, 62, 63 });

            return(true);
        }
예제 #6
0
        public bool TestReshape()
        {
            int[]   shape = new int[] { 2, 2, 2 };
            NcArray array = NcArray.Arange(NcDouble.Instance, 2 * 2 * 2).Reshape(shape);

            Assert.Equals(array.Shape, shape);
            array.Reshape(new int[] { 8 });
            Assert.Equals(array.Shape, new int[]  { 8 });
            try {
                array.GetValueAt(1, 1, 1);
                throw new AssertFailedException("Failed to throw index bounds exception");
            } catch (exceptions.NcInvalidArg) {
            }

            return(true);
        }
예제 #7
0
        public bool TestAddSub() {
            NcArray ones = new NcArray(NcInt.Instance, new int[] { 10 }).Fill(1);
            NcArray twos = ones + 1;
            NcArray threes = ones + 2;
            NcArray fours = twos + 2;

            Assert.True(threes.Equals(ones + twos));
            Assert.False(fours.Equals(ones + twos));
            Assert.True(fours.Equals(twos + twos));
            Assert.True(ones.Equals(threes - twos));
            Assert.True(twos.Equals(fours - twos));
            Assert.False(ones.Equals(fours - ones));


            double[] buf = new double[100];
            for(int i=0;i<100;i++) buf[i] = (double)i;
            NcArray wrapper = new NcArray(buf, NcDouble.Instance, new int[] { 100 });
            wrapper.Add(20.0);
            Assert.Equals(buf[0], 20.0);
            return true;
        }
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
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);
        }
예제 #12
0
        public bool TestMultDiv() {
            NcArray ones = new NcArray(NcInt.Instance, new int[] { 10 }).Fill(1);
            NcArray twos = ones * 2;
            NcArray threes = twos + 1;
            NcArray fours = twos * 2;
            NcArray zeros = ones * 0;


            Assert.True(threes.Equals(ones * threes));
            Assert.True(twos.Equals(fours / twos));
            Assert.True(twos.Equals(fours / 2));
            try {
                fours.Div(0);
                throw new AssertFailedException("Failed to throw DivideByZeroException");
            } catch (DivideByZeroException) {
            }

            NcArray buf = NcArray.Arange(NcDouble.Instance, 5);
            buf = buf * 10.0;
            int[] shape = new int[] { 1,3,5,7};
            NcArray uVector = NcArray.Arange(NcShort.Instance, 1 * 3 * 5 * 7).Reshape(shape);
            return true;
        }
예제 #13
0
 public void PutVar(NcArray array, bool strictChecking=true) {
     CheckNull();
     CheckData();
     if(strictChecking) {
         BufferCheck(array.Length);
         DimUnlimitedCheck();
     }
     switch(array.GetNcType().GetTypeClass()) {
         case NcTypeEnum.NC_BYTE:
             PutVar((sbyte[]) array.Array);
             return;
         case NcTypeEnum.NC_UBYTE:
             PutVar((byte[]) array.Array);
             return;
         case NcTypeEnum.NC_SHORT:
             PutVar((Int16[]) array.Array);
             return;
         case NcTypeEnum.NC_USHORT:
             PutVar((UInt16[]) array.Array);
             return;
         case NcTypeEnum.NC_INT:
             PutVar((Int32[]) array.Array);
             return;
         case NcTypeEnum.NC_UINT:
             PutVar((UInt32[]) array.Array);
             return;
         case NcTypeEnum.NC_INT64:
             PutVar((Int64[]) array.Array);
             return;
         case NcTypeEnum.NC_UINT64:
             PutVar((UInt64[]) array.Array);
             return;
         case NcTypeEnum.NC_FLOAT:
             PutVar((float[]) array.Array);
             return;
         case NcTypeEnum.NC_DOUBLE:
             PutVar((double[]) array.Array);
             return;
     }
 }
예제 #14
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;
        }