#include "stdio.h" #include "flatfile.h" #include "string.h" #include "astring.h" #include "stdlib.h" #include "amag.h" 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, 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); strcpy(stat,strmid(line,0,3)); change_station_name(stat); itime[0] = atoi(strmid(line,4,4)); itime[1] = atoi(strmid(line,9,2)); itime[2] = atoi(strmid(line,12,2)); itime[3] = 0; itime[4] = 0; itime[5] = 0; 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,"H,"); strcat(ff_var,stat); strcat(ff_var,"E,"); 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; while ((!feof(fpin)) && (!error)) { fgets(line,79,fpin); itime[1] = 0; itime[2] = atoi(strmid(line,0,3)); itime[3] = 0; itime[4] = 0; itime[5] = 0; basetime = c_i_to_r(itime); uttime = basetime + atof(strmid(line,4,2))*3600. + atof(strmid(line,7,2))*60.; if (uttime-basetime < 24.0*3600.0) { dataout[0] = atof(strmid(line,10,8)); dataout[1] = atof(strmid(line,19,9)); dataout[2] = atof(strmid(line,29,8)); 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); orow++; } else { error = 1; } } close(fpin); ffclose(unit); } }