#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], sta0[4], comp[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,15,3)); strcpy(comp,"HDZ"); change_station_name(stat); itime[0] = atoi(strmid(line,9,2)); itime[1] = 0; itime[2] = atoi(strmid(line,11,3)); 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,"); for (i=0;i<3;i++) { strcat(ff_var,stat); strcat(ff_var,strmid(comp,i,1)); if (i < 2) strcat(ff_var,","); } 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<6000; i++) { fgets(line,79,fpin); if (strpos(strmid(line,0,4),"DATA") >= 0 || strpos(line,"MINI") >= 0) break; } fgets(line,79,fpin); while ((!feof(fpin)) && (!error)) { fgets(line,79,fpin); itime[0] = atoi(strmid(line,2,2)); itime[1] = atoi(strmid(line,5,2)); itime[2] = atoi(strmid(line,8,3)); itime[3] = 0; itime[4] = 0; itime[5] = 0; basetime = c_i_to_r(itime); uttime = basetime + atof(strmid(line,11,2))*3600. + atof(strmid(line,14,2))*60. + atof(strmid(line,17,2)); if (uttime-basetime < 24.0*3600.0) { for (i=0;i<3; i++) { dataout[i] = atof(strmid(line,23+i*16,16)); if (dataout[i]==1.0e+34 || dataout[i]==999999.00) dataout[i]=missing; } error = fdput(unit,orow,uttime,dataout); orow++; } else { error = 1; } } close(fpin); ffclose(unit); } }