23 # pragma warning (disable: 4127) 26 #include "MagneticField.usage" 28 int main(
int argc,
const char*
const argv[]) {
33 bool verbose =
false, longfirst =
false;
36 std::string istring, ifile, ofile, cdelim;
39 bool timeset =
false, circle =
false, rate =
false;
40 real hguard = 500000, tguard = 50;
43 for (
int m = 1;
m < argc; ++
m) {
44 std::string
arg(argv[
m]);
46 if (++m == argc)
return usage(1,
true);
48 }
else if (arg ==
"-d") {
49 if (++m == argc)
return usage(1,
true);
51 }
else if (arg ==
"-t") {
52 if (++m == argc)
return usage(1,
true);
54 time = Utility::fractionalyear<real>(std::string(argv[m]));
58 catch (
const std::exception&
e) {
59 std::cerr <<
"Error decoding argument of " << arg <<
": " 63 }
else if (arg ==
"-c") {
64 if (m + 3 >= argc)
return usage(1,
true);
67 time = Utility::fractionalyear<real>(std::string(argv[++m]));
74 h = Utility::val<real>(std::string(argv[++m]));
78 catch (
const std::exception&
e) {
79 std::cerr <<
"Error decoding argument of " << arg <<
": " 83 }
else if (arg ==
"-r")
86 longfirst = !longfirst;
87 else if (arg ==
"-p") {
88 if (++m == argc)
return usage(1,
true);
90 prec = Utility::val<int>(std::string(argv[m]));
92 catch (
const std::exception&) {
93 std::cerr <<
"Precision " << argv[
m] <<
" is not a number\n";
96 }
else if (arg ==
"-T") {
97 if (++m == argc)
return usage(1,
true);
99 tguard = Utility::val<real>(std::string(argv[m]));
101 catch (
const std::exception&
e) {
102 std::cerr <<
"Error decoding argument of " << arg <<
": " 106 }
else if (arg ==
"-H") {
107 if (++m == argc)
return usage(1,
true);
109 hguard = Utility::val<real>(std::string(argv[m]));
111 catch (
const std::exception&
e) {
112 std::cerr <<
"Error decoding argument of " << arg <<
": " 116 }
else if (arg ==
"-v")
118 else if (arg ==
"--input-string") {
119 if (++m == argc)
return usage(1,
true);
121 }
else if (arg ==
"--input-file") {
122 if (++m == argc)
return usage(1,
true);
124 }
else if (arg ==
"--output-file") {
125 if (++m == argc)
return usage(1,
true);
127 }
else if (arg ==
"--line-separator") {
128 if (++m == argc)
return usage(1,
true);
129 if (std::string(argv[m]).
size() != 1) {
130 std::cerr <<
"Line separator must be a single character\n";
134 }
else if (arg ==
"--comment-delimiter") {
135 if (++m == argc)
return usage(1,
true);
137 }
else if (arg ==
"--version") {
138 std::cout << argv[0] <<
": GeographicLib version " 142 int retval = usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
144 std::cout<<
"\nDefault magnetic path = \"" 146 <<
"\"\nDefault magnetic name = \"" 153 if (!ifile.empty() && !istring.empty()) {
154 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
157 if (ifile ==
"-") ifile.clear();
158 std::ifstream infile;
159 std::istringstream instring;
160 if (!ifile.empty()) {
161 infile.open(ifile.c_str());
162 if (!infile.is_open()) {
163 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
166 }
else if (!istring.empty()) {
167 std::string::size_type
m = 0;
169 m = istring.find(lsep, m);
170 if (m == std::string::npos)
174 instring.str(istring);
176 std::istream* input = !ifile.empty() ? &infile :
177 (!istring.empty() ? &instring : &std::cin);
179 std::ofstream outfile;
180 if (ofile ==
"-") ofile.clear();
181 if (!ofile.empty()) {
182 outfile.open(ofile.c_str());
183 if (!outfile.is_open()) {
184 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
188 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
196 if ((timeset || circle)
201 " too far outside allowed range [" +
209 "km too far outside allowed range [" +
213 std::cerr <<
"Magnetic file: " << m.
MagneticFile() <<
"\n" 216 <<
"Date & Time: " << m.
DateTime() <<
"\n" 224 if ((timeset || circle) && (time < m.
MinTime() || time > m.
MaxTime()))
225 std::cerr <<
"WARNING: Time " << time
226 <<
" outside allowed range [" 229 std::cerr <<
"WARNING: Height " <<
h/1000
230 <<
"km outside allowed range [" 235 std::string
s, eol, stra, strb;
236 std::istringstream
str;
237 while (std::getline(*input, s)) {
240 if (!cdelim.empty()) {
241 std::string::size_type
n = s.find(cdelim);
242 if (n != std::string::npos) {
243 eol =
" " + s.substr(n) +
"\n";
247 str.clear(); str.str(s);
248 if (!(timeset || circle)) {
251 time = Utility::fractionalyear<real>(stra);
254 " too far outside allowed range [" +
259 std::cerr <<
"WARNING: Time " << time
260 <<
" outside allowed range [" 272 if (!(str >> stra >> strb))
279 "km too far outside allowed range [" +
283 std::cerr <<
"WARNING: Height " <<
h/1000
284 <<
"km outside allowed range [" 293 real bx, by, bz, bxt, byt, bzt;
295 c(lon, bx, by, bz, bxt, byt, bzt);
297 m(time,
lat, lon,
h, bx, by, bz, bxt, byt, bzt);
298 real
H,
F,
D,
I, Ht, Ft, Dt,
It;
300 H, F, D, I, Ht, Ft, Dt, It);
318 catch (
const std::exception&
e) {
319 *output <<
"ERROR: " << e.what() <<
"\n";
324 catch (
const std::exception&
e) {
325 std::cerr <<
"Error reading " << model <<
": " << e.what() <<
"\n";
330 catch (
const std::exception&
e) {
331 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
335 std::cerr <<
"Caught unknown exception\n";
Math::real MinTime() const
const std::string & MagneticModelName() const
noiseModel::Diagonal::shared_ptr model
Header for GeographicLib::Utility class.
static bool isfinite(T x)
Header for GeographicLib::MagneticCircle class.
Math::real MaxHeight() const
Math::real MaxTime() const
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
Model of the earth's magnetic field.
Geomagnetic field on a circle of latitude.
MagneticCircle Circle(real t, real lat, real h) const
const std::string & MagneticFile() const
static int extra_digits()
static void FieldComponents(real Bx, real By, real Bz, real &H, real &F, real &D, real &I)
const std::string & Description() const
static std::string Encode(real angle, component trailing, unsigned prec, flag ind=NONE, char dmssep=char(0))
int main(int argc, const char *const argv[])
#define GEOGRAPHICLIB_VERSION_STRING
static Math::real Decode(const std::string &dms, flag &ind)
Namespace for GeographicLib.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Header for GeographicLib::MagneticModel class.
static std::string str(T x, int p=-1)
static std::string DefaultMagneticName()
string::const_iterator It
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool longfirst=false)
static int set_digits(int ndigits=0)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
Exception handling for GeographicLib.
const std::string & DateTime() const
static std::string DefaultMagneticPath()
Math::real MinHeight() const
Header for GeographicLib::DMS class.