Example #1
0
        public bool TestGetGroupCount()
        {
            NcGroup group;
            NcFile  file = null;

            try {
                file  = newFile(filePath);
                group = file;
                int groupCount;
                groupCount = group.GetGroupCount(GroupLocation.AllGrps);
                Assert.Equals(groupCount, 1); // Only the root group/file so no groups are defined
                NcGroup childGroup = group.AddGroup("child1");
                Assert.False(childGroup.IsNull());
                Assert.Equals(group.GetGroupCount(GroupLocation.AllGrps), 2);
                Dictionary <string, NcGroup> groups = group.GetGroups(GroupLocation.AllGrps);
                for (int i = 0; i < groups.Count; i++)
                {
                    KeyValuePair <string, NcGroup> k = groups.ElementAt(i);
                    if (i == 0)
                    {
                        Assert.Equals(k.Key, "/");
                    }
                    else if (i == 1)
                    {
                        Assert.Equals(k.Key, "child1");
                    }
                }
            } finally {
                file.Close();
            }

            CheckDelete(filePath);
            return(true);
        }
Example #2
0
        // Constructor
        public NcType(NcGroup grp, string name)
        {
            nullObject = false;
            groupId    = grp.GetId();
            NcType typeTmp = grp.GetType(name, Location.ParentsAndCurrent);

            myId = typeTmp.GetId();
        }
Example #3
0
        // Constructor for an existing global attr
        public NcGroupAtt(NcGroup grp, int index) : base(false)
        {
            ASCIIEncoding encoder = new ASCIIEncoding();

            groupId = grp.GetId();
            varId   = NC_GLOBAL;
            byte[] buffer = new byte[(int)NetCDF.netCDF_limits.NC_MAX_NAME];
            NcCheck.Check(NetCDF.nc_inq_attname(groupId, varId, index, buffer));
            string sbuffer = encoder.GetString(buffer);

            myName = sbuffer.Substring(0, sbuffer.IndexOf('\0')); // A null-terminated C-string
        }
Example #4
0
        public bool TestGetParentGroup()
        {
            NcGroup group;
            NcGroup grpTest;
            NcFile  file = null;

            group = new NcGroup();
            try {
                grpTest = group.GetParentGroup();
                Assert.True(grpTest.IsNull());
                throw new AssertFailedException("NcNullGrp not thrown");
            } catch (exceptions.NcNullGrp) {
            }

            try {
                file  = newFile(filePath);
                group = file.GetParentGroup();
                Assert.True(group.IsNull());
            } finally {
                file.Close();
            }
            return(true);
        }
Example #5
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);
        }
Example #6
0
 public NcFile(NcGroup rhs) : base(rhs)
 {
 }
Example #7
0
 public NcEnumType(NcGroup grp, string name) : base(grp, name)
 {
 }
Example #8
0
 // Constructor for a non-global type
 public NcType(NcGroup grp, int id)
 {
     nullObject = false;
     myId       = id;
     groupId    = grp.GetId();
 }
Example #9
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);
        }
Example #10
0
 public NcOpaqueType(NcGroup grp, string name) : base(grp, name)
 {
 }
Example #11
0
 public NcVlenType(NcGroup grp, string name) : base(grp, name)
 {
 }
Example #12
0
 public NcDim(NcGroup grp, Int32 dimId)
 {
     nullObject = false;
     groupId    = grp.GetId();
     myId       = dimId;
 }