GeographicLib  1.46
Static Public Member Functions | List of all members
GeographicLib::MagneticModel Class Reference

Model of the earth's magnetic field. More...

#include <GeographicLib/MagneticModel.hpp>

Public Member Functions

Setting up the magnetic model
 MagneticModel (const std::string &name, const std::string &path="", const Geocentric &earth=Geocentric::WGS84())
 
Inspector functions
const std::string & Description () const
 
const std::string & DateTime () const
 
const std::string & MagneticFile () const
 
const std::string & MagneticModelName () const
 
const std::string & MagneticModelDirectory () const
 
Math::real MinHeight () const
 
Math::real MaxHeight () const
 
Math::real MinTime () const
 
Math::real MaxTime () const
 
Math::real MajorRadius () const
 
Math::real Flattening () const
 

Static Public Member Functions

static std::string DefaultMagneticPath ()
 
static std::string DefaultMagneticName ()
 

Compute the magnetic field

void operator() (real t, real lat, real lon, real h, real &Bx, real &By, real &Bz) const
 
void operator() (real t, real lat, real lon, real h, real &Bx, real &By, real &Bz, real &Bxt, real &Byt, real &Bzt) const
 
MagneticCircle Circle (real t, real lat, real h) const
 
static void FieldComponents (real Bx, real By, real Bz, real &H, real &F, real &D, real &I)
 
static void FieldComponents (real Bx, real By, real Bz, real Bxt, real Byt, real Bzt, real &H, real &F, real &D, real &I, real &Ht, real &Ft, real &Dt, real &It)
 

Detailed Description

Model of the earth's magnetic field.

Evaluate the earth's magnetic field according to a model. At present only internal magnetic fields are handled. These are due to the earth's code and crust; these vary slowly (over many years). Excluded are the effects of currents in the ionosphere and magnetosphere which have daily and annual variations.

See Magnetic models for details of how to install the magnetic models and the data format.

See

Example of use:

// Example of using the GeographicLib::MagneticModel class
#include <iostream>
#include <exception>
using namespace std;
using namespace GeographicLib;
int main() {
try {
MagneticModel mag("wmm2010");
double lat = 27.99, lon = 86.93, h = 8820, t = 2012; // Mt Everest
double Bx, By, Bz;
mag(t, lat,lon, h, Bx, By, Bz);
double H, F, D, I;
MagneticModel::FieldComponents(Bx, By, Bz, H, F, D, I);
cout << H << " " << F << " " << D << " " << I << "\n";
}
catch (const exception& e) {
cerr << "Caught exception: " << e.what() << "\n";
return 1;
}
return 0;
}

MagneticField is a command-line utility providing access to the functionality of MagneticModel and MagneticCircle.

Definition at line 63 of file MagneticModel.hpp.

Constructor & Destructor Documentation

GeographicLib::MagneticModel::MagneticModel ( const std::string &  name,
const std::string &  path = "",
const Geocentric earth = Geocentric::WGS84() 
)
explicit

Construct a magnetic model.

Parameters
[in]namethe name of the model.
[in]path(optional) directory for data file.
[in]earth(optional) Geocentric object for converting coordinates; default Geocentric::WGS84().
Exceptions
GeographicErrif the data file cannot be found, is unreadable, or is corrupt.
std::bad_allocif the memory necessary for storing the model can't be allocated.

A filename is formed by appending ".wmm" (World Magnetic Model) to the name. If path is specified (and is non-empty), then the file is loaded from directory, path. Otherwise the path is given by the DefaultMagneticPath().

This file contains the metadata which specifies the properties of the model. The coefficients for the spherical harmonic sums are obtained from a file obtained by appending ".cof" to metadata file (so the filename ends in ".wwm.cof").

The model is not tied to a particular ellipsoidal model of the earth. The final earth argument to the constructor specifies an ellipsoid to allow geodetic coordinates to the transformed into the spherical coordinates used in the spherical harmonic sum.

Definition at line 37 of file MagneticModel.cpp.

References DefaultMagneticPath(), GeographicLib::SphericalHarmonic::FULL, GeographicLib::Math::isfinite(), GeographicLib::Utility::ParseLine(), GeographicLib::SphericalEngine::coeff::readcoeffs(), and GeographicLib::SphericalHarmonic::SCHMIDT.

Member Function Documentation

void GeographicLib::MagneticModel::operator() ( real  t,
real  lat,
real  lon,
real  h,
real &  Bx,
real &  By,
real &  Bz 
) const
inline

Evaluate the components of the geomagnetic field.

Parameters
[in]tthe time (years).
[in]latlatitude of the point (degrees).
[in]lonlongitude of the point (degrees).
[in]hthe height of the point above the ellipsoid (meters).
[out]Bxthe easterly component of the magnetic field (nanotesla).
[out]Bythe northerly component of the magnetic field (nanotesla).
[out]Bzthe vertical (up) component of the magnetic field (nanotesla).

Definition at line 133 of file MagneticModel.hpp.

void GeographicLib::MagneticModel::operator() ( real  t,
real  lat,
real  lon,
real  h,
real &  Bx,
real &  By,
real &  Bz,
real &  Bxt,
real &  Byt,
real &  Bzt 
) const
inline

Evaluate the components of the geomagnetic field and their time derivatives

Parameters
[in]tthe time (years).
[in]latlatitude of the point (degrees).
[in]lonlongitude of the point (degrees).
[in]hthe height of the point above the ellipsoid (meters).
[out]Bxthe easterly component of the magnetic field (nanotesla).
[out]Bythe northerly component of the magnetic field (nanotesla).
[out]Bzthe vertical (up) component of the magnetic field (nanotesla).
[out]Bxtthe rate of change of Bx (nT/yr).
[out]Bytthe rate of change of By (nT/yr).
[out]Bztthe rate of change of Bz (nT/yr).

Definition at line 155 of file MagneticModel.hpp.

MagneticCircle GeographicLib::MagneticModel::Circle ( real  t,
real  lat,
real  h 
) const

Create a MagneticCircle object to allow the geomagnetic field at many points with constant lat, h, and t and varying lon to be computed efficiently.

Parameters
[in]tthe time (years).
[in]latlatitude of the point (degrees).
[in]hthe height of the point above the ellipsoid (meters).
Exceptions
std::bad_allocif the memory necessary for creating a MagneticCircle can't be allocated.
Returns
a MagneticCircle object whose MagneticCircle::operator()(real lon) member function computes the field at particular values of lon.

If the field at several points on a circle of latitude need to be calculated then creating a MagneticCircle and using its member functions will be substantially faster, especially for high-degree models.

Definition at line 212 of file MagneticModel.cpp.

Referenced by main().

static void GeographicLib::MagneticModel::FieldComponents ( real  Bx,
real  By,
real  Bz,
real &  H,
real &  F,
real &  D,
real &  I 
)
inlinestatic

Compute various quantities dependent on the magnetic field.

Parameters
[in]Bxthe x (easterly) component of the magnetic field (nT).
[in]Bythe y (northerly) component of the magnetic field (nT).
[in]Bzthe z (vertical, up positive) component of t