X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmagvar%2Fmagvar.hxx;h=605bece722bc09a99a80a249f803db8e84870048;hb=7bdb530440d1dadc991f305edb1b70ec85f27451;hp=1058e2273463bf74fb28a0a6250321062312632a;hpb=82459a2802a939434f9fc5b88d2b2aea58f0043d;p=simgear.git diff --git a/simgear/magvar/magvar.hxx b/simgear/magvar/magvar.hxx index 1058e227..605bece7 100644 --- a/simgear/magvar/magvar.hxx +++ b/simgear/magvar/magvar.hxx @@ -1,57 +1,111 @@ -// magvar.hxx -- compute local magnetic variation given position, -// altitude, and date -// -// This is an implimentation of the NIMA WMM 2000 -// -// http://www.nima.mil/GandG/ngdc-wmm2000.html -// -// Copyright (C) 2000 Edward A Williams +/** + * \file magvar.hxx + * Magnetic variation wrapper class. + */ + +// Written by Curtis Olson, started July 2000. // -// Adapted from Excel 3.0 version 3/27/94 EAW -// Recoded in C++ by Starry Chan -// WMM95 added and rearranged in ANSI-C EAW 7/9/95 -// Put shell around program and made Borland & GCC compatible EAW 11/22/95 -// IGRF95 added 2/96 EAW -// WMM2000 IGR2000 added 2/00 EAW -// Released under GPL 3/26/00 EAW -// Adaptions and modifications for the SimGear project 3/27/2000 CLO +// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. +// General Public License for more details. // -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 59 Temple Place - Suite 330, -// Boston, MA 02111-1307, USA. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ -#ifndef SG_MAGVAR_HXX -#define SG_MAGVAR_HXX +#ifndef _MAGVAR_HXX +#define _MAGVAR_HXX + + +#ifndef __cplusplus +# error This library requires C++ +#endif + + +// forward decls +class SGGeod; + +/** + * Magnetic variation wrapper class. + * + * The SGMagVar class calculates the magnetic variation and dip for + * any position, altitude, and time. It is a complete + * re-implimentation of the NIMA WMM 2000 (not derived from their demo + * code.) + * + * The SGMagVar class is really a simple wrapper around the core Ed + * Williams code which does all the hard work. This class allows you + * to crunch the math once and then do multiple polls of the + * data. However, if your position, altitude, or time has changed + * significantly, you should call the update() method to recrunch new + * numbers. + */ +class SGMagVar { + +private: + + double magvar; + double magdip; + +public: + + /** + * This creates an instance of the SGMagVar object. + * You must call the update() method before any queries will be valid. + */ + SGMagVar(); + + /** Destructor */ + ~SGMagVar(); + + /** Recalculate the magnetic offset and dip. + * The update() method requires you to pass in your position and + * the julian date. Lon and lat are specified in radians, altitude + * is specified in meters. Julian date can be conveniently + * calculated by using an instance of the SGTime class. + * @param lon longitude in radians + * @param lat latitude in radians + * @param alt_m altitude above sea level in meters + * @param jd julian date + */ + void update( double lon, double lat, double alt_m, double jd ); + /** + * overloaded variant taking an SGGeod to specify position + */ + void update( const SGGeod& geod, double jd ); -/* Convert date to Julian day 1950-2049 */ -unsigned long int yymmdd_to_julian_days( int yy, int mm, int dd ); + /** @return the current magnetic variation in radians. */ + double get_magvar() const { return magvar; } -/* Convert degrees to radians */ -double deg_to_rad( double deg ); + /** @return the current magnetic dip in radians. */ + double get_magdip() const { return magdip; } +}; -/* Convert radians to degrees */ -double rad_to_deg( double rad ); -/* return variation (in degrees) given geodetic latitude (radians), longitude -(radians) ,height (km) and (Julian) date -N and E lat and long are positive, S and W negative -*/ -double SGMagVar( double lat, double lon, double h, long dat, double* field ); +/** + * \relates SGMagVar + * Lookup the magvar for any arbitrary location (This function doesn't + * save state like the SGMagVar class. This function triggers a fair + * amount of CPU work, so use it cautiously. + * @return the magvar in radians + */ +double sgGetMagVar( double lon, double lat, double alt_m, double jd ); +/** + * overload version of the above to take a SGGeod + */ +double sgGetMagVar( const SGGeod& pos, double jd ); -#endif // SG_MAGVAR_HXX +#endif // _MAGVAR_HXX