#include "stdio.h" #include "flatfile.h" #include "string.h" #include "astring.h" #include "stdlib.h" #include "amag.h" #include "math.h" #include "misc.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], linein[135], stat[4], comp[6], c[15]; float dataout[4],data[4], missing,dt,pi,h,d; float hr, mn, sec, bx, by, bz; double uttime,basetime, utold, dumb1, dumb2, dumb3; int yr, mo, da, error, unit, nvar, nfiles, cfile,i, itime[6]; long orow, pos, lpos, row; FILE *fpin; 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"); printf("reading file : %s\n",filein); itime[0] = atoi(strmid(filein,2,2)); itime[1] = atoi(strmid(filein,4,2)); itime[2] = atoi(strmid(filein,6,2)); itime[3] = 0; itime[4] = 0; itime[5] = 0; basetime = c_i_to_r(itime); c_r_to_i(itime, basetime); strcpy(stat,(strmid(filein,9,3))); if (strpos(stat,"cas") >= 0) strcpy(stat,"CSY"); if (strpos(stat,"dav") >= 0) strcpy(stat,"DVS"); if (strpos(stat,"dwn") >= 0) strcpy(stat,"DRW"); /* printf("reading yr mon day : %s%d%d%d\n",stat,itime[0],itime[1],itime[2]); */ 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)); fgets(linein,130,fpin); strcpy(comp, strmid(linein,37,5)); strcat(ff_var,mkupper(strmid(comp,0,1))); strcat(ff_var,","); strcat(ff_var,mkupper(stat)); strcat(ff_var,mkupper(strmid(comp,2,1))); strcat(ff_var,","); strcat(ff_var,mkupper(stat)); strcat(ff_var,mkupper(strmid(comp,4,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; row = 0; utold = 0.0; orow = 0; error = 0; fgets(line,79,fpin); while ((!feof(fpin)) && (!error)) { fgets(line,79,fpin); hr = atof(strmid(line,0,2)); mn = atof(strmid(line,3,2)); sec = atof(strmid(line,6,5)); if (strmid(line,0,5) == " ") error = 1; uttime = basetime + (double) hr*3600. + (double) mn*60. + (double) sec; /* if (uttime-basetime < 24.0*3600.0) { */ if (uttime-basetime < 24.0*3600.0 && uttime > utold) { for (i=0;i<3; i++) { dataout[i] = atof(strmid(line,11+i*10,10)); if (dataout[i] > 70000.0) dataout[i] = missing; } error = fdput(unit,orow,uttime,dataout); utold = uttime; orow++; } else { error = 1; } } orow++; } close(fpin); ffclose(unit); }