#include "stdio.h" #include "flatfile.h" #include "astring.h" #include "string.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[200], stat[4], slat[10], slon[10]; float dataout[4], missing, dt, statn; double uttime,basetime, utold; int error, unit, nvar, nfiles, cfile, i, itime[6], done, day; long orow, nlines, row; FILE *fpin, *fpstat; 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,200,fpin); statn = atof(strmid(line,6,7)); fpstat = fopen("/export/data1/ganglu/mags/pfiles/usaf_spike.list","r"); done = 0; fgets(line,200,fpstat); while (!done) { fgets(line,200,fpstat); if (feof(fpstat)) { done = 2; } else { if (atof(strmid(line,1,5)) == statn) { strcpy(stat,strmid(line,9,3)); done = 1; } } } close(fpstat); if (done == 2) { strcpy(stat,"zzz"); } change_station_name(stat); fgets(line,200,fpin); itime[0] = atoi(strmid(line,2,2)); itime[1] = atoi(strmid(line,5,2)); itime[2] = atoi(strmid(line,8,2)); day = itime[2]; basetime = c_i_to_r(itime); strcpy(fileout,mklower(stat)); strcat(fileout,strmid(line,2,2)); strcat(fileout,strmid(line,5,2)); strcat(fileout,strmid(line,8,2)); printf("fileout : %s\n",fileout); strcpy(ff_var,"time,"); strcat(ff_var,stat); strcat(ff_var,"H,"); strcat(ff_var,stat); strcat(ff_var,"D,"); 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; rewind(fpin); fgets(line,200,fpin); orow = 0; while (!feof(fpin)) { fgets(line,79,fpin); if (!feof(fpin)) { itime[2] = atoi(strmid(line,8,2)); itime[3] = atoi(strmid(line,11,2)); itime[4] = atoi(strmid(line,14,2)); uttime = basetime + ((double) (itime[2] - day))*24.0*60.0*60.0 + ((double) itime[3])*60.0*60.0 + ((double) itime[4])*60.0; if ((itime[3] == 0) && (itime[4] == 0)) { printf("time %s\n",c_r_to_s(uttime)); } for (i=0;i<3; i++) { dataout[i] = atof(strmid(line,16+7*i,7)); if (dataout[i] >= 99999.0) { dataout[i] = missing; } } error = fdput(unit,orow,uttime,dataout); orow++; } } close(fpin); ffclose(unit); } }