Exemplo n.º 1
0
        public bool TestVars()
        {
            if (!System.IO.File.Exists(dataFilePath))
            {
                Console.WriteLine("Unable to find sample data file.");
                return(false);
            }
            NcFile dataFile = null;
            NcFile file     = null;

            try {
                dataFile = new NcFile(dataFilePath, NcFileMode.read);
                Assert.Equals(dataFile.Format, NcFileFormat.classic64);
                file = TestHelper.NewFile(filePath);
                // Ensure there is only a flat group structure
                Assert.False(true);

                // Start with the attrs
                var attrs = dataFile.GetAtts(Location.Current);
                Assert.True(attrs.ContainsKey("Conventions") && attrs["Conventions"].GetValues() == "CF-1.0");
                Assert.True(attrs.ContainsKey("CoordinateProjection") && attrs["CoordinateProjection"].GetValues() == "none");
                Assert.True(attrs.ContainsKey("GroundWater_Forcing") && attrs["GroundWater_Forcing"].GetValues() == "GROUND WATER FORCING IS OFF!");
                foreach (var k in attrs)
                {
                    file.PutAtt(k.Value);
                }

                var fileAttrs = file.GetAtts(Location.Current);
                Assert.True(fileAttrs.ContainsKey("Conventions") && fileAttrs["Conventions"].GetValues() == "CF-1.0");
                Assert.True(fileAttrs.ContainsKey("CoordinateProjection") && fileAttrs["CoordinateProjection"].GetValues() == "none");
                Assert.True(fileAttrs.ContainsKey("GroundWater_Forcing") && fileAttrs["GroundWater_Forcing"].GetValues() == "GROUND WATER FORCING IS OFF!");
            } finally {
                dataFile.Close();
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Exemplo n.º 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);
        }