#include "stdio.h" #include "flatfile.h" #include "string.h" #include "astring.h" #include "stdlib.h" #include "amag.h" #include "math.h" #include "misc.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[80], stat[4]; float dataout[4], missing, dt; double uttime,basetime, utold, dumb1, dumb2, dumb3; int yr, mo, da, error, unit, nvar, nfiles, cfile,i, itime[6]; long orow, pos, lpos; FILE *fpin; 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); orow = 0; error = 0; fgets(line,79,fpin); fgets(line,79,fpin); strcpy(stat,strmid(line,13,3)); change_station_name(stat); for (i=0; i<3; i++) fgets(line,79,fpin); printf("%s\n",strmid(line,0,50)); itime[0] = atoi(strmid(line,31,2)); itime[1] = month_decode(mkupper(strmid(line,25,3))); itime[2] = atoi(strmid(line,22,2)); itime[3] = 0; itime[4] = 0; itime[5] = 0; /* printf("YY MM DD :%2li%2li%2li\n",itime[0],itime[1],itime[2]); */ basetime = c_i_to_r(itime); c_r_to_i(itime, basetime); 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)); strcpy(ff_var,"time,"); strcat(ff_var,stat); strcat(ff_var,"X,"); strcat(ff_var,stat); strcat(ff_var,"Y,"); strcat(ff_var,stat); strcat(ff_var,"Z"); 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; for (i=0; i<2; i++) fgets(line,79,fpin); utold = 0.0; while ((!feof(fpin)) && (!error)) { fgets(line,79,fpin); itime[0] = atoi(strmid(line,9,2)); itime[1] = month_decode(mkupper(strmid(line,3,3))); itime[2] = atoi(strmid(line,0,2)); itime[3] = 0; itime[4] = 0; itime[5] = 0; basetime = c_i_to_r(itime); uttime = basetime + atof(strmid(line,12,2))*3600. + atof(strmid(line,15,2))*60.; if (uttime > 0.) { if (uttime-basetime < 24.0*3600.0 && uttime > utold) { dataout[0] = atof(strmid(line,29,10)); dataout[1] = atof(strmid(line,39,10)); dataout[2] = atof(strmid(line,49,10)); if (dataout[0] == 99999.0) dataout[0] = missing; if (dataout[1] == 99999.0) dataout[1] = missing; if (dataout[2] == 99999.0) dataout[2] = missing; error = fdput(unit,orow,uttime,dataout); utold = uttime; orow++; } } else { error = 1; } } ffclose(unit); } close(fpin); }