void computeGeoMagElements(void) { setupGeoMagWorkspace(); coordGeodetic.lambda = (float)gps.longitude * 1E-7f; // Convert to decimal degrees coordGeodetic.phi = (float)gps.latitude * 1E-7f; // Convert to decimal degrees coordGeodetic.HeightAboveEllipsoid = (float)gps.height * 1E-6f; // Convert from mm to km coordGeodetic.UseGeoid = 0; userDate.Year = gps.year; userDate.Month = gps.month; userDate.Day = gps.day; //cliPrintF("GPS Lat: %7.3f\n", coordGeodetic.phi); //cliPrintF("GPS Lon: %7.3f\n", coordGeodetic.lambda); //cliPrintF("GPS Alt: %7.3f\n", coordGeodetic.HeightAboveEllipsoid); //cliPrint ("\n"); //MAG_DateToYear(&userDate); //cliPrintF("GPS Mon: %4ld\n", userDate.Month); //cliPrintF("GPS Day: %4ld\n", userDate.Day); //cliPrintF("GPS Yr: %4ld\n", userDate.Year); //cliPrintF("GPS Dec Yr: %7.3f\n", userDate.DecimalYear); //cliPrint ("\n"); userDate.DecimalYear = readFloatCLI(); coordGeodetic.HeightAboveEllipsoid = readFloatCLI(); coordGeodetic.phi = readFloatCLI(); coordGeodetic.lambda = readFloatCLI(); MAG_GeodeticToSpherical(ellipsoid, coordGeodetic, &coordSpherical); MAG_TimelyModifyMagneticModel(userDate, magneticModel, timedMagneticModel); MAG_Geomag(ellipsoid, coordSpherical, coordGeodetic, timedMagneticModel, &geoMagneticElements); cliPrint ("\n"); cliPrintF("Dec Yr: %8.1f\n", userDate.DecimalYear); cliPrintF("Alt: %8.1f\n", coordGeodetic.HeightAboveEllipsoid); cliPrintF("Lat: %8.1f\n", coordGeodetic.phi); cliPrintF("Lon: %8.1f\n", coordGeodetic.lambda); cliPrint ("\n"); cliPrintF("X: %8.1f\n", geoMagneticElements.X); cliPrintF("Y: %8.1f\n", geoMagneticElements.Y); cliPrintF("Z: %8.1f\n", geoMagneticElements.Z); cliPrintF("H: %8.1f\n", geoMagneticElements.H); cliPrintF("F: %8.1f\n", geoMagneticElements.F); cliPrintF("INCL: %8.1f\n", geoMagneticElements.Incl); cliPrintF("DECL: %8.1f\n", geoMagneticElements.Decl); cliPrint ("\n"); clearGeoMagWorkspace(); }
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; }