public void Test_Evaluate(double t, string c, double h,
                                  double D_, double I_, double H_, double By_, double Bx_, double Bz_, double F_,
                                  double Dt_, double It_, double Ht_, double Byt_, double Bxt_, double Bzt_, double Ft_)
        {
            var tolerance = 1e-10;
            var coord     = new GeoCoords(c);

            var model = new MagneticModel("wmm2020",
                                          Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "magnetic"));

            var(Bx, By, Bz) = model.Evaluate(t, coord.Latitude, coord.Longitude, h, out var Bxt, out var Byt, out var Bzt);

            var(H, F, D, I) = MagneticModel.FieldComponents(Bx, By, Bz, Bxt, Byt, Bzt,
                                                            out var Ht, out var Ft, out var Dt, out var It);

            Assert.AreEqual(D_, D, tolerance);
            Assert.AreEqual(I_, I, tolerance);
            Assert.AreEqual(H_, H, tolerance);
            Assert.AreEqual(By_, By, tolerance);
            Assert.AreEqual(Bx_, Bx, tolerance);
            Assert.AreEqual(Bz_, -Bz, tolerance);
            Assert.AreEqual(F_, F, tolerance);

            Assert.AreEqual(Dt_, Dt, tolerance);
            Assert.AreEqual(It_, It, tolerance);
            Assert.AreEqual(Ht_, Ht, tolerance);
            Assert.AreEqual(Byt_, Byt, tolerance);
            Assert.AreEqual(Bxt_, Bxt, tolerance);
            Assert.AreEqual(Bzt_, -Bzt, tolerance);
            Assert.AreEqual(Ft_, Ft, tolerance);
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     try {
         MagneticModel mag = new MagneticModel("wmm2010", "");
         double        lat = 27.99, lon0 = 86.93, h = 8820, t = 2012; // Mt Everest
         {
             // Slow method of evaluating the values at several points on a circle of
             // latitude.
             for (int i = -5; i <= 5; ++i)
             {
                 double lon = lon0 + i * 0.2;
                 double Bx, By, Bz;
                 mag.Field(t, lat, lon, h, out Bx, out By, out Bz);
                 Console.WriteLine(String.Format("{0} {1} {2} {3}", lon, Bx, By, Bz));
             }
         }
         {
             // Fast method of evaluating the values at several points on a circle of
             // latitude using MagneticCircle.
             MagneticCircle circ = mag.Circle(t, lat, h);
             for (int i = -5; i <= 5; ++i)
             {
                 double lon = lon0 + i * 0.2;
                 double Bx, By, Bz;
                 circ.Field(lon, out Bx, out By, out Bz);
                 Console.WriteLine(String.Format("{0} {1} {2} {3}", lon, Bx, By, Bz));
             }
         }
     }
     catch (GeographicErr e) {
         Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
     }
 }
        private void OnSelectMagneticModel(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter     = "Magnetic Model (*.wmm)|*.wmm";
            dlg.DefaultExt = "wmm";

            if (dlg.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            m_path = dlg.FileName.Substring(0, dlg.FileName.LastIndexOf('\\')).Replace('\\', '/');
            int length = dlg.FileName.LastIndexOf('.') - dlg.FileName.LastIndexOf('\\') - 1;

            m_name = dlg.FileName.Substring(dlg.FileName.LastIndexOf('\\') + 1, length);

            try
            {
                m_magnetic = new MagneticModel(m_name, m_path);
                m_magneticModelNameTextBox.Text = dlg.FileName;
                m_nameTextBox.Text        = m_magnetic.MagneticModelName;
                m_descriptionTextBox.Text = m_magnetic.Description;
                m_dateTextBox.Text        = m_magnetic.DateTime;
                m_updateButton.Enabled    = true;
                m_magCircButton.Enabled   = true;
                m_validateButton.Enabled  = true;
            }
            catch (Exception xcpt)
            {
                MessageBox.Show(xcpt.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #4
0
        private void OnValidate(object sender, EventArgs e)
        {
            try
            {
                double bx, by, bz, bxt, byt, bzt, x, y, z;
                double time = 1.0;
                double lon  = -86.0;
                double lat  = 32.0;
                double alt  = 30.0;

                MagneticModel mag = new MagneticModel(m_name, m_path, new Geocentric());
                mag = new MagneticModel(m_name, m_path);
                mag.Field(time, lat, lon, alt, out bx, out by, out bz, out bxt, out byt, out bzt);
                mag.Field(time, lat, lon, alt, out x, out y, out z);
                if (bx != x || by != y || bz != z)
                {
                    throw new Exception("Error in MagneticField.Field");
                }
                MagneticCircle mc = mag.Circle(time, lat, alt);
                mc.Field(lon, out bx, out by, out bz);
                mc.Field(lon, out x, out y, out z, out bxt, out byt, out bzt);
                if (bx != x || by != y || bz != z)
                {
                    throw new Exception("Error in MagneticCircle.Field (2)");
                }

                MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception xcpt)
            {
                MessageBox.Show(xcpt.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 static void Main(string[] args)
 {
     try {
         MagneticModel mag = new MagneticModel("wmm2010","");
         double lat = 27.99, lon0 = 86.93, h = 8820, t = 2012; // Mt Everest
         {
             // Slow method of evaluating the values at several points on a circle of
             // latitude.
             for (int i = -5; i <= 5; ++i) {
                 double lon = lon0 + i * 0.2;
                 double Bx, By, Bz;
                 mag.Field(t, lat, lon, h, out Bx, out By, out Bz);
                 Console.WriteLine(String.Format("{0} {1} {2} {3}", lon, Bx, By, Bz));
             }
         }
         {
             // Fast method of evaluating the values at several points on a circle of
             // latitude using MagneticCircle.
             MagneticCircle circ = mag.Circle(t, lat, h);
             for (int i = -5; i <= 5; ++i) {
                 double lon = lon0 + i * 0.2;
                 double Bx, By, Bz;
                 circ.Field(lon, out Bx, out By, out Bz);
                 Console.WriteLine(String.Format("{0} {1} {2} {3}", lon, Bx, By, Bz));
             }
         }
     }
     catch (GeographicErr e) {
         Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
     }
 }
        public void Test_LoadModel_EMM2017()
        {
            var model = new MagneticModel("emm2017",
                                          Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "magnetic"));

            Assert.AreEqual("Enhanced Magnetic Model 2017", model.Description);
            Assert.AreEqual(DateTime.Parse("2017-07-05"), model.DateTime);
            Assert.AreEqual("emm2017", model.MagneticModelName);
            Assert.AreEqual(2000, model.MinTime);
            Assert.AreEqual(2022, model.MaxTime);
            Assert.AreEqual(-20000, model.MinHeight);
            Assert.AreEqual(10000000, model.MaxHeight);
        }
        public void Test_LoadModel()
        {
            var model = new MagneticModel("wmm2020",
                                          Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "magnetic"));

            Assert.AreEqual("World Magnetic Model 2020", model.Description);
            Assert.AreEqual(DateTime.Parse("2019-12-10"), model.DateTime);
            Assert.AreEqual("wmm2020", model.MagneticModelName);
            Assert.AreEqual(2020, model.MinTime);
            Assert.AreEqual(2025, model.MaxTime);
            Assert.AreEqual(-1000, model.MinHeight);
            Assert.AreEqual(850000, model.MaxHeight);
        }
 static void Main(string[] args)
 {
     try {
         MagneticModel mag = new MagneticModel("wmm2010","");
         double lat = 27.99, lon = 86.93, h = 8820, t = 2012; // Mt Everest
         double Bx, By, Bz;
         mag.Field(t, lat,lon, h, out Bx, out By, out Bz);
         double H, F, D, I;
         MagneticModel.FieldComponents(Bx, By, Bz, out H, out F, out D, out I);
         Console.WriteLine(String.Format("{0} {1} {2} {3}", H, F, D, I));
     }
     catch (GeographicErr e) {
         Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
     }
 }
Beispiel #9
0
 static void Main(string[] args)
 {
     try {
         MagneticModel mag = new MagneticModel("wmm2010", "");
         double        lat = 27.99, lon = 86.93, h = 8820, t = 2012; // Mt Everest
         double        Bx, By, Bz;
         mag.Field(t, lat, lon, h, out Bx, out By, out Bz);
         double H, F, D, I;
         MagneticModel.FieldComponents(Bx, By, Bz, out H, out F, out D, out I);
         Console.WriteLine(String.Format("{0} {1} {2} {3}", H, F, D, I));
     }
     catch (GeographicErr e) {
         Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
     }
 }
Beispiel #10
0
        private void OnSelectMagneticModel(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Magnetic Model (*.wmm)|*.wmm";
            dlg.DefaultExt = "wmm";

            if (dlg.ShowDialog() == DialogResult.Cancel) return;

            m_path = dlg.FileName.Substring(0, dlg.FileName.LastIndexOf('\\')).Replace('\\', '/');
            int length = dlg.FileName.LastIndexOf('.') - dlg.FileName.LastIndexOf('\\') - 1;
            m_name = dlg.FileName.Substring(dlg.FileName.LastIndexOf('\\') + 1, length);

            try
            {
                m_magnetic = new MagneticModel(m_name, m_path);
                m_magneticModelNameTextBox.Text = dlg.FileName;
                m_nameTextBox.Text = m_magnetic.MagneticModelName;
                m_descriptionTextBox.Text = m_magnetic.Description;
                m_dateTextBox.Text = m_magnetic.DateTime;
                m_updateButton.Enabled = true;
                m_magCircButton.Enabled = true;
                m_validateButton.Enabled = true;
            }
            catch (Exception xcpt)
            {
                MessageBox.Show(xcpt.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #11
0
        private void OnValidate(object sender, EventArgs e)
        {
            try
            {
                double bx, by, bz, bxt, byt, bzt, x, y, z;
                double time = 1.0;
                double lon = -86.0;
                double lat = 32.0;
                double alt = 30.0;

                MagneticModel mag = new MagneticModel(m_name, m_path, new Geocentric());
                mag = new MagneticModel(m_name, m_path);
                mag.Field(time, lat, lon, alt, out bx, out by, out bz, out bxt, out byt, out bzt);
                mag.Field(time, lat, lon, alt, out x, out y, out z);
                if (bx != x || by != y || bz != z)
                    throw new Exception("Error in MagneticField.Field");
                MagneticCircle mc = mag.Circle(time, lat, alt);
                mc.Field(lon, out bx, out by, out bz);
                mc.Field(lon, out x, out y, out z, out bxt, out byt, out bzt);
                if (bx != x || by != y || bz != z )
                    throw new Exception("Error in MagneticCircle.Field (2)");

                MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception xcpt)
            {
                MessageBox.Show(xcpt.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }