#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], f1[100], f2[100]; char *vn, *vu, *vs, *vt, no[1000], not[3000]; char *vnt, *vut, *vst, *vtt; 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, total_vars; int *unit_list, *nvars, ivar; long srow, erow, nrow[1], orow, irow; float *data, *datat; 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; total_vars = 1; unit_list = calloc(sizeof(int),nfiles); nvars = calloc(sizeof(int),nfiles); 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]]); } if (cfiles == 1) { strcpy(not, "Merged from the following files :"); } strcat(not, ", "); strcat(not,filein); inunit = ffopen(filein); nvars[cfiles-1] = (n_columns(inunit)-1); total_vars += (n_columns(inunit)-1); unit_list[cfiles-1] = inunit; } vnt = calloc(sizeof(char),total_vars*16+2); vut = calloc(sizeof(char),total_vars*16+2); vst = calloc(sizeof(char),total_vars*31+2); vtt = calloc(sizeof(char),total_vars*2+2); datat = calloc(sizeof(float),total_vars); vn = calloc(sizeof(char),total_vars*16+2); vu = calloc(sizeof(char),total_vars*16+2); vs = calloc(sizeof(char),total_vars*31+2); vt = calloc(sizeof(char),total_vars*2+2); data = calloc(sizeof(float),total_vars); for (cfiles=1;cfiles<=nfiles;cfiles++) { strcpy(vn, ""); strcpy(vu, ""); strcpy(vs, ""); strcpy(vt, ""); strcpy(no, ""); error = rdhead(unit_list[cfiles-1],vn,vu,vs,vt,no, stime,etime,nrow,ncol,csize); if (cfiles == 1) { strcpy(vnt, vn); strcpy(vut, vu); strcpy(vst, vs); strcpy(vtt, vt);} else { strcat(vnt,","); strcat(vut,","); strcat(vst,","); strcat(vtt,","); strl = strlen(vn); strcat(vnt,strmid(vn,15,strl-15)); strl = strlen(vu); strcat(vut,strmid(vu,15,strl-15)); strl = strlen(vs); strcat(vst,strmid(vs,30,strl-30)); strl = strlen(vt); strcat(vtt,strmid(vt,2,strl-1)); } } error = mkhead(fileout,total_vars,vnt,vut,vst,vtt,not); outunit = ffcreate(fileout); if (outunit != -1) { srow = 0; erow = n_rows(unit_list[0])-1; for (irow=srow; irow<=erow; irow++) { ivar = 0; for (cfiles=1;cfiles<=nfiles;cfiles++) { error = fdget(unit_list[cfiles-1],irow,uttime,data); for (i=0;i