#include "stdio.h" #include "stdlib.h" #include "astring.h" #include "string.h" #include "flatfile.h" int month_decode(char *smonth) { int month; month = 0; if (strstr(smonth,"JAN")) month = 1; if (strstr(smonth,"FEB")) month = 2; if (strstr(smonth,"MAR")) month = 3; if (strstr(smonth,"APR")) month = 4; if (strstr(smonth,"MAY")) month = 5; if (strstr(smonth,"JUN")) month = 6; if (strstr(smonth,"JUL")) month = 7; if (strstr(smonth,"AUG")) month = 8; if (strstr(smonth,"SEP")) month = 9; if (strstr(smonth,"OCT")) month = 10; if (strstr(smonth,"NOV")) month = 11; if (strstr(smonth,"DEC")) month = 12; return month; } void main(int argc, char *argv[]) { char ff_var[100],ff_units[100],ff_source[100],ff_type[100]; char ff_notes[300], filein[100], fileout[100]; char line[200], stat[4], comp[5], slat[10], slon[10]; char cshdz, csxyz, cshdz1; float dataout[4], missing, dt, data[4][1440]; double uttime,basetime, utold; int error, unit, nvar, nfiles, cfile, i, k, l, itime[6], comps, m; long orow, nlines, row, ifirst; FILE *fpin; char linein[100], sdata[10]; long strl, n, ind; int done, days, hour, min, order[4]; float temp; missing = -1.0e32; if (argc < 2) { printf("Enter filename to convert : "); gets(filein); nfiles = 1; } else { nfiles = argc - 1; strcpy(filein, argv[1]); } for (cfile=1;cfile<=nfiles;cfile++) { if (cfile > 1) strcpy(filein,argv[cfile]); fpin = fopen(filein,"r"); printf("reading file : %s\n",filein); if (fpin == NULL) { days = 0; printf("There is an error with the input file name.\n"); } else { done = 0; ifirst = 0; while (!done && !feof(fpin)) { fgets(linein, 99, fpin); fgets(linein, 99, fpin); printf("reading linein : %s\n",linein); if (atoi(strmid(linein,7,2)) > 0) { strcpy(stat, strmid(linein,1,3)); if (strpos(stat,"PBQ") >= 0) strcpy(stat,"PDB"); if (strpos(stat,"RES") >= 0) strcpy(stat,"RBC"); if (strpos(stat,"GLN") >= 0) strcpy(stat,"GLL"); strcpy(comp, strmid(linein,14,4)); itime[0] = atoi(strmid(linein,7,2)); itime[1] = 0; itime[2] = atoi(strmid(linein,10,3)); itime[3] = 0; itime[4] = 0; itime[5] = 0; basetime = c_i_to_r(itime); if (ifirst==0) { strcpy(fileout,mklower(stat)); strcat(fileout,c_int_str(itime[0],2)); strcat(fileout,c_int_str(itime[1],2)); strcat(fileout,c_int_str(itime[2],2)); printf("fileout : %s\n",fileout); strcpy(ff_var,"time,"); for(comps=0;comps<3;comps++) { m = 0; if (comps==0) { cshdz = 'H'; cshdz1 = 'H'; csxyz = 'X'; } if (comps==1) { cshdz = 'D'; cshdz1 = 'd'; csxyz = 'Y'; } if (comps==2) { cshdz = 'Z'; cshdz1 = 'Z'; csxyz = 'Z'; } for (i=0;i<4;i++) { if ((comp[i] == cshdz) || (comp[i] == csxyz) || (comp[i] == cshdz1)) { strcat(ff_var,stat); strcat(ff_var,strmid(comp,i,1)); if (comps < 2) strcat(ff_var,","); m = i; } } order[comps] = m; } strcpy(ff_units, "s,nT,nT,nT"); strcpy(ff_source,"from file listed below,same,same,same"); strcpy(ff_type,"T,R,R,R"); strcpy(ff_notes,"Converted from file : "); strcat(ff_notes,filein); nvar = 4; error = mkhead(fileout,nvar,ff_var,ff_units,ff_source, ff_type,ff_notes); if (!error) unit = ffcreate(fileout); if (error || unit == -1) error = 1; orow = 0; } printf("ifirst done : %d %d\n",ifirst,done); for (i=0;i<4;i++) { fgets(linein, 99, fpin); fgets(linein, 99, fpin); fgets(linein, 99, fpin); l = 0; for (hour=0;hour<24;hour++) { for (k=0;k<6;k++) { for (min=0;min<10;min++) { fscanf(fpin,"%f",&temp); data[i][l] = temp/10.0; if (temp < -30000.0) data[i][l] = temp/100.0; if (data[i][l] > 99998.0) data[i][l] = missing; l++; } fgets(linein, 99, fpin); } } fgets(linein, 99, fpin); } for (i=0;i<1440;i++) { for (k=0;k<3;k++) { uttime=basetime+((double) 24*3600.0)*(double) i/((double) 1440); dataout[k] = data[k][i]; } error = fdput(unit,orow,uttime,dataout); orow++; } if (feof(fpin)) done = 1; ifirst++; } } ffclose(unit); close(fpin); } } }