1 /**
2  * \file NETGeographicLib/GravityCircle.cpp
3  * \brief Implementation for NETGeographicLib::GravityCircle 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/GravityCircle.hpp"
13 #include "GravityModel.h"
14 #include "GravityCircle.h"
15 #include "NETGeographicLib.h"
16 
17 using namespace NETGeographicLib;
18 
19 //*****************************************************************************
20 GravityCircle::!GravityCircle(void)
21 {
22     if ( m_pGravityCircle != NULL )
23     {
24         delete m_pGravityCircle;
25         m_pGravityCircle = NULL;
26     }
27 }
28 
29 //*****************************************************************************
GravityCircle(const GeographicLib::GravityCircle & gc)30 GravityCircle::GravityCircle( const GeographicLib::GravityCircle& gc )
31 {
32     try
33     {
34         m_pGravityCircle = new GeographicLib::GravityCircle(gc);
35     }
36     catch ( std::bad_alloc )
37     {
38         throw gcnew GeographicErr( "Failed to allocate memory for a GeographicLib::GravityCircle" );
39     }
40 }
41 
42 //*****************************************************************************
43 double GravityCircle::Gravity(double lon,
44     [System::Runtime::InteropServices::Out] double% gx,
45     [System::Runtime::InteropServices::Out] double% gy,
46     [System::Runtime::InteropServices::Out] double% gz)
47 {
48     double lgx, lgy, lgz;
49     double out = m_pGravityCircle->Gravity( lon, lgx, lgy, lgz );
50     gx = lgx;
51     gy = lgy;
52     gz = lgz;
53     return out;
54 }
55 
56 //*****************************************************************************
57 double GravityCircle::Disturbance(double lon,
58     [System::Runtime::InteropServices::Out] double% deltax,
59     [System::Runtime::InteropServices::Out] double% deltay,
60     [System::Runtime::InteropServices::Out] double% deltaz)
61 {
62     double ldeltax, ldeltay, ldeltaz;
63     double out = m_pGravityCircle->Disturbance( lon, ldeltax, ldeltay, ldeltaz );
64     deltax = ldeltax;
65     deltay = ldeltay;
66     deltaz = ldeltaz;
67     return out;
68 }
69 
70 //*****************************************************************************
GeoidHeight(double lon)71 double GravityCircle::GeoidHeight(double lon)
72 {
73     return m_pGravityCircle->GeoidHeight( lon );
74 }
75 
76 //*****************************************************************************
77 void GravityCircle::SphericalAnomaly(double lon,
78     [System::Runtime::InteropServices::Out] double% Dg01,
79     [System::Runtime::InteropServices::Out] double% xi,
80     [System::Runtime::InteropServices::Out] double% eta)
81 {
82     double lDg01, lxi, leta;
83     m_pGravityCircle->SphericalAnomaly( lon, lDg01, lxi, leta );
84     Dg01 = lDg01;
85     xi = lxi;
86     eta = leta;
87 }
88 
89 //*****************************************************************************
90 double GravityCircle::W(double lon,
91     [System::Runtime::InteropServices::Out] double% gX,
92     [System::Runtime::InteropServices::Out] double% gY,
93     [System::Runtime::InteropServices::Out] double% gZ)
94 {
95     double lgx, lgy, lgz;
96     double out = m_pGravityCircle->W( lon, lgx, lgy, lgz );
97     gX = lgx;
98     gY = lgy;
99     gZ = lgz;
100     return out;
101 }
102 
103 //*****************************************************************************
104 double GravityCircle::V(double lon,
105     [System::Runtime::InteropServices::Out] double% GX,
106     [System::Runtime::InteropServices::Out] double% GY,
107     [System::Runtime::InteropServices::Out] double% GZ)
108 {
109     double lgx, lgy, lgz;
110     double out = m_pGravityCircle->V( lon, lgx, lgy, lgz );
111     GX = lgx;
112     GY = lgy;
113     GZ = lgz;
114     return out;
115 }
116 
117 //*****************************************************************************
118 double GravityCircle::T(double lon,
119     [System::Runtime::InteropServices::Out] double% deltaX,
120     [System::Runtime::InteropServices::Out] double% deltaY,
121     [System::Runtime::InteropServices::Out] double% deltaZ)
122 {
123     double lgx, lgy, lgz;
124     double out = m_pGravityCircle->T( lon, lgx, lgy, lgz );
125     deltaX = lgx;
126     deltaY = lgy;
127     deltaZ = lgz;
128     return out;
129 }
130 
131 //*****************************************************************************
T(double lon)132 double GravityCircle::T(double lon)
133 {
134     return m_pGravityCircle->T( lon );
135 }
136 
137 //*****************************************************************************
get()138 double GravityCircle::EquatorialRadius::get()
139 {
140     if ( m_pGravityCircle->Init() )
141         return m_pGravityCircle->EquatorialRadius();
142     throw gcnew GeographicErr("GravityCircle::EquatorialRadius failed because the GravityCircle is not initialized.");
143 }
144 
145 //*****************************************************************************
get()146 double GravityCircle::Flattening::get()
147 {
148     if ( m_pGravityCircle->Init() )
149         return m_pGravityCircle->Flattening();
150     throw gcnew GeographicErr("GravityCircle::Flattening failed because the GravityCircle is not initialized.");
151 }
152 
153 //*****************************************************************************
get()154 double GravityCircle::Latitude::get()
155 {
156     if ( m_pGravityCircle->Init() )
157         return m_pGravityCircle->Latitude();
158     throw gcnew GeographicErr("GravityCircle::Latitude failed because the GravityCircle is not initialized.");
159 }
160 
161 //*****************************************************************************
get()162 double GravityCircle::Height::get()
163 {
164     if ( m_pGravityCircle->Init() )
165         return m_pGravityCircle->Height();
166     throw gcnew GeographicErr("GravityCircle::Height failed because the GravityCircle is not initialized.");
167 }
168 
169 //*****************************************************************************
get()170 bool GravityCircle::Init::get() { return m_pGravityCircle->Init(); }
171 
172 //*****************************************************************************
Capabilities()173 GravityModel::Mask GravityCircle::Capabilities()
174 { return static_cast<GravityModel::Mask>(m_pGravityCircle->Capabilities()); }
175 
176 //*****************************************************************************
Capabilities(GravityModel::Mask testcaps)177 bool GravityCircle::Capabilities(GravityModel::Mask testcaps)
178 { return m_pGravityCircle->Capabilities( (unsigned int)testcaps ); }
179