inline DsMagvar::DsMagvar(const char* file) { if (file != 0) { geomag(12,file); haveData = true; } else { haveData = 0; } }
/* That's the worst code I've ever had to modify !! * To test the function use lat=-40deg long=120deg altitude=0 date=2007.5 then myDeclinaison=14.75 * Declination is considered positive when the angle measured is east of true north and negative when west * that means that heading_true_north = heading_magnetic_north - declination */ void DMU_comp_geomag(double decim_date, GPS_Struct gps, double *myDeclination) { static int maxdeg; static float altm, dlat, dlon; static float ati, adec, adip; static float alt, time, dec, dip, ti, gv; static float time1, dec1, dip1, ti1; static float time2, dec2, dip2, ti2; int warn_H, warn_H_strong, warn_P; char fname[100] = "/WMM.COF"; char decd[5], dipd[5],d_str[81],modl[20]; float x1,x2,y1,y2,z1,z2,h1,h2; float ax,ay,az,ah; float rTd=0.017453292; float epochlowlim,epochuplim; float epochrange = 5.0; float warn_H_val, warn_H_strong_val; FILE *wmmtemp; printf("Before fopen\n"); wmmtemp = fopen(fname,"r"); if(wmmtemp == NULL) { printf("DMU_comp_geomag -> Could not open %s\n", fname); printf("Download it from http://www.ngdc.noaa.gov/seg/WMM/\n"); *myDeclination = 0.0; return; } printf("Now we read the file\n"); fgets(d_str, 80, wmmtemp); sscanf(d_str,"%f%s",&epochlowlim,modl); fclose(wmmtemp); printf("Read of %s success\n", fname); /* strcpy (goodbye,"\n -- End of WMM Point Calculation Program -- \n\n");*/ /* INITIALIZE GEOMAG ROUTINE */ maxdeg = 12; warn_H = 0; warn_H_val = 99999.0; warn_H_strong = 0; warn_H_strong_val = 99999.0; warn_P = 0; geomag(&maxdeg); dlat = -RAD2DEG(gps.latitude); dlon = -RAD2DEG(gps.longitude); altm = gps.altitude; alt = altm/1000; epochuplim = epochlowlim + epochrange; if(decim_date < epochlowlim || decim_date > epochuplim) { fprintf(stderr, "Date bad range (%f)\n", decim_date); fprintf(stderr, "ENTER TIME IN DECIMAL YEAR (%-7.2f - %-7.2f)\n",epochlowlim,epochuplim); exit(EXIT_FAILURE); } time = decim_date; geomg1(alt,dlat,dlon,time,&dec,&dip,&ti,&gv); time1 = time; dec1 = dec; dip1 = dip; ti1 = ti; time = time1 + 1.0; geomg1(alt,dlat,dlon,time,&dec,&dip,&ti,&gv); time2 = time; dec2 = dec; dip2 = dip; ti2 = ti; /*COMPUTE X, Y, Z, AND H COMPONENTS OF THE MAGNETIC FIELD*/ x1=ti1*(cos((dec1*rTd))*cos((dip1*rTd))); x2=ti2*(cos((dec2*rTd))*cos((dip2*rTd))); y1=ti1*(cos((dip1*rTd))*sin((dec1*rTd))); y2=ti2*(cos((dip2*rTd))*sin((dec2*rTd))); z1=ti1*(sin((dip1*rTd))); z2=ti2*(sin((dip2*rTd))); h1=ti1*(cos((dip1*rTd))); h2=ti2*(cos((dip2*rTd))); /* COMPUTE ANNUAL CHANGE FOR TOTAL INTENSITY */ ati = ti2 - ti1; /* COMPUTE ANNUAL CHANGE FOR DIP & DEC */ adip = (dip2 - dip1) * 60.; adec = (dec2 - dec1) * 60.; /* COMPUTE ANNUAL CHANGE FOR X, Y, Z, AND H */ ax = x2-x1; ay = y2-y1; az = z2-z1; ah = h2-h1; if (dec1 < 0.0) { strcpy (decd,"(WEST)"); } else { strcpy(decd,"(EAST)"); } if (dip1 < 0.0) { strcpy(dipd,"(UP) "); } else { strcpy(dipd,"(DOWN)"); } /* deal with geographic and magnetic poles */ if (h1 < 100.0) /* at magnetic poles */ { dec1 = NaN; adec = NaN; strcpy(decd,"(VOID)"); /* while rest is ok */ } if (h1 < 1000.0) { warn_H = 0; warn_H_strong = 1; warn_H_strong_val = h1; } else if (h1 < 5000.0 && !warn_H_strong) { warn_H = 1; warn_H_val = h1; } if (90.0-fabs(dlat) <= 0.001) /* at geographic poles */ { x1 = NaN; y1 = NaN; dec1 = NaN; ax = NaN; ay = NaN; adec = NaN; strcpy(decd,"(VOID)"); warn_P = 1; warn_H = 0; warn_H_strong = 0; /* while rest is ok */ } *myDeclination = DEG2RAD(dec1); return; }