#include "stdio.h" #include "string.h" #include "astring.h" #include "stdlib.h" #include "misc.h" #include "math.h" void main(int argc, char *argv[]) { FILE *fpin, *fplat; int flag, flatf, helpf, ifilef, datef, error; int i, pos, found, done, strl; float lat, tlat; char filein[100], line[80], datafile[80], *uname, master[100]; char stat[4], sdate[10]; char *filelist, rmspikeo[50], rmspike_c[200]; char rmold[200]; strcpy(rmspikeo,"rmspike -z -m"); helpf = 0; error = 0; flatf = 0; ifilef = 0; if (argc >= 2) { for (i=2; i<=argc; i++) { if (strpos(argv[i-1],"-")==0) { flag = 0; if (strpos(argv[i-1],"l")>0) { flatf = 1; flag=1; } if (strpos(argv[i-1],"d")>0) { datef = 1; strcpy(sdate,strmid(argv[i-1],2,9)); flag=1; } if ((strpos(argv[i-1],"h")>0) || (!flag)) { helpf = 1; printf("usage : \n"); printf("despike_all [-h] [-l] [-ddd-mon-yy]\n"); printf(" -ddd-mon-yy use dd-mon-yy to locate files\n"); printf(" -l do not delete old flat files\n"); printf(" -h show help\n"); } } else { if (!ifilef) { ifilef = 1; strcpy(filein,argv[i-1]); } } } } if (!helpf) { filelist = spawn("ls *.hed"); 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); if (datef) { strcat(master,"."); strcat(master,sdate); } fpin = fopen(master,"r"); fgets(master, 80, fpin); fgets(master, 80, fpin); fclose(fpin); strcpy(master,strmid(master,0,strlen(master)-1)); fpin = fopen(master,"r"); done = 0; while (!done) { pos = strpos(filelist,"\n"); if (pos > 0) { strcpy(datafile,strmid(filelist,0,strpos(filelist,"\n")-4)); filelist = filelist + strpos(filelist,"\n")+1; strl = strlen(filelist); if (strl < 4) done = 1; } else { done = 1; } printf("file ---%s---\n",datafile); strcpy(stat,strmid(datafile,0,3)); rewind(fpin); found = 0; while (!found) { fgets(line,79,fpin); if (feof(fpin)) { found = 1; lat = 65.0; } else { pos = strpos(line, mkupper(stat)); if (pos == 4) { found = 1; lat = fabs(atof(strmid(line,36,6))); } } } strcpy(rmspike_c, rmspikeo); fplat = fopen("/export/data1/ganglu/mags/pfiles/despike.list","r"); found = 0; while (!found) { fgets(line,79,fplat); tlat = atof(strmid(line,0,4)); if (lat <= tlat) { found = 1; strcat(rmspike_c,strmid(line,7,6)); strcat(rmspike_c," -d"); strcat(rmspike_c,strmid(line,16,3)); strcat(rmspike_c," "); } } fclose(fplat); strcat(rmspike_c, datafile); strcat(rmspike_c, " "); strcat(rmspike_c, datafile); strcat(rmspike_c, "_f"); if (!flatf) { strcpy(rmold, "/bin/rm "); strcat(rmold, datafile); strcat(rmold, ".hed "); strcat(rmold, datafile); strcat(rmold, ".dat"); } printf("%s\n",rmspike_c); system(rmspike_c); if (!flatf) { printf("%s\n",rmold); system(rmold); } } close(fpin); } }