Beispiel #1
0
void setupGeoMagWorkspace(void)
{
    uint8_t  index;
    uint16_t nMax = 12;
    uint16_t numTerms;

    ///////////////////////////////////

    numTerms = CALCULATE_NUMTERMS(nMax);

    magneticModel = MAG_AllocateModelMemory(numTerms);

    ///////////////////////////////////

    magneticModel->nMax       = nMax;
	magneticModel->nMaxSecVar = nMax;
    magneticModel->epoch      = 2010.0f;

    strncpy(magneticModel->ModelName, "WMM-2010        11/20/2009\0", sizeof(magneticModel->ModelName));

    magneticModel->Main_Field_Coeff_G[0]  = 0.0f;
    magneticModel->Main_Field_Coeff_H[0]  = 0.0f;
    magneticModel->Secular_Var_Coeff_G[0] = 0.0f;
    magneticModel->Secular_Var_Coeff_H[0] = 0.0f;

    for ( index = 1; index < 91; index++)
    {
		magneticModel->Main_Field_Coeff_G[index]  = wmmCoefficients[index - 1][0];  // gnm
		magneticModel->Main_Field_Coeff_H[index]  = wmmCoefficients[index - 1][1];  // hnm
        magneticModel->Secular_Var_Coeff_G[index] = wmmCoefficients[index - 1][2];  // dgnm
		magneticModel->Secular_Var_Coeff_H[index] = wmmCoefficients[index - 1][3];  // dhnm
	}

	magneticModel->CoefficientFileEndDate = magneticModel->epoch + 5.0f;

	///////////////////////////////////

	numTerms = ((nMax + 1) * (nMax + 2) / 2);

    timedMagneticModel = MAG_AllocateModelMemory(numTerms);

    ///////////////////////////////////

    //  Set WGS-84 parameters
	ellipsoid.a     = 6378.137f;                                                               // semi-major axis of the ellipsoid in km
	ellipsoid.b     = 6356.7523142f;                                                           // semi-minor axis of the ellipsoid in km
	ellipsoid.fla   = 1.0f / 298.257223563f;                                                   // flattening
	ellipsoid.eps   = sqrt(1.0f - (ellipsoid.b * ellipsoid.b) / (ellipsoid.a * ellipsoid.a));  // first eccentricity
	ellipsoid.epssq = (ellipsoid.eps * ellipsoid.eps);                                         // first eccentricity squared
    ellipsoid.re    = 6371.2f;                                                                 // earth's radius in km

    ///////////////////////////////////
}
Beispiel #2
0
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;
}