1 /**
2 * \file NETGeographicLib/MagneticCircle.cpp
3 * \brief Implementation for NETGeographicLib::MagneticCircle class
4 *
5 * NETGeographicLib is copyright (c) Scott Heiman (2013)
6 * GeographicLib is Copyright (c) Charles Karney (2010-2012)
7 * <charles@karney.com> and licensed under the MIT/X11 License.
8 * For more information, see
9 * https://geographiclib.sourceforge.io/
10 **********************************************************************/
11 #include "stdafx.h"
12 #include "GeographicLib/MagneticCircle.hpp"
13 #include "MagneticCircle.h"
14 #include "NETGeographicLib.h"
15
16 using namespace NETGeographicLib;
17
18 //*****************************************************************************
19 MagneticCircle::!MagneticCircle(void)
20 {
21 if ( m_pMagneticCircle != NULL )
22 {
23 delete m_pMagneticCircle;
24 m_pMagneticCircle = NULL;
25 }
26 }
27
28 //*****************************************************************************
MagneticCircle(const GeographicLib::MagneticCircle & c)29 MagneticCircle::MagneticCircle( const GeographicLib::MagneticCircle& c )
30 {
31 try
32 {
33 m_pMagneticCircle = new GeographicLib::MagneticCircle( c );
34 }
35 catch ( std::bad_alloc )
36 {
37 throw gcnew GeographicErr( "Failed to allocate memory for a GeographicLib::MagneticCircle" );
38 }
39 }
40
41 //*****************************************************************************
42 void MagneticCircle::Field(double lon,
43 [System::Runtime::InteropServices::Out] double% Bx,
44 [System::Runtime::InteropServices::Out] double% By,
45 [System::Runtime::InteropServices::Out] double% Bz)
46 {
47 double lx, ly, lz;
48 m_pMagneticCircle->operator()( lon, lx, ly, lz );
49 Bx = lx;
50 By = ly;
51 Bz = lz;
52 }
53
54 //*****************************************************************************
55 void MagneticCircle::Field(double lon,
56 [System::Runtime::InteropServices::Out] double% Bx,
57 [System::Runtime::InteropServices::Out] double% By,
58 [System::Runtime::InteropServices::Out] double% Bz,
59 [System::Runtime::InteropServices::Out] double% Bxt,
60 [System::Runtime::InteropServices::Out] double% Byt,
61 [System::Runtime::InteropServices::Out] double% Bzt)
62 {
63 double lx, ly, lz, lxt, lyt, lzt;
64 m_pMagneticCircle->operator()( lon, lx, ly, lz, lxt, lyt, lzt );
65 Bx = lx;
66 By = ly;
67 Bz = lz;
68 Bxt = lxt;
69 Byt = lyt;
70 Bzt = lzt;
71 }
72
73 //*****************************************************************************
get()74 double MagneticCircle::EquatorialRadius::get()
75 {
76 if ( m_pMagneticCircle->Init() )
77 return m_pMagneticCircle->EquatorialRadius();
78 throw gcnew GeographicErr("MagneticCircle::EquatorialRadius failed because the MagneticCircle is not initialized.");
79 }
80
81 //*****************************************************************************
get()82 double MagneticCircle::Flattening::get()
83 {
84 if ( m_pMagneticCircle->Init() )
85 return m_pMagneticCircle->Flattening();
86 throw gcnew GeographicErr("MagneticCircle::Flattening failed because the MagneticCircle is not initialized.");
87 }
88
89 //*****************************************************************************
get()90 double MagneticCircle::Latitude::get()
91 {
92 if ( m_pMagneticCircle->Init() )
93 return m_pMagneticCircle->Latitude();
94 throw gcnew GeographicErr("MagneticCircle::Latitude failed because the MagneticCircle is not initialized.");
95 }
96
97 //*****************************************************************************
get()98 double MagneticCircle::Height::get()
99 {
100 if ( m_pMagneticCircle->Init() )
101 return m_pMagneticCircle->Height();
102 throw gcnew GeographicErr("MagneticCircle::Height failed because the MagneticCircle is not initialized.");
103 }
104
105 //*****************************************************************************
get()106 double MagneticCircle::Time::get()
107 {
108 if ( m_pMagneticCircle->Init() )
109 return m_pMagneticCircle->Height();
110 throw gcnew GeographicErr("MagneticCircle::Height failed because the MagneticCircle is not initialized.");
111 }
112
113 //*****************************************************************************
get()114 bool MagneticCircle::Init::get() { return m_pMagneticCircle->Init(); }
115