1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
/**
* \file NETGeographicLib/MagneticModel.cpp
* \brief Implementation for NETGeographicLib::MagneticModel class
*
* NETGeographicLib is copyright (c) Scott Heiman (2013)
* GeographicLib is Copyright (c) Charles Karney (2010-2012)
* <charles@karney.com> and licensed under the MIT/X11 License.
* For more information, see
* http://geographiclib.sourceforge.net/
**********************************************************************/
#include "stdafx.h"
#include "GeographicLib/MagneticModel.hpp"
#include "MagneticModel.h"
#include "GeographicLib/MagneticCircle.hpp"
#include "MagneticCircle.h"
#include "Geocentric.h"
#include "NETGeographicLib.h"
using namespace NETGeographicLib;
const char BADALLOC[] = "Failed to allocate memory for a GeographicLib::MagneticModel";
//*****************************************************************************
MagneticModel::!MagneticModel(void)
{
if ( m_pMagneticModel != NULL )
{
delete m_pMagneticModel;
m_pMagneticModel = NULL;
}
}
//*****************************************************************************
MagneticModel::MagneticModel(System::String^ name,
System::String^ path,
Geocentric^ earth)
{
if ( name == nullptr ) throw gcnew GeographicErr("name cannot be a null pointer.");
if ( path == nullptr ) throw gcnew GeographicErr("path cannot be a null pointer.");
if ( earth == nullptr ) throw gcnew GeographicErr("earth cannot be a null pointer.");
try
{
const GeographicLib::Geocentric* pGeocentric =
reinterpret_cast<const GeographicLib::Geocentric*>(
earth->GetUnmanaged()->ToPointer() );
m_pMagneticModel = new GeographicLib::MagneticModel(
StringConvert::ManagedToUnmanaged( name ),
StringConvert::ManagedToUnmanaged( path ),
*pGeocentric );
}
catch ( std::bad_alloc )
{
throw gcnew GeographicErr( BADALLOC );
}
catch (const std::exception& err )
{
throw gcnew GeographicErr( err.what() );
}
}
//*****************************************************************************
MagneticModel::MagneticModel(System::String^ name,
System::String^ path)
{
if ( name == nullptr ) throw gcnew GeographicErr("name cannot be a null pointer.");
if ( path == nullptr ) throw gcnew GeographicErr("path cannot be a null pointer.");
try
{
m_pMagneticModel = new GeographicLib::MagneticModel(
StringConvert::ManagedToUnmanaged( name ),
StringConvert::ManagedToUnmanaged( path ),
GeographicLib::Geocentric::WGS84() );
}
catch ( std::bad_alloc )
{
throw gcnew GeographicErr( BADALLOC );
}
catch (const std::exception& err )
{
throw gcnew GeographicErr( err.what() );
}
}
//*****************************************************************************
void MagneticModel::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)
{
double lx, ly, lz;
m_pMagneticModel->operator()( t, lat, lon, h, lx, ly, lz );
Bx = lx;
By = ly;
Bz = lz;
}
//*****************************************************************************
void MagneticModel::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,
[System::Runtime::InteropServices::Out] double% Bxt,
[System::Runtime::InteropServices::Out] double% Byt,
[System::Runtime::InteropServices::Out] double% Bzt)
{
double lx, ly, lz, lxt, lyt, lzt;
m_pMagneticModel->operator()( t, lat, lon, h, lx, ly, lz, lxt, lyt, lzt );
Bx = lx;
By = ly;
Bz = lz;
Bxt = lxt;
Byt = lyt;
Bzt = lzt;
}
//*****************************************************************************
MagneticCircle^ MagneticModel::Circle(double t, double lat, double h)
{
try
{
return gcnew MagneticCircle( m_pMagneticModel->Circle( t, lat, h ) );
}
catch ( std::bad_alloc )
{
throw gcnew GeographicErr("Failed to allocate memory for a MagneticCircle in MagneticModel::Circle");
}
}
//*****************************************************************************
void MagneticModel::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)
{
double lh, lf, ld, li;
GeographicLib::MagneticModel::FieldComponents(Bx, By, Bz, lh, lf, ld, li);
H = lh;
F = lf;
D = ld;
I = li;
}
//*****************************************************************************
void MagneticModel::FieldComponents(double Bx, double By, double Bz,
double Bxt, double Byt, double Bzt,
[System::Runtime::InteropServices::Out] double% H,
[System::Runtime::InteropServices::Out] double% F,
[System::Runtime::InteropServices::Out] double% D,
[System::Runtime::InteropServices::Out] double% I,
[System::Runtime::InteropServices::Out] double% Ht,
[System::Runtime::InteropServices::Out] double% Ft,
[System::Runtime::InteropServices::Out] double% Dt,
[System::Runtime::InteropServices::Out] double% It)
{
double lh, lf, ld, li, lht, lft, ldt, lit;
GeographicLib::MagneticModel::FieldComponents(Bx, By, Bz, Bxt, Byt, Bzt,
lh, lf, ld, li, lht, lft, ldt, lit);
H = lh;
F = lf;
D = ld;
I = li;
Ht = lht;
Ft = lft;
Dt = ldt;
It = lit;
}
//*****************************************************************************
System::String^ MagneticModel::Description::get()
{
return StringConvert::UnmanagedToManaged( m_pMagneticModel->Description() );
}
//*****************************************************************************
System::String^ MagneticModel::DateTime::get()
{
return StringConvert::UnmanagedToManaged( m_pMagneticModel->DateTime() );
}
//*****************************************************************************
System::String^ MagneticModel::MagneticFile::get()
{
return StringConvert::UnmanagedToManaged( m_pMagneticModel->MagneticFile() );
}
//*****************************************************************************
System::String^ MagneticModel::MagneticModelName::get()
{
return StringConvert::UnmanagedToManaged( m_pMagneticModel->MagneticModelName() );
}
//*****************************************************************************
System::String^ MagneticModel::MagneticModelDirectory::get()
{
return StringConvert::UnmanagedToManaged( m_pMagneticModel->MagneticModelDirectory() );
}
//*****************************************************************************
System::String^ MagneticModel::DefaultMagneticPath()
{
return StringConvert::UnmanagedToManaged( GeographicLib::MagneticModel::DefaultMagneticPath() );
}
//*****************************************************************************
System::String^ MagneticModel::DefaultMagneticName()
{
return StringConvert::UnmanagedToManaged( GeographicLib::MagneticModel::DefaultMagneticName() );
}
//*****************************************************************************
double MagneticModel::MinHeight::get()
{ return m_pMagneticModel->MinHeight(); }
//*****************************************************************************
double MagneticModel::MaxHeight::get()
{ return m_pMagneticModel->MaxHeight(); }
//*****************************************************************************
double MagneticModel::MinTime::get() { return m_pMagneticModel->MinTime(); }
//*****************************************************************************
double MagneticModel::MaxTime::get() { return m_pMagneticModel->MaxTime(); }
//*****************************************************************************
double MagneticModel::MajorRadius::get()
{ return m_pMagneticModel->MajorRadius(); }
//*****************************************************************************
double MagneticModel::Flattening::get()
{ return m_pMagneticModel->Flattening(); }
|