#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[400], fileout[400], f1[400], f2[400]; 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, nfiles, cfiles, i; int *map, same, outflag, helpflag, goodflag, strl; long srow, erow, nrow[1], orow, irow; float *data; outflag = -1; helpflag = 0; if (argc < 2) { printf("Enter number of flatfiles to merge : "); scanf("%d",&nfiles); } else { cfiles=1; while ((cfiles<=argc-1) && (outflag < 0)) { if (strloc(argv[cfiles],"-") == 1) { goodflag = 0; strl = strlen(argv[cfiles]); for (i=0;i 1) { strcpy(f1,strmid(argv[cfiles-1],0,strlen(argv[cfiles-1])-4)); strcpy(f2,strmid(argv[cfiles],0,strlen(argv[cfiles])-4)); if ((strloc(f1,f2) != -1) && (strloc(argv[cfiles-1],"dat") != -1) && (strloc(argv[cfiles],"hed") != -1)) { same = 1; } } if (same) { strcpy(argv[cfiles-1],f2); same = 0; } else { if ((cfiles != outflag) && (cfiles != outflag+1)) { map[nfiles] = cfiles; nfiles++; } } } } if (!helpflag) { printf("nfiles : %d \n",nfiles); if (outflag < 0) { printf("Enter output file name : "); scanf("%s",fileout); } orow = 0; for (cfiles=1;cfiles<=nfiles;cfiles++) { if (argc < 2) { printf("Enter file name #%d to convert : ",cfiles); scanf("%s",filein); } else { strcpy(filein, argv[map[cfiles-1]]); } printf("Ingesting file : %s\n",filein); inunit = ffopen(filein); if (cfiles == 1 ) { 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,",Merged from (first) file : "); strcat(no,filein); error = mkhead(fileout,ncol[0],vn,vu,vs,vt,no); outunit = ffcreate(fileout); free(vn); free(vu); free(vs); free(vt); } if (outunit != -1) { srow = 0; erow = ff_rows[inunit]-1; for (irow=srow; irow<=erow; irow++) { error = fdget(inunit,irow,uttime,data); error = fdput(outunit,orow,uttime[0],data); orow++; } ffclose(inunit); } } ffclose(outunit); free(map); free(data); } }