#include "stdio.h" #include "string.h" #include "astring.h" #include "stdlib.h" #include "flatfile.h" #include "misc.h" #include "math.h" void main(int argc, char *argv[]) { FILE *fpout, *fppsi; char line[80], stat[4], sdate[24], edate[24], qdate[24], uname[100]; char input_v[20], datafile[80], temp[100], *filelist, master[100]; long sloc; float mlat, cutlat; int found, done, strl, pos; cutlat = 60.0; if (argc >= 2) { strcpy(sdate,argv[1]); } else { printf("Enter start date : "); gets(sdate); } if (argc >= 3) { strcpy(edate,argv[2]); } else { printf("Enter end date : "); gets(edate); } strl = strlen(edate); if (strl < 10) { strcat(edate," 23:59:59.000"); } if (argc >= 4) { strcpy(qdate,argv[3]); } else { printf("Enter start time of quiet day (ex 02-nov-93 10:00) : "); gets(qdate); } fpout = fopen("mean_input","w"); fprintf(fpout,"%s\n",sdate); fprintf(fpout,"%s\n",edate); fprintf(fpout,"m\n"); fprintf(fpout,"%s\n",qdate); fclose(fpout); fpout = fopen("curve_input","w"); fprintf(fpout,"%s\n",sdate); fprintf(fpout,"%s\n",edate); fprintf(fpout,"c\n"); fprintf(fpout,"%s\n",qdate); fclose(fpout); strcpy(uname,spawn("/usr/bin/whoami")); strcpy(uname,strmid(uname,0,strlen(uname)-1)); strcpy(master, "/export/data1/ganglu/mags/tempfiles/mas.loc."); strcat(master,uname); strcat(master,"."); strcat(master,sdate); fppsi = fopen(master,"r"); fgets(master, 80, fppsi); fgets(master, 80, fppsi); fclose(fppsi); strcpy(master,strmid(master,0,strlen(master)-1)); fppsi = fopen(master,"r"); if (fppsi == NULL) printf("can not open master_psi file\n"); fpout = fopen("process","w"); fprintf(fpout,"#!/bin/sh\n"); fprintf(fpout,"\n"); filelist = spawn("ls *.hed"); done = 0; while (!done) { pos = strpos(filelist,"\n"); if (pos > 0) { strcpy(datafile,strmid(filelist,0,strpos(filelist,"\n"))); filelist = filelist + strpos(filelist,"\n")+1; strl = strlen(filelist); if (strl < 4) done = 1; } else { done = 1; } printf("file ---%s---\n",datafile); strcpy(stat,mkupper(strmid(datafile,0,3))); fseek(fppsi,0,SEEK_SET); found = 0; strcpy(input_v, "mean_input"); while (found == 0) { fgets(line, 79, fppsi);; if (feof(fppsi)) found = 1; sloc = strloc(line, stat); if ((sloc > 3) && (sloc < 6)) { mlat = atof(strmid(line,36,6)); if (fabs(mlat) <= cutlat) strcpy(input_v, "curve_input"); found = 2; } } if (found == 2) { strcpy(temp,strmid(datafile,0,strpos(datafile,".hed"))); fprintf(fpout,"echo ---- remca %s ------\n",mklower(stat)); fprintf(fpout,"mkremca %s %s.remca < %s\n", temp,strmid(temp,0,7),input_v); fprintf(fpout,"echo ---- done with %s ------\n",mklower(stat)); } else { fprintf(fpout, "echo ****** station %s not found in master list ! ******\n", mklower(stat)); printf("****** station %s not found in master list ! ******\n", mklower(stat)); } } close(fppsi); close(fpout); system("chmod a+x process"); /*system("process"); system("/bin/rm mean_input curve_input process");*/ }