Beispiel #1
0
 public bool TestOpenCreate() {
     string filePath = "nc_clobber.nc";
     CheckDelete(filePath);
     NcFile file = null;
     try {
         file = new NcFile(filePath, NcFileMode.replace, NcFileFormat.nc4);
     } finally { 
         file.Close();
     }
     CheckDelete(filePath);
     return true;
 }
Beispiel #2
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;
        }
Beispiel #3
0
 public static NcFile NewFile(string filePath) {
     NcFile file;
     CheckDelete(filePath);
     file = new NcFile(filePath, NcFileMode.replace, NcFileFormat.nc4);
     return file;
 }
Beispiel #4
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;
        }
Beispiel #5
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);
 }
Beispiel #6
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");
 }
Beispiel #7
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;
        }