1=head1 NAME 2 3MagneticField -- compute the earth's magnetic field 4 5=head1 SYNOPSIS 6 7B<MagneticField> [ B<-n> I<name> ] [ B<-d> I<dir> ] 8[ B<-N> I<Nmax> ] [ B<-M> I<Mmax> ] 9[ B<-t> I<time> | B<-c> I<time> I<lat> I<h> ] 10[ B<-r> ] [ B<-w> ] [ B<-T> I<tguard> ] [ B<-H> I<hguard> ] [ B<-p> I<prec> ] 11[ B<-v> ] 12[ B<--comment-delimiter> I<commentdelim> ] 13[ B<--version> | B<-h> | B<--help> ] 14[ B<--input-file> I<infile> | B<--input-string> I<instring> ] 15[ B<--line-separator> I<linesep> ] 16[ B<--output-file> I<outfile> ] 17 18=head1 DESCRIPTION 19 20B<MagneticField> reads in times and positions on standard input and 21prints out the geomagnetic field on standard output and, optionally, its 22rate of change. 23 24The input line is of the form I<time> I<lat> I<lon> I<h>. I<time> is a 25date of the form 2012-07-03, a fractional year such as 2012.5, or the 26string "now". I<lat> and I<lon> are the latitude and longitude 27expressed as decimal degrees or degrees, minutes, and seconds; for 28details on the allowed formats for latitude and longitude, see the 29C<GEOGRAPHIC COORDINATES> section of GeoConvert(1). I<h> is the height 30above the ellipsoid in meters; this is optional and defaults to zero. 31Alternatively, I<time> can be given on the command line as the argument 32to the B<-t> option, in which case it should not be included on the 33input lines. Finally, the magnetic field can be computed at various 34points on a circle of latitude (constant I<time>, I<lat>, and I<h>) via 35the B<-c> option; in this case only the longitude should be given on the 36input lines. 37 38The output consists of the following 7 items: 39 40 the declination (the direction of the horizontal component of 41 the magnetic field measured clockwise from north) in degrees, 42 the inclination (the direction of the magnetic field measured 43 down from the horizontal) in degrees, 44 the horizontal field in nanotesla (nT), 45 the north component of the field in nT, 46 the east component of the field in nT, 47 the vertical component of the field in nT (down is positive), 48 the total field in nT. 49 50If the B<-r> option is given, a second line is printed giving the rates 51of change of these quantities in degrees/yr and nT/yr. 52 53The WGS84 ellipsoid is used, I<a> = 6378137 m, I<f> = 1/298.257223563. 54 55=head1 OPTIONS 56 57=over 58 59=item B<-n> I<name> 60 61use magnetic field model I<name> instead of the default C<wmm2020>. See 62L</MODELS>. 63 64=item B<-d> I<dir> 65 66read magnetic models from I<dir> instead of the default. See 67L</MODELS>. 68 69=item B<-N> I<Nmax> 70 71limit the degree of the model to I<Nmax>. 72 73=item B<-M> I<Mmax> 74 75limit the order of the model to I<Mmax>. 76 77=item B<-t> I<time> 78 79evaluate the field at I<time> instead of reading the time from the input 80lines. 81 82=item B<-c> I<time> I<lat> I<h> 83 84evaluate the field on a circle of latitude given by I<time>, I<lat>, 85I<h> instead of reading these quantities from the input lines. In this 86case, B<MagneticField> can calculate the field considerably more 87quickly. 88 89=item B<-r> 90 91toggle whether to report the rates of change of the field. 92 93=item B<-w> 94 95toggle the longitude first flag (it starts off); if the flag is on, then 96on input and output, longitude precedes latitude (except that, on input, 97this can be overridden by a hemisphere designator, I<N>, I<S>, I<E>, 98I<W>). 99 100=item B<-T> I<tguard> 101 102signal an error if I<time> lies I<tguard> years (default 50 yr) beyond 103the range for the model. 104 105=item B<-H> I<hguard> 106 107signal an error if I<h> lies I<hguard> meters (default 500000 m) beyond 108the range for the model. 109 110=item B<-p> I<prec> 111 112set the output precision to I<prec> (default 1). Fields are printed 113with precision with I<prec> decimal places; angles use I<prec> + 1 114places. 115 116=item B<-v> 117 118print information about the magnetic model on standard error before 119processing the input. 120 121=item B<--comment-delimiter> I<commentdelim> 122 123set the comment delimiter to I<commentdelim> (e.g., "#" or "//"). If 124set, the input lines will be scanned for this delimiter and, if found, 125the delimiter and the rest of the line will be removed prior to 126processing and subsequently appended to the output line (separated by a 127space). 128 129=item B<--version> 130 131print version and exit. 132 133=item B<-h> 134 135print usage, the default magnetic path and name, and exit. 136 137=item B<--help> 138 139print full documentation and exit. 140 141=item B<--input-file> I<infile> 142 143read input from the file I<infile> instead of from standard input; a file 144name of "-" stands for standard input. 145 146=item B<--input-string> I<instring> 147 148read input from the string I<instring> instead of from standard input. 149All occurrences of the line separator character (default is a semicolon) 150in I<instring> are converted to newlines before the reading begins. 151 152=item B<--line-separator> I<linesep> 153 154set the line separator character to I<linesep>. By default this is a 155semicolon. 156 157=item B<--output-file> I<outfile> 158 159write output to the file I<outfile> instead of to standard output; a 160file name of "-" stands for standard output. 161 162=back 163 164=head1 MODELS 165 166B<MagneticField> computes the geomagnetic field using one of the 167following models 168 169 wmm2010, the World Magnetic Model 2010, which approximates the 170 main magnetic field for the period 2010-2015. See 171 https://ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml 172 wmm2015v2, the World Magnetic Model 2015, which approximates the 173 main magnetic field for the period 2015-2020. See 174 https://ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml 175 wmm2015, a deprecated version of wmm2015v2 176 wmm2020, the World Magnetic Model 2020, which approximates the 177 main magnetic field for the period 2020-2025. See 178 https://ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml 179 igrf11, the International Geomagnetic Reference Field (11th 180 generation), which approximates the main magnetic field for 181 the period 1900-2015. See 182 https://ngdc.noaa.gov/IAGA/vmod/igrf.html 183 igrf12, the International Geomagnetic Reference Field (12th 184 generation), which approximates the main magnetic field for 185 the period 1900-2020. See 186 https://ngdc.noaa.gov/IAGA/vmod/igrf.html 187 igrf13, the International Geomagnetic Reference Field (13th 188 generation), which approximates the main magnetic field for 189 the period 1900-2025. See 190 https://ngdc.noaa.gov/IAGA/vmod/igrf.html 191 emm2010, the Enhanced Magnetic Model 2010, which approximates 192 the main and crustal magnetic fields for the period 2010-2015. 193 See https://ngdc.noaa.gov/geomag/EMM/index.html 194 emm2015, the Enhanced Magnetic Model 2015, which approximates 195 the main and crustal magnetic fields for the period 2000-2020. 196 See https://ngdc.noaa.gov/geomag/EMM/index.html 197 emm2017, the Enhanced Magnetic Model 2017, which approximates 198 the main and crustal magnetic fields for the period 2000-2022. 199 See https://ngdc.noaa.gov/geomag/EMM/index.html 200 201These models approximate the magnetic field due to the earth's core and 202(in the case of emm20xx) its crust. They neglect magnetic fields due to 203the ionosphere, the magnetosphere, nearby magnetized materials, 204electrical machinery, etc. 205 206By default, the C<wmm2020> magnetic model is used. This may changed by 207setting the environment variable C<GEOGRAPHICLIB_MAGNETIC_NAME> or with 208the B<-n> option. 209 210The magnetic models will be loaded from a directory specified at compile 211time. This may changed by setting the environment variables 212C<GEOGRAPHICLIB_MAGNETIC_PATH> or C<GEOGRAPHICLIB_DATA>, or with the 213B<-d> option. The B<-h> option prints the default magnetic path and 214name. Use the B<-v> option to ascertain the full path name of the data 215file. 216 217Instructions for downloading and installing magnetic models are 218available at 219L<https://geographiclib.sourceforge.io/html/magnetic.html#magneticinst>. 220 221=head1 ENVIRONMENT 222 223=over 224 225=item B<GEOGRAPHICLIB_MAGNETIC_NAME> 226 227Override the compile-time default magnetic name of C<wmm2020>. The 228B<-h> option reports the value of B<GEOGRAPHICLIB_MAGNETIC_NAME>, if 229defined, otherwise it reports the compile-time value. If the B<-n> 230I<name> option is used, then I<name> takes precedence. 231 232=item B<GEOGRAPHICLIB_MAGNETIC_PATH> 233 234Override the compile-time default magnetic path. This is typically 235C</usr/local/share/GeographicLib/magnetic> on Unix-like systems and 236C<C:/ProgramData/GeographicLib/magnetic> on Windows systems. The B<-h> 237option reports the value of B<GEOGRAPHICLIB_MAGNETIC_PATH>, if defined, 238otherwise it reports the compile-time value. If the B<-d> I<dir> option 239is used, then I<dir> takes precedence. 240 241=item B<GEOGRAPHICLIB_DATA> 242 243Another way of overriding the compile-time default magnetic path. If it 244is set (and if B<GEOGRAPHICLIB_MAGNETIC_PATH> is not set), then 245$B<GEOGRAPHICLIB_DATA>/magnetic is used. 246 247=back 248 249=head1 ERRORS 250 251An illegal line of input will print an error message to standard output 252beginning with C<ERROR:> and causes B<MagneticField> to return an exit 253code of 1. However, an error does not cause B<MagneticField> to 254terminate; following lines will be converted. If I<time> or I<h> are 255outside the recommended ranges for the model (but inside the ranges 256increase by I<tguard> and I<hguard>), a warning is printed on standard 257error and the field (which may be inaccurate) is returned in the normal 258way. 259 260=head1 EXAMPLES 261 262The magnetic field from WMM2020 in Timbuktu on 2020-01-01 263 264 echo 2020-01-01 16:46:33N 3:00:34W 300 | MagneticField -r 265 => -1.60 12.00 33973.5 33960.3 -948.1 7223.0 34732.8 266 0.13 -0.02 21.8 23.9 77.9 -8.4 19.5 267 268The first two numbers returned are the declination and inclination of 269the field. The second line gives the annual change. 270 271=head1 SEE ALSO 272 273GeoConvert(1), geographiclib-get-magnetic(8). 274 275=head1 AUTHOR 276 277B<MagneticField> was written by Charles Karney. 278 279=head1 HISTORY 280 281B<MagneticField> was added to GeographicLib, 282L<https://geographiclib.sourceforge.io>, in version 1.15. 283