-
Notifications
You must be signed in to change notification settings - Fork 1
/
wmm_point.c
102 lines (85 loc) · 3.61 KB
/
wmm_point.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//---------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include "GeomagnetismHeader.h"
//#include "GeomagnetismLibrary.c"
#include "EGM9615.h"
//---------------------------------------------------------------------------
/*
WMM Point Calculation Program.
The Geomagnetism Library is used to make a command prompt program. The program prompts
the user to enter a location, performs the computations and prints the results to the
standard output. The program expects the files GeomagnetismLibrary.c, GeomagnetismHeader.h,
WMM.COF and EGM9615.h to be in the same directory.
April 21, 2011
* Revision Number: $Revision: 842 $
* Last changed by: $Author: awoods $
* Last changed on: $Date: 2012-04-20 14:59:13 -0600 (Fri, 20 Apr 2012) $
*/
int main()
{
MAGtype_MagneticModel * MagneticModels[1], *TimedMagneticModel;
MAGtype_Ellipsoid Ellip;
MAGtype_CoordSpherical CoordSpherical;
MAGtype_CoordGeodetic CoordGeodetic;
MAGtype_Date UserDate;
MAGtype_GeoMagneticElements GeoMagneticElements;
MAGtype_Geoid Geoid;
char ans[20], b;
char filename[] = "WMM.COF";
char VersionDate_Large[] = "$Date: 2012-04-20 14:59:13 -0600 (Fri, 20 Apr 2012) $";
char VersionDate[12];
int NumTerms, Flag = 1, nMax = 0;
int epochs = 1;
/* Memory allocation */
strncpy(VersionDate, VersionDate_Large + 39, 11);
VersionDate[11] = '\0';
MAG_robustReadMagModels(filename, &MagneticModels, epochs);
if(nMax < MagneticModels[0]->nMax) nMax = MagneticModels[0]->nMax;
NumTerms = ((nMax + 1) * (nMax + 2) / 2);
TimedMagneticModel = MAG_AllocateModelMemory(NumTerms); /* For storing the time modified WMM Model parameters */
if(MagneticModels[0] == NULL || TimedMagneticModel == NULL)
{
MAG_Error(2);
}
MAG_SetDefaults(&Ellip, &Geoid); /* Set default values and constants */
/* Check for Geographic Poles */
//MAG_InitializeGeoid(&Geoid); /* Read the Geoid file */
/* Set EGM96 Geoid parameters */
Geoid.GeoidHeightBuffer = GeoidHeightBuffer;
Geoid.Geoid_Initialized = 1;
/* Set EGM96 Geoid parameters END */
b = MAG_GeomagIntroduction_WMM(MagneticModels[0], VersionDate);
while(Flag == 1 && b != 'x')
{
if(MAG_GetUserInput(MagneticModels[0], &Geoid, &CoordGeodetic, &UserDate) == 1) /*Get User Input */
{
MAG_GeodeticToSpherical(Ellip, CoordGeodetic, &CoordSpherical); /*Convert from geodetic to Spherical Equations: 17-18, WMM Technical report*/
MAG_TimelyModifyMagneticModel(UserDate, MagneticModels[0], TimedMagneticModel); /* Time adjust the coefficients, Equation 19, WMM Technical report */
MAG_Geomag(Ellip, CoordSpherical, CoordGeodetic, TimedMagneticModel, &GeoMagneticElements); /* Computes the geoMagnetic field elements and their time change*/
MAG_CalculateGridVariation(CoordGeodetic, &GeoMagneticElements);
MAG_PrintUserData(GeoMagneticElements, CoordGeodetic, UserDate, TimedMagneticModel, &Geoid); /* Print the results */
}
printf("\n\n Do you need more point data ? (y or n) \n ");
fgets(ans, 20, stdin);
switch(ans[0]) {
case 'Y':
case 'y':
Flag = 1;
break;
case 'N':
case 'n':
Flag = 0;
break;
default:
Flag = 0;
break;
}
}
MAG_FreeMagneticModelMemory(TimedMagneticModel);
MAG_FreeMagneticModelMemory(MagneticModels[0]);
return 0;
}