00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _POSIX_C_SOURCE
00017 #define _POSIX_C_SOURCE
00018 #endif
00019
00020
00021
00022
00023
00024 #define READONLYMODE "r"
00025 #define MAXLINELENGTH (1024)
00026 #define NOOFPARAMS (15)
00027 #define NOOFCOEFFICIENTS (7)
00028
00029
00030 #define _DEGREE_NOT_FOUND (-2)
00031 #define CALCULATE_NUMTERMS(N) (N * ( N + 1 ) / 2 + N)
00032
00033 #ifndef WMMHEADER_H
00034 #define WMMHEADER_H
00035
00036 #ifndef M_PI
00037 #define M_PI ((2)*(acos(0.0)))
00038 #endif
00039
00040 #define RAD2DEG(rad) ((rad)*(180.0L/M_PI))
00041 #define DEG2RAD(deg) ((deg)*(M_PI/180.0L))
00042 #define ATanH(x) (0.5 * log((1 + x) / (1 - x)))
00043
00044
00045 #define TRUE ((int)1)
00046 #define FALSE ((int)0)
00047
00048
00049
00050
00051 #define MAG_PS_MIN_LAT_DEGREE -55
00052 #define MAG_PS_MAX_LAT_DEGREE 55
00053 #define MAG_UTM_MIN_LAT_DEGREE -80.5
00054 #define MAG_UTM_MAX_LAT_DEGREE 84.5
00055
00056 #define MAG_GEO_POLE_TOLERANCE 1e-5
00057 #define MAG_USE_GEOID 1
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 typedef struct {
00069 double EditionDate;
00070 double epoch;
00071 char ModelName[32];
00072 double *Main_Field_Coeff_G;
00073 double *Main_Field_Coeff_H;
00074 double *Secular_Var_Coeff_G;
00075 double *Secular_Var_Coeff_H;
00076 int nMax;
00077 int nMaxSecVar;
00078 int SecularVariationUsed;
00079 double CoefficientFileEndDate;
00080 } MAGtype_MagneticModel;
00081
00082 typedef struct {
00083 double a;
00084 double b;
00085 double fla;
00086 double epssq;
00087 double eps;
00088 double re;
00089 } MAGtype_Ellipsoid;
00090
00091 typedef struct {
00092 double lambda;
00093 double phi;
00094 double HeightAboveEllipsoid;
00095 double HeightAboveGeoid;
00096 int UseGeoid;
00097 } MAGtype_CoordGeodetic;
00098
00099 typedef struct {
00100 double lambda;
00101 double phig;
00102 double r;
00103 } MAGtype_CoordSpherical;
00104
00105 typedef struct {
00106 int Year;
00107 int Month;
00108 int Day;
00109 double DecimalYear;
00110 } MAGtype_Date;
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 typedef struct {
00121 double *Pcup;
00122 double *dPcup;
00123 } MAGtype_LegendreFunction;
00124
00125 typedef struct {
00126 double Bx;
00127 double By;
00128 double Bz;
00129 } MAGtype_MagneticResults;
00130
00131 typedef struct {
00132 double *RelativeRadiusPower;
00133 double *cos_mlambda;
00134 double *sin_mlambda;
00135 } MAGtype_SphericalHarmonicVariables;
00136
00137 typedef struct {
00138 double Decl;
00139 double Incl;
00140 double F;
00141 double H;
00142 double X;
00143 double Y;
00144 double Z;
00145 double GV;
00146 double Decldot;
00147 double Incldot;
00148 double Fdot;
00149 double Hdot;
00150 double Xdot;
00151 double Ydot;
00152 double Zdot;
00153 double GVdot;
00154 } MAGtype_GeoMagneticElements;
00155
00156 typedef struct {
00157 int NumbGeoidCols;
00158 int NumbGeoidRows;
00159 int NumbHeaderItems;
00160 int ScaleFactor;
00161 float *GeoidHeightBuffer;
00162 int NumbGeoidElevs;
00163 int Geoid_Initialized;
00164 int UseGeoid;
00165 } MAGtype_Geoid;
00166
00167 typedef struct {
00168 char Longitude[40];
00169 char Latitude[40];
00170 } MAGtype_CoordGeodeticStr;
00171
00172 typedef struct {
00173 double Easting;
00174 double Northing;
00175 int Zone;
00176 char HemiSphere;
00177 double CentralMeridian;
00178 double ConvergenceOfMeridians;
00179 double PointScale;
00180 } MAGtype_UTMParameters;
00181
00182 enum PARAMS {
00183 SHDF,
00184 MODELNAME,
00185 PUBLISHER,
00186 RELEASEDATE,
00187 DATACUTOFF,
00188 MODELSTARTYEAR,
00189 MODELENDYEAR,
00190 EPOCH,
00191 INTSTATICDEG,
00192 INTSECVARDEG,
00193 EXTSTATICDEG,
00194 EXTSECVARDEG,
00195 GEOMAGREFRAD,
00196 NORMALIZATION,
00197 SPATBASFUNC
00198 };
00199
00200 enum COEFFICIENTS {
00201 IE,
00202 N,
00203 M,
00204 GNM,
00205 HNM,
00206 DGNM,
00207 DHNM
00208 };
00209
00210 enum YYYYMMDD {
00211 YEAR,
00212 MONTH,
00213 DAY
00214 };
00215
00216
00217
00218
00219 int MAG_Geomag(MAGtype_Ellipsoid Ellip,
00220 MAGtype_CoordSpherical CoordSpherical,
00221 MAGtype_CoordGeodetic CoordGeodetic,
00222 MAGtype_MagneticModel *TimedMagneticModel,
00223 MAGtype_GeoMagneticElements *GeoMagneticElements);
00224
00225 int MAG_Grid(MAGtype_CoordGeodetic minimum,
00226 MAGtype_CoordGeodetic maximum,
00227 double step_size,
00228 double altitude_step_size,
00229 double time_step,
00230 MAGtype_MagneticModel *MagneticModel,
00231 MAGtype_Geoid *geoid,
00232 MAGtype_Ellipsoid Ellip,
00233 MAGtype_Date StartDate,
00234 MAGtype_Date EndDate,
00235 int ElementOption,
00236 int PrintOption,
00237 char *OutputFile);
00238
00239 int MAG_robustReadMagneticModel_Large(char *filename, char* filenameSV, MAGtype_MagneticModel **MagneticModel, int array_size);
00240
00241 int MAG_robustReadMagModels(char *filename, MAGtype_MagneticModel *(*magneticmodels)[], int array_size);
00242
00243 int MAG_SetDefaults(MAGtype_Ellipsoid *Ellip, MAGtype_Geoid *Geoid);
00244
00245
00246
00247 void MAG_Error(int control);
00248
00249 char MAG_GeomagIntroduction_WMM(MAGtype_MagneticModel *MagneticModel, char *VersionDate);
00250
00251 char MAG_GeomagIntroduction_EMM(MAGtype_MagneticModel *MagneticModel, char *VersionDate);
00252
00253 int MAG_GetUserGrid(MAGtype_CoordGeodetic *minimum,
00254 MAGtype_CoordGeodetic *maximum,
00255 double *step_size,
00256 double *a_step_size,
00257 double *step_time,
00258 MAGtype_Date *StartDate,
00259 MAGtype_Date *EndDate,
00260 int *ElementOption,
00261 int *PrintOption,
00262 char *OutputFile,
00263 MAGtype_Geoid *Geoid);
00264
00265 int MAG_GetUserInput(MAGtype_MagneticModel *MagneticModel,
00266 MAGtype_Geoid *Geoid,
00267 MAGtype_CoordGeodetic *CoordGeodetic,
00268 MAGtype_Date *MagneticDate);
00269
00270 void MAG_PrintUserData(MAGtype_GeoMagneticElements GeomagElements,
00271 MAGtype_CoordGeodetic SpaceInput,
00272 MAGtype_Date TimeInput,
00273 MAGtype_MagneticModel *MagneticModel,
00274 MAGtype_Geoid *Geoid);
00275
00276 int MAG_ValidateDMSstringlat(char *input, char *Error);
00277
00278 int MAG_ValidateDMSstringlong(char *input, char *Error);
00279
00280 int MAG_Warnings(int control, double value, MAGtype_MagneticModel *MagneticModel);
00281
00282
00283
00284 MAGtype_LegendreFunction *MAG_AllocateLegendreFunctionMemory(int NumTerms);
00285
00286 MAGtype_MagneticModel *MAG_AllocateModelMemory(int NumTerms);
00287
00288 MAGtype_SphericalHarmonicVariables *MAG_AllocateSphVarMemory(int nMax);
00289
00290 void MAG_AssignHeaderValues(MAGtype_MagneticModel *model, char values[][MAXLINELENGTH]);
00291
00292 void MAG_AssignMagneticModelCoeffs(MAGtype_MagneticModel *Assignee, MAGtype_MagneticModel *Source, int nMax, int nMaxSecVar);
00293
00294 int MAG_FreeMemory(MAGtype_MagneticModel *MagneticModel, MAGtype_MagneticModel *TimedMagneticModel, MAGtype_LegendreFunction *LegendreFunction);
00295
00296 int MAG_FreeLegendreMemory(MAGtype_LegendreFunction *LegendreFunction);
00297
00298 int MAG_FreeMagneticModelMemory(MAGtype_MagneticModel *MagneticModel);
00299
00300 int MAG_FreeSphVarMemory(MAGtype_SphericalHarmonicVariables *SphVar);
00301
00302 void MAG_PrintWMMFormat(char *filename, MAGtype_MagneticModel *MagneticModel);
00303
00304 void MAG_PrintEMMFormat(char *filename, char *filenameSV, MAGtype_MagneticModel *MagneticModel);
00305
00306 int MAG_readMagneticModel(char *filename, MAGtype_MagneticModel *MagneticModel);
00307
00308 int MAG_readMagneticModel_Large(char *filename, char *filenameSV, MAGtype_MagneticModel *MagneticModel);
00309
00310 int MAG_readMagneticModel_SHDF(char *filename, MAGtype_MagneticModel *(*magneticmodels)[], int array_size);
00311
00312 int MAG_swab_type();
00313
00314 char *MAG_Trim(char *str);
00315
00316 float MAG_FloatSwap(float f);
00317
00318
00319
00320 int MAG_CalculateGeoMagneticElements(MAGtype_MagneticResults *MagneticResultsGeo, MAGtype_GeoMagneticElements *GeoMagneticElements);
00321
00322 int MAG_CalculateSecularVariationElements(MAGtype_MagneticResults MagneticVariation, MAGtype_GeoMagneticElements *MagneticElements);
00323
00324 int MAG_CalculateGridVariation(MAGtype_CoordGeodetic location, MAGtype_GeoMagneticElements *elements);
00325
00326 int MAG_DateToYear(MAGtype_Date *Calendar_Date, char *Error);
00327
00328 void MAG_DegreeToDMSstring(double DegreesOfArc, int UnitDepth, char *DMSstring);
00329
00330 void MAG_DMSstringToDegree(char *DMSstring, double *DegreesOfArc);
00331
00332 int MAG_GeodeticToSpherical(MAGtype_Ellipsoid Ellip, MAGtype_CoordGeodetic CoordGeodetic, MAGtype_CoordSpherical *CoordSpherical);
00333
00334 int MAG_GetTransverseMercator(MAGtype_CoordGeodetic CoordGeodetic, MAGtype_UTMParameters *UTMParameters);
00335
00336 int MAG_GetUTMParameters(double Latitude,
00337 double Longitude,
00338 int *Zone,
00339 char *Hemisphere,
00340 double *CentralMeridian);
00341
00342 int MAG_isNaN(double d);
00343
00344 int MAG_RotateMagneticVector(MAGtype_CoordSpherical,
00345 MAGtype_CoordGeodetic CoordGeodetic,
00346 MAGtype_MagneticResults MagneticResultsSph,
00347 MAGtype_MagneticResults *MagneticResultsGeo);
00348
00349 void MAG_SphericalToCartesian(MAGtype_CoordSpherical CoordSpherical, double *x, double *y, double *z);
00350
00351 void MAG_TMfwd4(double Eps, double Epssq, double K0R4, double K0R4oa,
00352 double Acoeff[], double Lam0, double K0, double falseE,
00353 double falseN, int XYonly, double Lambda, double Phi,
00354 double *X, double *Y, double *pscale, double *CoM);
00355
00356 int MAG_YearToDate(MAGtype_Date *Date);
00357
00358
00359
00360
00361 int MAG_AssociatedLegendreFunction(MAGtype_CoordSpherical CoordSpherical, int nMax, MAGtype_LegendreFunction *LegendreFunction);
00362
00363 int MAG_CheckGeographicPole(MAGtype_CoordGeodetic *CoordGeodetic);
00364
00365 int MAG_ComputeSphericalHarmonicVariables(MAGtype_Ellipsoid Ellip,
00366 MAGtype_CoordSpherical CoordSpherical,
00367 int nMax,
00368 MAGtype_SphericalHarmonicVariables * SphVariables);
00369
00370 int MAG_PcupHigh(double *Pcup, double *dPcup, double x, int nMax);
00371
00372 int MAG_PcupLow(double *Pcup, double *dPcup, double x, int nMax);
00373
00374 int MAG_SecVarSummation(MAGtype_LegendreFunction *LegendreFunction,
00375 MAGtype_MagneticModel *MagneticModel,
00376 MAGtype_SphericalHarmonicVariables SphVariables,
00377 MAGtype_CoordSpherical CoordSpherical,
00378 MAGtype_MagneticResults *MagneticResults);
00379
00380 int MAG_SecVarSummationSpecial(MAGtype_MagneticModel *MagneticModel,
00381 MAGtype_SphericalHarmonicVariables SphVariables,
00382 MAGtype_CoordSpherical CoordSpherical,
00383 MAGtype_MagneticResults *MagneticResults);
00384
00385 int MAG_Summation(MAGtype_LegendreFunction *LegendreFunction,
00386 MAGtype_MagneticModel *MagneticModel,
00387 MAGtype_SphericalHarmonicVariables SphVariables,
00388 MAGtype_CoordSpherical CoordSpherical,
00389 MAGtype_MagneticResults *MagneticResults);
00390
00391 int MAG_SummationSpecial(MAGtype_MagneticModel *MagneticModel,
00392 MAGtype_SphericalHarmonicVariables SphVariables,
00393 MAGtype_CoordSpherical CoordSpherical,
00394 MAGtype_MagneticResults *MagneticResults);
00395
00396 int MAG_TimelyModifyMagneticModel(MAGtype_Date UserDate, MAGtype_MagneticModel *MagneticModel, MAGtype_MagneticModel *TimedMagneticModel);
00397
00398
00399
00400 int MAG_InitializeGeoid(MAGtype_Geoid *Geoid);
00401
00402
00403
00404 int MAG_ConvertGeoidToEllipsoidHeight(MAGtype_CoordGeodetic *CoordGeodetic, MAGtype_Geoid *Geoid);
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417 int MAG_GetGeoidHeight(double Latitude, double Longitude, double *DeltaHeight, MAGtype_Geoid *Geoid);
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435 #endif