wmm_point.c
Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 
00003 #include <stdio.h>
00004 #include <string.h>
00005 #include <math.h>
00006 #include <stdlib.h>
00007 
00008 
00009 #include "GeomagnetismHeader.h"
00010 //#include "GeomagnetismLibrary.c"
00011 #include "EGM9615.h"
00012 
00013 //---------------------------------------------------------------------------
00014 
00015 /* 
00016 WMM Point Calculation Program.
00017 
00018 The Geomagnetism Library is used to make a command prompt program. The program prompts
00019 the user to enter a location, performs the computations and prints the results to the
00020 standard output. The program expects the files GeomagnetismLibrary.c, GeomagnetismHeader.h,
00021 WMM.COF and EGM9615.h to be in the same directory. 
00022 
00023 Manoj.C.Nair@Noaa.Gov
00024 April 21, 2011
00025 
00026  *  Revision Number: $Revision: 842 $
00027  *  Last changed by: $Author: awoods $
00028  *  Last changed on: $Date: 2012-04-20 14:59:13 -0600 (Fri, 20 Apr 2012) $
00029  */
00030 
00031 int main()
00032 {
00033     MAGtype_MagneticModel * MagneticModels[1], *TimedMagneticModel;
00034     MAGtype_Ellipsoid Ellip;
00035     MAGtype_CoordSpherical CoordSpherical;
00036     MAGtype_CoordGeodetic CoordGeodetic;
00037     MAGtype_Date UserDate;
00038     MAGtype_GeoMagneticElements GeoMagneticElements;
00039     MAGtype_Geoid Geoid;
00040     char ans[20], b;
00041     char filename[] = "WMM.COF";
00042     char VersionDate_Large[] = "$Date: 2012-04-20 14:59:13 -0600 (Fri, 20 Apr 2012) $";
00043     char VersionDate[12];
00044     int NumTerms, Flag = 1, nMax = 0;
00045     int epochs = 1;
00046     /* Memory allocation */
00047 
00048     strncpy(VersionDate, VersionDate_Large + 39, 11);
00049     VersionDate[11] = '\0';
00050     MAG_robustReadMagModels(filename, &MagneticModels, epochs);
00051     if(nMax < MagneticModels[0]->nMax) nMax = MagneticModels[0]->nMax;
00052     NumTerms = ((nMax + 1) * (nMax + 2) / 2);
00053     TimedMagneticModel = MAG_AllocateModelMemory(NumTerms); /* For storing the time modified WMM Model parameters */
00054     if(MagneticModels[0] == NULL || TimedMagneticModel == NULL)
00055     {
00056         MAG_Error(2);
00057     }
00058     MAG_SetDefaults(&Ellip, &Geoid); /* Set default values and constants */
00059     /* Check for Geographic Poles */
00060 
00061 
00062     //MAG_InitializeGeoid(&Geoid);    /* Read the Geoid file */
00063 
00064     /* Set EGM96 Geoid parameters */
00065     Geoid.GeoidHeightBuffer = GeoidHeightBuffer;
00066     Geoid.Geoid_Initialized = 1;
00067     /* Set EGM96 Geoid parameters END */
00068     b = MAG_GeomagIntroduction_WMM(MagneticModels[0], VersionDate);
00069     while(Flag == 1 && b != 'x')
00070     {
00071         if(MAG_GetUserInput(MagneticModels[0], &Geoid, &CoordGeodetic, &UserDate) == 1) /*Get User Input */
00072         {
00073             MAG_GeodeticToSpherical(Ellip, CoordGeodetic, &CoordSpherical); /*Convert from geodetic to Spherical Equations: 17-18, WMM Technical report*/
00074             MAG_TimelyModifyMagneticModel(UserDate, MagneticModels[0], TimedMagneticModel); /* Time adjust the coefficients, Equation 19, WMM Technical report */
00075             MAG_Geomag(Ellip, CoordSpherical, CoordGeodetic, TimedMagneticModel, &GeoMagneticElements); /* Computes the geoMagnetic field elements and their time change*/
00076             MAG_CalculateGridVariation(CoordGeodetic, &GeoMagneticElements);
00077             MAG_PrintUserData(GeoMagneticElements, CoordGeodetic, UserDate, TimedMagneticModel, &Geoid); /* Print the results */
00078         }
00079         printf("\n\n Do you need more point data ? (y or n) \n ");
00080         fgets(ans, 20, stdin);
00081         switch(ans[0]) {
00082             case 'Y':
00083             case 'y':
00084                 Flag = 1;
00085                 break;
00086             case 'N':
00087             case 'n':
00088                 Flag = 0;
00089                 break;
00090             default:
00091                 Flag = 0;
00092                 break;
00093         }
00094 
00095     }
00096 
00097 
00098     MAG_FreeMagneticModelMemory(TimedMagneticModel);
00099     MAG_FreeMagneticModelMemory(MagneticModels[0]);
00100 
00101     return 0;
00102 }


world_magnetic_model
Author(s): National Geophysical Data Center (NGDC, Boulder CO, USA), British Geological Survey (BGS, Edinburgh, Scotland)
autogenerated on Sat Jul 26 2014 07:02:19