Пример #1
0
        public void TestSetBitmap()
        {
            using (GribFile file = new GribFile(Settings.REG_LATLON_GRB1))
            {
                var msg = file.First();

                int      numVals = 10;
                double[] vals    = new double[numVals];
                double   val     = 42;

                for (int i = 0; i < numVals; i++)
                {
                    vals[i] = val;
                }

                msg.HasBitmap = true;
                msg.SetValues(vals);
                double[] vals2;
                msg.Values(out vals2);

                for (int i = 0; i < numVals; i++)
                {
                    Assert.AreEqual(vals[i], vals2[i]);
                    Assert.AreEqual(val, vals2[i]);
                }
            }
        }
Пример #2
0
        public void TestTime()
        {
            using (GribFile file = new GribFile(Settings.TIME))
            {
                Assert.IsTrue(file.MessageCount > 0);

                int diff = 0;
                int i    = 0;

                foreach (var msg in file)
                {
                    if (i++ == 0)
                    {
                        continue;
                    }

                    diff = msg["P2"].AsInt();
                    Assert.IsTrue(diff > 0);
                    var t = msg.ReferenceTime.AddHours(diff);
                    Assert.AreNotEqual(msg.ReferenceTime, t);
                    Assert.AreEqual(t, msg.Time);
                }
                Assert.IsTrue(i > 2);
            }
        }
Пример #3
0
 public void TestIterateKeyValuePairs()
 {
     using (var file = new GribFile(Settings.SPHERICAL_PRESS_LVL)) {
         Assert.IsTrue(file.MessageCount > 0);
         Assert.IsTrue(file.First().Any());
     }
 }
Пример #4
0
 public void TestOpenComplex()
 {
     using (GribFile file = new GribFile(Settings.COMPLEX_GRID))
     {
         Assert.IsTrue(file.MessageCount > 0);
         foreach (var msg in file)
         {
             try
             {
                 Assert.IsTrue(msg["packingType"].AsString().ToLower().Contains("complex"));
                 Assert.IsTrue(msg.ValuesCount > 0);
                 double[] vals;
                 msg.Values(out vals);
                 Assert.IsTrue(vals.Any());
                 foreach (var v in vals)
                 {
                     Assert.AreNotEqual(Double.NaN, v);
                 }
             } catch (GribApiException e)
             {
                 Console.WriteLine(e.Message);
                 Console.WriteLine(msg.ShortName);
                 Console.WriteLine(msg.ToString());
                 Assert.IsTrue(false);
             }
         }
     }
 }
Пример #5
0
        public void TestOpenPng()
        {
            using (GribFile file = new GribFile(Settings.PNG_COMPRESSION))
            {
                Assert.IsTrue(file.MessageCount > 0);

                var msg = file.First();

                try
                {
                    Assert.IsTrue(msg["packingType"].AsString().ToLower().EndsWith("_png"));
                    Assert.IsTrue(msg.ValuesCount > 0);
                    Assert.IsTrue(msg.GeoSpatialValues.Any());
                    int i = 0;
                    foreach (var v in msg.GeoSpatialValues)
                    {
                        Assert.AreNotEqual(Double.NaN, v.Value);
                        if (i++ > 1000)
                        {
                            break;
                        }
                    }
                } catch (GribApiException e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(msg.ShortName);
                    Console.WriteLine(msg.ToString());
                    Assert.IsTrue(false);
                }
            }
        }
Пример #6
0
        public void TestGetParallel()
        {
            var files = new[] { Settings.REDUCED_LATLON_GRB2, Settings.BIN, Settings.COMPLEX_GRID, Settings.REG_LATLON_GRB1, Settings.GAUSS, Settings.PACIFIC_WIND };

            Parallel.ForEach(files, (path, s) =>
            {
                using (var file = new GribFile(path))
                {
                    Parallel.ForEach(file, (msg, s2) =>
                    {
                        if (msg.ShortName == "shww")
                        {
                            return;
                        }

                        try
                        {
                            foreach (var v in msg.GeoSpatialValues)
                            {
                                Assert.AreNotEqual(Double.NaN, v.Latitude);
                                Assert.AreNotEqual(Double.NaN, v.Longitude);
                                Assert.AreNotEqual(Double.NaN, v.Value);
                            }
                        } catch (GribApiException e)
                        {
                            Console.WriteLine(e.Message);
                            Console.WriteLine(msg.ShortName);
                            Console.WriteLine(msg.ToString());
                            Assert.IsTrue(false);
                        }
                    });
                }
            });
        }
Пример #7
0
        public void TestGetParallel()
        {
            var files = new[] { Settings.TIME, Settings.COMPLEX_GRID, Settings.PACIFIC_WIND, Settings.REDUCED_LATLON_GRB2, Settings.REG_GAUSSIAN_SURFACE_GRB2, Settings.GRIB };

            Parallel.ForEach(files, (path, s) =>
            {
                using (var file = new GribFile(path))
                {
                    Parallel.ForEach(file, (msg, s2) =>
                    {
                        if (!msg.HasBitmap)
                        {
                            return;
                        }

                        try
                        {
                            foreach (var v in msg.GridCoordinateValues)
                            {
                                Assert.AreNotEqual(Double.NaN, v.Latitude);
                                Assert.AreNotEqual(Double.NaN, v.Longitude);
                                Assert.AreNotEqual(Double.NaN, v.Value);
                            }
                        }
                        catch (GribApiException e)
                        {
                            Console.WriteLine(e.Message);
                            Console.WriteLine(msg.ParameterShortName);
                            Console.WriteLine(path);
                            Assert.IsTrue(false);
                        }
                    });
                }
            });
        }
Пример #8
0
        public void TestSetBitmap()
        {
            using (GribFile file = new GribFile(Settings.REG_LATLON_GRB1))
            {
                var msg = file.First();

                int numVals = 10;
                double[] vals = new double[numVals];  
                double val = 42;

                for(int i =0; i < numVals; i++)
                {
                    vals[i] = val;
                }

                msg.HasBitmap = true;
                msg.SetValues(vals);
                double[] vals2;
                msg.Values(out vals2);

                for (int i = 0; i < numVals; i++)
                {
                    Assert.AreEqual(vals[i], vals2[i]);
                    Assert.AreEqual(val, vals2[i]);
                }                
            }
        }
Пример #9
0
 public void TestDumpNoError()
 {
     using (GribFile file = new GribFile(Settings.REG_LATLON_GRB1))
     {
         var msg = file.First();
         msg.Dump();
     }
 }
Пример #10
0
		public void TestPrecision()
		{
			var file = new GribFile(Settings.REG_GAUSSIAN_SURFACE_GRB2);
			var msg = file.First();
			Assert.AreEqual(msg["bitsPerValue"].AsInt(), 14);
			msg.DecimalPrecision = 4;
			Assert.AreEqual(msg["bitsPerValue"].AsInt(), 20);
		}
Пример #11
0
 public void TestPrecision ()
 {
     var file = new GribFile(Settings.GAUSS);
     var msg = file.First();
     Assert.AreEqual(msg["bitsPerValue"].AsInt(), 13);
     msg.DecimalPrecision = 4;
     Assert.AreEqual(msg["bitsPerValue"].AsInt(), 20);
 }
Пример #12
0
        public void ParseLocalUseSection()
        {
            var gribFile = new GribFile(Common.TestFile);

            var localUse = gribFile.Records[0].LocalUse;

            Assert.True(localUse == null);
        }
Пример #13
0
 public void TestIterateKeyValuePairs ()
 {
     using(var file = new GribFile(Settings.BIN))
     {
         Assert.IsTrue(file.MessageCount > 0);
         Assert.IsTrue(file.First().Any());
     }
 }
Пример #14
0
 public void TestPrecision()
 {
     using (var file = new GribFile(Settings.REG_GAUSSIAN_SURFACE_GRB2)) {
         var msg = file.First();
         Assert.AreEqual(msg["bitsPerValue"].AsInt(), 14);
         msg.DecimalPrecision = 4;
         Assert.AreEqual(msg["bitsPerValue"].AsInt(), 20);
     }
 }
Пример #15
0
 public void TestUnexpectedFields2()
 {
     //if an exception is thrown one cause it there were messaged in the file we didn't expect
     using (GribFile file = new GribFile(@"..\..\TestFiles\unexpected_fields2.grib2"))
     {
         var rowList = GribUtilities.ParseNamGribFile(file);
         Assert.AreEqual(31313, rowList.Count, "Expected count to be equal to 31313");
     }
 }
Пример #16
0
        public void TestPrecision()
        {
            var file = new GribFile(Settings.GAUSS);
            var msg  = file.First();

            Assert.AreEqual(msg["bitsPerValue"].AsInt(), 13);
            msg.DecimalPrecision = 4;
            Assert.AreEqual(msg["bitsPerValue"].AsInt(), 20);
        }
Пример #17
0
 public void TestForecastTimeGreaterThan24()
 {
     //if an exception is thrown one cause it there were messaged in the file we didn't expect
     using (GribFile file = new GribFile(@"..\..\TestFiles\dateover12.grib2"))
     {
         var rowList = GribUtilities.ParseNamGribFile(file);
         Assert.AreEqual("20171130T84forecastHour00", rowList[0].PartitionKey, "Incorrect date processing accounting for incorrect hours");
         Assert.AreEqual(31313, rowList.Count, "Expected count to be equal to 31313");
     }
 }
Пример #18
0
        public void ParseIndicatorSection()
        {
            var gribFile = new GribFile(Common.TestFile);

            var indicator = gribFile.Records[0].Indicator;

            Assert.True(indicator.Discipline == Tables.Disciplines.Meteorological, "Discipline is not meteorological");
            Assert.True(indicator.Edition == 2, "GRIB Edition is not 2");
            Assert.True(indicator.Length == 644548, "GRIB File length is invalid");
        }
Пример #19
0
        public static List <string> DumpGribFile(GribFile file)
        {
            var returnList = new List <string>();

            foreach (GribMessage msg in file)
            {
                returnList.Add(msg.ParameterName + " ");
            }
            return(returnList);
        }
Пример #20
0
 public void TestSteographic()
 {
     using (GribFile file = new GribFile(Settings.STEREO)) {
         GribMessage msg = file.First();
         Assert.Greater(msg.ValuesCount, 1);
         foreach (GeoSpatialValue gs in msg.GeoSpatialValues)
         {
             Assert.Greater(gs.Latitude, 15);
         }
     }
 }
Пример #21
0
 public void TestNullFile()
 {
     try
     {
         using (GribFile file = new GribFile(null))
         {
             // shouldn't get here
             Assert.Fail();
         }
     }
     catch (ArgumentNullException) { }
 }
Пример #22
0
 public void TestOpenPng()
 {
     using (GribFile file = new GribFile(Settings.PNG_COMPRESSION))
     {
         Assert.IsTrue(file.MessageCount > 0);
         foreach (var msg in file)
         {
             Assert.IsTrue(msg["packingType"].AsString().ToLower().Contains("png"));
             Assert.IsTrue(msg.ValuesCount > 0);
         }
     }
 }
Пример #23
0
 public void TestOpenComplex ()
 {
     using (GribFile file = new GribFile(Settings.COMPLEX_GRID))
     {
         Assert.IsTrue(file.MessageCount > 0);
         foreach (var msg in file)
         {
             Assert.IsTrue(msg["packingType"].AsString().ToLower().Contains("complex"));
             Assert.IsTrue(msg.ValuesCount > 0);
         }
     }
 }
Пример #24
0
        public void TestGetNativeType()
        {
            using (GribFile file = new GribFile(Settings.REG_LATLON_GRB1)) {
                var msg = file.First();
                Assert.AreEqual(msg["packingType"].NativeType, GribValueType.String);
                Assert.AreEqual(msg["longitudeOfFirstGridPointInDegrees"].NativeType, GribValueType.Double);
                Assert.AreEqual(msg["numberOfPointsAlongAParallel"].NativeType, GribValueType.Int);
                Assert.AreEqual(msg["values"].NativeType, GribValueType.DoubleArray);

                // TODO: test other types
            }
        }
Пример #25
0
 public void TestExpectedFieldsSecondHour()
 {
     //if an exception is thrown one cause it there were messaged in the file we didn't expect
     using (GribFile file = new GribFile(@"..\..\TestFiles\expected_fields_hour2.grib2"))
     {
         var rowList = GribUtilities.ParseNamGribFile(file);
         Assert.AreEqual(31313, rowList.Count, "Expected count to be equal to 31313");
         var firstRow = rowList[0];
         Assert.AreEqual(Math.Round(firstRow.RH2mAboveGround.Value, 2), 76.8, "Expected first element returned to have RH at 2m of this value.");
         Assert.AreEqual(Math.Round(firstRow.UGRD10m.Value, 2), -1.15, "Expected first element returned to have UGRD at 10m of this value.");
     }
 }
Пример #26
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (GribFile grib = new GribFile(Server.MapPath("~/Content/reduced_latlon_surface.grib2")))
            {
                Text.Text = String.Format("There are {0} grib messages.\n", grib.MessageCount);

                foreach (var msg in grib)
                {
                    Text.Text = String.Format("   {0}\n", msg.ToString());
                }
            }
        }
Пример #27
0
        static void Main(string[] args)
        {
            var gr = new GribFile(args[0]);

            foreach (var message in gr)
            {
                var vals = message.GridCoordinateValues;
                Console.WriteLine($"Time: {message.Time}");
                Console.WriteLine($"Ref time: {message.ReferenceTime}");
                Console.WriteLine($"Param name: {message.ParameterName}");
            }
        }
Пример #28
0
 public void TestNonExistingFile()
 {
     try
     {
         using (GribFile file = new GribFile(string.Empty))
         {
             // shouldn't get here
             Assert.Fail();
         }
     }
     catch (FileNotFoundException) { }
 }
Пример #29
0
 public void TestForOffsetStepStart()
 {
     //if an exception is thrown one cause it there were messaged in the file we didn't expect
     using (GribFile file = new GribFile(@"..\..\TestFiles\checkfornullapcp.grib2"))
     {
         var rowList = GribUtilities.ParseNamGribFile(file);
         Assert.AreEqual(31313, rowList.Count, "Expected count to be equal to 31313");
         var secondRow = rowList[1];
         Assert.AreEqual(secondRow.APCPStepSize.Value, 11, "Incorrect step size.");
         Assert.AreEqual(Math.Round(secondRow.APCPSurface.Value, 4), .0625, "Incorrect APCPSurface value");
         Assert.AreEqual(secondRow.Date, new DateTime(2017, 12, 4, 23, 0, 0), "Incorrect date");
     }
 }
Пример #30
0
 public void TestGetCounts()
 {
     using (GribFile file = new GribFile(Settings.GRIB)) {
         Assert.IsTrue(file.MessageCount > 0);
         foreach (var msg in file)
         {
             Assert.AreNotEqual(msg.DataPointsCount, 0);
             Assert.AreNotEqual(msg.ValuesCount, 0);
             Assert.AreEqual(msg.ValuesCount, msg["numberOfCodedValues"].AsInt());
             Assert.IsTrue(msg["numberOfCodedValues"].IsReadOnly);
             Assert.AreEqual(msg.DataPointsCount, msg.ValuesCount + msg.MissingCount);
         }
     }
 }
Пример #31
0
 public void TestGetCounts()
 {
     using (GribFile file = new GribFile(Settings.GRIB))
     {
         Assert.IsTrue(file.MessageCount > 0);
         foreach(var msg in file)
         {
             Assert.AreNotEqual(msg.DataPointsCount, 0);
             Assert.AreNotEqual(msg.ValuesCount, 0);
             Assert.AreEqual(msg.ValuesCount, msg["numberOfCodedValues"].AsInt());
             Assert.IsTrue(msg["numberOfCodedValues"].IsReadOnly);
             Assert.AreEqual(msg.DataPointsCount, msg.ValuesCount + msg.MissingCount);
         }
     }
 }
Пример #32
0
        public void TestInvalidFiles()
        {
            try {
                using (GribFile file = new GribFile(Settings.BAD)) {
                    // shouldn't get here
                    Assert.IsTrue(false);
                }
            } catch (FileLoadException) { }

            try {
                using (GribFile file = new GribFile(Settings.EMPTY)) {
                    // shouldn't get here
                    Assert.IsTrue(false);
                }
            } catch (FileLoadException) { }
        }
Пример #33
0
            public void TestIterateLatLong()
            {
                using (var file = new GribFile(Settings.REDUCED_LATLON_GRB2)) {
                    Assert.IsTrue(file.MessageCount > 0);
                    foreach (var msg in file)
                    {
                        int c = msg.Count();

                        msg.Namespace = "geography";

                        Assert.AreNotEqual(c, msg.Count());

                        Assert.IsTrue(msg.GeoSpatialValues.Any());
                    }
                }
            }
Пример #34
0
		public void TestInvalidFiles()
		{
			try {
				using (GribFile file = new GribFile(Settings.BAD)) {
					// shouldn't get here
					Assert.IsTrue(false);
				}
			} catch (FileLoadException) { }

			try {
				using (GribFile file = new GribFile(Settings.EMPTY)) {
					// shouldn't get here
					Assert.IsTrue(false);
				}
			} catch (FileLoadException) { }
		}
Пример #35
0
 public void TesNearest()
 {
     using (var file = new GribFile(Settings.REDUCED_LATLON_GRB2))
     {
         Assert.IsTrue(file.MessageCount > 0);
         foreach (var msg in file)
         {
             var val     = msg.GridCoordinateValues.First();
             var nearest = msg.FindNearestCoordinates(val);
             Assert.IsTrue(nearest.Length == 4);
             foreach (var n in nearest)
             {
                 Assert.IsTrue(n.Value.Latitude >= 80 && n.Value.Latitude < 82);
             }
         }
     }
 }
Пример #36
0
 public void TestUnexpectedFields()
 {
     //if an exception is thrown one cause it there were messaged in the file we didn't expect
     using (GribFile file = new GribFile(@"..\..\TestFiles\unexpected_fields.grib2"))
     {
         try
         {
             var rowList = GribUtilities.ParseNamGribFile(file);
         }
         catch (Exception e)
         {
             Assert.IsInstanceOfType(e, typeof(NotSupportedException), "Didn't get the exception type we expected");
             return;
         }
         Assert.Fail("Expected to get an exception and we didn't");
     }
 }
Пример #37
0
        public void TestIterateLatLong ()
        {
            Console.WriteLine();

            using (var file = new GribFile(Settings.REDUCED_LATLON_GRB2))
            {
                Assert.IsTrue(file.MessageCount > 0);
                foreach (var msg in file)
                {
                    int c = msg.Count();

                    msg.Namespace = "geography";

                    Assert.AreNotEqual(c, msg.Count());

                    Assert.IsTrue(msg.GeoSpatialValues.Any());
                }
            }
        }
Пример #38
0
        public void TestEnumDisposal()
        {
            using (var file1 = new GribFile(Settings.COMPLEX_GRID))
                using (var file2 = new GribFile(Settings.TIME)) {
                    var msg1 = file1.First();
                    var msg2 = file2.First();

                    var msgEnumerator1 = msg1.GetEnumerator();
                    var msgEnumerator2 = msg2.GetEnumerator();
                    int i = 0;
                    while (msgEnumerator1.MoveNext() && msgEnumerator2.MoveNext())
                    {
                        i++;
                        Assert.IsNotEmpty(msgEnumerator1.Current.Key);
                        Assert.IsNotEmpty(msgEnumerator2.Current.Key);
                    }
                    Assert.IsTrue(i > 3);
                }
        }
Пример #39
0
        public void TestGetGrib2()
        {
            double delta = 0.1d;

            using (GribFile file = new GribFile(Settings.REDUCED_LATLON_GRB2))
            {
                var msg = file.First();

                // "InDegrees" is a magic token that converts coordinate double values to degrees
                // explicit degree conversion via key name
                double latitudeOfFirstGridPointInDegrees = msg["latitudeOfFirstGridPoint"].AsDouble();
                Assert.AreEqual(latitudeOfFirstGridPointInDegrees, 90, delta);

                // degree conversion via accessor
                double longitudeOfFirstGridPointInDegrees = msg["longitudeOfFirstGridPoint"].AsDouble();
                Assert.AreEqual(longitudeOfFirstGridPointInDegrees, 0, delta);

                // degree conversion via accessor
                double latitudeOfLastGridPointInDegrees = msg["latitudeOfLastGridPoint"].AsDouble();
                Assert.AreEqual(latitudeOfLastGridPointInDegrees, -90, delta);

                // degree conversion via accessor
                double longitudeOfLastGridPointInDegrees = msg["longitudeOfLastGridPoint"].AsDouble();
                Assert.AreEqual(longitudeOfLastGridPointInDegrees, 360, .5);

                // degree conversion via accessor
                double jDirectionIncrementInDegrees = msg["jDirectionIncrement"].AsDouble();
                Assert.AreEqual(jDirectionIncrementInDegrees, 0.36, delta);

                // degree conversion via accessor
                double iDirectionIncrementInDegrees = msg["iDirectionIncrement"].AsDouble();
                Assert.AreEqual(iDirectionIncrementInDegrees, -1.0E+100, delta);

                int numberOfPointsAlongAParallel = msg["numberOfPointsAlongAParallel"].AsInt();
                Assert.AreEqual(numberOfPointsAlongAParallel, 0x7FFFFFFF);

                int numberOfPointsAlongAMeridian = msg["numberOfPointsAlongAMeridian"].AsInt();
                Assert.AreEqual(numberOfPointsAlongAMeridian, 501);

                string packingType = msg["packingType"].AsString();
                Assert.AreEqual("grid_simple", packingType);
            }
        }
Пример #40
0
        public void TestWrite()
        {
            if (File.Exists(Settings.OUT_GRIB))
            {
                File.Delete(Settings.OUT_GRIB);
            }

            int count = 0;
            int valCount = 0;

            using (var readFile = new GribFile(Settings.PACIFIC_WIND))
            {
                var msg = readFile.First();
                Assert.AreNotEqual(33, msg["latitudeOfFirstGridPoint"].AsDouble());
                msg["latitudeOfFirstGridPoint"].AsDouble(33);
                valCount = msg.ValuesCount;
                GribFile.Write(Settings.OUT_GRIB, msg);
            }

            using (var readFile = new GribFile(Settings.OUT_GRIB))
            {
                var msg = readFile.First();
                count = readFile.MessageCount;
                Assert.AreEqual(valCount, msg.ValuesCount);
                Assert.AreEqual(count, readFile.MessageCount);
                Assert.AreEqual(33, msg["latitudeOfFirstGridPoint"].AsDouble());
            }

            using (var readFile = new GribFile(Settings.PACIFIC_WIND))
            {
                GribFile.Write(Settings.OUT_GRIB, readFile as IEnumerable<GribMessage>, FileMode.Append);
                count += readFile.MessageCount;
            }

            using (var readFile = new GribFile(Settings.OUT_GRIB))
            {
                Assert.AreEqual(count, readFile.MessageCount);
                Assert.AreEqual(33, readFile.First()["latitudeOfFirstGridPoint"].AsDouble());
            }
        }
Пример #41
0
        public void TestSetBitmapMissing ()
        {
            using (GribFile file = new GribFile(Settings.REG_LATLON_GRB1))
            {
                var msg = file.First();
                int missing = 3333;
                // set the value used to represent missing data
                msg.MissingValue = missing;
                Assert.AreEqual(msg.MissingValue, missing);
                Assert.IsFalse(msg.HasBitmap);

                int numVals = 10;
                double[] vals = new double[numVals];                

                for (int i = 0; i < numVals; i++)
                {
                    vals[i] = missing;
                }

                msg.HasBitmap = true;
                msg.SetValues(vals);
                double[] vals2;
                msg.Values(out vals2);

                for (int i = 0; i < numVals; i++)
                {
                    Assert.AreEqual(vals[i], vals2[i]);
                    Assert.AreEqual(missing, vals2[i]);
                }

                missing = 9898;
                msg.MissingValue = missing;
                msg.Values(out vals);

                for (int i = 0; i < numVals; i++)
                {
                    Assert.AreEqual(missing, vals[i]);
                }
            }
        }
Пример #42
0
        public void TestGetBox() 
        {
            using (GribFile file = new GribFile(Settings.GAUSS)) 
            {
                Assert.IsTrue(file.MessageCount > 0);
                foreach (var msg in file)
                {
                    var pts = msg.Box(new GeoCoordinate(60, -10), new GeoCoordinate(10, 30));
                    foreach (var val in pts.Latitudes)
                    {
                        Assert.GreaterOrEqual(60, val);
                        Assert.LessOrEqual(10, val);
                    }

                    foreach (var val in pts.Longitudes)
                    {
                        Assert.GreaterOrEqual(val, -10);
                        Assert.LessOrEqual(val, 30);
                    }
                }
            }
        }
Пример #43
0
		public void TestOpenComplex()
		{
			using (GribFile file = new GribFile(Settings.COMPLEX_GRID)) {
				Assert.IsTrue(file.MessageCount > 0);
				foreach (var msg in file) {
					try {
						Assert.IsTrue(msg["packingType"].AsString().ToLower().Contains("complex"));
						Assert.IsTrue(msg.ValuesCount > 0);
						double[] vals;
						msg.Values(out vals);
						Assert.IsTrue(vals.Any());
						foreach (var v in vals) {
							Assert.AreNotEqual(Double.NaN, v);
						}
					} catch (GribApiException e) {
						Console.WriteLine(e.Message);
						Console.WriteLine(msg.ShortName);
						Console.WriteLine(msg.ToString());
						Assert.IsTrue(false);
					}
				}
			}
		}
Пример #44
0
		public void TestOpenPng()
		{
			using (GribFile file = new GribFile(Settings.PNG_COMPRESSION)) {
				Assert.IsTrue(file.MessageCount > 0);

				var msg = file.First();

				try {
					Assert.IsTrue(msg["packingType"].AsString().ToLower().EndsWith("_png"));
					Assert.IsTrue(msg.ValuesCount > 0);
					Assert.IsTrue(msg.GeoSpatialValues.Any());
					int i = 0;
					foreach (var v in msg.GeoSpatialValues) {
						Assert.AreNotEqual(Double.NaN, v.Value);
						if (i++ > 1000) break;
					}
				} catch (GribApiException e) {
					Console.WriteLine(e.Message);
					Console.WriteLine(msg.ShortName);
					Console.WriteLine(msg.ToString());
					Assert.IsTrue(false);
				}
			}
		}
Пример #45
0
 public static void GribDumpActionTree(GribContext c, GribFile f) {
   GribApiProxyPINVOKE.GribDumpActionTree(c.Reference, f.Reference);
 }
Пример #46
0
        public void TestGetGrib2 ()
        {
            double delta = 0.1d;

            using (GribFile file = new GribFile(Settings.REDUCED_LATLON_GRB2))
            {
                var msg = file.First();

                // "InDegrees" is a magic token that converts coordinate double values to degrees
                // explicit degree conversion via key name
                double latitudeOfFirstGridPointInDegrees = msg["latitudeOfFirstGridPoint"].AsDouble();
                Assert.AreEqual(latitudeOfFirstGridPointInDegrees, 90, delta);

                // degree conversion via accessor
                double longitudeOfFirstGridPointInDegrees = msg["longitudeOfFirstGridPoint"].AsDouble(/* inDegrees == true */);
                Assert.AreEqual(longitudeOfFirstGridPointInDegrees, 0, delta);

                // degree conversion via accessor
                double latitudeOfLastGridPointInDegrees = msg["latitudeOfLastGridPoint"].AsDouble(/* inDegrees == true */);
                Assert.AreEqual(latitudeOfLastGridPointInDegrees, -90, delta);

                // degree conversion via accessor
                double longitudeOfLastGridPointInDegrees = msg["longitudeOfLastGridPoint"].AsDouble(/* inDegrees == true */);
                Assert.AreEqual(longitudeOfLastGridPointInDegrees, 360, .5);

                // degree conversion via accessor
                double jDirectionIncrementInDegrees = msg["jDirectionIncrement"].AsDouble(/* inDegrees == true */);
                Assert.AreEqual(jDirectionIncrementInDegrees, 0.36, delta);

                // degree conversion via accessor
                double iDirectionIncrementInDegrees = msg["iDirectionIncrement"].AsDouble(/* inDegrees == true */);
                Assert.AreEqual(iDirectionIncrementInDegrees, -1.0E+100, delta);

                int numberOfPointsAlongAParallel = msg["numberOfPointsAlongAParallel"].AsInt();
                Assert.AreEqual(numberOfPointsAlongAParallel, -1);

                int numberOfPointsAlongAMeridian = msg["numberOfPointsAlongAMeridian"].AsInt();
                Assert.AreEqual(numberOfPointsAlongAMeridian, 501);

                string packingType = msg["packingType"].AsString();
                Assert.AreEqual("grid_simple", packingType);             
            }
        }
Пример #47
0
        public void TestGetParallel ()
        {
            var files = new[] { Settings.REDUCED_LATLON_GRB2, Settings.BIN, Settings.COMPLEX_GRID, Settings.REG_LATLON_GRB1 };

            Parallel.ForEach(files, (path, s) =>
            {
                using (var file = new GribFile(path))
                {
                    Parallel.ForEach(file, (msg, s2) =>
                    {
                        try
                        {
                            if (!msg.GridType.ToLower().Contains("mercator") &&
                                !msg.ShortName.ToLower().Contains("shww"))
                            {
                                Assert.IsTrue(msg.GeoSpatialValues.Any());
                            }
                        } catch (GribApiException)
                        {
                            Console.WriteLine(path);
                            Console.WriteLine(msg.ShortName);
                            Console.WriteLine(msg.ToString());
                            Assert.IsTrue(false);
                        }
                    });

                }

            });
        }
Пример #48
0
        public void TestCanConvertToDegress ()
        {
            using (GribFile file = new GribFile(Settings.REDUCED_LATLON_GRB2))
            {
                var msg = file.First();

                // true
                Assert.IsTrue(msg["latitudeOfFirstGridPointInDegrees"].CanConvertToDegrees);
                Assert.IsTrue(msg["latitudeOfFirstGridPoint"].CanConvertToDegrees);
                Assert.IsTrue(msg["longitudeOfFirstGridPointInDegrees"].CanConvertToDegrees);
                Assert.IsTrue(msg["longitudeOfFirstGridPoint"].CanConvertToDegrees);
                Assert.IsTrue(msg["latitudeOfLastGridPointInDegrees"].CanConvertToDegrees);
                Assert.IsTrue(msg["latitudeOfLastGridPoint"].CanConvertToDegrees);
                Assert.IsTrue(msg["jDirectionIncrement"].CanConvertToDegrees);
                Assert.IsTrue(msg["iDirectionIncrement"].CanConvertToDegrees);

                // false
                Assert.IsFalse(msg["numberOfPointsAlongAParallel"].CanConvertToDegrees);
                Assert.IsFalse(msg["numberOfPointsAlongAParallelInDegrees"].CanConvertToDegrees);
                Assert.IsFalse(msg["numberOfPointsAlongAMeridian"].CanConvertToDegrees);
                Assert.IsFalse(msg["numberOfPointsAlongAMeridianInDegrees"].CanConvertToDegrees);
                Assert.IsFalse(msg["packingType"].CanConvertToDegrees);
            }
        }
Пример #49
0
		public void TestEnumDisposal ()
		{
			using (var file1 = new GribFile(Settings.COMPLEX_GRID))
			using (var file2 = new GribFile(Settings.TIME)) {
				var msg1 = file1.First();
				var msg2 = file2.First();

				var msgEnumerator1 = msg1.GetEnumerator();
				var msgEnumerator2 = msg2.GetEnumerator();
				int i = 0;
				while (msgEnumerator1.MoveNext() && msgEnumerator2.MoveNext()) {
					i++;
					Assert.IsNotEmpty(msgEnumerator1.Current.Key);
					Assert.IsNotEmpty(msgEnumerator2.Current.Key);
				}
				Assert.IsTrue(i > 3);
			}
		}
Пример #50
0
  public static void GribCountInFile(GribContext c, GribFile f, out int n) {
    int ret = GribApiProxyPINVOKE.GribCountInFile(c.Reference, f.Reference, out n);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
Пример #51
0
        public void TestCompression (string grid)
        {
            if (File.Exists(Settings.OUT_GRIB))
            {
                File.Delete(Settings.OUT_GRIB);
            }

            int count = 0;
            double val = Double.NaN;

            Dictionary<int, GeoSpatialValue> orig = new Dictionary<int, GeoSpatialValue>();

            using (var readFile = new GribFile(Settings.REDUCED_LATLON_GRB2))
            {
                var msg = readFile.First();
                count = msg.ValuesCount;
                val = msg["latitudeOfFirstGridPoint"].AsDouble();
                Assert.AreNotEqual(val, Double.NaN);
                Assert.AreNotEqual(msg["packingType"].AsString(), grid);

                {
                    for (int j = 0; j < 50; j++)
                    {
                        int k = 0;

                        do
                        {
                            // over 200k values, so only pick from a subset
                            k = GetRandomNumber(0, (count) / 20);
                        }
                        while (orig.ContainsKey(k));

                        orig.Add(k, new GeoSpatialValue());
                    }

                    int x = 0;
                    int y = 0;
                    foreach(var gsv in msg.GeoSpatialValues)
                    {
                        if (orig.ContainsKey(x))
                        {
                            orig[x] = gsv;
                            y++;
                            if (y == orig.Count) break;
                        }
                        x++;
                    }

                    Assert.IsTrue(y == orig.Count);
                    Assert.IsTrue(x > 0);
                }

                msg["packingType"].AsString(grid);
                Assert.AreEqual(msg["packingType"].AsString(), grid);
                Assert.AreEqual(count, msg.ValuesCount);
                Assert.AreEqual(val, msg["latitudeOfFirstGridPoint"].AsDouble());
                GribFile.Write(Settings.OUT_GRIB, msg);

                var newGsv = msg.GeoSpatialValues.ToArray();
                Assert.IsTrue(newGsv.Any());

                foreach (var kvp in orig)
                {
                    var nv = newGsv[kvp.Key];
                    Assert.AreEqual(kvp.Value.Value, nv.Value, 0.01);
                }
            }

            using (var readFile = new GribFile(Settings.OUT_GRIB))
            {
                var msg = readFile.First();
                Assert.AreEqual(count, msg.ValuesCount);
                Assert.AreEqual(val, msg["latitudeOfFirstGridPoint"].AsDouble());
                Assert.AreEqual(msg["packingType"].AsString(), grid);

                var newGsv = msg.GeoSpatialValues.ToArray();
                Assert.IsTrue(newGsv.Any());

                foreach (var kvp in orig)
                {
                    var nv = newGsv[kvp.Key];
                    Assert.AreEqual(kvp.Value.Value, nv.Value, 0.01);
                }
            }
        }
Пример #52
0
 public static void GribDumpContent(GribHandle h, GribFile arg1, string mode, uint option_flags, byte[] arg) {
   GribApiProxyPINVOKE.GribDumpContent(h.Reference, arg1.Reference, mode, option_flags, arg);
 }
Пример #53
0
  public static void GribMultiHandleWrite(SWIGTYPE_p_grib_multi_handle mh, GribFile f) {
    int ret = GribApiProxyPINVOKE.GribMultiHandleWrite(SWIGTYPE_p_grib_multi_handle.getCPtr(mh), f.Reference);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
Пример #54
0
  public static GribHandle EccodeGribNewFromFile(GribContext c, GribFile f, int headers_only, out int error) {
		System.IntPtr pVal = GribApiProxyPINVOKE.EccodeGribNewFromFile(c.Reference, f.Reference, headers_only, out error);

		return pVal == System.IntPtr.Zero ? null : new GribHandle(pVal);
	}
Пример #55
0
  public static byte[] WmoReadBufrFromFileMalloc(GribFile f, int headers_only, ref SizeT size, ref SizeT offset, out int err) {
    return GribApiProxyPINVOKE.WmoReadBufrFromFileMalloc(f.Reference, headers_only, ref  size.Value, ref  offset.Value, out err);
}
Пример #56
0
  public static void WmoReadGtsFromFile(GribFile f, byte[] buffer, ref SizeT len) {
    int ret = GribApiProxyPINVOKE.WmoReadGtsFromFile(f.Reference, buffer, ref  len.Value);
	
	if (ret != 0)
	{
		throw Grib.Api.Interop.GribApiException.Create(ret);
	}
  }
Пример #57
0
 public static void GribPrintApiVersion(GribFile arg0) {
   GribApiProxyPINVOKE.GribPrintApiVersion(arg0.Reference);
 }
Пример #58
0
        public void TestGetNativeType()
        {
            using (GribFile file = new GribFile(Settings.REG_LATLON_GRB1))
            {
                var msg = file.First();
                Assert.AreEqual(msg["packingType"].NativeType, GribValueType.String);
                Assert.AreEqual(msg["longitudeOfFirstGridPointInDegrees"].NativeType, GribValueType.Double);
                Assert.AreEqual(msg["numberOfPointsAlongAParallel"].NativeType, GribValueType.Int);
                Assert.AreEqual(msg["values"].NativeType, GribValueType.DoubleArray);

                // TODO: test other types
            }
        }
Пример #59
0
        private List<WaveWindModel> WaveParsing(string path)
        {
            //string path = @"D:\NOAA 데이터\" + fileNameBox.Text +".grib2";

            //using (GribFile file = new GribFile(@"D:\NOAA 데이터\2015020106.grib2"))

            using (GribFile file = new GribFile(path))

            {
                file.Context.EnableMultipleFieldMessages = true;

                DateTime UTC;
                double[] LAT = { };
                double[] LONG = { };
                double[] ICEC = { };
                double[] SWDIR_Seq1 = { };
                double[] SWDIR_Seq2 = { };
                double[] WVDIR = { };
                double[] MWSPER = { };
                double[] SWPER_Seq1 = { };
                double[] SWPER_Seq2 = { };
                double[] WVPER = { };
                double[] DIRPW = { };
                double[] PERPW = { };
                double[] DIRSW = { };
                double[] PERSW = { };
                double[] HTSGW = { };
                double[] SWELL_Seq1 = { };
                double[] SWELL_Seq2 = { };
                double[] WVHGT = { };
                double[] UGRD = { };
                double[] VGRD = { };
                double[] WDIR = { };
                double[] WIND = { };

                List<GribMessage> WaveWind = new List<GribMessage>();

                foreach (GribMessage item in file)
                {
                    if (item.StepRange != "0")
                    {
                        break;
                    }

                    WaveWind.Add(item);
                }

                UTC = WaveWind.ElementAt(1).Time;
                LAT = WaveWind.ElementAt(1).GeoSpatialValues.Select(d => d.Latitude).ToArray();
                LONG = WaveWind.ElementAt(1).GeoSpatialValues.Select(d => d.Longitude).ToArray();
                //WaveWind.ElementAt(4).Values(out ICEC);

                WaveWind.ElementAt(16).Values(out SWDIR_Seq1);
                WaveWind.ElementAt(17).Values(out SWDIR_Seq2);

                WaveWind.ElementAt(7).Values(out WVDIR);
                //WaveWind.ElementAt(6).Values(out MWSPER);
                WaveWind.ElementAt(13).Values(out SWPER_Seq1);
                WaveWind.ElementAt(14).Values(out SWPER_Seq2);

                WaveWind.ElementAt(5).Values(out WVPER);
                WaveWind.ElementAt(8).Values(out DIRPW);
                WaveWind.ElementAt(6).Values(out PERPW);
                WaveWind.ElementAt(15).Values(out DIRSW);
                WaveWind.ElementAt(12).Values(out PERSW);
                WaveWind.ElementAt(4).Values(out HTSGW);
                WaveWind.ElementAt(10).Values(out SWELL_Seq1);
                WaveWind.ElementAt(11).Values(out SWELL_Seq2);

                WaveWind.ElementAt(9).Values(out WVHGT);
                WaveWind.ElementAt(2).Values(out UGRD);
                WaveWind.ElementAt(3).Values(out VGRD);
                WaveWind.ElementAt(1).Values(out WDIR);
                WaveWind.ElementAt(0).Values(out WIND);

                List<WaveWindModel> wavedataout = new List<WaveWindModel> { };

                for (int i = 0; i < LAT.Length; i++)
                {
                    wavedataout.Add(new WaveWindModel
                    {
                        UTC = UTC,
                        lat = LAT[i],
                        lon = LONG[i],
                        //ICEC = ICEC[i],
                        SWDIR_Seq1 = SWDIR_Seq1[i],
                        SWDIR_Seq2 = SWDIR_Seq2[i],
                        WVDIR = WVDIR[i],
                        //MWSPER = MWSPER[i],
                        SWPER_Seq1 = SWPER_Seq1[i],
                        SWPER_Seq2 = SWPER_Seq2[i],
                        WVPER = WVPER[i],
                        DIRPW = DIRPW[i],
                        PERPW = PERPW[i],
                        DIRSW = DIRSW[i],
                        PERSW = PERSW[i],
                        HTSGW = HTSGW[i],
                        SWELL_Seq1 = SWELL_Seq1[i],
                        SWELL_Seq2 = SWELL_Seq2[i],
                        WVHGT = WVHGT[i],
                        UGRD = UGRD[i],
                        VGRD = VGRD[i],
                        WDIR = WDIR[i],
                        WIND = WIND[i]
                    });
                }

                return wavedataout;
            }
        }
Пример #60
0
 public static void GribMultiSupportResetFile(GribContext c, GribFile f) {
   GribApiProxyPINVOKE.GribMultiSupportResetFile(c.Reference, f.Reference);
 }