#include "stdio.h" #include "string.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, strl; long srow, erow, nrow[1], orow, irow; float *data; if (argc < 2) { printf("Enter flat file to copy : "); 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); strcat(no,",Copied from file : "); strcat(no,filein); error = mkhead(fileout,ncol[0],vn,vu,vs,vt,no); outunit = ffcreate(fileout); if (outunit != -1) { printf("Start time of input file : %s\n",stime); printf("Enter new start time of output file : "); gets(outstime); printf("\n"); printf("End time of input file : %s\n",etime); printf("Enter new end time of output file : "); gets(outetime); strl = strlen(outstime); if (strl < 9) strcpy(outstime,stime); strl = strlen(outetime); if (strl < 9) strcpy(outetime,etime); suttime = c_s_to_r(outstime); euttime = c_s_to_r(outetime); srow = fdsearch(inunit, suttime); erow = fdsearch(inunit, euttime); error = fdget(inunit,srow,uttime,data); if (uttime[0] < suttime) srow++; orow = 0; for (irow=srow; irow<=erow; irow++) { error = fdget(inunit,irow,uttime,data); error = fdput(outunit,orow,uttime[0],data); orow++; } ffclose(inunit); ffclose(outunit); } }