/******************************************************************** * ********************************************************************/ #include #include #include #include "gsf.h" /* global external data required by this module */ extern int gsfError; /* static global data for this module */ static gsfRecords gsfRec; static gsfDataID id; static int shortOutput; static int pingTimeOutput; int main(int argc, char *argv[]) { char gsfFileName[128], str[64]; char *ptr; int gsfHandle, bytes; int i, j, val, sid, numave, nave; int num_header = 0, num_svp = 0, num_pparam = 0, num_sparam = 0, num_comment = 0; int num_ping = 0, num_history = 0, num_nav_error = 0, num_ping_sum = 0, record_number = 0; double dsum, rlat, rlon; struct tm *t; struct tm st; time_t StartTime=0; /* check the command line arguments */ if (argc < 5) { fprintf(stderr, "Useage: %s file.gsf source_id numave topo.grd > filename.cm \n", argv[0]); fprintf(stderr," file.gsf - gsf bathymetry file\n"); fprintf(stderr," source_id unique ID number for each file\n"); fprintf(stderr," numave - number of beams to average (across) (9999 - output lon, lat only \n"); fprintf(stderr," topo.grd grd-file of predicted depth\n\n"); exit(0); } /* parse the command line */ sscanf(argv[1], "%s", gsfFileName); sid = atoi(argv[2]); numave = atoi(argv[3]); /* Try to open the specified file */ if (gsfOpen(gsfFileName, GSF_READONLY_INDEX, &gsfHandle)) { gsfPrintError(stderr); exit(1); } /* Reset the file pointer to the begining of the file */ if (gsfSeek(gsfHandle, GSF_REWIND)) { gsfPrintError(stderr); exit(1); } /* force the timezone to gmt */ putenv("TZ=GMT"); tzset(); for (;;) { /* we want the next record, no matter what it is */ bytes = gsfRead(gsfHandle, GSF_NEXT_RECORD, &id, &gsfRec, NULL, 0); if (bytes < 0) { if (gsfError == GSF_READ_TO_END_OF_FILE) { fprintf(stderr,"Finished processing input file: %s\n", gsfFileName); exit(0); } else { gsfPrintError(stderr); } } else if (bytes == 0) { fprintf(stderr, "Read to end of file: %s\n", gsfFileName); exit(0); } record_number++; switch (id.recordID) { case (GSF_RECORD_HEADER): num_header++; break; case (GSF_RECORD_SWATH_BATHYMETRY_PING): num_ping++; if (numave == 9999) { t = gmtime(&gsfRec.mb_ping.ping_time.tv_sec); rlon=gsfRec.mb_ping.longitude; if(rlon > 180.) rlon=rlon-360; rlat=gsfRec.mb_ping.latitude; fprintf(stdout,"%12.7f %12.7f \n",rlon,rlon); } else { fprintf(stdout, "%05d GSF MB Ping:\n", record_number); t = gmtime(&gsfRec.mb_ping.ping_time.tv_sec); for (i = 0; i < gsfRec.mb_ping.number_beams; i=i+numave) { /* if the data are not flagged then average over numave pings */ nave=0; dsum=0.; for (j = 0; j < numave; j++) { if(gsfRec.mb_ping.depth[i+j] > 0.) { dsum=dsum+gsfRec.mb_ping.depth[i+j]; nave=nave+1; } } if(nave > 0) { dsum=-dsum/nave; fprintf(stdout,"%11.6f %11.6f %8.2f %d \n",gsfRec.mb_ping.longitude,gsfRec.mb_ping.latitude,dsum,nave); } /* sprintf(str,"%11.6f %11.6f",gsfRec.mb_ping.longitude,gsfRec.mb_ping.latitude); sprintf(str, "%s %03d",str, i + 1); if (gsfRec.mb_ping.depth != NULL) { if (gsfRec.mb_ping.depth[i] < 100.0) { sprintf(str, "%s %07.2f", str, -gsfRec.mb_ping.depth[i]); } else { sprintf(str, "%s %07.1f", str, -gsfRec.mb_ping.depth[i]); } } if (gsfRec.mb_ping.across_track != NULL) { sprintf(str, "%s %+07.1f", str, gsfRec.mb_ping.across_track[i]); } if (gsfRec.mb_ping.along_track != NULL) { sprintf(str, "%s %+07.1f", str, gsfRec.mb_ping.along_track[i]); } if (gsfRec.mb_ping.quality_factor != NULL) { sprintf(str, "%s %07.1f", str, gsfRec.mb_ping.quality_factor[i]); } if (gsfRec.mb_ping.quality_flags != NULL) { sprintf(str, "%s %0.7d", str, gsfRec.mb_ping.quality_flags[i]); } if (gsfRec.mb_ping.beam_flags != NULL) { sprintf(str, "%s %0.7d", str, gsfRec.mb_ping.beam_flags[i]); } fprintf(stdout, "%s\n", str); */ } } if (pingTimeOutput) { continue; } break; default: break; } } return (0); }