/* in file.list: jap, this code processes Japenese-Canada data */ #include "stdio.h" #include "astring.h" #include "string.h" #include "flatfile.h" void main(int argc, char *argv[]) { char ff_var[100],ff_units[100],ff_source[100],ff_type[100]; char ff_notes[1000], filein[100], fileout[100], stat[4], c1, c2; FILE *fpin; int nfiles, itime[6], t1, t2, error, unit, cfile,nvar,comp; double basetime, uttime; float missing=-1.0e32, miss_data=9999.0; long orow; float dataout[3]; 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,"rb"); if (fpin == NULL) { printf("error in opening file %s.\n",filein); } else { strcpy(stat,strmid(filein,9,3)); strcpy(fileout,stat); strcat(fileout,strmid(filein,0,2)); strcat(fileout,strmid(filein,3,4)); printf("writing file %s\n",fileout); strcpy(ff_var,"time,"); strcat(ff_var,mkupper(stat)); strcat(ff_var,"X,"); strcat(ff_var,mkupper(stat)); strcat(ff_var,"Y,"); strcat(ff_var,mkupper(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); } else { unit = -1; } if (unit != -1) { itime[0] = atoi(strmid(filein,0,2)); itime[1] = atoi(strmid(filein,3,2)); itime[2] = atoi(strmid(filein,5,2)); basetime = c_i_to_r(itime); orow=0; while (orow < 60*24) { for (comp=0; comp<3; comp++) { c2 = getc(fpin); c1 = getc(fpin); t1 = (int) c1; t2 = (int) c2; dataout[comp] = ((float) (t1*256 + t2))/32.0; } uttime = basetime + ((double) orow)*60.0; error = fdput(unit,orow,uttime,dataout); orow++; } ffclose(unit); } fclose(fpin); } } }