#include "stdio.h" #include "stdlib.h" #include "astring.h" #include "string.h" #include "flatfile.h" int month_decode(char *smonth) { int month; month = 0; if (strstr(smonth,"JAN")) month = 1; if (strstr(smonth,"FEB")) month = 2; if (strstr(smonth,"MAR")) month = 3; if (strstr(smonth,"APR")) month = 4; if (strstr(smonth,"MAY")) month = 5; if (strstr(smonth,"JUN")) month = 6; if (strstr(smonth,"JUL")) month = 7; if (strstr(smonth,"AUG")) month = 8; if (strstr(smonth,"SEP")) month = 9; if (strstr(smonth,"OCT")) month = 10; if (strstr(smonth,"NOV")) month = 11; if (strstr(smonth,"DEC")) month = 12; return month; } 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], comp[5], slat[10], slon[10]; char cshdz, csxyz; float dataout[4], missing, dt, data[4]; double uttime,basetime, utold; int error, unit, nvar, nfiles, cfile, i, itime[6], comps, m; long orow, nlines, row; FILE *fpin; char linein[100], sdata[10]; long strl, n, ind; int done, days, hour, min, order[3]; long x0,y0,z0,x,y,z; 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++) { printf("inside the loop >>>.\n"); if (cfile > 1) strcpy(filein,argv[cfile]); fpin = fopen(filein,"r"); if (fpin == NULL) { days = 0; printf("There is an error with the input file name.\n"); } else { fgets(linein,99,fpin); if(strpos(linein," PC") ==0) { strcpy(stat,"CSY");} else { strcpy(stat,"DVS");} itime[0] = atoi(strmid(linein,6,2)); itime[1] = 01; itime[2] = atoi(strmid(linein,9,3)); itime[3] = 0; itime[4] = 0; itime[5] = 0; basetime = c_i_to_r(itime); c_r_to_i(itime,basetime); fgets(linein,99,fpin); fscanf(fpin,"%6li%5li%5li",&x0,&y0,&z0); printf("%6li %5li %5li\n",x0,y0,z0); 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,stat); strcat(ff_var,"X,"); strcat(ff_var,stat); strcat(ff_var,"Y,"); 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; orow = 0; while (!feof(fpin) && orow < 8640) { fscanf(fpin,"%6li%5li%5li",&x,&y,&z); dataout[0] = ((float)x0*1000.+(float)x)/10.0; if (x >= 99998) { dataout[0] = missing; } dataout[1] = ((float)y0*1000.+(float)y)/10.0; if (y >= 99998) { dataout[1] = missing; } dataout[2] = ((float)z0*1000.+(float)z)/10.0; if (z >= 99998) { dataout[2] = missing; } uttime=basetime+(double) orow*10.0; error = fdput(unit,orow,uttime,dataout); orow++; } ffclose(unit); } close(fpin); } }