#include "stdio.h" #include "string.h" #include "astring.h" #include "flatfile.h" #include "stdlib.h" void main(int argc, char *argv[]) { FILE *fpout, *fpstat; char filein[100], fileout[100], slat[10],slon[10], stat[10], line[80]; char *vn, *vu, *vs, *vt, no[1000]; char stime[24],etime[24], outstime[24]; double suttime, euttime, uttime[1], t, dt; int inunit, outunit, ncol[1], csize[1], error, ndays, i,j,itime[6]; int strl, found, npts, imin; long srow, erow, fnrow[1], nrow, row, orow, irow, avev; long *datasave, *stdsave, *nptssave, ilat, ilon; float *data, missing, glat, glon; missing = -1.0e32; if (argc < 2) { printf("Enter flat file to copy : "); gets(filein); } else { strcpy(filein,argv[1]); } if (argc < 3) { printf("Enter output file name : "); gets(fileout); } else { strcpy(fileout,argv[2]); } inunit = ffopen(filein); vn = calloc(sizeof(char),ff_ncol[inunit]*16+2); vu = calloc(sizeof(char),ff_ncol[inunit]*16+2); vs = calloc(sizeof(char),ff_ncol[inunit]*31+2); vt = calloc(sizeof(char),ff_ncol[inunit]*2+2); data = calloc(sizeof(float),ff_ncol[inunit]); error = rdhead(inunit,vn,vu,vs,vt,no, stime,etime,fnrow,ncol,csize); strcpy(stat,strmid(vn,15,3)); printf("stat : %s\n",stat); fpstat = fopen("/galileo/d/ganglu/mags/pfiles/master.stalist","r"); glat = 0.0; glon = 0.0; if (fpstat == NULL) { printf("Error - could not find master station list!\n"); } else { found = 0; while (!found) { fgets(line,80,fpstat); if (!feof(fpstat)) { if (strpos(line,stat) == 0) { glat = atof(strmid(line,37,6)); glon = atof(strmid(line,44,6)); found = 1; } } else { found = 1; } } fclose(fpstat); } ilat = (long) ((90.0-glat)*1000.0); ilon = (long) (glon*1000.0); strcpy(slat, c_long_str(ilat,6)); strcpy(slon, c_long_str(ilon,6)); printf("%s %s\n",slat,slon); fpout = fopen(fileout,"w"); if (fpout != NULL) { error = fdget(inunit,0,uttime,data); t = uttime[0]; error = fdget(inunit,1,uttime,data); dt = uttime[0] - t; nrow = (long) (3600.0*24.0/dt); datasave = calloc(sizeof(long),nrow*3); irow = 0; erow = n_rows(inunit); suttime = start_time(inunit); euttime = end_time(inunit); ndays = (int) ((euttime-suttime)/(24.0*3600.0) + 0.5); printf("ndays : %d\n",ndays); euttime = suttime + (double) ndays * 24.0 * 3600.0; uttime[0] = 0.0; orow = 0; t = suttime; row = 0; while (t <= euttime) { if (((row%nrow == 0) && (row > 0)) || (t == euttime)) { for (i=0; i<3; i++) { for (orow=0; orow 0) { avev = avev/npts; } fprintf(fpout,"%6ld",avev); } } } if (irow < erow) error = fdget(inunit,irow,uttime,data); else uttime[0] = suttime+dt*row + 1.0; if (uttime[0] > suttime+dt*row) { for (i=0; i<3; i++) { datasave[i*nrow+(row%nrow)] = 99999; } } else { irow++; for (i=0; i<3; i++) { if (data[i] == missing) { datasave[i*nrow+(row%nrow)] = 99999; } else { datasave[i*nrow+(row%nrow)] = (long) data[i]; } } } row++; t = t + dt; } ffclose(inunit); close(fpout); } }