dotnet/NETGeographicLib/MagneticModel.cpp
Go to the documentation of this file.
1 
11 #include "stdafx.h"
13 #include "MagneticModel.h"
15 #include "MagneticCircle.h"
16 #include "Geocentric.h"
17 #include "NETGeographicLib.h"
18 
19 using namespace NETGeographicLib;
20 
21 const char BADALLOC[] = "Failed to allocate memory for a GeographicLib::MagneticModel";
22 
23 //*****************************************************************************
25 {
26  if ( m_pMagneticModel != NULL )
27  {
28  delete m_pMagneticModel;
29  m_pMagneticModel = NULL;
30  }
31 }
32 
33 //*****************************************************************************
35  System::String^ path,
36  Geocentric^ earth)
37 {
38  if ( name == nullptr ) throw gcnew GeographicErr("name cannot be a null pointer.");
39  if ( path == nullptr ) throw gcnew GeographicErr("path cannot be a null pointer.");
40  if ( earth == nullptr ) throw gcnew GeographicErr("earth cannot be a null pointer.");
41 
42  try
43  {
44  const GeographicLib::Geocentric* pGeocentric =
45  reinterpret_cast<const GeographicLib::Geocentric*>(
46  earth->GetUnmanaged()->ToPointer() );
47 
51  *pGeocentric );
52  }
53  catch ( std::bad_alloc )
54  {
55  throw gcnew GeographicErr( BADALLOC );
56  }
57  catch (const std::exception& err )
58  {
59  throw gcnew GeographicErr( err.what() );
60  }
61 }
62 
63 //*****************************************************************************
65  System::String^ path)
66 {
67  if ( name == nullptr ) throw gcnew GeographicErr("name cannot be a null pointer.");
68  if ( path == nullptr ) throw gcnew GeographicErr("path cannot be a null pointer.");
69 
70  try
71  {
76  }
77  catch ( std::bad_alloc )
78  {
79  throw gcnew GeographicErr( BADALLOC );
80  }
81  catch (const std::exception& err )
82  {
83  throw gcnew GeographicErr( err.what() );
84  }
85 }
86 
87 //*****************************************************************************
88 void MagneticModel::Field(double t, double lat, double lon, double h,
89  [System::Runtime::InteropServices::Out] double% Bx,
90  [System::Runtime::InteropServices::Out] double% By,
91  [System::Runtime::InteropServices::Out] double% Bz)
92 {
93  double lx, ly, lz;
94  m_pMagneticModel->operator()( t, lat, lon, h, lx, ly, lz );
95  Bx = lx;
96  By = ly;
97  Bz = lz;
98 }
99 
100 //*****************************************************************************
101 void MagneticModel::Field(double t, double lat, double lon, double h,
102  [System::Runtime::InteropServices::Out] double% Bx,
103  [System::Runtime::InteropServices::Out] double% By,
104  [System::Runtime::InteropServices::Out] double% Bz,
105  [System::Runtime::InteropServices::Out] double% Bxt,
106  [System::Runtime::InteropServices::Out] double% Byt,
107  [System::Runtime::InteropServices::Out] double% Bzt)
108 {
109  double lx, ly, lz, lxt, lyt, lzt;
110  m_pMagneticModel->operator()( t, lat, lon, h, lx, ly, lz, lxt, lyt, lzt );
111  Bx = lx;
112  By = ly;
113  Bz = lz;
114  Bxt = lxt;
115  Byt = lyt;
116  Bzt = lzt;
117 }
118 
119 //*****************************************************************************
120 MagneticCircle^ MagneticModel::Circle(double t, double lat, double h)
121 {
122  try
123  {
124  return gcnew MagneticCircle( m_pMagneticModel->Circle( t, lat, h ) );
125  }
126  catch ( std::bad_alloc )
127  {
128  throw gcnew GeographicErr("Failed to allocate memory for a MagneticCircle in MagneticModel::Circle");
129  }
130 }
131 
132 //*****************************************************************************
133 void MagneticModel::FieldComponents(double Bx, double By, double Bz,
134  [System::Runtime::InteropServices::Out] double% H,
135  [System::Runtime::InteropServices::Out] double% F,
136  [System::Runtime::InteropServices::Out] double% D,
137  [System::Runtime::InteropServices::Out] double% I)
138 {
139  double lh, lf, ld, li;
140  GeographicLib::MagneticModel::FieldComponents(Bx, By, Bz, lh, lf, ld, li);
141  H = lh;
142  F = lf;
143  D = ld;
144  I = li;
145 }
146 
147 //*****************************************************************************
148 void MagneticModel::FieldComponents(double Bx, double By, double Bz,
149  double Bxt, double Byt, double Bzt,
150  [System::Runtime::InteropServices::Out] double% H,
151  [System::Runtime::InteropServices::Out] double% F,
152  [System::Runtime::InteropServices::Out] double% D,
153  [System::Runtime::InteropServices::Out] double% I,
154  [System::Runtime::InteropServices::Out] double% Ht,
155  [System::Runtime::InteropServices::Out] double% Ft,
156  [System::Runtime::InteropServices::Out] double% Dt,
157  [System::Runtime::InteropServices::Out] double% It)
158 {
159  double lh, lf, ld, li, lht, lft, ldt, lit;
160  GeographicLib::MagneticModel::FieldComponents(Bx, By, Bz, Bxt, Byt, Bzt,
161  lh, lf, ld, li, lht, lft, ldt, lit);
162  H = lh;
163  F = lf;
164  D = ld;
165  I = li;
166  Ht = lht;
167  Ft = lft;
168  Dt = ldt;
169  It = lit;
170 }
171 
172 //*****************************************************************************
173 System::String^ MagneticModel::Description::get()
174 {
176 }
177 
178 //*****************************************************************************
179 System::String^ MagneticModel::DateTime::get()
180 {
182 }
183 
184 //*****************************************************************************
185 System::String^ MagneticModel::MagneticFile::get()
186 {
188 }
189 
190 //*****************************************************************************
192 {
194 }
195 
196 //*****************************************************************************
198 {
200 }
201 
202 //*****************************************************************************
204 {
206 }
207 
208 //*****************************************************************************
210 {
212 }
213 
214 //*****************************************************************************
216 { return m_pMagneticModel->MinHeight(); }
217 
218 //*****************************************************************************
220 { return m_pMagneticModel->MaxHeight(); }
221 
222 //*****************************************************************************
224 
225 //*****************************************************************************
227 
228 //*****************************************************************************
230 { return m_pMagneticModel->MajorRadius(); }
231 
232 //*****************************************************************************
234 { return m_pMagneticModel->Flattening(); }
static void FieldComponents(double Bx, double By, double Bz, [System::Runtime::InteropServices::Out] double% H, [System::Runtime::InteropServices::Out] double% F, [System::Runtime::InteropServices::Out] double% D, [System::Runtime::InteropServices::Out] double% I)
MagneticCircle Circle(double t, double lat, double h)
Math::real MinHeight() const
#define I
Definition: main.h:112
const GeographicLib::MagneticModel * m_pMagneticModel
Definition: MagneticModel.h:67
Header for NETGeographicLib::MagneticModel class.
Header for NETGeographicLib::NETGeographicLib objects.
.NET wrapper for GeographicLib::MagneticCircle.
const std::string & Description() const
Math::real MajorRadius() const
Key F(std::uint64_t j)
static const double lat
Exception class for NETGeographicLib.
Header for GeographicLib::MagneticCircle class.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange [*:*] noreverse nowriteback set trange [*:*] noreverse nowriteback set urange [*:*] noreverse nowriteback set vrange [*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
Model of the earth&#39;s magnetic field.
.NET wrapper for GeographicLib::Geocentric.
Definition: Geocentric.h:68
static void FieldComponents(real Bx, real By, real Bz, real &H, real &F, real &D, real &I)
const std::string & MagneticModelDirectory() const
Geocentric coordinates
Definition: Geocentric.hpp:67
static System::String UnmanagedToManaged(const std::string &s)
Header for NETGeographicLib::Geocentric class.
MagneticModel(System::String^ name, System::String^ path, Geocentric^ earth)
static const Geocentric & WGS84()
Header for GeographicLib::MagneticModel class.
#define NULL
Definition: ccolamd.c:609
static std::string DefaultMagneticName()
const std::string & MagneticModelName() const
Math::real Flattening() const
const double h
Math::real MaxHeight() const
static std::string ManagedToUnmanaged(System::String^ s)
const std::string & MagneticFile() const
.NET wrapper for GeographicLib::MagneticModel.
Definition: MagneticModel.h:63
static std::string DefaultMagneticPath()
static const double lon
void Field(double t, double lat, double lon, double h, [System::Runtime::InteropServices::Out] double% Bx, [System::Runtime::InteropServices::Out] double% By, [System::Runtime::InteropServices::Out] double% Bz)
Annotation for function names.
Definition: attr.h:48
const std::string & DateTime() const
Container::iterator get(Container &c, Position position)
Header for NETGeographicLib::MagneticCircle class.
Point2 t(10, 10)
MagneticCircle Circle(real t, real lat, real h) const


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:35