00001 // magvar.cxx -- magnetic variation wrapper class 00002 // 00003 // Written by Curtis Olson, started July 2000. 00004 // 00005 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt 00006 // 00007 // This program is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU General Public License as 00009 // published by the Free Software Foundation; either version 2 of the 00010 // License, or (at your option) any later version. 00011 // 00012 // This program is distributed in the hope that it will be useful, but 00013 // WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 // General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with this program; if not, write to the Free Software 00019 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00020 // 00021 // $Id: magvar_8cxx_source.html,v 1.3 2010/02/23 22:10:14 curt Exp $ 00022 00023 00024 #include <math.h> 00025 00026 #include <simgear/magvar/magvar.hxx> 00027 00028 #include "coremag.hxx" 00029 #include "magvar.hxx" 00030 00031 00032 SGMagVar::SGMagVar() 00033 : magvar(0.0), 00034 magdip(0.0) 00035 { 00036 } 00037 00038 SGMagVar::~SGMagVar() { 00039 } 00040 00041 00042 void SGMagVar::update( double lon, double lat, double alt_m, double jd ) { 00043 // Calculate local magnetic variation 00044 double field[6]; 00045 // cout << "alt_m = " << alt_m << endl; 00046 magvar = calc_magvar( lat, lon, alt_m / 1000.0, (long)jd, field ); 00047 magdip = atan(field[5]/sqrt(field[3]*field[3]+field[4]*field[4])); 00048 } 00049 00050 00051 double sgGetMagVar( double lon, double lat, double alt_m, double jd ) { 00052 // cout << "lat = " << lat << " lon = " << lon << " elev = " << alt_m 00053 // << " JD = " << jd << endl; 00054 00055 double field[6]; 00056 return calc_magvar( lat, lon, alt_m / 1000.0, (long)jd, field ); 00057 }