5
|
1 |
|
|
2 |
#include "geomag.h"
|
|
3 |
#include <time.h>
|
|
4 |
#include <math.h>
|
|
5 |
|
|
6 |
|
|
7 |
static char usage[] = " Usage:\n"
|
|
8 |
" magdec lon lat [year [month [day]]]\n"
|
|
9 |
" lon, lat: in decimal degrees\n"
|
|
10 |
" year, month, day: integer date\n"
|
|
11 |
" or just decimal year\n"
|
|
12 |
" If no date is given, the present date is used\n"
|
|
13 |
" 1 is substituted for missing month and/or day\n\n"
|
|
14 |
" Prints to stdout: 4 floating point"
|
|
15 |
" numbers separated by spaces:\n"
|
|
16 |
" declination, inclination in degrees\n"
|
|
17 |
" horizontal field, total field in nanoTeslas\n\n"
|
|
18 |
" "
|
|
19 |
" Note: this version uses IGRF11, released in Dec. 2009."
|
|
20 |
" Model parameters are hard-coded; no external"
|
|
21 |
" file is needed."
|
|
22 |
"";
|
|
23 |
|
|
24 |
|
|
25 |
int main(int argc, char **argv)
|
|
26 |
{
|
|
27 |
struct model_t **model_array;
|
|
28 |
int nmodels;
|
|
29 |
double dtest, itest, htest, ftest;
|
|
30 |
int year, month, day;
|
|
31 |
double dyear;
|
|
32 |
double lon, lat;
|
|
33 |
struct tm *now;
|
|
34 |
time_t now_seconds;
|
|
35 |
int nscan;
|
|
36 |
|
|
37 |
if (argc < 3 || argc > 6)
|
|
38 |
{
|
|
39 |
puts(usage);
|
|
40 |
return 1;
|
|
41 |
}
|
|
42 |
|
|
43 |
nscan = sscanf(argv[1], "%lf", &lon);
|
|
44 |
nscan += sscanf(argv[2], "%lf", &lat);
|
|
45 |
|
|
46 |
if (nscan != 2)
|
|
47 |
{
|
|
48 |
puts(usage);
|
|
49 |
return 1;
|
|
50 |
}
|
|
51 |
|
|
52 |
|
|
53 |
if (argc == 3)
|
|
54 |
{
|
|
55 |
now_seconds = time(NULL);
|
|
56 |
now = gmtime(&now_seconds);
|
|
57 |
year = now->tm_year + 1900;
|
|
58 |
month = now->tm_mon + 1;
|
|
59 |
day = now->tm_mday;
|
|
60 |
}
|
|
61 |
else
|
|
62 |
{
|
|
63 |
if (argc == 4)
|
|
64 |
{
|
|
65 |
dyear = atof(argv[3]);
|
|
66 |
/* the rest won't actually be used in this case */
|
|
67 |
year = (int)dyear;
|
|
68 |
month = 1 + (int)((dyear - year) * 12);
|
|
69 |
day = 1;
|
|
70 |
}
|
|
71 |
if (argc > 4)
|
|
72 |
{
|
|
73 |
year = atoi(argv[3]);
|
|
74 |
month = atoi(argv[4]);
|
|
75 |
day = 1;
|
|
76 |
}
|
|
77 |
if (argc == 6)
|
|
78 |
{
|
|
79 |
day = atoi(argv[5]);
|
|
80 |
}
|
|
81 |
}
|
|
82 |
|
|
83 |
if (argc != 4)
|
|
84 |
{
|
|
85 |
dyear = julday(month, day, year);
|
|
86 |
/* julday function is mis-named--it simply returns decimal year */
|
|
87 |
}
|
|
88 |
|
|
89 |
while (lon > 180.0)
|
|
90 |
{
|
|
91 |
lon -= 360.0;
|
|
92 |
}
|
|
93 |
while (lon < -180.0)
|
|
94 |
{
|
|
95 |
lon += 360.0;
|
|
96 |
}
|
|
97 |
/* printf("lon %lf lat %lf dyear %lf year %d month %d day %d\n",
|
|
98 |
* lon, lat, dyear, year, month, day);
|
|
99 |
*/
|
|
100 |
|
|
101 |
nmodels = models_from_lines(&model_array);
|
|
102 |
|
|
103 |
dihf_from_models(model_array, nmodels,
|
|
104 |
dyear, lon, lat,
|
|
105 |
&dtest, &itest, &htest, &ftest);
|
|
106 |
printf("%lf %lf %lf %lf\n",
|
|
107 |
dtest, itest, htest, ftest);
|
|
108 |
|
|
109 |
free_models(model_array, nmodels);
|
|
110 |
return 0;
|
|
111 |
}
|
|
112 |
|