#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], comp[4]; float dataout[4], missing, dt, xyr, sec, sec1, bx, by, bz; 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)); strcpy(comp,strmid(line,4,3)); change_station_name(stat); dt = atof(strmid(line,30,5)); itime[0] = atoi(strmid(line,10,2)); itime[1] = atoi(strmid(line,13,2)); itime[2] = atoi(strmid(line,16,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,strmid(line,10,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(stat,strmid(filein,0,3)); */ strcpy(stat,"hba"); strcpy(comp,"XYZ"); change_station_name(stat); itime[0] = atoi(strmid(filein,5,2)); itime[1] = atoi(strmid(filein,7,2)); itime[2] = atoi(strmid(filein,9,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,"); for (i=0;i<3;i++) { strcat(ff_var,mkupper(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; while ((!feof(fpin)) && (!error)) { /* fscanf(fpin,"%f%d%d%f%f%f%f%f",&xyr,&yr,&da,&sec,&sec1,&bx,&by,&bz); itime[0] = atoi(strmid(line,2,2)); itime[1] = atoi(strmid(line,4,2)); itime[2] = atoi(strmid(line,6,2)); itime[0] = yr - 2000; itime[1] = 0; itime[2] = da; itime[3] = 0; itime[4] = 0; itime[5] = 0; basetime = c_i_to_r(itime); uttime = basetime + sec; */ fgets(line,79,fpin); 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<2; i++) { dataout[i] = atof(strmid(line,21+i*8,8)); if (dataout[i] > 70000.0) dataout[i] = missing; } dataout[2] = atof(strmid(line,37,9)); error = fdput(unit,orow,uttime,dataout); orow++; } else { error = 1; } } close(fpin); ffclose(unit); } }