#include "stdio.h" #include "stdlib.h" #include "astring.h" #include "string.h" #include "math.h" #include "misc.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, dec, data[4], pi, h, d, z; double uttime,basetime, utold; int error, unit, nvar, nfiles, cfile, i, itime[6], comps, m; long orow, nlines, row; FILE *fpin; char sdata[10]; long strl, n, ind; int done, days, hour, min, order[3]; float temp; missing = -1.0e32; pi = 3.1415; 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"); if (fpin == NULL) { days = 0; printf("There is an error with the input file name.\n"); } else { strcpy(stat, strmid(filein,11,3)); change_station_name(stat); for (i=0;i<5;i++) fgets(line,79,fpin); strcpy(comp,"HDZ"); itime[0] = atoi(strmid(filein,18,2)); itime[1] = atoi(strmid(filein,20,2)); itime[2] = atoi(strmid(filein,22,2)); itime[3] = 0; itime[4] = 0; itime[5] = 0; basetime = c_i_to_r(itime); if (orow == 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,"); strcat(ff_var,mkupper(stat)); strcat(ff_var,mkupper(strmid(comp,0,1))); strcat(ff_var,","); strcat(ff_var,mkupper(stat)); strcat(ff_var,mkupper(strmid(comp,1,1))); strcat(ff_var,","); strcat(ff_var,mkupper(stat)); strcat(ff_var,mkupper(strmid(comp,2,1))); 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; error = 0; while ((!feof(fpin)) && (!error)) { fgets(line,79,fpin); uttime = basetime+atof(strmid(line,0,10)); if (uttime - basetime < 24.*3600.) { for (i=0;i<3; i++) { dataout[i] = atof(strmid(line,10+i*10,10)); if (dataout[i] > 90000.0) dataout[i] = missing; } error = fdput(unit,orow,uttime,dataout); orow++; } else { error = 1; } } } close(fpin); ffclose(unit); } }