GeographicLib  1.21
MagneticCircle.cpp
Go to the documentation of this file.
00001 /**
00002  * \file MagneticCircle.cpp
00003  * \brief Implementation for GeographicLib::MagneticCircle class
00004  *
00005  * Copyright (c) Charles Karney (2011) <charles@karney.com> and licensed under
00006  * the MIT/X11 License.  For more information, see
00007  * http://geographiclib.sourceforge.net/
00008  **********************************************************************/
00009 
00010 #include <GeographicLib/MagneticCircle.hpp>
00011 #include <fstream>
00012 #include <sstream>
00013 #include <GeographicLib/Geocentric.hpp>
00014 
00015 #define GEOGRAPHICLIB_MAGNETICCIRCLE_CPP \
00016   "$Id: 8cd933c406708a1f8b90e029e89bb99d2eb177b0 $"
00017 
00018 RCSID_DECL(GEOGRAPHICLIB_MAGNETICCIRCLE_CPP)
00019 RCSID_DECL(GEOGRAPHICLIB_MAGNETICCIRCLE_HPP)
00020 
00021 #define MAGNETIC_DEFAULT_PATH "/home/ckarney/geographiclib/magnetic"
00022 
00023 namespace GeographicLib {
00024 
00025   using namespace std;
00026 
00027   void MagneticCircle::Field(real lon, bool diffp,
00028                              real& Bx, real& By, real& Bz,
00029                              real& Bxt, real& Byt, real& Bzt) const throw() {
00030     real clam, slam;
00031     CircularEngine::cossin(lon, clam, slam);
00032     real M[Geocentric::dim2_];
00033     Geocentric::Rotation(_sphi, _cphi, slam, clam, M);
00034     real BX0, BY0, BZ0, BX1, BY1, BZ1; // Components in geocentric basis
00035     _circ0(clam, slam, BX0, BY0, BZ0);
00036     _circ1(clam, slam, BX1, BY1, BZ1);
00037     if (_interpolate) {
00038       BX1 = (BX1 - BX0) / _dt0;
00039       BY1 = (BY1 - BY0) / _dt0;
00040       BZ1 = (BZ1 - BZ0) / _dt0;
00041     }
00042     BX0 += _t1 * BX1;
00043     BY0 += _t1 * BY1;
00044     BZ0 += _t1 * BZ1;
00045     if (diffp) {
00046       Geocentric::Unrotate(M, BX1, BY1, BZ1, Bxt, Byt, Bzt);
00047       Bxt *= - _a;
00048       Byt *= - _a;
00049       Bzt *= - _a;
00050     }
00051     Geocentric::Unrotate(M, BX0, BY0, BZ0, Bx, By, Bz);
00052     Bx *= - _a;
00053     By *= - _a;
00054     Bz *= - _a;
00055   }
00056 
00057 } // namespace GeographicLib