?? geomag6.c
字號:
#include<reg51.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* The following include file must define a function 'isnan' */
/* This function, which returns '1' if the number is NaN and 0*/
/* otherwise, could be hand-written if not available. */
/* Comment out one of the two following lines, as applicable */
#include <math.h> /* for gcc */
//#include <mathimf.h> /* for Intel icc */
#define NaN log(-1.0)
static void E0000(int IENTRY, int *maxdeg, float alt,float glat,float glon, float time, float *dec, float *dip, float *ti, float *gv);
void geomag(int *maxdeg);
void geomg1(float alt, float glat, float glon, float time, float *dec, float *dip, float *ti, float *gv);
char geomag_introduction(float epochlowlim);
int main()
{
//const char d_str[]={"2005.0 WMM-2005 10/18/2004"};
//int warn_H, warn_H_strong, warn_P;
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;
//char answer, ans;
char idata decd[5], dipd[5];//,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 = 7.0;
float warn_H_val, warn_H_strong_val;
float dmin, imin, ddeg, ideg;
SCON=0X50;
TCON = 0x40;//定時器0和定時器1運行
TMOD = 0x21;//定時器1工作方式2,定時器0工作方式1
TH1 = 0xe8;//波特
TI=1;
TR1=1;
while(1)
{
dlat=30.29; //維度
dlon=120.13; //經度
altm=0; //海拔
time=2007.4; //時間
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);
alt = altm/1000;
epochuplim = epochlowlim + epochrange;
// printf("ENTER TIME IN DECIMAL YEAR (%-7.2f - %-7.2f)\n",epochlowlim,epochuplim);
// scanf("%f%*[^\n]",&time);
// getchar();
geomg1(alt,dlat,dlon,time,&dec,&dip,&ti,&gv);
time1 = time;
dec1 = dec;
dip1 = dip;
ti1 = ti;
time = time1 ;
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 */
}
/* convert D and I to deg and min */
// if (isnan(dec1))
// ddeg = dec1;
// else
ddeg=(int)dec1;
dmin=(dec1-(float)ddeg)*60;
if(ddeg!=0)
dmin=fabs(dmin);
// if (isnan(dip1))
// ideg = dip1;
// else
ideg=(int)dip1;
imin=(dip1-(float)ideg)*60;
if(ideg!=0)
imin=fabs(imin);
printf("\n Results For \n");
if (dlat < 0)
printf("\n LATITUDE: %7.2fS",-dlat);
else
printf("\n LATITUDE: %7.2fN",dlat);
if (dlon < 0)
printf("\n LONGITUDE: %7.2fW",-dlon);
else
printf("\n LONGITUDE: %7.2fE",dlon);
printf("\n ALTITUDE: %8.2f METERS AMSL (WGS84)",altm);
printf("\n DATE: %6.1f\n",time1);
printf("\n Main Field \t\t\t Secular Change");
printf("\n F = %-9.1f nT\t\t dF = %-8.1f nT/yr",ti1,ati);
// if (isnan(h1))
// printf("\n H = NaN \t\t dH = NaN");
// else
printf("\n H = %-9.1f nT\t\t dH = %-8.1f nT/yr",h1,ah);
// if (isnan(x1))
// printf("\n X = NaN \t\t dX = NaN");
// else
printf("\n X = %-9.1f nT\t\t dX = %8.1f nT/yr ",x1,ax);
// if (isnan(y1))
// printf("\n Y = NaN \t\t dY = NaN");
// else
printf("\n Y = %-9.1f nT\t\t dY = %-8.1f nT/yr ",y1,ay);
printf("\n Z = %-9.1f nT\t\t dZ = %-8.1f nT/yr ",z1,az);
// if (isnan(dec1))
// printf("\n D = NaN \t\t dD = NaN");
// else
printf("\n D = %4.0f Deg %3.0f Min %s\t dD = %-8.1f Min/yr",ddeg,dmin,decd,adec);
printf("\n I = %4.0f Deg %3.0f Min %s\t dI = %-8.1f Min/yr",ideg,imin,dipd,adip);
/* if (warn_H)
{
printf("\n\nWarning: The horizontal field strength at this location is only %6.1f nT\n",warn_H_val);
printf(" Compass readings have large uncertainties in areas where H is\n");
printf(" smaller than 5000 nT\n");
}
if (warn_H_strong)
{
printf("\n\nWarning: The horizontal field strength at this location is only %6.1f nT\n",warn_H_strong_val);
printf(" Compass readings have VERY LARGE uncertainties in areas where H is\n");
printf(" smaller than 1000 nT\n");
}
if (warn_P)
{
printf("\n\nWarning: Location is at geographic pole where X, Y, and Decl are undefined\n");
} */
/* printf("\n\nDO YOU NEED MORE POINT DATA? (y or n) ");
scanf("%c%*[^\n]", &answer);
getchar();*/
// answer = 'y';
// if ((answer =='y')||(answer == 'Y')) goto S1;
/* else
{
printf("%s",goodbye);
}*/
// }
/* else
{
printf("%s",goodbye);
}*/
// exit(0);
}
}
/*************************************************************************/
static void E0000(int IENTRY, int *maxdeg, float alt, float glat, float glon, float time, float *dec, float *dip, float *ti, float *gv)
{
static int maxord,i,icomp,n,m,D1,D2,D3,D4;
static float snorm[169], sp[13],cp[13],fn[13],fm[13],pp[13],k[13][13],pi,dtr,a,b,re,
a2,b2,c2,a4,b4,c4,epoch,gnm,hnm,dgnm,dhnm,flnmj,otime,oalt,
olat,olon,dt,rlon,rlat,srlon,srlat,crlon,crlat,srlat2,
crlat2,q,q1,q2,ct,st,r2,r,d,ca,sa,aor,ar,br,bt,bp,bpp,
par,temp1,temp2,parp,bx,by,bz,bh;
static float xdata c[13][13],cd[13][13],tc[13][13],dp[13][13];
static idata char model[20], c_new[5];
static float *p = snorm;
int t=1,j=0;
// char answer;
const char code c_str[][50]={
{"2005.0 WMM-2005 10/18/2004"},
{" 1 0 -29556.8 0.0 8.0 0.0"},
{" 1 1 -1671.7 5079.8 10.6 -20.9"},
{" 2 0 -2340.6 0.0 -15.1 0.0"},
{" 2 1 3046.9 -2594.7 -7.8 -23.2"},
{" 2 2 1657.0 -516.7 -0.8 -14.6"},
{" 3 0 1335.4 0.0 0.4 0.0"},
{" 3 1 -2305.1 -199.9 -2.6 5.0"},
{" 3 2 1246.7 269.3 -1.2 -7.0"},
{" 3 3 674.0 -524.2 -6.5 -0.6"},
{" 4 0 919.8 0.0 -2.5 0.0"},
{" 4 1 798.1 281.5 2.8 2.2"},
{" 4 2 211.3 -226.0 -7.0 1.6"},
{" 4 3 -379.4 145.8 6.2 5.8"},
{" 4 4 100.0 -304.7 -3.8 0.1"},
{" 5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 -2.3 0.0 0.0 0.0"},
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -