180 register int n,m,D3,D4;
181 static int maxord,
i,icomp,j,D1,D2,in,im;
182 static float c[13][13],cd[13][13],tc[13][13],dp[13][13],snorm[169],
183 sp[13],cp[13],fn[13],fm[13],pp[13],k[13][13],dtr,
a,
b,
re,
184 a2,b2,c2,a4,b4,c4,epoch=0.,gnm,hnm,dgnm,dhnm,flnmj,otime,oalt,
185 olat,olon,
dt,glon,glat,srlon,srlat,crlon,crlat,srlat2,
186 crlat2,q,q1,q2,ct,st,r2,r,d,ca,sa,aor,ar,br,bt,bp,bpp,
187 par,temp1,temp2,parp,bh;
188 static char model[20], c_str[81], c_new[5];
189 static float *
p = snorm;
195 switch(IENTRY){
case 0:
goto GEOMAG;
case 1:
goto GEOMG1;}
198 if ((wmmdat=fopen(
fname,
"r")) == NULL)
207 cp[0] = *p = pp[0] = 1.0;
210 b = (float)6356.7523142;
223 ichar = fgets(c_str, 80, wmmdat);
226 sscanf(c_str,
"%f%s",&epoch,model);
229 ichar = fgets(c_str, 80, wmmdat);
231 for (i=0; i<4 && (c_str[
i] !=
'\0'); i++)
236 icomp = strcmp(
"9999", c_new);
237 if (icomp == 0)
goto S4;
239 sscanf(c_str,
"%d%d%f%f%f%f",&in,&im,&gnm,&hnm,&dgnm,&dhnm);
255 for (n=1; n<=maxord; n++)
257 *(snorm+n) = *(snorm+n-1)*(float)(2*n-1)/(float)n;
259 for (m=0,D1=1,D2=(n-m+D1)/D1; D2>0; D2--,m+=D1)
261 k[m][n] = (float)(((n-1)*(n-1))-(m*m))/(float)((2*n-1)*(2*n-3));
264 flnmj = (float)((n-m+1)*j)/(
float)(n+m);
265 *(snorm+n+m*13) = *(snorm+n+(m-1)*13)*sqrt(flnmj);
267 c[n][m-1] = *(snorm+n+m*13)*c[n][m-1];
268 cd[n][m-1] = *(snorm+n+m*13)*cd[n][m-1];
270 c[m][n] = *(snorm+n+m*13)*c[m][n];
271 cd[m][n] = *(snorm+n+m*13)*cd[m][n];
273 fn[n] = (float)(n+1);
278 otime = oalt = olat = olon = -1000.0;
286 if (otime < 0.0 && (dt < 0.0 || dt > 15.0))
304 *bx = *by =*bz = *dec = *dip = *ti = *gv = 0.;
321 dtr = (float)(
DPI/180.0);
328 srlat2 = srlat*srlat;
329 crlat2 = crlat*crlat;
334 if (alt != oalt || glat != olat)
336 q = sqrt(a2-c2*srlat2);
338 q2 = ((q1+a2)/(q1+b2))*((q1+a2)/(q1+b2));
339 ct = srlat/sqrt(q2*crlat2+srlat2);
340 st = (float)sqrt(1.0-(ct*ct));
341 r2 = (float)((alt*alt)+2.0*q1+(a4-c4*srlat2)/(q*q));
343 d = sqrt(a2*crlat2+b2*srlat2);
345 sa = c2*crlat*srlat/(r*d);
349 for (m=2; m<=maxord; m++)
351 sp[m] = sp[1]*cp[m-1]+cp[1]*sp[m-1];
352 cp[m] = cp[1]*cp[m-1]-sp[1]*sp[m-1];
357 br = bt = bp = bpp = 0.0;
358 for (n=1; n<=maxord; n++)
361 for (m=0,D3=1,D4=(n+m+D3)/D3; D4>0; D4--,m+=D3)
367 if (alt != oalt || glat != olat)
371 *(p+n+m*13) = st**(p+n-1+(m-1)*13);
372 dp[m][n] = st*dp[m-1][n-1]+ct**(p+n-1+(m-1)*13);
375 if (n == 1 && m == 0)
377 *(p+n+m*13) = ct**(p+n-1+m*13);
378 dp[m][n] = ct*dp[m][n-1]-st**(p+n-1+m*13);
383 if (m > n-2) *(p+n-2+m*13) = 0.0;
384 if (m > n-2) dp[m][n-2] = 0.0;
385 *(p+n+m*13) = ct**(p+n-1+m*13)-k[m][n]**(p+n-2+m*13);
386 dp[m][n] = ct*dp[m][n-1] - st**(p+n-1+m*13)-k[m][n]*dp[m][n-2];
395 tc[m][n] = c[m][n]+dt*cd[m][n];
396 if (m != 0) tc[n][m-1] = c[n][m-1]+dt*cd[n][m-1];
401 par = ar**(p+n+m*13);
404 temp1 = tc[m][n]*cp[m];
405 temp2 = tc[m][n]*sp[m];
409 temp1 = tc[m][n]*cp[m]+tc[n][m-1]*sp[m];
410 temp2 = tc[m][n]*sp[m]-tc[n][m-1]*cp[m];
412 bt = bt-ar*temp1*dp[m][n];
413 bp += (fm[m]*temp2*par);
414 br += (fn[n]*temp1*par);
418 if (st == 0.0 && m == 1)
420 if (n == 1) pp[n] = pp[n-1];
421 else pp[n] = ct*pp[n-1]-k[m][n]*pp[n-2];
423 bpp += (fm[m]*temp2*parp);
427 if (st == 0.0) bp = bpp;
446 bh = sqrt((*bx**bx)+(*by**by));
447 *ti = sqrt((bh*bh)+(*bz**bz));
448 *dec = atan2(*by,*bx);
449 *dip = atan2(*bz,bh);
458 if (fabs(glat) >= 55.)
460 if (glat > 0.0 && glon >= 0.0) *gv = (*dec-rlon)/dtr;
461 if (glat > 0.0 && glon < 0.0) *gv = (*dec+fabs(rlon))/dtr;
462 if (glat < 0.0 && glon >= 0.0) *gv = (*dec+rlon)/dtr;
463 if (glat < 0.0 && glon < 0.0) *gv = (*dec-fabs(rlon))/dtr;
464 if (*gv > +180.0) *gv -= 360.0;
465 if (*gv < -180.0) *gv += 360.0;
static double re
Definition: nrlmsise-00.cpp:67
ElapsedTime dt
Definition: agent_file3.cpp:183
int i
Definition: rw_test.cpp:37
long b
Definition: jpegint.h:371
static double * p
Definition: gauss_jackson_test.cpp:42
static uint16_t model
Definition: add_radio.cpp:19
static char fname[100]
Definition: geomag.cpp:89
Definition: eci2kep_test.cpp:33
const double DPI
Double precision PI.
Definition: math/constants.h:14
#define GEOMAG_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:247
#define GEOMAG_ERROR_NOTFOUND
Definition: cosmos-errno.h:246