#include "stdio.h" #include "string.h" #include "astring.h" #include "flatfile.h" #include "stdlib.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]; double suttime, euttime, uttime[1]; int inunit, outunit, ncol[1], csize[1], error, found, *nptsm, i; int j, ntimep, itime[6], k, ndt, strl; long *srow, *erow, nrow[1], orow, irow; float *data, missing, *sdt, *edt, t; missing = -1.0e32; if (argc < 2) { printf("Enter flat file to remove data from : "); 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]); nptsm = calloc(sizeof(int),ff_ncol[inunit]); error = rdhead(inunit,vn,vu,vs,vt,no, stime,etime,nrow,ncol,csize); strcat(no,",This data file has had data removed. Original file : "); strcat(no,filein); error = mkhead(fileout,ncol[0],vn,vu,vs,vt,no); outunit = ffcreate(fileout); if (outunit != -1) { printf("Since some data files are corrupt every day at the same time,\n"); printf("you can enter a start time of 'd hh:mm', and an end time of\n"); printf("'d hh:mm', and the data between these two times will be\n"); printf("removed every day of the data file.\n"); printf("This daily removal counts as one time period.\n"); printf("Enter number of time periods to remove : "); scanf("%d",&ntimep); getchar(); srow = calloc(sizeof(long),ntimep); erow = calloc(sizeof(long),ntimep); sdt = calloc(sizeof(float),ntimep); edt = calloc(sizeof(float),ntimep); ndt = 0; printf("\n"); printf("Start time of input file : %s\n",stime); printf("End time of input file : %s\n",etime); for (i=0; i= 9) { euttime = c_s_to_r(outetime); erow[i] = fdsearch(inunit, euttime); } else { erow[i] = srow[i]+1; } } } orow = 0; for (irow=0; irow<=nrow[0]-1; irow++) { error = fdget(inunit,irow,uttime,data); for (i=0; i= srow[i] && irow <= erow[i]) { for (j=0; j<=ncol[0]-2; j++) { data[j] = missing; nptsm[j]++; } } else { if (ndt > 0) { c_r_to_i(itime,uttime[0]); t = ((float) itime[3])*3600.0 + ((float) itime[4])*60.0 + (float) itime[5]; for (j=0; j= sdt[j] && t <= edt[j]) { for (k=0; k<=ncol[0]-2; k++) { data[k] = missing; nptsm[k]++; } } } } } } error = fdput(outunit,orow,uttime[0],data); orow++; } for (i=0; i<=ncol[0]-2; i++) { printf("Number of points missing in column %d : %d\n",i+2,nptsm[i]); } ffclose(inunit); ffclose(outunit); } }