/****************************************************************/ /* b2apfout.C */ /* K.Hayashi */ /****************************************************************/ #include #include #include #include #include #include #include #include # define O_RDONLY 0000000 /* Open for reading only */ # define O_WRONLY 0000001 /* Open for writing only */ # define O_RDWR 0000002 /* Open for reading or writing */ # define O_ACCMODE 0000003 /* Mask for file access modes */ # define O_CREAT 0000400 /* Open with file c reate (uses third open arg) */ void opf(void); void stn_db_read(void); int handle,pps,mstn; char sfn[30],sfnp[30],fno[30],stn1[4]=""; struct { char nam[20], abr[4], dr[15]; double mazm; double fac; int h; int lx;}stn[30]; double argmg; FILE *outpath; main(int argc, char **argv) { char input,fout[3]; char shfn[]="shplotp2",sbfn[]="sbplotp2"; unsigned char buf[8640],*j, ea; int i,ii,ifc,ix,iy,iz; long sx,sy,sz; double fx,fy,fz,fmi; if (argc<2) printf("put an argv of file name like 94_0101m.cbb to create ascii file of a940101m.cbb"); sprintf(sfn,"%s",argv[1]); strncpy(stn1,sfn+9,3); stn_db_read(); printf("%s --",stn[pps].nam); opf(); read(handle,buf,8640); sx=0;sy=0;sz=0; for (ii=0; ii<1440;ii++){ /* printf("\n%4d ",ii); */ i=ii*6; /* printf("%02x%02x %02x%02x %02x%02x\n",buf[i+1],buf[i],buf[i+3],buf[i+2],buf[i+5],buf[i+4]); */ /* ix=(short)(((int)(buf[i+1])<<8)+(int)buf[i]); iy=(short)(((int)(buf[i+3])<<8)+(int)buf[i+2]); iz=(short)(((int)(buf[i+5])<<8)+(int)buf[i+4]); */ ix=(short)((((unsigned short)buf[i+1])<<8)+(unsigned short)buf[i]); iy=(short)((((unsigned short)buf[i+3])<<8)+(unsigned short)buf[i+2]); iz=(short)((((unsigned short)buf[i+5])<<8)+(unsigned short)buf[i+4]); sx+=(long)ix;sy+=(long)iy;sz+=(long)iz; } /* sx=0;sy=0;sz=0; */ for (ii=0; ii<1440;ii++){ i=ii*6; ix=(short)((((unsigned short)buf[i+1])<<8)+(unsigned short)buf[i]) -(short)(sx/1440); iy=(short)((((unsigned short)buf[i+3])<<8)+(unsigned short)buf[i+2])-(short)(sy/1440); iz=(short)((((unsigned short)buf[i+5])<<8)+(unsigned short)buf[i+4])-(short)(sz/1440); /* ix=(short)(((int)(buf[i+1])<<8)+(int)buf[i]) -(short)(sx/1440); iy=(short)(((int)(buf[i+3])<<8)+(int)buf[i+2])-(short)(sy/1440); iz=(short)(((int)(buf[i+5])<<8)+(int)buf[i+4])-(short)(sz/1440); */ /* fmi=M_PI*argmg/180.0; */ fmi=M_PI*stn[pps].mazm/180.0; /* printf("%d %d %d %lf %f %d\n",ix,iy,iz,fmi,argmg,tfn);*/ fx= stn[pps].fac*cos(fmi)*(double)ix+sin(fmi)*(double)iy/32.0; fy=-stn[pps].fac*sin(fmi)*(double)ix+cos(fmi)*(double)iy/32.0; fz=stn[pps].fac*(double)iz/32.0; fprintf(outpath,"#%4d= %9.2f %9.2f %9.2f \x0d\n",ii,fx,fy,fz); } close(outpath); close(handle); printf("-->>out file %s was closed\n",fno); } void opf() { short ch,dy,dm,dm1,dd; static char ay[3]="90",am[3]="01",ad[3]="01"; short mnn[13]={31,31,29,31,30,31,30,31,31,30,31,30,31}; if ((handle= open(sfn, O_RDONLY)) == -1){ printf( "Could not find \"%s\" \n", sfn); exit(1); } printf("open %s ! ",sfn); strcpy(sfnp,sfn); strncpy(ay,sfn,2);dy=atoi(ay); mnn[2]=29-(dy%4+3)/4; strncpy(am,sfn+3,2);dm=atoi(am); strncpy(ad,sfn+5,2);dd=atoi(ad); strncpy(stn1,sfn+9,3); sprintf(fno,"a%02d%02d%02dm.%s",dy,dm,dd,stn1); outpath=fopen(fno,"wt"); dm1=dm+dd/mnn[dm]; dd=1+dd%mnn[dm]; dm=dm1; if(dm>=13){dy++;dm=1;dd=1;} sprintf(sfn,"%02d_%02d%02dm.%s",dy,dm,dd,stn1); /* printf("\n %02d_%02d%02dm.%s",dy,dm,dd,stn1); */ } /* ********************************************* */ void stn_db_read() { int i,ii; char dmm[3],dm1[8],dm2[4], dm3[6],dm4[6]; FILE *fp; if ((fp=fopen("fxstndb.txt","r"))==0)fprintf(stderr,"fxstndb.txt no exist!"); i=0; for(ii=0;ii<25;ii++){ fscanf(fp,"%14c %s %s %s %s %s %s%2c", stn[i].nam, stn[i].abr, stn[i].dr, dm1,dm2,dm3,dm4,dmm); stn[i].mazm=atof(dm1); stn[i].fac=atof(dm2); stn[i].h=atoi(dm3); stn[i].lx=atoi(dm4); if (stn[i].h!=0)i++; } mstn=i; close(fp); for (i=0;i