/****************************************************************/ /* sm_ps_1fout.c */ /* Stack plot of magnetograms K.Hayashi */ /****************************************************************/ #include #include #include #include #include #include #include #include #include #include #include "mplt_stn2.h" int h_w=2000; int main(int argc, char **argv) { char date_h[50]="",fout[3]="",stab[4]="",mst[3]="",dst[3]=""; char fnout[30]="",fbuf[8192], outd[20]; int i,ii,j,tfn=3,ntpdv,ifc,ist=0,smn,sdy,dlb,eday,rsft,hhi,hfo,tnofd=1,cnod=0,nofb,year4; static int xysd=0; short *xx,*yy,*zz, hh,ix0,iy0,iz0,ipx,ipy,ipz; long ix,iy,iz,dix,diy,diz,dxif,dyif,dzif; long ixx[1440],iyy[1440],izz[1440]; long sx,sy,sz; FILE *tp; FILE *fp; double fmi,mcos,msin,flt,M_PI; struct { short x[1440]; short y[1440]; short z[1440];} fo[25]; time_t ltime; if(argc<=1) {printf("argv = \ 1:file name \"99_1231.erk\"\n \ [2:Total number of pages <1> (3 days par page)\n \ [3:nT par div(4mm) [12(12.5)||25||50||100||<200>]\n \ [4:Style,<0>:XYZ or 1:JhZ\n \ [5:Output directory <\\temp>]]]]\n \ Data files must be in ..\\_\"location\"\\\"yy\"\\m\\"); exit(0); sprintf(sfn,"02_0101.hcm"); } if(argc>1)sprintf(sfn,"%s",argv[1]); if(argc>2)tnofd=atoi(argv[2]);else tnofd=1; if(argc>3)ntpdv=atoi(argv[3]);else ntpdv=200; if(argc>4)xysd=atoi(argv[4]);else xysd=0; if(argc>5)sprintf(outd,argv[5]); else sprintf(outd,"\\temp"); if(xysd==0)tfn=3; else tfn=4; printf("argc=%d fnam=%s pages=%d ntpdv=%d mod=%d dpp=%d \n",argc, sfn, tnofd, ntpdv,xysd,tfn); if(ntpdv==200)rsft=4; else if(ntpdv==100)rsft=3; else if(ntpdv==50)rsft=2; else if(ntpdv==25)rsft=1; else if(ntpdv==12)rsft=0; else {printf("2nd arg must be 200||100||50||25||12"); exit(1);} if((xysd!=0)&&(xysd!=1)&&(xysd!=2)){printf("4th arg must be 0 or 1 or 2"); exit(1);} printf("File %s Pages%d nT/dv%d Style:%d Destination %s ", sfn, tnofd, ntpdv, xysd, outd); M_PI=4.0*atan(1.0); stn_db_read(); strncpy(stab,sfn+8,3); strncpy(mst,sfn+3,2); strncpy(dst,sfn+5,2); sdy=atoi(dst); smn=atoi(mst); /* for(i=0;i<25;i++)printf("%s ",stn[i].abr); */ for (i=0;(strcmp(stab,stn[i].abr)!=0);i++) ist=i+1; /* printf("%s \n",stn[i].abr); */ if((fp=fopen(".\\prlg_s.ps","r"))==NULL) printf("Could not open prlg_s.ps \n"); nofb=fread(fbuf,1,8192,fp);if(nofb==0){printf("Error!\n");exit(0);} /* printf("sfn=%s mstn=%d stab=%s stn.abr=%s ist=%d\n",sfn, mstn, stab, stn[ist].abr,ist ); */ while(1){ /* printf("start tfn=%d\n",tfn); */ for(ifc=0;ifc> ",msfn[ist]); if((handle[ist]= _open(msfn[ist], O_RDONLY))==-1) break; _read(handle[ist],buf,8640); sx=sy=sz=0;dix=diy=diz=dxif=dyif=dzif=0; for (ii=0; ii<1440;ii++){ i=ii*6; if ((buf[i+1]==0x80) && (buf[i]==0)){ix=0;ix0=0;buf[i+1]=0;} else {ix0=(((short)buf[i+1])<<8)|(short)buf[i]; dix=(int)ix0-(int)ipx; if (((dix>32767)||(dix<-32767)) &&((dix *dxif)<=0)) dxif+=dix/labs(dix); ix=(int)ix0-dxif*65536; } ipx=ix0; sx+=ix; ixx[ii]=ix; if (buf[i+3]==0x80 && buf[i+2]==0){iy0=0;iy=0;buf[i+3]=0;} else {iy0=(((short)buf[i+3])<<8)|(short)buf[i+2]; diy=(int)iy0-(int)ipy; if (((diy>32767)||(diy<-32767))&& ((diy *dyif)<=0)) dyif+=diy/labs(diy); iy=(int)iy0-dyif*65536; } ipy=iy0;sy+=iy; iyy[ii]=iy; if (buf[i+5]==0x80 && buf[i+4]==0){iz0=0;iz=0;buf[i+5]=0;} else {iz0=(((short)buf[i+5])<<8)|(short)buf[i+4]; diz=(int)iz0-(int)ipz; if (((diz>32767)||(diz<-32767))&& ((diz *dzif)<=0)) dzif+=diz/labs(diz); iz=(int)iz0-dzif*65536; } if(strcmp(stn[ist].abr,"upv")==0)iz=0; ipz=iz0; sz+=iz; izz[ii]=iz; } sx/=1440; sy/=1440; sz/=1440; xx=fo[ifc].x; yy=fo[ifc].y; zz=fo[ifc].z; fmi=stn[ist].mazm*M_PI/180.0; flt=stn[ist].lg *M_PI/180.0; hh=0; for (ii=0; ii<1440;ii++){ ix=ixx[ii] -sx; iy=iyy[ii] -sy; iz=izz[ii] -sz; /* printf("%d %d %d\n",ix,iy,iz,fmi);*/ mcos=cos(fmi)*stn[ist].fac; msin=sin(fmi)*stn[ist].fac; *xx++=(short)(((int)( mcos * (double)ix + msin * (double)iy))>>rsft); *yy++=(short)(((int)(-msin * (double)ix + mcos * (double)iy))>>rsft); *zz++=(short)(((int)( stn[ist].fac * (double)iz) )>>rsft); /* 0.01 mm <==> 0.125*2^(rsft-2) nT */ } } close(handle[ist]); } /* ======================================================== */ /* xyzxyzxyzxyzxysxyzxyzxyzxyz */ if (y_f[ist]!=0){ eday=1+(sdy+tfn-2)%mnn[smn]; if(xysd==0) sprintf(fnout,"%s\\%02d%02d%02d-%02d%sxyz.ps",outd,year,smn,sdy,eday,stab); if(xysd==1) sprintf(fnout,"%s\\%02d%02d%02d-%02d%sVsdZ.ps",outd,year,smn,sdy,eday,stab); if (year>50)year4=1900+year; else year4=2000+year; sprintf(date_h,"%s %02d - %s %02d, %d %s) ashow\n",mnam[smn],sdy,mnam[smn+(sdy+tfn-2)/mnn[smn]],eday,year4,stn[ist].nam); if((tp=fopen(fnout,"wt"))==NULL) printf("Could not open"); printf("Out file >> %s\n",fnout); fwrite(fbuf,1,nofb,tp); if(xysd==0) fprintf(tp,"0 U@pt 0 (X,Y,Z %s",date_h); else if(xysd==1) fprintf(tp,"0 U@pt 0 (Vsd,Z %s",date_h); fprintf(tp,"21000 23400 0 0 0 2800 view\n"); fprintf(tp,"18600 12368 mto\n"); fprintf(tp,"0.0 [0 -12 U@pt -12 U@pt 0 0 0] //TRF F\n"); fprintf(tp,"0 -0 U@pt (%4d nT/div) ashow\n",ntpdv); fprintf(tp,"21000 21000 0 0 0 4000 view\n"); fprintf(tp,"%%Data(%s)\n%s",stn[ist].nam,view_lsty); if(xysd==0){ /* printf("xysd=%d Data got and converted\n",xysd); */ for(i=1;i<=tfn;i++) { /* date lable at left edge of each base line */ fprintf(tp,"21000 21000 0 0 0 4000 view\n"); hhi=h_w*(i-1)*3 +1600+(i-1)*800; dlb=1+(sdy+i-2) % mnn[smn]; fprintf(tp,"0.0 [16 U@pt 0 0 -16 U@pt 0 0] //TRF F\n"); fprintf(tp,"%d %d mto\n0 U@pt 0 (%s %02d) ashow\n", 1800,hhi-500,mnam[smn + (sdy+i-2)/mnn[smn]],dlb); fprintf(tp,"0.0 [12 U@pt 0 0 -12 U@pt 0 0] //TRF F\n"); fprintf(tp,"%d %d mto\n0 U@pt 0 (Bx) ashow\n",3000,hhi); fprintf(tp,"%d %d mto\n0 U@pt 0 (By) ashow\n",3000,hhi+h_w); fprintf(tp,"%d %d mto\n0 U@pt 0 (Bz) ashow\n",3000,hhi+h_w+h_w); fprintf(tp, "5 [50 50] 0 0.0 2 0 lsty\n 3790 %d 18210 %d l\n",hhi,hhi); fprintf(tp, "5 [50 50] 0 0.0 2 0 lsty\n 3790 %d 18210 %d l\n",hhi+h_w,hhi+h_w); fprintf(tp, "5 [50 50] 0 0.0 2 0 lsty\n 3790 %d 18210 %d l\n",hhi+h_w+h_w,hhi+h_w+h_w); } fprintf(tp,"21000 21000 0 0 0 4000 view\n"); for (ii=0;ii-By,Vy<=>Bx */ fprintf(tp,"st\n"); hfo=1800+h_w*ii*2+h_w+ii*800; fprintf(tp,"%%Data(%s)\n%s",stn[ist].nam,view_lsty); fprintf(tp,"%-5d %-5d mto\n",10,hfo-*(fo[ii].z)); for(j=1;j<1440;j++){ fprintf(tp,"%-5d %-5d lto\n",j*10+10,hfo-*(fo[ii].z+j));} fprintf(tp,"st\n"); } } time(<ime); fprintf(tp,"21000 23600 0 0 0 4000 view\n2000 23500 mto\n0.0 [10 U@pt 0 0 -10 U@pt 0 0] //TRF F\n0 U@pt 0 (Printed %s) ashow",ctime(<ime)); fprintf(tp,"%s",pstail); fclose(tp); } fclose(tp); sdy=day; smn=mon; cnod ++; if(cnod>=tnofd) break; } /* while */ return(0); } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ int opf(ist) int ist; { int dy,dm,dm1,dd, i; char ay[3]="",am[3]="",ad[3]=""; 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); /* year=(int)dy; mon=(int)dm; day=(int)dd; */ /* printf("ay %s am %s ad %s year=%d \n",ay,am, ad, year); */ i=ist; sprintf(msfn[i], ".\\%s\\%02d\\m\\%02d_%02d%02dm.%s",stn[i].dr,dy,dy,dm,dd,stn[i].abr); if((handle[i]= _open(msfn[i], O_RDONLY)) == -1){ /* printf( ">>>>>No data \"%s\" \n", msfn[i]); */ y_f[i]=0; /* *tfn --; */ } else y_f[i]=1; /* printf( ">>>>>\"%s\" was found \n", msfn[i]); */ close(handle[i]); dm1=dm+dd/mnn[dm];dd=1+dd%mnn[dm]; dm=dm1; if(dm>=13){dy++;dm=1;dd=1;} sprintf(sfn,"%2d_%02d%02dm",dy,dm,dd); year=(int)dy; mon=(int)dm; day=(int)dd; return(1); } /* ********************************************* */ void stn_db_read(){ int i,ii; char dmm[3],dm1[8],dm2[4], dm3[6],dm4[6],dm5[6]; FILE *fp; if ((fp=fopen("fx1stndb.txt","r"))==0)fprintf(stderr,"fx1stndb.txt no exist!"); i=0; for(ii=0;ii<25;ii++){ fscanf(fp,"%14c %s %s %s %s %s %s %s%2c", stn[i].nam, stn[i].abr, stn[i].dr, dm1,dm2,dm3,dm4,dm5,dmm); stn[i].mazm=atof(dm1); stn[i].fac=atof(dm2); stn[i].h=atoi(dm3); stn[i].lx=atoi(dm4);stn[i].lg=atof(dm5); if (stn[i].h!=0)i++; } mstn=i; fclose(fp); /* for (i=0;i