#include "stdio.h" #include "astring.h" #include "string.h" #include "stdlib.h" #include "misc.h" void main(int argc, char *argv[]) { FILE *fpin; int flag, flatf, helpf, ifilef, amief, datef, error; int i, pos, done, strl; char filein[100], datafile[80], line[80], avefile[100], *uname; char stat[4], sdate[22]; char *filelist, ave_c[200], ave_o[50]; char rmold[200]; helpf = 0; error = 0; flatf = 0; datef = 0; amief = 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],"a")>0) { amief = 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("average_all [-h] [-l] [-ddd-mon-yy]\n"); printf(" -l do not delete old flat files\n"); printf(" -ddd-mon-yy use dd-mon-yy to locate files\n"); printf(" -a output std dev and npts to the flatfiles\n"); printf(" -h show help\n"); } } else { if (!ifilef) { ifilef = 1; strcpy(filein,argv[i-1]); } } } } if (!helpf) { if (!amief) { strcpy(ave_o,"aveflat -m -t"); } else { strcpy(ave_o,"aveflat -msn -t"); } uname = spawn("/usr/bin/whoami"); strcpy(uname,strmid(uname,0,strlen(uname)-1)); strcpy(avefile,"/export/data1/ganglu/mags/tempfiles/nav."); strcat(avefile, uname); strcat(avefile, "."); strcat(avefile, sdate); fpin = fopen(avefile,"r"); fgets(line,80,fpin); fclose(fpin); strcat(ave_o,strmid(line,0,strlen(line)-1)); strcat(ave_o," "); filelist = spawn("ls *.hed"); 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; } strcpy(ave_c, ave_o); strcat(ave_c, datafile); strcat(ave_c, " "); strcat(ave_c, datafile); strcat(ave_c, "_a"); if (!flatf) { strcpy(rmold, "/bin/rm "); strcat(rmold, datafile); strcat(rmold, ".hed "); strcat(rmold, datafile); strcat(rmold, ".dat"); } printf("%s\n",ave_c); system(ave_c); if (!flatf) { printf("%s\n",rmold); system(rmold); } } } }