#include "stdio.h" #include "string.h" #include "astring.h" #include "misc.h" #include "stdlib.h" #include "flatfile.h" void main(int argc, char *argv[]) { FILE *fpin; int flag, flatf, helpf, ifilef, datef, error; int i, pos, done, strl; char filein[100], datafile[80], line[80], actfile[100], *uname; char stat[4], sdate[10]; char *filelist, trim_c[200], trim_o[50]; char rmold[200]; double active1, active2; strcpy(trim_o,"cpflat "); helpf = 0; error = 0; flatf = 0; datef = 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("trim_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) { /* want to cut files down to smaller size - only include active days +/- 3 days */ uname = spawn("/usr/bin/whoami"); strcpy(uname,strmid(uname,0,strlen(uname)-1)); strcpy(actfile,"/export/data1/ganglu/mags/tempfiles/act.tim."); strcat(actfile,uname); if (datef) { strcat(actfile,"."); strcat(actfile,sdate); } fpin = fopen(actfile,"r"); if (fpin == NULL) { printf("COULD NOT FIND active.time FILE - FILES NOT TRIMMED\n"); fpin = fopen("TEMP_INPUT","w"); fprintf(fpin,"\n"); fprintf(fpin,"\n"); fclose(fpin); } else { /* take away 3 days from midnight on the first active day */ fgets(line,79,fpin); active1 = c_s_to_r(strmid(line,0,9)) - 3.0*24.0*3600.0; /* add 4 days (active + 3) from midnight on the last active day */ fgets(line,79,fpin); active2 = c_s_to_r(strmid(line,0,9)) + 4.0*24.0*3600.0 - 1.0; fclose(fpin); fpin = fopen("TEMP_INPUT","w"); fprintf(fpin,"%s\n",c_r_to_s(active1)); fprintf(fpin,"%s\n",c_r_to_s(active2)); fclose(fpin); } 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(trim_c, trim_o); strcat(trim_c, datafile); strcat(trim_c, " "); strcat(trim_c, datafile); strcat(trim_c, "_t"); strcat(trim_c, " < TEMP_INPUT"); if (!flatf) { strcpy(rmold, "/bin/rm "); strcat(rmold, datafile); strcat(rmold, ".hed "); strcat(rmold, datafile); strcat(rmold, ".dat"); } printf("%s\n",trim_c); system(trim_c); if (!flatf) { printf("%s\n",rmold); system(rmold); } } system("/bin/rm TEMP_INPUT"); } }