Geo Stars Library  0.9.3
Geodetic and Astrometry library
geoMag.c File Reference

This file contains the source for deriving geomagnetic variables from geodetic coordinates. More...

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "geoStars.h"
Include dependency graph for geoMag.c:

Go to the source code of this file.

Macros

#define wmmData   wmmDta2010
 
#define EPOCH   2010.0
 
#define snorm   p
 
#define MAXDEG   12
 

Functions

static void geoMagInit (void)
 
int geoMag (double alt, double glat, double glon, double time, double *dec, double *dip, double *ti, double *gv, double *adec, double *adip, double *ati, double *x, double *y, double *z, double *h, double *ax, double *ay, double *az, double *ah)
 This routine computes all of the relevant geomagnetic data. More...
 
int geomg1 (double alt, double glat, double glon, double time, double *dec, double *dip, double *ti, double *gv)
 
int geoMagGetDec (double lat, double lon, double hgt, int month, int day, int year, double *dec)
 This routine computes magnetic declination. More...
 
double geoMagGetDecRet (double lat, double lon, double hgt, int month, int day, int year)
 This routine computes and returns magnetic declination for a specific date. More...
 
double geoMagGetDecNow (double lat, double lon, double hgt)
 This routine computes magnetic declination for now time. More...
 
int geoMagFillDec (GEO_LOCATION *l, double *dec)
 

Variables

static WMM_DATA wmmDta2000 []
 This structure array contains the all of the coefficients for WMM-2000 used in this library. More...
 
static WMM_DATA wmmDta2005 []
 This structure array contains the all of the coefficients for WMM-2005 used in this library. More...
 
static WMM_DATA wmmDta2010 []
 
static int started = 0
 
static double c [13][13]
 C - GAUSS COEFFICIENTS OF MAIN GEOMAGNETIC MODEL (NT) More...
 
static double cd [13][13]
 CD - GAUSS COEFFICIENTS OF SECULAR GEOMAGNETIC MODEL (NT/YR) More...
 
static double tc [13][13]
 TC - TIME ADJUSTED GEOMAGNETIC GAUSS COEFFICIENTS (NT) More...
 
static double dp [13][13]
 DP(N,M)- THETA DERIVATIVE OF P(N,M) (UNNORMALIZED) More...
 
static double p [13][13]
 SNORM - SCHMIDT NORMALIZATION FACTORS. More...
 
static double sp [13]
 SP(M) - SINE OF (M*SPHERICAL COORD. LONGITUDE) More...
 
static double cp [13]
 CP(M) - COSINE OF (M*SPHERICAL COORD. LONGITUDE) More...
 
static double fn [13]
 
static double fm [13]
 
static double pp [13]
 PP(N) - ASSOCIATED LEGENDRE POLYNOMIALS FOR M=1 (UNNORMALIZED) More...
 
static double k [13][13]
 
static double epoch
 
static int maxord
 MAXORD - MAXIMUM ORDER OF SPHERICAL HARMONIC MODEL. More...
 

Detailed Description

This file contains the source for deriving geomagnetic variables from geodetic coordinates.

Definition in file geoMag.c.

Macro Definition Documentation

#define EPOCH   2010.0

Definition at line 15 of file geoMag.c.

Referenced by geoMagInit().

#define MAXDEG   12

Definition at line 395 of file geoMag.c.

Referenced by geoMagInit().

#define snorm   p

Flag for limiting multiple initializations

Definition at line 394 of file geoMag.c.

Referenced by geoMagInit().

#define wmmData   wmmDta2010

Definition at line 14 of file geoMag.c.

Referenced by geoMagInit().

Function Documentation

int geoMag ( double  alt,
double  glat,
double  glon,
double  time,
double *  dec,
double *  dip,
double *  ti,
double *  gv,
double *  adec,
double *  adip,
double *  ati,
double *  x,
double *  y,
double *  z,
double *  h,
double *  ax,
double *  ay,
double *  az,
double *  ah 
)

This routine computes all of the relevant geomagnetic data.

Parameters
doublealt : in: altitude in meters
doubleglat : in: latitude in decimal degrees
doubleglon : in: longitude in decimal degrees
doubletime : in: time in decimal years
double*dec :out: declination in degrees
double*dip :out: dip in degrees
double*ti :out: total intensity in nT
double*gv :out: geomagnetic grid variation
double*adec :out: Annual declination in degrees
double*adip :out: Annual dip in degrees
double*ati :out: Annual total intensity in nT
double*x :out: X Component of the magnetic field
double*y :out: Y Component of the magnetic field
double*z :out: Z Component of the magnetic field
double*h :out: h Component of the magnetic field
double*ax :out: Annual X Component of the magnetic field
double*ay :out: Annual Y Component of the magnetic field
double*az :out: Annual Z Component of the magnetic field
double*ah :out: Annual H Component of the magnetic field
Return values
GEO_OKon success
GEO_ERRORon error

{

Definition at line 523 of file geoMag.c.

References DEG_TO_MIN, DEG_TO_RAD, GEO_OK, geoMagInit(), and geomg1().

528 {
529  double time1;
530  double dec2, dip2, ti2, rdec, rdip, rdec2, rdip2;
531  double x2,y2,z2,h2;
532  double c_rdip,c_rdip2;
533  // double rTd=0.017453292;
534 
535  geoMagInit();
536 
537  geomg1(alt,glat,glon,time,dec,dip,ti,gv);
538  time1 = time + 1.0; // add a year to time
539  geomg1(alt,glat,glon,time1,&dec2,&dip2,&ti2,gv);
540 
541 
542 
543  /*COMPUTE X, Y, Z, AND H COMPONENTS OF THE MAGNETIC FIELD*/
544  rdec = *dec * DEG_TO_RAD;
545  rdip = *dip * DEG_TO_RAD;
546  rdec2 = dec2 * DEG_TO_RAD;
547  rdip2 = dip2 * DEG_TO_RAD;
548  c_rdip = cos(rdip);
549  c_rdip2 = cos(rdip2);
550  /*
551  *x= *ti * (cos(rdec) * cos(rdip));
552  *y= *ti * (cos(rdip) * sin(rdec));
553  *z= *ti * (sin(rdip));
554  *h= *ti * (cos(rdip));
555 
556  x2=ti2*(cos(rdec2) * cos(rdip2));
557  y2=ti2*(cos(rdip2) * sin(rdec2));
558  z2=ti2*(sin(rdip2));
559  h2=ti2*(cos(rdip2));
560 */
561  *x= *ti * (cos(rdec) * c_rdip);
562  *y= *ti * (c_rdip * sin(rdec));
563  *z= *ti * (sin(rdip));
564  *h= *ti * (c_rdip);
565 
566  x2=ti2*(cos(rdec2) * c_rdip2);
567  y2=ti2*(c_rdip2 * sin(rdec2));
568  z2=ti2*(sin(rdip2));
569  h2=ti2*(c_rdip2);
570 
571 
572  /* COMPUTE ANNUAL CHANGE FOR TOTAL INTENSITY */
573  *ati = ti2 - *ti;
574 
575  /* COMPUTE ANNUAL CHANGE FOR DIP & DEC (in minutes) */
576  *adip = (dip2 - *dip) * DEG_TO_MIN;
577  *adec = (dec2 - *dec) * DEG_TO_MIN;
578 
579 
580  /* COMPUTE ANNUAL CHANGE FOR X, Y, Z, AND H */
581  *ax = x2 - *x;
582  *ay = y2 - *y;
583  *az = z2 - *z;
584  *ah = h2 - *h;
585 
586  return(GEO_OK);
587 }

Here is the call graph for this function:

int geoMagFillDec ( GEO_LOCATION l,
double *  dec 
)

Definition at line 903 of file geoMag.c.

References GEO_LOCATION::Declination, GEO_OK, geoMagGetDec(), GEO_LOCATION::hgt, GEO_LOCATION::lat, and GEO_LOCATION::lon.

Referenced by geoInitLocation().

904 {
905  struct tm *newtime;
906  time_t aclock;
907 
908  /* Compute the Magnetic Declination */
909  time( &aclock ); /* Get time in seconds */
910  newtime = localtime( &aclock ); /* Convert time to struct tm form */
911 
912  if(newtime->tm_year < 200 ) newtime->tm_year += 1900;
913 
914  // printf("%d / %d / %d \n",newtime->tm_mon+1, newtime->tm_mday, newtime->tm_year);
915  geoMagGetDec(l->lat,l->lon,l->hgt,
916  newtime->tm_mon+1, newtime->tm_mday, newtime->tm_year, dec);
917  l->Declination = *dec;
918 
919  return (GEO_OK);
920 }

Here is the call graph for this function:

int geoMagGetDec ( double  lat,
double  lon,
double  hgt,
int  month,
int  day,
int  year,
double *  dec 
)

This routine computes magnetic declination.

Parameters
doublelat : in: latitude in decimal degrees
doublelon : in: longitude in decimal degrees
doublehgt : in: altitude in meters
intmonth : in: Month of the year
intday : in: Day of the month
intyear : in: Year
doubledec :out: declination in degrees

Definition at line 825 of file geoMag.c.

References GEO_OK, geoMagInit(), geomg1(), and jday().

Referenced by geoMagFillDec(), and geoMagGetDecNow().

827 {
828  /* Days in each month 1-12 */
829  int jday[] = {0,0,31,59,90,120,151,180,211,242,272,303,333 };
830  double time,dip,ti,gv;
831 
832  /* Determin decimal years from date */
833  time = ((jday[month]+day) / 365.0) + year;
834 
835  /* Determin declination */
836  geoMagInit();
837  geomg1(hgt,lat,lon,time,dec,&dip,&ti,&gv);
838 
839  return (GEO_OK);
840 
841 }

Here is the call graph for this function:

double geoMagGetDecNow ( double  lat,
double  lon,
double  hgt 
)

This routine computes magnetic declination for now time.

Parameters
doublelat : in: latitude in decimal degrees
doublelon : in: longitude in decimal degrees
doublehgt : in: altitude in meters
Return values
doubledec :out: declination in degrees

Definition at line 882 of file geoMag.c.

References geoMagGetDec().

883 {
884  struct tm *newtime;
885  time_t aclock;
886  double dec;
887 
888  /* Compute the Magnetic Declination */
889  time( &aclock ); /* Get time in seconds */
890  newtime = localtime( &aclock ); /* Convert time to struct tm form */
891 
892  if(newtime->tm_year < 200 ) newtime->tm_year += 1900;
893 
894  // printf("%d / %d / %d \n",newtime->tm_mon+1, newtime->tm_mday, newtime->tm_year);
895  geoMagGetDec(lat,lon,hgt,
896  newtime->tm_mon+1, newtime->tm_mday, newtime->tm_year, &dec);
897 
898  return (dec);
899 
900 }

Here is the call graph for this function:

double geoMagGetDecRet ( double  lat,
double  lon,
double  hgt,
int  month,
int  day,
int  year 
)

This routine computes and returns magnetic declination for a specific date.

Parameters
doublelat : in: latitude in decimal degrees
doublelon : in: longitude in decimal degrees
doublehgt : in: altitude in meters
intmonth : in: Month of the year
intday : in: Day of the month
intyear : in: Year
Return values
doubledec :out: declination in degrees

Definition at line 855 of file geoMag.c.

References geoMagInit(), geomg1(), and jday().

857 {
858  /* Days in each month 1-12 */
859  double dec;
860  int jday[] = {0,0,31,59,90,120,151,180,211,242,272,303,333 };
861  double time,dip,ti,gv;
862 
863  /* Determin decimal years from date */
864  time = ((jday[month]+day) / 365.0) + year;
865 
866  /* Determin declination */
867  geoMagInit();
868  geomg1(hgt,lat,lon,time,&dec,&dip,&ti,&gv);
869 
870  return (dec);
871 
872 }

Here is the call graph for this function:

static void geoMagInit ( void  )
static

Definition at line 424 of file geoMag.c.

References c, cd, cp, dp, EPOCH, epoch, fm, fn, k, MAXDEG, maxord, n(), p, pp, snorm, sp, started, and wmmData.

Referenced by geoMag(), geoMagGetDec(), and geoMagGetDecRet().

425 {
426  int n,m,i,j;
427  double flnmj,n2m1,nm12,n2m1stuff;
428 
429  /* Only do this once */
430  if(started) return;
431  started = 1;
432 
433  // INITIALIZE CONSTANTS
434  maxord = MAXDEG;
435  sp[0] = 0.0;
436  cp[0] = p[0][0] = pp[0] = 1.0;
437  dp[0][0] = 0.0;
438 
439  // READ WORLD MAGNETIC MODEL SPHERICAL HARMONIC COEFFICIENTS
440  c[0][0] = 0.0;
441  cd[0][0] = 0.0;
442 
443  // Load the WMM Coefficients
444  epoch=EPOCH;
445  for( i=0;i<90;i++)
446  {
447  n=wmmData[i].n;
448  m=wmmData[i].m;
449  if (m <= n)
450  {
451  c[m][n] = wmmData[i].gnm;
452  cd[m][n] = wmmData[i].dgnm;
453  if (m != 0)
454  {
455  c[n][m-1] = wmmData[i].hnm;
456  cd[n][m-1] = wmmData[i].dhnm;
457  }
458  }
459  } //end for
460 
461 
462  /* CONVERT SCHMIDT NORMALIZED GAUSS COEFFICIENTS TO UNNORMALIZED */
463 
464  snorm[0][0] = 1.0;
465  for (n=1; n<=maxord; n++)
466  {
467  nm12 = (n-1)*(n-1);
468  n2m1 = (double)2*n-1;
469  n2m1stuff = (double)(n2m1*(2*n-3));
470  snorm[0][n] = snorm[0][n-1]*n2m1/(double)n;
471  j = 2;
472  for (m=0;m<=n;m++)
473  {
474  k[m][n] = (double)(nm12-(m*m))/n2m1stuff;
475  if (m > 0)
476  {
477  flnmj = (double)((n-m+1)*j)/(double)(n+m);
478  snorm[m][n] = snorm[m-1][n]*sqrt(flnmj);
479  j = 1;
480  c[n][m-1] = snorm[m][n]*c[n][m-1];
481  cd[n][m-1] = snorm[m][n]*cd[n][m-1];
482  }
483  c[m][n] = snorm[m][n]*c[m][n];
484  cd[m][n] = snorm[m][n]*cd[m][n];
485  } //end for m
486  fn[n] = (double)(n+1);
487  fm[n] = (double)n;
488  } //end for n
489  k[1][1] = 0.0;
490 
491 
492 }

Here is the call graph for this function:

int geomg1 ( double  alt,
double  glat,
double  glon,
double  time,
double *  dec,
double *  dip,
double *  ti,
double *  gv 
)

This is documentation that came with the WMM. It is included here for completeness.

//       MAXDEG - MAXIMUM DEGREE OF SPHERICAL HARMONIC MODEL    (INPUT)
//       TIME   - COMPUTATION TIME (YRS)                        (INPUT)
//                (EG. 1 JULY 1995 = 1995.500)
//       ALT    - GEODETIC ALTITUDE (M)                        (INPUT)
//       GLAT   - GEODETIC LATITUDE (DEG.)                      (INPUT)
//       GLON   - GEODETIC LONGITUDE (DEG.)                     (INPUT)
//       EPOCH  - BASE TIME OF GEOMAGNETIC MODEL (YRS)
//       P(N,M) - ASSOCIATED LEGENDRE POLYNOMIALS (UNNORMALIZED)
//       DEC    - GEOMAGNETIC DECLINATION (DEG.)                (OUTPUT)
//                  EAST=POSITIVE ANGLES
//                  WEST=NEGATIVE ANGLES
//       DIP    - GEOMAGNETIC INCLINATION (DEG.)                (OUTPUT)
//                  DOWN=POSITIVE ANGLES
//                    UP=NEGATIVE ANGLES
//       TI     - GEOMAGNETIC TOTAL INTENSITY (NT)              (OUTPUT)
//       GV     - GEOMAGNETIC GRID VARIATION (DEG.)             (OUTPUT)
//                REFERENCED TO GRID NORTH
//                GRID NORTH REFERENCED TO 0 MERIDIAN
//                OF A POLAR STEREOGRAPHIC PROJECTION
//                (ARCTIC/ANTARCTIC ONLY)
//       A      - SEMIMAJOR AXIS OF WGS-84 ELLIPSOID (KM)
//       B      - SEMIMINOR AXIS OF WGS-84 ELLIPSOID (KM)
//       RE     - MEAN RADIUS OF IAU-66 ELLIPSOID (KM)
//       a2,             // a * a
//       b2,             // b * b
//       c2,             // a2 - b2
//       a4,             // a2 * a2
//       b4,             // b2 * b2
//       c4,             // a4 - b4
//       ct,             //C       CT     - COSINE OF (SPHERICAL COORD. LATITUDE)
//       st,             //C       ST     - SINE OF (SPHERICAL COORD. LATITUDE)
//       r2,
//       r,              //C       R      - SPHERICAL COORDINATE RADIAL POSITION (KM)
//       ca,             //C       CA     - COSINE OF SPHERICAL TO GEODETIC VECTOR ROTATION ANGLE
//       sa,             //C       SA     - SINE OF SPHERICAL TO GEODETIC VECTOR ROTATION ANGLE
//       br,             //C       BR     - RADIAL COMPONENT OF GEOMAGNETIC FIELD (NT)
//       bt,             //C       BT     - THETA COMPONENT OF GEOMAGNETIC FIELD (NT)
//       bp,             //C       BP     - PHI COMPONENT OF GEOMAGNETIC FIELD (NT)
//       bx,             //C       BX     - NORTH GEOMAGNETIC COMPONENT (NT)
//       by,             //C       BY     - EAST GEOMAGNETIC COMPONENT (NT)
//       bz,             //C       BZ     - VERTICALLY DOWN GEOMAGNETIC COMPONENT (NT)
//       bh;             //C       BH     - HORIZONTAL GEOMAGNETIC COMPONENT (NT)

Definition at line 595 of file geoMag.c.

References GEO_ELLIPSOID::a, c, cd, CIRCLE, cp, DEG_TO_RAD, dp, ellips, epoch, fm, fn, GEO_B, GEO_DATUM_WE, GEO_OK, HALF_CIRCLE, k, maxord, n(), p, pp, RAD_TO_DEG, sp, and tc.

Referenced by geoMag(), geoMagGetDec(), and geoMagGetDecRet().

597 {
598 
599  /*!
600 This is documentation that came with the WMM. It is included here for completeness.
601 \verbatim
602 // MAXDEG - MAXIMUM DEGREE OF SPHERICAL HARMONIC MODEL (INPUT)
603 // TIME - COMPUTATION TIME (YRS) (INPUT)
604 // (EG. 1 JULY 1995 = 1995.500)
605 // ALT - GEODETIC ALTITUDE (M) (INPUT)
606 // GLAT - GEODETIC LATITUDE (DEG.) (INPUT)
607 // GLON - GEODETIC LONGITUDE (DEG.) (INPUT)
608 // EPOCH - BASE TIME OF GEOMAGNETIC MODEL (YRS)
609 // P(N,M) - ASSOCIATED LEGENDRE POLYNOMIALS (UNNORMALIZED)
610 // DEC - GEOMAGNETIC DECLINATION (DEG.) (OUTPUT)
611 // EAST=POSITIVE ANGLES
612 // WEST=NEGATIVE ANGLES
613 // DIP - GEOMAGNETIC INCLINATION (DEG.) (OUTPUT)
614 // DOWN=POSITIVE ANGLES
615 // UP=NEGATIVE ANGLES
616 // TI - GEOMAGNETIC TOTAL INTENSITY (NT) (OUTPUT)
617 // GV - GEOMAGNETIC GRID VARIATION (DEG.) (OUTPUT)
618 // REFERENCED TO GRID NORTH
619 // GRID NORTH REFERENCED TO 0 MERIDIAN
620 // OF A POLAR STEREOGRAPHIC PROJECTION
621 // (ARCTIC/ANTARCTIC ONLY)
622 // A - SEMIMAJOR AXIS OF WGS-84 ELLIPSOID (KM)
623 // B - SEMIMINOR AXIS OF WGS-84 ELLIPSOID (KM)
624 // RE - MEAN RADIUS OF IAU-66 ELLIPSOID (KM)
625 // a2, // a * a
626 // b2, // b * b
627 // c2, // a2 - b2
628 // a4, // a2 * a2
629 // b4, // b2 * b2
630 // c4, // a4 - b4
631 // ct, //C CT - COSINE OF (SPHERICAL COORD. LATITUDE)
632 // st, //C ST - SINE OF (SPHERICAL COORD. LATITUDE)
633 // r2,
634 // r, //C R - SPHERICAL COORDINATE RADIAL POSITION (KM)
635 // ca, //C CA - COSINE OF SPHERICAL TO GEODETIC VECTOR ROTATION ANGLE
636 // sa, //C SA - SINE OF SPHERICAL TO GEODETIC VECTOR ROTATION ANGLE
637 // br, //C BR - RADIAL COMPONENT OF GEOMAGNETIC FIELD (NT)
638 // bt, //C BT - THETA COMPONENT OF GEOMAGNETIC FIELD (NT)
639 // bp, //C BP - PHI COMPONENT OF GEOMAGNETIC FIELD (NT)
640 // bx, //C BX - NORTH GEOMAGNETIC COMPONENT (NT)
641 // by, //C BY - EAST GEOMAGNETIC COMPONENT (NT)
642 // bz, //C BZ - VERTICALLY DOWN GEOMAGNETIC COMPONENT (NT)
643 // bh; //C BH - HORIZONTAL GEOMAGNETIC COMPONENT (NT)
644 \endverbatim
645 */
646 
647  int m,n;
648  double temp1, temp2,d,ar,aor,dt,bpp,
649  par, parp,r,r2,sa,ca,st,ct,br,bt,bp,bx,by,bz,bh;
650 
651  double rlon,rlat,
652  srlon, srlat, crlon, crlat,
653  srlat2, crlat2,
654  a, // A - SEMIMAJOR AXIS OF WGS-84 ELLIPSOID (KM)
655  b, // B - SEMIMINOR AXIS OF WGS-84 ELLIPSOID (KM)
656  re, // RE - MEAN RADIUS OF IAU-66 ELLIPSOID (KM)
657  a2, // a * a
658  b2, // b * b
659  c2, // a2 - b2
660  a4, // a2 * a2
661  b4, // b2 * b2
662  c4, // a4 - b4
663 
664  q, q1, q2;
665 
666  a = ellips[GEO_DATUM_WE].a; //6378137.0;
667  b = GEO_B(ellips[GEO_DATUM_WE].a, (ellips[GEO_DATUM_WE].f1)); //6356752.3142; //wgs-84
668  re = 6371200.0;
669  a2 = a*a;
670  b2 = b*b;
671  c2 = a2-b2;
672  a4 = a2*a2;
673  b4 = b2*b2;
674  c4 = a4 - b4;
675 
676 
677  dt = time - epoch;
678  // if (dt < 0.0 || dt > 5.0)
679  // printf("\n WARNING geoMag - TIME EXTENDS BEYOND MODEL 5-YEAR LIFE SPAN (dt=%f, time=%f)\n",dt,time);
680 
681  rlon = glon*DEG_TO_RAD;
682  rlat = glat*DEG_TO_RAD;
683  srlon = sin(rlon);
684  srlat = sin(rlat);
685  crlon = cos(rlon);
686  crlat = cos(rlat);
687  srlat2 = srlat*srlat;
688  crlat2 = crlat*crlat;
689  sp[1] = srlon;
690  cp[1] = crlon;
691 
692  /* CONVERT FROM GEODETIC COORDS. TO SPHERICAL COORDS. */
693 
694  q = sqrt(a2-c2*srlat2);
695  q1 = alt*q;
696  q2 = ((q1+a2)/(q1+b2))*((q1+a2)/(q1+b2));
697  ct = srlat/sqrt(q2*crlat2+srlat2);
698  st = sqrt(1.0-(ct*ct));
699  r2 = (alt*alt)+2.0*q1+(a4-c4*srlat2)/(q*q);
700  r = sqrt(r2);
701  d = sqrt(a2*crlat2+b2*srlat2);
702  ca = (alt+d)/r;
703  sa = c2*crlat*srlat/(r*d);
704 
705  for (m=2; m<=maxord; m++)
706  {
707  sp[m] = sp[1]*cp[m-1]+cp[1]*sp[m-1];
708  cp[m] = cp[1]*cp[m-1]-sp[1]*sp[m-1];
709  }
710 
711  aor = re/r;
712  ar = aor*aor;
713  br = bt = bp = bpp = 0.0;
714  for (n=1; n<=maxord; n++)
715  {
716  ar = ar*aor;
717  for (m=0;m<=n;m++)
718  {
719  /*
720  COMPUTE UNNORMALIZED ASSOCIATED LEGENDRE POLYNOMIALS
721  AND DERIVATIVES VIA RECURSION RELATIONS
722  */
723  if (n == m)
724  {
725  p[m][n] = st * p[m-1][n-1];
726  dp[m][n] = st * dp[m-1][n-1] + ct * p[m-1][n-1];
727  goto S50;
728  }
729  if (n == 1 && m == 0)
730  {
731  p[m][n] = ct * p[m][n-1];
732  dp[m][n] = ct * dp[m][n-1] - st * p[m][n-1];
733  goto S50;
734  }
735  if (n > 1 && n != m)
736  {
737  if (m > n-2) p[m][n-2] = 0.0;
738  if (m > n-2) dp[m][n-2] = 0.0;
739  p[m][n] = ct * p[m][n-1] - k[m][n] * p[m][n-2];
740  dp[m][n] = ct * dp[m][n-1] - st * p[m][n-1] - k[m][n] * dp[m][n-2];
741  }
742 S50:
743  // TIME ADJUST THE GAUSS COEFFICIENTS
744  tc[m][n] = c[m][n]+dt*cd[m][n];
745  if (m != 0) tc[n][m-1] = c[n][m-1]+dt*cd[n][m-1];
746 
747  // ACCUMULATE TERMS OF THE SPHERICAL HARMONIC EXPANSIONS
748  par = ar * p[m][n];
749  if (m == 0)
750  {
751  temp1 = tc[m][n]*cp[m];
752  temp2 = tc[m][n]*sp[m];
753  }
754  else
755  {
756  temp1 = tc[m][n]*cp[m]+tc[n][m-1]*sp[m];
757  temp2 = tc[m][n]*sp[m]-tc[n][m-1]*cp[m];
758  }
759  bt = bt-ar*temp1*dp[m][n];
760  bp += (fm[m]*temp2*par);
761  br += (fn[n]*temp1*par);
762 
763  // SPECIAL CASE: NORTH/SOUTH GEOGRAPHIC POLES
764  if (st == 0.0 && m == 1)
765  {
766  if (n == 1) pp[n] = pp[n-1];
767  else pp[n] = ct*pp[n-1]-k[m][n]*pp[n-2];
768  parp = ar*pp[n];
769  bpp += (fm[m]*temp2*parp);
770  }
771  }
772  }
773  if (st == 0.0) bp = bpp;
774  else bp /= st;
775  /*
776  ROTATE MAGNETIC VECTOR COMPONENTS FROM SPHERICAL TO
777  GEODETIC COORDINATES
778 */
779  bx = -bt*ca-br*sa;
780  by = bp;
781  bz = bt*sa-br*ca;
782  /*
783 ** COMPUTE DECLINATION (DEC), INCLINATION (DIP) AND
784 ** TOTAL INTENSITY (TI)
785 */
786  bh = sqrt((bx*bx)+(by*by));
787  *ti = sqrt((bh*bh)+(bz*bz));
788  *dec = atan2(by,bx)*RAD_TO_DEG;
789  *dip = atan2(bz,bh)*RAD_TO_DEG;
790 
791  /*
792 ** COMPUTE MAGNETIC GRID VARIATION IF THE CURRENT
793 ** GEODETIC POSITION IS IN THE ARCTIC OR ANTARCTIC
794 ** (I.E. GLAT > +55 DEGREES OR GLAT < -55 DEGREES)
795 **
796 ** OTHERWISE, SET MAGNETIC GRID VARIATION TO -999.0
797 */
798  *gv = -999.0;
799  if (fabs(glat) >= 55.)
800  {
801  if (glat > 0.0 && glon >= 0.0) *gv = *dec-glon;
802  if (glat > 0.0 && glon < 0.0) *gv = *dec+fabs(glon);
803  if (glat < 0.0 && glon >= 0.0) *gv = *dec+glon;
804  if (glat < 0.0 && glon < 0.0) *gv = *dec-fabs(glon);
805  if (*gv > +HALF_CIRCLE) *gv -= CIRCLE;
806  if (*gv < -HALF_CIRCLE) *gv += CIRCLE;
807  }
808 
809  return (GEO_OK);
810 
811 }

Here is the call graph for this function:

Variable Documentation

double c[13][13]
static

C - GAUSS COEFFICIENTS OF MAIN GEOMAGNETIC MODEL (NT)

Definition at line 404 of file geoMag.c.

Referenced by geoMagInit(), geomg1(), and geoSunAA().

double cd[13][13]
static

CD - GAUSS COEFFICIENTS OF SECULAR GEOMAGNETIC MODEL (NT/YR)

Definition at line 404 of file geoMag.c.

Referenced by geoMagInit(), and geomg1().

double cp[13]
static

CP(M) - COSINE OF (M*SPHERICAL COORD. LONGITUDE)

Definition at line 404 of file geoMag.c.

Referenced by geoMagInit(), and geomg1().

double dp[13][13]
static

DP(N,M)- THETA DERIVATIVE OF P(N,M) (UNNORMALIZED)

Definition at line 404 of file geoMag.c.

Referenced by geoMagInit(), and geomg1().

double epoch
static

Definition at line 404 of file geoMag.c.

Referenced by geoMagInit(), and geomg1().

double fm[13]
static

Definition at line 404 of file geoMag.c.

Referenced by geoMagInit(), and geomg1().

double fn[13]
static

Definition at line 404 of file geoMag.c.

Referenced by geoMagInit(), and geomg1().

double k[13][13]
static

Definition at line 404 of file geoMag.c.

Referenced by geoEfg2Llh_vermeille(), geoEfg2Llh_vermeille_fast(), geoMagInit(), and geomg1().

int maxord
static

MAXORD - MAXIMUM ORDER OF SPHERICAL HARMONIC MODEL.

Definition at line 420 of file geoMag.c.

Referenced by geoMagInit(), and geomg1().

double pp[13]
static

PP(N) - ASSOCIATED LEGENDRE POLYNOMIALS FOR M=1 (UNNORMALIZED)

Definition at line 404 of file geoMag.c.

Referenced by geoMagInit(), and geomg1().

double sp[13]
static

SP(M) - SINE OF (M*SPHERICAL COORD. LONGITUDE)

Definition at line 404 of file geoMag.c.

Referenced by geoEfg2Llh_heikkinen(), geoMagInit(), and geomg1().

int started = 0
static

Definition at line 392 of file geoMag.c.

Referenced by geoMagInit().

double tc[13][13]
static

TC - TIME ADJUSTED GEOMAGNETIC GAUSS COEFFICIENTS (NT)

Definition at line 404 of file geoMag.c.

Referenced by geomg1().

WMM_DATA wmmDta2000[]
static

This structure array contains the all of the coefficients for WMM-2000 used in this library.

This is documentation that came with the WMM. It is included here for completeness.

C     MODEL:  THE WMM SERIES GEOMAGNETIC MODELS ARE COMPOSED
C             OF TWO PARTS:  THE MAIN FIELD MODEL, WHICH IS
C             VALID AT THE BASE EPOCH OF THE CURRENT MODEL AND
C             A SECULAR VARIATION MODEL, WHICH ACCOUNTS FOR SLOW
C             TEMPORAL VARIATIONS IN THE MAIN GEOMAGNETIC FIELD
C             FROM THE BASE EPOCH TO A MAXIMUM OF 5 YEARS BEYOND
C             THE BASE EPOCH.  FOR EXAMPLE, THE BASE EPOCH OF
C             THE WMM-2005 MODEL IS 2005.0.  THIS MODEL IS THEREFORE
C             CONSIDERED VALID BETWEEN 2005.0 AND 2010.0. THE
C             COMPUTED MAGNETIC PARAMETERS ARE REFERENCED TO THE
C             WGS-84 ELLIPSOID.
C
C***********************************************************************
C
C     ACCURACY:  IN OCEAN AREAS AT THE EARTH'S SURFACE OVER THE
C                ENTIRE 5 YEAR LIFE OF THE DEGREE AND ORDER 12
C                SPHERICAL HARMONIC MODEL WMM-2005, THE ESTIMATED
C                MAXIMUM RMS ERRORS FOR THE VARIOUS MAGNETIC COMPONENTS
C                ARE:
C
C                DEC  -   0.5 Degrees
C                DIP  -   0.5 Degrees
C                TI   - 280.0 nanoTeslas (nT)
C                GV   -   0.5 Degrees
C
C                OTHER MAGNETIC COMPONENTS THAT CAN BE DERIVED FROM
C                THESE FOUR BY SIMPLE TRIGONOMETRIC RELATIONS WILL
C                HAVE THE FOLLOWING APPROXIMATE ERRORS OVER OCEAN AREAS:
C
C                X    - 140 nT (North)
C                Y    - 140 nT (East)
C                Z    - 200 nT (Vertical) Positive is down
C                H    - 200 nT (Horizontal)
C
C                OVER LAND THE MAXIMUM RMS ERRORS ARE EXPECTED TO BE
C                HIGHER, ALTHOUGH THE RMS ERRORS FOR DEC, DIP, AND GV
C                ARE STILL ESTIMATED TO BE LESS THAN 1.0 DEGREE, FOR
C                THE ENTIRE 5-YEAR LIFE OF THE MODEL AT THE EARTH's
C                SURFACE.  THE OTHER COMPONENT ERRORS OVER LAND ARE
C                MORE DIFFICULT TO ESTIMATE AND SO ARE NOT GIVEN.
C
C                THE ACCURACY AT ANY GIVEN TIME FOR ALL OF THESE
C                GEOMAGNETIC PARAMETERS DEPENDS ON THE GEOMAGNETIC
C                LATITUDE.  THE ERRORS ARE LEAST FROM THE EQUATOR TO
C                MID-LATITUDES AND GREATEST NEAR THE MAGNETIC POLES.
C
C                IT IS VERY IMPORTANT TO NOTE THAT A DEGREE AND
C                ORDER 12 MODEL, SUCH AS WMM-2005, DESCRIBES ONLY
C                THE LONG WAVELENGTH SPATIAL MAGNETIC FLUCTUATIONS
C                DUE TO EARTH'S CORE.  NOT INCLUDED IN THE WMM SERIES
C                MODELS ARE INTERMEDIATE AND SHORT WAVELENGTH
C                SPATIAL FLUCTUATIONS OF THE GEOMAGNETIC FIELD
C                WHICH ORIGINATE IN THE EARTH'S MANTLE AND CRUST.
C                CONSEQUENTLY, ISOLATED ANGULAR ERRORS AT VARIOUS
C                POSITIONS ON THE SURFACE (PRIMARILY OVER LAND, IN
C                CONTINENTAL MARGINS AND OVER OCEANIC SEAMOUNTS,
C                RIDGES AND TRENCHES) OF SEVERAL DEGREES MAY BE
C                EXPECTED. ALSO NOT INCLUDED IN THE MODEL ARE
C                NONSECULAR TEMPORAL FLUCTUATIONS OF THE GEOMAGNETIC
C                FIELD OF MAGNETOSPHERIC AND IONOSPHERIC ORIGIN.
C                DURING MAGNETIC STORMS, TEMPORAL FLUCTUATIONS CAN
C                CAUSE SUBSTANTIAL DEVIATIONS OF THE GEOMAGNETIC
C                FIELD FROM MODEL VALUES.  IN ARCTIC AND ANTARCTIC
C                REGIONS, AS WELL AS IN EQUATORIAL REGIONS, DEVIATIONS
C                FROM MODEL VALUES ARE BOTH FREQUENT AND PERSISTENT.
C
C                IF THE REQUIRED DECLINATION ACCURACY IS MORE
C                STRINGENT THAN THE WMM SERIES OF MODELS PROVIDE, THEN
C                THE USER IS ADVISED TO REQUEST SPECIAL (REGIONAL OR
C                LOCAL) SURVEYS BE PERFORMED AND MODELS PREPARED.
C                REQUESTS OF THIS NATURE SHOULD BE MADE TO NIMA
C                AT THE ADDRESS ABOVE.

Definition at line 98 of file geoMag.c.

WMM_DATA wmmDta2005[]
static

This structure array contains the all of the coefficients for WMM-2005 used in this library.

Definition at line 199 of file geoMag.c.

WMM_DATA wmmDta2010[]
static

Definition at line 297 of file geoMag.c.