#include "stdio.h" #include "string.h" #include "stdlib.h" #include "astring.h" #include "flatfile.h" void main(int argc, char *argv[]) { FILE *fpout; char filein[100], fileout[100]; char *vn, *vu, *vs, *vt, no[1000]; char stime[24],etime[24], outstime[24], outetime[24], yorn[20]; double suttime, euttime, uttime[1], ut; int inunit, outunit, ncol[1], csize[1], error; long srow, erow, nrow[1], orow, irow, *npts, timep, i, j, k, tenpercent; float *data, dt, dts, *superdata, missing, *aveval; missing = -1.0e32; if (argc < 2) { printf("Enter flat file to low pass filter : "); gets(filein); } else { strcpy(filein,argv[1]); } if (argc < 3) { printf("Enter output file name : "); gets(fileout); } else { strcpy(fileout,argv[2]); } inunit = ffopen(filein); vn = calloc(sizeof(char),ff_ncol[inunit]*16+2); vu = calloc(sizeof(char),ff_ncol[inunit]*16+2); vs = calloc(sizeof(char),ff_ncol[inunit]*31+2); vt = calloc(sizeof(char),ff_ncol[inunit]*2+2); data = calloc(sizeof(float),ff_ncol[inunit]); error = rdhead(inunit,vn,vu,vs,vt,no, stime,etime,nrow,ncol,csize); printf("Start time of input file : %s\n",stime); printf("End time of input file : %s\n",etime); printf("Enter number of minutes for low pass filter cut off : "); scanf("%f",&dt); getchar(); dt = dt*60.0; strcat(no,",Low pass filtered from file : "); strcat(no,filein); strcat(no,",Filter time : "); strcat(no,c_int_str((int) dt,2)); strcat(no," seconds"); error = mkhead(fileout,ncol[0],vn,vu,vs,vt,no); outunit = ffcreate(fileout); if (outunit != -1) { suttime = c_s_to_r(stime); euttime = suttime + (double) dt; srow = fdsearch(inunit,suttime); erow = fdsearch(inunit,euttime); irow = erow - srow; superdata = calloc(sizeof(float),(irow)*(ncol[0]-1)); npts = calloc(sizeof(long), (ncol[0]-1)); aveval = calloc(sizeof(float), (ncol[0]-1)); for (j=0;j<(irow)*(ncol[0]-1); j++) { superdata[j] = missing; } for (j=0;j<(ncol[0]-1); j++) { npts[j] = 0; } srow = 0; erow = irow-1; for (i=0; i<=irow-1; i++) { error = fdget(inunit,i,uttime,data); for (j=0; j 0) { data[j] = aveval[j]/(float) npts[j]; } else { data[j] = missing; } } ut = uttime[0] - dt/2.0; error = fdput(outunit,orow,ut,data); orow++; } ffclose(inunit); ffclose(outunit); free(vn); free(vu); free(vs); free(vt); free(data); free(superdata); free(npts); free(aveval); } }