Beispiel #1
0
        public bool TestGetGroups()
        {
            NcGroup group;
            NcFile  file = null;

            NcGroup child1_1;
            NcGroup child1_2;

            try {
                file  = newFile(filePath);
                group = file;
                /* -- Check differentiability for GetGroup -- */
                child1_1 = file.AddGroup("group1");
                file.AddGroup("group2");

                group = file.GetGroup("group1");
                Assert.Equals(group.GetName(), "group1");
                /* -- Check that sets work for GetGroups -- */
                child1_2 = child1_1.AddGroup("group1"); // Second one named group1
                HashSet <NcGroup> groups = file.GetGroups("group1");
                foreach (NcGroup g in groups)
                {
                    if (g.GetId() != child1_1.GetId() && g.GetId() != child1_2.GetId())
                    {
                        throw new AssertFailedException("Incorrect group in set");
                    }
                }
            } finally {
                file.Close();
            }

            CheckDelete(filePath);
            return(true);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }