Beispiel #1
0
        public void MagneticVariationCalculationCacheTest()
        {
            var point1 = new CoordinatePoint(Latitude.FromDegrees(60.12345888), Longitude.FromDegrees(30.12345888));

            var watch           = Stopwatch.StartNew();
            var point1Variation = MagneticVariation.GetMagneticVariation(point1, 6, 0, DateTimeOffset.UtcNow,
                                                                         MagneticVariation.MagneticVariationModels.WMM2015, out _);

            watch.Stop();

            var elapsed1 = watch.Elapsed;

            point1Variation = MagneticVariation.GetMagneticVariation(point1, 6, 0, DateTimeOffset.UtcNow,
                                                                     MagneticVariation.MagneticVariationModels.WMM2015, out _);
            point1Variation = MagneticVariation.GetMagneticVariation(point1, 6, 0, DateTimeOffset.UtcNow,
                                                                     MagneticVariation.MagneticVariationModels.WMM2015, out _);
            point1Variation = MagneticVariation.GetMagneticVariation(point1, 6, 0, DateTimeOffset.UtcNow,
                                                                     MagneticVariation.MagneticVariationModels.WMM2015, out _);

            watch.Restart();
            point1Variation = MagneticVariation.GetMagneticVariation(point1, 6, 0, DateTimeOffset.UtcNow,
                                                                     MagneticVariation.MagneticVariationModels.WMM2015, out _);
            watch.Stop();

            var elapsed2 = watch.Elapsed;

            // first run takes more time
            Assert.IsTrue(elapsed1 > elapsed2);
        }
Beispiel #2
0
        public void GetMagneticVariationTest()
        {
            var julianDay = new DateTimeOffset(2017, 09, 16, 00, 00, 00, TimeSpan.Zero);

            //expected values from windows gui app https://www.ngdc.noaa.gov/geomag/WMM/wmm_gdownload.shtml
            var lat1 = 60 * _toRadians;
            var lon1 = 30 * _toRadians;
            var point1ExpectedDecination = 10.65 * _toRadians;

            Assert.AreEqual(point1ExpectedDecination,
                            MagneticVariation.GetMagneticVariation(lat1, lon1, 0, julianDay, MagneticVariation.MagneticVariationModels.WMM2015, out _), 0.0001d);

            var lat2 = -30 * _toRadians;
            var lon2 = 130 * _toRadians;
            var point2ExpectedDecination = 3.95 * _toRadians;

            Assert.AreEqual(point2ExpectedDecination,
                            MagneticVariation.GetMagneticVariation(lat2, lon2, 0, julianDay, MagneticVariation.MagneticVariationModels.WMM2015, out _), 0.0001d);

            var lat3 = 40 * _toRadians;
            var lon3 = -70 * _toRadians;
            var point3ExpectedDecination = -14.5 * _toRadians;

            Assert.AreEqual(point3ExpectedDecination,
                            MagneticVariation.GetMagneticVariation(lat3, lon3, 0, julianDay, MagneticVariation.MagneticVariationModels.WMM2015, out _), 0.0001d);

            var lat4 = -50 * _toRadians;
            var lon4 = -170 * _toRadians;
            var point4ExpectedDecination = 31.04 * _toRadians;

            Assert.AreEqual(point4ExpectedDecination,
                            MagneticVariation.GetMagneticVariation(lat4, lon4, 0, julianDay, MagneticVariation.MagneticVariationModels.WMM2015, out _), 0.0001d);
        }
Beispiel #3
0
            public static MagneticVariation FromStrings(string deg, string direct)
            {
                MagneticVariation mv = new MagneticVariation();

                //TODO: hack for empty value
                if (direct == "")
                {
                    direct = "U";
                }

                mv.degrees   = Util.NullableDouble(deg);
                mv.direction = Enum.GetValues(typeof(Direction)).Cast <Direction>().FirstOrDefault(a => (char)a == direct[0]);

                return(mv);
            }
Beispiel #4
0
        public GprmcData(string[] sa)
        {
            head = "GPRMC";
            string times      = sa[1];
            string navWarning = sa[2];

            latitude                  = new Latitude(sa[3], sa[4]);
            longitude                 = new Longitude(sa[5], sa[6]);
            speedOverGroundKnots      = Convert.ToDouble(sa[7]);
            courseMadeGoodDegreesTrue = Convert.ToDouble(sa[8]);
            string date = sa[9];
            string mode = sa[12];

            warning           = Enum.GetValues(typeof(NavigationReceiverWarning)).Cast <NavigationReceiverWarning>().FirstOrDefault(a => (char)a == navWarning[0]);
            magneticVariation = MagneticVariation.FromStrings(sa[10], sa[11]);
            dateTime          = Util.DateTimeFromString(date, times);
            modeIndicator     = Enum.GetValues(typeof(ModeIndicator)).Cast <ModeIndicator>().FirstOrDefault(a => (char)a == mode[0]);
        }
Beispiel #5
0
        public void CoordinatesRoundingAndMagVarCalculationTest()
        {
            var point1 = new CoordinatePoint(Latitude.FromDegrees(60.12345888), Longitude.FromDegrees(30.12345888));
            var point2 = new CoordinatePoint(Latitude.FromDegrees(60.12345666), Longitude.FromDegrees(30.12345666));

            var point1Variation = MagneticVariation.GetMagneticVariation(point1, 6, 0, DateTimeOffset.UtcNow,
                                                                         MagneticVariation.MagneticVariationModels.WMM2015, out _);
            var point2Variation = MagneticVariation.GetMagneticVariation(point2, 6, 0, DateTimeOffset.UtcNow,
                                                                         MagneticVariation.MagneticVariationModels.WMM2015, out _);

            Assert.AreNotEqual(point1Variation, point2Variation);

            point1Variation = MagneticVariation.GetMagneticVariation(point1, 5, 0, DateTimeOffset.UtcNow,
                                                                     MagneticVariation.MagneticVariationModels.WMM2015, out _);
            point2Variation = MagneticVariation.GetMagneticVariation(point2, 5, 0, DateTimeOffset.UtcNow,
                                                                     MagneticVariation.MagneticVariationModels.WMM2015, out _);

            Assert.AreEqual(point1Variation, point2Variation);
        }
Beispiel #6
0
        public void GetMagneticVariationTest2()
        {
            // expected values from https://www.ngdc.noaa.gov/geomag/WMM/data/WMM2015/WMM2015_Report.pdf, page 20

            var date1  = new DateTimeOffset(2015, 1, 1, 0, 0, 0, 0, TimeSpan.Zero);
            var point1 = new CoordinatePoint(Latitude.FromDegrees(80), Longitude.FromDegrees(0));

            var point1ExpectedDecination = -3.85 * _toRadians;

            Assert.AreEqual(point1ExpectedDecination,
                            MagneticVariation.GetMagneticVariation(point1, 5, 0, date1, MagneticVariation.MagneticVariationModels.WMM2015
                                                                   , out _), 0.00002d);


            var date2  = new DateTimeOffset(2015, 1, 1, 0, 0, 0, 0, TimeSpan.Zero);
            var point2 = new CoordinatePoint(Latitude.FromDegrees(0), Longitude.FromDegrees(120));

            var point2ExpectedDecination = 0.57 * _toRadians;

            Assert.AreEqual(point2ExpectedDecination,
                            MagneticVariation.GetMagneticVariation(point2, 5, 0, date2, MagneticVariation.MagneticVariationModels.WMM2015
                                                                   , out _), 0.00001d);
        }