/*------------------------------------------------------------------------------*/ int mbview_allocvectorarrays(int verbose, int npointtotal, double **veclon, double **veclat, double **vecz, double **vecdata, int *error) { /* local variables */ char *function_name = "mbview_allocvectorarrays"; int status = MB_SUCCESS; /* print starting debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBIO function <%s> called\n", function_name); fprintf(stderr,"dbg2 MB-system Version %s\n",MB_VERSION); fprintf(stderr,"dbg2 Input arguments:\n"); fprintf(stderr,"dbg2 verbose: %d\n", verbose); fprintf(stderr,"dbg2 npointtotal: %d\n", npointtotal); fprintf(stderr,"dbg2 veclon: %lu\n", (size_t)*veclon); fprintf(stderr,"dbg2 veclat: %lu\n", (size_t)*veclat); fprintf(stderr,"dbg2 vecz: %lu\n", (size_t)*vecz); fprintf(stderr,"dbg2 vecdata: %lu\n", (size_t)*vecdata); } /* allocate the arrays using mb_realloc */ status = mb_reallocd(verbose,__FILE__,__LINE__,npointtotal*sizeof(double),(void **)veclon,error); if (status == MB_SUCCESS) status = mb_reallocd(verbose,__FILE__,__LINE__,npointtotal*sizeof(double),(void **)veclat,error); if (status == MB_SUCCESS) status = mb_reallocd(verbose,__FILE__,__LINE__,npointtotal*sizeof(double),(void **)vecz,error); if (status == MB_SUCCESS) status = mb_reallocd(verbose,__FILE__,__LINE__,npointtotal*sizeof(double),(void **)vecdata,error); /* print output debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBIO function <%s> completed\n", function_name); fprintf(stderr,"dbg2 Return values:\n"); fprintf(stderr,"dbg2 veclon: %lu\n", (size_t)*veclon); fprintf(stderr,"dbg2 veclat: %lu\n", (size_t)*veclat); fprintf(stderr,"dbg2 vecz: %lu\n", (size_t)*vecz); fprintf(stderr,"dbg2 vecdata: %lu\n", (size_t)*vecdata); fprintf(stderr,"dbg2 error: %d\n", *error); fprintf(stderr,"dbg2 Return status:\n"); fprintf(stderr,"dbg2 status: %d\n", status); } /* return */ return(status); }
/*------------------------------------------------------------------------------*/ int mbview_allocprofilepoints(int verbose, int npoints, struct mbview_profilepoint_struct **points, int *error) { /* local variables */ char *function_name = "mbview_allocprofilepoints"; int status = MB_SUCCESS; /* print starting debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBIO function <%s> called\n", function_name); fprintf(stderr,"dbg2 MB-system Version %s\n",MB_VERSION); fprintf(stderr,"dbg2 Input arguments:\n"); fprintf(stderr,"dbg2 verbose: %d\n", verbose); fprintf(stderr,"dbg2 npoints: %d\n", npoints); fprintf(stderr,"dbg2 points: %lu\n", (size_t)*points); } /* allocate the arrays using mb_realloc */ status = mb_reallocd(verbose, __FILE__, __LINE__, npoints * sizeof(struct mbview_profilepoint_struct), (void **)points,error); /* print output debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBIO function <%s> completed\n", function_name); fprintf(stderr,"dbg2 Return values:\n"); fprintf(stderr,"dbg2 points: %lu\n", (size_t)*points); fprintf(stderr,"dbg2 error: %d\n", *error); fprintf(stderr,"dbg2 Return status:\n"); fprintf(stderr,"dbg2 status: %d\n", status); } /* return */ return(status); }
/*------------------------------------------------------------------------------*/ int mbview_addvector(int verbose, size_t instance, int npoint, double *veclon, double *veclat, double *vecz, double *vecdata, int veccolor, int vecsize, mb_path vecname, double vecdatamin, double vecdatamax, int *error) { /* local variables */ char *function_name = "mbview_addvector"; int status = MB_SUCCESS; struct mbview_world_struct *view; struct mbview_struct *data; int ivec; int recalculate_minmax = MB_NO; int i, j; /* print starting debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> called\n", function_name); fprintf(stderr, "dbg2 MB-system Version %s\n", MB_VERSION); fprintf(stderr, "dbg2 Input arguments:\n"); fprintf(stderr, "dbg2 verbose: %d\n", verbose); fprintf(stderr, "dbg2 instance: %zu\n", instance); fprintf(stderr, "dbg2 npoint: %d\n", npoint); for (i = 0; i < npoint; i++) { fprintf(stderr, "dbg2 point:%d lon:%f lat:%f z:%f data:%f\n", i, veclon[i], veclat[i], vecz[i], vecdata[i]); } fprintf(stderr, "dbg2 veccolor: %d\n", veccolor); fprintf(stderr, "dbg2 vecsize: %d\n", vecsize); fprintf(stderr, "dbg2 vecname: %s\n", vecname); fprintf(stderr, "dbg2 vecdatamin: %f\n", vecdatamin); fprintf(stderr, "dbg2 vecdatamax: %f\n", vecdatamax); } /* get view */ view = &(mbviews[instance]); data = &(view->data); /* make sure no vec is selected */ shared.shareddata.vector_selected = MBV_SELECT_NONE; shared.shareddata.vector_point_selected = MBV_SELECT_NONE; /* set vec id so that new vec is created */ ivec = shared.shareddata.nvector; /* allocate memory for a new vec if required */ if (shared.shareddata.nvector_alloc < shared.shareddata.nvector + 1) { shared.shareddata.nvector_alloc = shared.shareddata.nvector + 1; status = mb_reallocd(mbv_verbose, __FILE__, __LINE__, shared.shareddata.nvector_alloc * sizeof(struct mbview_vector_struct), (void **)&(shared.shareddata.vectors), error); if (status == MB_FAILURE) { shared.shareddata.nvector_alloc = 0; } else { for (i = shared.shareddata.nvector; i < shared.shareddata.nvector_alloc; i++) { shared.shareddata.vectors[i].color = MBV_COLOR_RED; shared.shareddata.vectors[i].size = 4; shared.shareddata.vectors[i].name[0] = '\0'; shared.shareddata.vectors[i].npoints = 0; shared.shareddata.vectors[i].npoints_alloc = 0; shared.shareddata.vectors[i].nselected = 0; shared.shareddata.vectors[i].vectorpts = NULL; shared.shareddata.vectors[i].segments = NULL; } } } /* allocate memory to for vec arrays */ if (shared.shareddata.vectors[ivec].npoints_alloc < npoint) { shared.shareddata.vectors[ivec].npoints_alloc = npoint; status = mb_reallocd(mbv_verbose, __FILE__, __LINE__, shared.shareddata.vectors[ivec].npoints_alloc * sizeof(struct mbview_vectorpointw_struct), (void **)&(shared.shareddata.vectors[ivec].vectorpts), error); status = mb_reallocd(mbv_verbose, __FILE__, __LINE__, shared.shareddata.vectors[ivec].npoints_alloc * sizeof(struct mbview_linesegmentw_struct), (void **)&(shared.shareddata.vectors[ivec].segments), error); for (j = 0; j < shared.shareddata.vectors[ivec].npoints_alloc - 1; j++) { shared.shareddata.vectors[ivec].segments[j].nls = 0; shared.shareddata.vectors[ivec].segments[j].nls_alloc = 0; shared.shareddata.vectors[ivec].segments[j].lspoints = NULL; shared.shareddata.vectors[ivec].segments[j].endpoints[0] = shared.shareddata.vectors[ivec].vectorpts[j].point; shared.shareddata.vectors[ivec].segments[j].endpoints[1] = shared.shareddata.vectors[ivec].vectorpts[j + 1].point; } } /* add the new vec */ if (status == MB_SUCCESS) { /* set nvector */ shared.shareddata.nvector++; /* set color size and name for new vec */ shared.shareddata.vectors[ivec].color = veccolor; shared.shareddata.vectors[ivec].size = vecsize; strcpy(shared.shareddata.vectors[ivec].name, vecname); shared.shareddata.vectors[ivec].datamin = vecdatamin; shared.shareddata.vectors[ivec].datamax = vecdatamax; if (vecdatamin == vecdatamax) recalculate_minmax = MB_YES; /* loop over the points in the new vec */ shared.shareddata.vectors[ivec].npoints = npoint; for (i = 0; i < npoint; i++) { /* set status values */ shared.shareddata.vectors[ivec].vectorpts[i].selected = MB_NO; /* set data */ shared.shareddata.vectors[ivec].vectorpts[i].data = vecdata[i]; /* get min max of data if necessary */ if (recalculate_minmax == MB_YES) { if (i == 0) { shared.shareddata.vectors[ivec].datamin = vecdata[i]; shared.shareddata.vectors[ivec].datamax = vecdata[i]; } else { shared.shareddata.vectors[ivec].datamin = MIN(vecdata[i], shared.shareddata.vectors[ivec].datamin); shared.shareddata.vectors[ivec].datamax = MAX(vecdata[i], shared.shareddata.vectors[ivec].datamax); } } /* ************************************************* */ /* get vec positions in grid and display coordinates */ shared.shareddata.vectors[ivec].vectorpts[i].point.xlon = veclon[i]; shared.shareddata.vectors[ivec].vectorpts[i].point.ylat = veclat[i]; shared.shareddata.vectors[ivec].vectorpts[i].point.zdata = vecz[i]; status = mbview_projectfromlonlat(instance, shared.shareddata.vectors[ivec].vectorpts[i].point.xlon, shared.shareddata.vectors[ivec].vectorpts[i].point.ylat, shared.shareddata.vectors[ivec].vectorpts[i].point.zdata, &(shared.shareddata.vectors[ivec].vectorpts[i].point.xgrid[instance]), &(shared.shareddata.vectors[ivec].vectorpts[i].point.ygrid[instance]), &(shared.shareddata.vectors[ivec].vectorpts[i].point.xdisplay[instance]), &(shared.shareddata.vectors[ivec].vectorpts[i].point.ydisplay[instance]), &(shared.shareddata.vectors[ivec].vectorpts[i].point.zdisplay[instance])); mbview_updatepointw(instance, &(shared.shareddata.vectors[ivec].vectorpts[i].point)); /*fprintf(stderr,"Depth: llz:%f %f %f grid:%f %f dpy:%f %f %f\n", shared.shareddata.vectors[ivec].vectorpts[i].point.xlon, shared.shareddata.vectors[ivec].vectorpts[i].point.ylat, shared.shareddata.vectors[ivec].vectorpts[i].point.zdata, shared.shareddata.vectors[ivec].vectorpts[i].point.xgrid[instance], shared.shareddata.vectors[ivec].vectorpts[i].point.ygrid[instance], shared.shareddata.vectors[ivec].vectorpts[i].point.xdisplay[instance], shared.shareddata.vectors[ivec].vectorpts[i].point.ydisplay[instance], shared.shareddata.vectors[ivec].vectorpts[i].point.zdisplay[instance]);*/ /* ************************************************* */ } /* make vecs viewable */ data->vector_view_mode = MBV_VIEW_ON; /* some info to terminal */ fprintf(stderr, "Added %d point vector with data bounds: min:%f max:%f\n", shared.shareddata.vectors[ivec].npoints, shared.shareddata.vectors[ivec].datamin, shared.shareddata.vectors[ivec].datamax); } /* print vec debug statements */ if (mbv_verbose >= 2) { fprintf(stderr, "\ndbg2 vec data altered in function <%s>\n", function_name); fprintf(stderr, "dbg2 vec values:\n"); fprintf(stderr, "dbg2 vector_mode: %d\n", shared.shareddata.vector_mode); fprintf(stderr, "dbg2 vector_view_mode: %d\n", data->vector_view_mode); fprintf(stderr, "dbg2 nvector: %d\n", shared.shareddata.nvector); fprintf(stderr, "dbg2 nvector_alloc: %d\n", shared.shareddata.nvector_alloc); fprintf(stderr, "dbg2 vector_selected: %d\n", shared.shareddata.vector_selected); fprintf(stderr, "dbg2 vector_point_selected: %d\n", shared.shareddata.vector_point_selected); for (i = 0; i < shared.shareddata.nvector; i++) { fprintf(stderr, "dbg2 vec %d color: %d\n", i, shared.shareddata.vectors[i].color); fprintf(stderr, "dbg2 vec %d size: %d\n", i, shared.shareddata.vectors[i].size); fprintf(stderr, "dbg2 vec %d name: %s\n", i, shared.shareddata.vectors[i].name); fprintf(stderr, "dbg2 vec %d npoints: %d\n", i, shared.shareddata.vectors[i].npoints); fprintf(stderr, "dbg2 vec %d npoints_alloc: %d\n", i, shared.shareddata.vectors[i].npoints_alloc); fprintf(stderr, "dbg2 vec %d nselected: %d\n", i, shared.shareddata.vectors[i].nselected); for (j = 0; j < shared.shareddata.vectors[i].npoints; j++) { fprintf(stderr, "dbg2 vec %d %d selected: %d\n", i, j, shared.shareddata.vectors[i].vectorpts[j].selected); fprintf(stderr, "dbg2 vec %d %d data: %f\n", i, j, shared.shareddata.vectors[i].vectorpts[j].data); fprintf(stderr, "dbg2 vec %d %d xgrid: %f\n", i, j, shared.shareddata.vectors[i].vectorpts[j].point.xgrid[instance]); fprintf(stderr, "dbg2 vec %d %d ygrid: %f\n", i, j, shared.shareddata.vectors[i].vectorpts[j].point.ygrid[instance]); fprintf(stderr, "dbg2 vec %d %d xlon: %f\n", i, j, shared.shareddata.vectors[i].vectorpts[j].point.xlon); fprintf(stderr, "dbg2 vec %d %d ylat: %f\n", i, j, shared.shareddata.vectors[i].vectorpts[j].point.ylat); fprintf(stderr, "dbg2 vec %d %d zdata: %f\n", i, j, shared.shareddata.vectors[i].vectorpts[j].point.zdata); fprintf(stderr, "dbg2 vec %d %d xdisplay: %f\n", i, j, shared.shareddata.vectors[i].vectorpts[j].point.xdisplay[instance]); fprintf(stderr, "dbg2 vec %d %d ydisplay: %f\n", i, j, shared.shareddata.vectors[i].vectorpts[j].point.ydisplay[instance]); fprintf(stderr, "dbg2 vec %d %d zdisplay: %f\n", i, j, shared.shareddata.vectors[i].vectorpts[j].point.zdisplay[instance]); } for (j = 0; j < shared.shareddata.vectors[i].npoints - 1; j++) { fprintf(stderr, "dbg2 vec %d %d nls: %d\n", i, j, shared.shareddata.vectors[i].segments[j].nls); fprintf(stderr, "dbg2 vec %d %d nls_alloc: %d\n", i, j, shared.shareddata.vectors[i].segments[j].nls_alloc); fprintf(stderr, "dbg2 vec %d %d endpoints[0]: %p\n", i, j, &shared.shareddata.vectors[i].segments[j].endpoints[0]); fprintf(stderr, "dbg2 vec %d %d endpoints[1]: %p\n", i, j, &shared.shareddata.vectors[i].segments[j].endpoints[1]); } } } /* print output debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> completed\n", function_name); fprintf(stderr, "dbg2 Return values:\n"); fprintf(stderr, "dbg2 error: %d\n", *error); fprintf(stderr, "dbg2 Return status:\n"); fprintf(stderr, "dbg2 status: %d\n", status); } /* return */ return (status); }
/*--------------------------------------------------------------------*/ int mbr_swplssxp_rd_data(int verbose, void *mbio_ptr, void *store_ptr, int *error) { char *function_name = "mbr_swplssxp_rd_data"; int status = MB_SUCCESS; struct mb_io_struct *mb_io_ptr; struct mbsys_swathplus_struct *store; char **bufferptr; char *buffer; int *bufferalloc; int *recordid; int *recordidlast; int *size; int *nbadrec; int done; size_t read_len; int skip; int i; /* print input debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> called\n", function_name); fprintf(stderr, "dbg2 Revision id: %s\n", rcs_id); fprintf(stderr, "dbg2 Input arguments:\n"); fprintf(stderr, "dbg2 verbose: %d\n", verbose); fprintf(stderr, "dbg2 mbio_ptr: %p\n", mbio_ptr); fprintf(stderr, "dbg2 store_ptr: %p\n", store_ptr); } /* get pointer to mbio descriptor */ mb_io_ptr = (struct mb_io_struct *)mbio_ptr; /* get pointer to raw data structure */ store = (struct mbsys_swathplus_struct *)store_ptr; /* get saved values */ recordid = (int *)&mb_io_ptr->save3; recordidlast = (int *)&mb_io_ptr->save4; bufferptr = (char **)&mb_io_ptr->saveptr1; buffer = (char *)*bufferptr; bufferalloc = (int *)&mb_io_ptr->save6; size = (int *)&mb_io_ptr->save8; nbadrec = (int *)&mb_io_ptr->save9; /* set file position */ mb_io_ptr->file_pos = mb_io_ptr->file_bytes; /* loop over reading data until a record is ready for return */ done = MB_NO; *error = MB_ERROR_NO_ERROR; while (done == MB_NO) { /* read next record header into buffer */ read_len = (size_t)SWPLS_SIZE_BLOCKHEADER; status = mb_fileio_get(verbose, mbio_ptr, buffer, &read_len, error); /* check header - if not a good header read a byte at a time until a good header is found */ skip = 0; while (status == MB_SUCCESS && swpls_chk_header(verbose, mbio_ptr, buffer, recordid, size, error) != MB_SUCCESS) { /* get next byte */ for (i = 0; i < SWPLS_SIZE_BLOCKHEADER - 1; i++) { buffer[i] = buffer[i + 1]; } read_len = (size_t)1; status = mb_fileio_get(verbose, mbio_ptr, &buffer[SWPLS_SIZE_BLOCKHEADER - 1], &read_len, error); skip++; } /* report problem */ if ((skip > 0) && (verbose >= 0)) { if (*nbadrec == 0) { fprintf(stderr, "The MBR_SWPLSSXP module skipped data between identified\n" "data records. Something is broken, most probably the data...\n" "However, the data may include a data record type that we\n" "haven't seen yet, or there could be an error in the code.\n" "If skipped data are reported multiple times, \n" "we recommend you send a data sample and problem \n" "description to the MB-System team \n" "([email protected] and [email protected])\n" "Have a nice day...\n"); } fprintf(stderr, "MBR_SWPLSSXP skipped %d bytes between records %4.4X:%d and %4.4X:%d\n", skip, *recordidlast, *recordidlast, *recordid, *recordid); (*nbadrec)++; } *recordidlast = *recordid; store->type = *recordid; /* allocate memory to read rest of record if necessary */ if (*bufferalloc < *size + SWPLS_SIZE_BLOCKHEADER) { status = mb_reallocd(verbose, __FILE__, __LINE__, *size + SWPLS_SIZE_BLOCKHEADER, (void **)bufferptr, error); if (status != MB_SUCCESS) { *bufferalloc = 0; done = MB_YES; } else { *bufferalloc = *size + SWPLS_SIZE_BLOCKHEADER; buffer = (char *)*bufferptr; } } /* read the rest of the record */ if (status == MB_SUCCESS) { read_len = (size_t)*size; status = mb_fileio_get(verbose, mbio_ptr, &buffer[SWPLS_SIZE_BLOCKHEADER], &read_len, error); } /* parse the data record */ if ((status == MB_SUCCESS) && (done == MB_NO)) { if (*recordid == SWPLS_ID_SXP_HEADER_DATA) { status = swpls_rd_sxpheader(verbose, buffer, store_ptr, error); done = MB_YES; } else if (*recordid == SWPLS_ID_PROCESSED_PING) { status = swpls_rd_sxpping(verbose, buffer, store_ptr, SWPLS_ID_PROCESSED_PING, error); done = MB_YES; } else if (*recordid == SWPLS_ID_PROCESSED_PING2) { status = swpls_rd_sxpping(verbose, buffer, store_ptr, SWPLS_ID_PROCESSED_PING2, error); done = MB_YES; } else if (*recordid == SWPLS_ID_COMMENT) { status = swpls_rd_comment(verbose, buffer, store_ptr, error); done = MB_YES; } else if (*recordid == SWPLS_ID_PROJECTION) { status = swpls_rd_projection(verbose, buffer, store_ptr, error); done = MB_YES; } else { done = MB_NO; } } if (status == MB_FAILURE) { done = MB_YES; } } /* get file position */ mb_io_ptr->file_bytes = ftell(mb_io_ptr->mbfp); /* print output debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> completed\n", function_name); fprintf(stderr, "dbg2 Return values:\n"); fprintf(stderr, "dbg2 error: %d\n", *error); fprintf(stderr, "dbg2 Return status:\n"); fprintf(stderr, "dbg2 status: %d\n", status); } /* return status */ return (status); } /* mbr_swplssxp_rd_data */
/*--------------------------------------------------------------------*/ int mbr_rt_swplssxp(int verbose, void *mbio_ptr, void *store_ptr, int *error) { char *function_name = "mbr_rt_swplssxp"; int status = MB_SUCCESS; struct mb_io_struct *mb_io_ptr; struct mbsys_swathplus_struct *store; swpls_header *header; swpls_sxpping *ping; swpls_comment *comment; swpls_projection *projection; /* print input debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> called\n", function_name); fprintf(stderr, "dbg2 Revision id: %s\n", rcs_id); fprintf(stderr, "dbg2 Input arguments:\n"); fprintf(stderr, "dbg2 verbose: %d\n", verbose); fprintf(stderr, "dbg2 mbio_ptr: %p\n", mbio_ptr); fprintf(stderr, "dbg2 store_ptr: %p\n", store_ptr); } /* get pointers to mbio descriptor */ mb_io_ptr = (struct mb_io_struct *)mbio_ptr; /* read next data from file */ status = mbr_swplssxp_rd_data(verbose, mbio_ptr, store_ptr, error); /* get pointer to data structure */ store = (struct mbsys_swathplus_struct *)store_ptr; header = &store->sxp_header; ping = &store->sxp_ping; comment = &store->comment; projection = &store->projection; /* check if projection has been set from *.prj file, if so, copy into projection structure */ if ((store->projection_set == MB_NO) && (mb_io_ptr->projection_initialized == MB_YES)) { projection->time_d = time(NULL); projection->microsec = 0; projection->nchars = strnlen(mb_io_ptr->projection_id, MB_NAME_LENGTH); if (projection->projection_alloc < projection->nchars) { status = mb_reallocd(verbose, __FILE__, __LINE__, (size_t)projection->nchars, (void **)&(projection->projection_id), error); if (status != MB_SUCCESS) { projection->projection_alloc = 0; } else { projection->projection_alloc = projection->nchars; } } if (status == MB_SUCCESS) { strncpy(projection->projection_id, mb_io_ptr->projection_id, (size_t)projection->nchars); store->projection_set = MB_YES; } } /* check if projection has been read from *mb222 file, if so, tell mb system */ else if ((store->projection_set == MB_YES) && (mb_io_ptr->projection_initialized == MB_NO)) { mb_proj_init(verbose, projection->projection_id, &(mb_io_ptr->pjptr), error); strncpy(mb_io_ptr->projection_id, projection->projection_id, MB_NAME_LENGTH); mb_io_ptr->projection_initialized = MB_YES; } /* throw away data if the time stamp makes no sense */ if ((status == MB_SUCCESS) && (store->kind == MB_DATA_DATA) && (store->time_i[0] < 2003)) { status = MB_FAILURE; *error = MB_ERROR_UNINTELLIGIBLE; } /* save fix data, used to calculate vessel speed */ if ((status == MB_SUCCESS) && (store->kind == MB_DATA_DATA)) { /* add latest fix */ mb_navint_add(verbose, mbio_ptr, store->time_d, store->sxp_ping.txer_e, store->sxp_ping.txer_n, error); } /* set error and kind in mb_io_ptr */ mb_io_ptr->new_error = *error; mb_io_ptr->new_kind = store->kind; /* print output debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> completed\n", function_name); fprintf(stderr, "dbg2 Return values:\n"); fprintf(stderr, "dbg2 error: %d\n", *error); fprintf(stderr, "dbg2 Return status:\n"); fprintf(stderr, "dbg2 status: %d\n", status); } /* return status */ return (status); } /* mbr_rt_swplssxp */
/*--------------------------------------------------------------------*/ int mbr_alm_swplssxp(int verbose, void *mbio_ptr, int *error) { char *function_name = "mbr_alm_swplssxp"; int status = MB_SUCCESS; struct mb_io_struct *mb_io_ptr; int *recordid; int *recordidlast; char **bufferptr; char *buffer; int *bufferalloc; int *size; int *nbadrec; int *header_rec_written; int *projection_rec_written; /* print input debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> called\n", function_name); fprintf(stderr, "dbg2 Revision id: %s\n", rcs_id); fprintf(stderr, "dbg2 Input arguments:\n"); fprintf(stderr, "dbg2 verbose: %d\n", verbose); fprintf(stderr, "dbg2 mbio_ptr: %p\n", mbio_ptr); } /* get pointer to mbio descriptor */ mb_io_ptr = (struct mb_io_struct *)mbio_ptr; /* set initial status */ status = MB_SUCCESS; /* allocate memory for data structure */ mb_io_ptr->structure_size = 0; mb_io_ptr->data_structure_size = 0; status = mbsys_swathplus_alloc(verbose, mbio_ptr, &mb_io_ptr->store_data, error); recordid = (int *)&mb_io_ptr->save3; recordidlast = (int *)&mb_io_ptr->save4; bufferptr = (char **)&mb_io_ptr->saveptr1; buffer = (char *)*bufferptr; bufferalloc = (int *)&mb_io_ptr->save6; size = (int *)&mb_io_ptr->save8; nbadrec = (int *)&mb_io_ptr->save9; header_rec_written = (int *)&(mb_io_ptr->save1); projection_rec_written = (int *)&(mb_io_ptr->save2); *recordid = SWPLS_ID_NONE; *recordidlast = SWPLS_ID_NONE; *bufferptr = NULL; *bufferalloc = 0; *size = 0; *nbadrec = 0; *header_rec_written = MB_NO; *projection_rec_written = MB_NO; /* allocate memory if necessary */ if (status == MB_SUCCESS) { status = mb_reallocd(verbose, __FILE__, __LINE__, SWPLS_BUFFER_STARTSIZE, (void **)bufferptr, error); if (status == MB_SUCCESS) { *bufferalloc = SWPLS_BUFFER_STARTSIZE; } } /* print output debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> completed\n", function_name); fprintf(stderr, "dbg2 Return values:\n"); fprintf(stderr, "dbg2 error: %d\n", *error); fprintf(stderr, "dbg2 Return status:\n"); fprintf(stderr, "dbg2 status: %d\n", status); } /* return status */ return (status); } /* mbr_alm_swplssxp */
int main (int argc, char **argv) { /* id variables */ char program_name[] = "MBrolltimelag"; char help_message[] = "MBrolltimelag extracts the roll time series and the apparent \nbottom slope time series from swath data, and then calculates \nthe cross correlation between the roll and the slope minus roll \nfor a specified set of time lags."; char usage_message[] = "mbrolltimelag -Iswathdata [-Fformat -Krollsource -Nnping -Ooutputname -Snavchannel -Tnlag/lagmin/lagmax -V -H ]"; /* parsing variables */ extern char *optarg; int errflg = 0; int c; int help = 0; int flag = 0; /* MBIO status variables */ int status = MB_SUCCESS; int verbose = 0; int error = MB_ERROR_NO_ERROR; /* Files and formats */ char swathdata[MB_PATH_MAXLINE]; char swathfile[MB_PATH_MAXLINE]; char swathroot[MB_PATH_MAXLINE]; char outroot[MB_PATH_MAXLINE]; char outroot_defined = MB_NO; char xcorfile[MB_PATH_MAXLINE]; char xcorfiletot[MB_PATH_MAXLINE]; char cmdfile[MB_PATH_MAXLINE]; char estimatefile[MB_PATH_MAXLINE]; char histfile[MB_PATH_MAXLINE]; char fhistfile[MB_PATH_MAXLINE]; char modelfile[MB_PATH_MAXLINE]; int format = 0; int formatguess = 0; FILE *fp = NULL; FILE *fpx = NULL; FILE *fpf = NULL; FILE *fpt = NULL; FILE *fpe = NULL; FILE *fph = NULL; FILE *fpm = NULL; int read_datalist = MB_NO; int read_data = MB_NO; void *datalist; int look_processed = MB_DATALIST_LOOK_UNSET; double file_weight; /* cross correlation parameters */ int navchannel = MB_DATA_DATA; int kind = MB_DATA_NONE; int npings = 100; double rthreshold = 0.9; int nlag = 41; double lagstart = -2.0; double lagend = 2.0; double lagmax; double lagstep = 0.05; double *rr = NULL; /* slope data */ int nslope = 0; int nslopetot = 0; int nslope_alloc = 0; double *slope_time_d = NULL; double *slope_slope = NULL; double *slope_roll = NULL; int nroll = 0; int nroll_alloc = 0; double *roll_time_d = NULL; double *roll_roll = NULL; /* timelag histogram array */ int *timelaghistogram = NULL; double time_d; double roll; double slope; double timelag; double sumsloperoll; double sumslopesq; double sumrollsq; double slopeminusmean; double rollminusmean; double r; double sum_x, sum_y, sum_xy, sum_x2, sum_y2; double mmm, bbb; int nrollmean; double rollmean; double slopemean; double maxtimelag; double maxr; double peaktimelag; double peakr; int peakk; int peakkmax; int peakksum; double time_d_avg; int nestimate = 0; int nmodel = 0; int nr; double rollint; int found; int nscan; int j0, j1; int i, j, k, l; /* set default input */ strcpy(swathdata, "datalist.mb-1"); /* process argument list */ while ((c = getopt(argc, argv, "VvHhC:c:F:f:I:i:K:k:O:o:N:n:S:s:T:t:")) != -1) switch (c) { case 'H': case 'h': help++; break; case 'V': case 'v': verbose++; break; case 'C': case 'c': sscanf (optarg,"%lf", &rthreshold); flag++; break; case 'F': case 'f': sscanf (optarg,"%d", &format); flag++; break; case 'I': case 'i': sscanf (optarg,"%s", swathdata); flag++; break; case 'K': case 'k': sscanf (optarg,"%d", &kind); flag++; break; case 'N': case 'n': sscanf (optarg,"%d", &npings); flag++; break; case 'O': case 'o': sscanf (optarg,"%s", outroot); outroot_defined = MB_YES; flag++; break; case 'S': case 's': sscanf (optarg,"%d", &navchannel); flag++; break; case 'T': case 't': sscanf (optarg,"%d/%lf/%lf", &nlag, &lagstart, &lagend); lagmax = MAX(fabs(lagstart), fabs(lagend)); flag++; break; case '?': errflg++; } /* if error flagged then print it and exit */ if (errflg) { fprintf(stderr,"usage: %s\n", usage_message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); error = MB_ERROR_BAD_USAGE; exit(error); } /* print starting message */ if (verbose == 1 || help) { fprintf(stderr,"\nProgram %s\n",program_name); fprintf(stderr,"MB-system Version %s\n",MB_VERSION); } /* print starting debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Program <%s>\n",program_name); fprintf(stderr,"dbg2 MB-system Version %s\n",MB_VERSION); fprintf(stderr,"dbg2 Control Parameters:\n"); fprintf(stderr,"dbg2 verbose: %d\n",verbose); fprintf(stderr,"dbg2 help: %d\n",help); fprintf(stderr,"dbg2 format: %d\n",format); fprintf(stderr,"dbg2 rthreshold: %f\n",rthreshold); fprintf(stderr,"dbg2 swathdata: %s\n",swathdata); fprintf(stderr,"dbg2 npings: %d\n",npings); fprintf(stderr,"dbg2 nlag: %d\n",nlag); fprintf(stderr,"dbg2 lagstart: %f\n",lagstart); fprintf(stderr,"dbg2 lagend: %f\n",lagend); fprintf(stderr,"dbg2 lagmax: %f\n",lagmax); fprintf(stderr,"dbg2 navchannel: %d\n",navchannel); fprintf(stderr,"dbg2 kind: %d\n",kind); } /* if help desired then print it and exit */ if (help) { fprintf(stderr,"\n%s\n",help_message); fprintf(stderr,"\nusage: %s\n", usage_message); exit(error); } /* get format if required */ mb_get_format(verbose,swathdata,swathroot,&formatguess,&error); if (format == 0) format = formatguess; if (outroot_defined == MB_NO) strcpy(outroot, swathroot); /* determine whether to read one file or a list of files */ if (format < 0) read_datalist = MB_YES; /* get time lag step */ lagstep = 2 * lagmax / (nlag - 1); status = mb_reallocd(verbose,__FILE__,__LINE__, nlag * sizeof(double), (void **)&rr, &error); status = mb_reallocd(verbose,__FILE__,__LINE__, nlag * sizeof(int), (void **)&timelaghistogram, &error); /* print out some helpful information */ if (verbose > 0) { fprintf(stderr, "Program %s parameters:\n", program_name); fprintf(stderr, " Input: %s\n", swathdata); fprintf(stderr, " Format: %d\n", format); fprintf(stderr, " Number of pings per estimate: %d\n", npings); fprintf(stderr, " Number of time lag calculations: %d\n", nlag); fprintf(stderr, " Start time lag reported: %f\n", lagstart); fprintf(stderr, " End time lag reported: %f\n", lagend); fprintf(stderr, " Maximum time lag: %f\n", lagmax); fprintf(stderr, " Time lag step: %f\n", lagstep); } /* first get roll data from the entire swathdata (which can be a datalist ) */ if (kind > MB_DATA_NONE) sprintf(cmdfile, "mbnavlist -I%s -F%d -K%d -OMR", swathdata, format, kind); else sprintf(cmdfile, "mbnavlist -I%s -F%d -N%d -OMR", swathdata, format, navchannel); fprintf(stderr,"\nRunning %s...\n",cmdfile); fp = popen(cmdfile, "r"); while ((nscan = fscanf(fp, "%lf %lf", &time_d, &roll)) == 2) { if (nroll >= nroll_alloc) { nroll_alloc += MBRTL_ALLOC_CHUNK; status = mb_reallocd(verbose,__FILE__,__LINE__, nroll_alloc * sizeof(double), (void **)&roll_time_d, &error); status = mb_reallocd(verbose,__FILE__,__LINE__, nroll_alloc * sizeof(double), (void **)&roll_roll, &error); } if (nroll == 0 || time_d > roll_time_d[nroll-1]) { roll_time_d[nroll] = time_d; roll_roll[nroll] = roll; nroll++; } } pclose(fp); fprintf(stderr,"%d roll data read from %s\n", nroll, swathdata); /* open total cross correlation file */ if (read_datalist == MB_YES) { sprintf(xcorfiletot, "%s_xcorr.txt", outroot); if ((fpt = fopen(xcorfiletot, "w")) == NULL) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open cross correlation output: %s\n", xcorfiletot); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } } /* open time lag estimate file */ sprintf(estimatefile, "%s_timelagest.txt", outroot); if ((fpe = fopen(estimatefile, "w")) == NULL) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open estimate output: %s\n", estimatefile); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* open time lag histogram file */ sprintf(histfile, "%s_timelaghist.txt", outroot); if ((fph = fopen(histfile, "w")) == NULL) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open histogram output: %s\n", histfile); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* open time lag model file */ sprintf(modelfile, "%s_timelagmodel.txt", outroot); if ((fpm = fopen(modelfile, "w")) == NULL) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open time lag model output: %s\n", modelfile); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* open file list */ if (read_datalist == MB_YES) { if ((status = mb_datalist_open(verbose,&datalist, swathdata,look_processed,&error)) != MB_SUCCESS) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open data list file: %s\n", swathdata); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } if ((status = mb_datalist_read(verbose,datalist, swathfile,&format,&file_weight,&error)) == MB_SUCCESS) read_data = MB_YES; else read_data = MB_NO; } /* else copy single filename to be read */ else { strcpy(swathfile, swathdata); read_data = MB_YES; } /* loop over all files to be read */ while (read_data == MB_YES) { nestimate = 0; nslope = 0; time_d_avg = 0.0; sprintf(cmdfile, "mblist -I%s -F%d -OMAR", swathfile, format); fprintf(stderr,"\nRunning %s...\n",cmdfile); fp = popen(cmdfile, "r"); while ((nscan = fscanf(fp, "%lf %lf %lf", &time_d, &slope, &roll)) == 3) { if (nslope >= nslope_alloc) { nslope_alloc += MBRTL_ALLOC_CHUNK; status = mb_reallocd(verbose,__FILE__,__LINE__, nslope_alloc * sizeof(double), (void **)&slope_time_d, &error); status = mb_reallocd(verbose,__FILE__,__LINE__, nslope_alloc * sizeof(double), (void **)&slope_slope, &error); status = mb_reallocd(verbose,__FILE__,__LINE__, nslope_alloc * sizeof(double), (void **)&slope_roll, &error); } if (nslope == 0 || time_d > slope_time_d[nslope-1]) { slope_time_d[nslope] = time_d; time_d_avg += time_d; slope_slope[nslope] = roll - slope; slope_roll[nslope] = roll; nslope++; } } pclose(fp); nslopetot += nslope; if (nslope > 0) time_d_avg /= nslope; fprintf(stderr,"%d slope data read from %s\n", nslope, swathfile); /* open time lag histogram file */ sprintf(fhistfile, "%s_timelaghist.txt", swathfile); if ((fpf = fopen(fhistfile, "w")) == NULL) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open histogram output: %s\n", fhistfile); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* open cross correlation file */ sprintf(xcorfile, "%s_xcorr.txt", swathfile); if ((fpx = fopen(xcorfile, "w")) == NULL) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open cross correlation output: %s\n", xcorfile); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* initialize time lag histogram */ for (k=0;k<nlag;k++) { timelaghistogram[k] = 0; } /* now do cross correlation calculations */ for (i=0;i<nslope/npings;i++) { /* get ping range in this chunk */ j0 = i * npings; j1 = j0 + npings - 1; /* get mean slope in this chunk */ slopemean = 0.0; for (j = j0; j <= j1; j++) { slopemean += slope_slope[j]; } slopemean /= npings; /* get mean roll in this chunk */ rollmean = 0.0; nrollmean = 0; for (j = 0; j < nroll; j++) { if ((roll_time_d[j] >= slope_time_d[j0] - lagmax) && (roll_time_d[j] <= slope_time_d[j1] + lagmax)) { rollmean += roll_roll[j]; nrollmean++; } } if (nrollmean > 0) { rollmean /= nrollmean; } /* calculate cross correlation for the specified time lags */ if (nrollmean > 0) { fprintf(fpx, ">\n"); if (fpt != NULL) fprintf(fpt, ">\n"); for (k = 0; k < nlag; k++) { timelag = -lagmax + k * lagstep; sumsloperoll = 0.0; sumslopesq = 0.0; sumrollsq = 0.0; nr = 0; for (j = j0; j <= j1; j++) { /* interpolate lagged roll value */ found = MB_NO; time_d = slope_time_d[j] + timelag; for (l = nr; l < nroll - 1 && found == MB_NO; l++) { if (time_d >= roll_time_d[l] && time_d <= roll_time_d[l+1]) { nr = l; found = MB_YES; } } if (found == MB_NO && time_d < roll_time_d[0]) { rollint = roll_roll[0]; } else if (found == MB_NO && time_d > roll_time_d[nroll - 1]) { rollint = roll_roll[nroll - 1]; } else { rollint = roll_roll[nr] + (roll_roll[nr+1] - roll_roll[nr]) * (time_d - roll_time_d[nr]) / (roll_time_d[nr+1] - roll_time_d[nr]); } /* add to sums */ slopeminusmean = (slope_slope[j] - slopemean); rollminusmean = (rollint - rollmean); sumslopesq += slopeminusmean * slopeminusmean; sumrollsq += rollminusmean * rollminusmean; sumsloperoll += slopeminusmean * rollminusmean; } r = sumsloperoll / sqrt(sumslopesq) / sqrt(sumrollsq); rr[k] = r; /* output results */ fprintf(fpx, "%5.3f %5.3f \n", timelag, r); if (fpt != NULL) fprintf(fpt, "%5.3f %5.3f \n", timelag, r); } /* get max and closest peak cross correlations */ maxr = 0.0; peakr = 0.0; peaktimelag = 0.0; for (k = 0; k < nlag; k++) { timelag = -lagmax + k * lagstep; if (timelag >= lagstart && timelag <= lagend) { if (rr[k] > maxr) { maxr = rr[k]; maxtimelag = timelag; } if (k == 0) { peakk = k; peakr = rr[k]; peaktimelag = timelag; } else if (k < nlag - 1 && rr[k] > 0.0 && rr[k] > rr[k-1] && rr[k] > rr[k+1] && fabs(timelag) < fabs(peaktimelag)) { peakk = k; peakr = rr[k]; peaktimelag = timelag; } else if (k == nlag - 1 && peaktimelag == -lagmax && rr[k] > peakr) { peakk = k; peakr = rr[k]; peaktimelag = timelag; } } } } /* print out best correlated time lag estimates */ if (peakr > rthreshold) { timelaghistogram[peakk]++; } /* augment histogram */ if (peakr > rthreshold) { fprintf(fpe, "%10.3f %6.3f\n", slope_time_d[(j0+j1)/2], peaktimelag); fprintf(fpf, "%6.3f\n", peaktimelag); fprintf(fph, "%6.3f\n", peaktimelag); sum_x += slope_time_d[(j0+j1)/2]; sum_y += peaktimelag; sum_xy += slope_time_d[(j0+j1)/2] * peaktimelag; sum_x2 += slope_time_d[(j0+j1)/2] * slope_time_d[(j0+j1)/2]; sum_y2 += peaktimelag * peaktimelag; nestimate++; } /* print out max and closest peak cross correlations */ if (verbose > 0) { fprintf(stderr, "cross correlation pings %5d - %5d: max: %6.3f %5.3f peak: %6.3f %5.3f\n", j0, j1, maxtimelag, maxr, peaktimelag, peakr); } } /* close cross correlation and histogram files */ fclose(fpx); fclose(fpf); /* generate plot shellscript for cross correlation file */ sprintf(cmdfile, "mbm_xyplot -I%s -N", xcorfile); fprintf(stderr, "Running: %s...\n", cmdfile); system(cmdfile); /* generate plot shellscript for time lag histogram */ sprintf(cmdfile, "mbm_histplot -I%s -C%g -L\"Frequency Histogram of %s:Time Lag (sec):Frequency:\"", fhistfile, lagstep, swathfile); fprintf(stderr, "Running: %s...\n", cmdfile); system(cmdfile); /* output peak time lag */ peakk = 0; peakkmax = 0; peakksum = 0; timelag = 0.0; for (k=0;k<nlag;k++) { if (timelaghistogram[k] > peakkmax) { peakkmax = timelaghistogram[k]; peakk = k; } peakksum += timelaghistogram[k]; } if (nslope > 0 && peakksum > 0 && peakkmax > 1 && peakkmax > peakksum / 5) { timelag = -lagmax + peakk * lagstep; fprintf(fpm, "%f %f\n", time_d_avg, timelag); nmodel++; fprintf(stderr,"Time lag model point: %f %f | nslope:%d peakksum:%d peakkmax:%d\n", time_d_avg, timelag, nslope, peakksum, peakkmax); } else { if (peakkmax > 0) timelag = -lagmax + peakk * lagstep; fprintf(stderr,"Time lag model point: %f %f | nslope:%d peakksum:%d peakkmax:%d | REJECTED\n", time_d_avg, timelag, nslope, peakksum, peakkmax); } /* figure out whether and what to read next */ if (read_datalist == MB_YES) { if ((status = mb_datalist_read(verbose,datalist, swathfile,&format,&file_weight,&error)) == MB_SUCCESS) read_data = MB_YES; else read_data = MB_NO; } else { read_data = MB_NO; } /* end loop over files in list */ } if (read_datalist == MB_YES) mb_datalist_close(verbose,&datalist,&error); /* close cross correlation file */ if (read_datalist == MB_YES) fclose(fpt); /* close estimate file */ fclose(fpe); /* close histogram file */ fclose(fph); /* close time lag model file */ fclose(fpm); /* generate plot shellscript for cross correlation file */ if (read_datalist == MB_YES) { sprintf(cmdfile, "mbm_xyplot -I%s -N", xcorfiletot); fprintf(stderr, "Running: %s...\n", cmdfile); system(cmdfile); } /* generate plot shellscript for time lag histogram */ sprintf(cmdfile, "mbm_histplot -I%s -C%g -L\"Frequency Histogram of %s:Time Lag (sec):Frequency:\"", histfile, lagstep, swathdata); fprintf(stderr, "Running: %s...\n", cmdfile); system(cmdfile); /* generate plot shellscript for time lag model if it exists */ if (nmodel > 1 || nestimate > 1) { mmm = (nestimate * sum_xy - sum_x * sum_y) / (nestimate * sum_x2 - sum_x * sum_x); bbb = (sum_y - mmm * sum_x) / nestimate; sprintf(cmdfile, "mbm_xyplot -I%s -ISc0.05:%s -I%s -ISc0.1:%s -L\"Time lag model of %s:Time (sec):Time Lag (sec):\"", modelfile, estimatefile, modelfile, modelfile, swathdata); fprintf(stderr, "Running: %s...\n", cmdfile); system(cmdfile); } /* deallocate memory for data arrays */ mb_freed(verbose,__FILE__,__LINE__,(void **)&slope_time_d,&error); mb_freed(verbose,__FILE__,__LINE__,(void **)&slope_slope,&error); mb_freed(verbose,__FILE__,__LINE__,(void **)&slope_roll,&error); mb_freed(verbose,__FILE__,__LINE__,(void **)&roll_time_d,&error); mb_freed(verbose,__FILE__,__LINE__,(void **)&roll_roll,&error); mb_freed(verbose,__FILE__,__LINE__,(void **)&rr,&error); mb_freed(verbose,__FILE__,__LINE__,(void **)&timelaghistogram,&error); /* check memory */ if (verbose >= 4) status = mb_memory_list(verbose,&error); /* give the statistics */ if (verbose >= 1) { fprintf(stderr,"\n%d input roll records\n", nroll); fprintf(stderr,"%d input slope\n", nslopetot); } /* end it all */ exit(error); }
int main (int argc, char **argv) { char program_name[] = "mbctdlist"; char help_message[] = "mbctdlist lists all CTD records within swath data files\nThe -O option specifies how the values are output\nin an mblist-likefashion.\n"; char usage_message[] = "mbctdlist [-A -Ddecimate -Fformat -Gdelimeter -H -Ifile -Llonflip -Ooutput_format -V -Zsegment]"; extern char *optarg; int errflg = 0; int c; int help = 0; int flag = 0; /* MBIO status variables */ int status = MB_SUCCESS; int interp_status = MB_SUCCESS; int verbose = 0; int error = MB_ERROR_NO_ERROR; char *message; /* MBIO read control parameters */ int read_datalist = MB_NO; char read_file[MB_PATH_MAXLINE]; void *datalist; int look_processed = MB_DATALIST_LOOK_UNSET; double file_weight; int format; int pings; int decimate; int lonflip; double bounds[4]; int btime_i[7]; int etime_i[7]; double btime_d; double etime_d; double speedmin; double timegap; char file[MB_PATH_MAXLINE]; int beams_bath; int beams_amp; int pixels_ss; /* output format list controls */ char list[MAX_OPTIONS]; int n_list; double distance_total = 0.0; int time_j[5]; int mblist_next_value = MB_NO; int invert_next_value = MB_NO; int signflip_next_value = MB_NO; int first = MB_YES; int ascii = MB_YES; int segment = MB_NO; char segment_tag[MB_PATH_MAXLINE]; char delimiter[MB_PATH_MAXLINE]; /* MBIO read values */ void *mbio_ptr = NULL; void *store_ptr; int kind; int time_i[7]; double time_d; double navlon; double navlat; double speed; double heading; double distance; double altitude; double sonardepth; char *beamflag = NULL; double *bath = NULL; double *bathacrosstrack = NULL; double *bathalongtrack = NULL; double *amp = NULL; double *ss = NULL; double *ssacrosstrack = NULL; double *ssalongtrack = NULL; char comment[MB_COMMENT_MAXLINE]; /* navigation, heading, attitude data */ int survey_count = 0; int survey_count_tot = 0; int nnav = 0; int nnav_alloc = 0; double *nav_time_d = NULL; double *nav_lon = NULL; double *nav_lat = NULL; double *nav_sonardepth = NULL; double *nav_heading = NULL; double *nav_speed = NULL; double *nav_altitude = NULL; /* CTD values */ int ctd_count = 0; int ctd_count_tot = 0; int nctd; double ctd_time_d[MB_CTD_MAX]; double ctd_conductivity[MB_CTD_MAX]; double ctd_temperature[MB_CTD_MAX]; double ctd_depth[MB_CTD_MAX]; double ctd_salinity[MB_CTD_MAX]; double ctd_soundspeed[MB_CTD_MAX]; int nsensor; double sensor_time_d[MB_CTD_MAX]; double sensor1[MB_CTD_MAX]; double sensor2[MB_CTD_MAX]; double sensor3[MB_CTD_MAX]; double sensor4[MB_CTD_MAX]; double sensor5[MB_CTD_MAX]; double sensor6[MB_CTD_MAX]; double sensor7[MB_CTD_MAX]; double sensor8[MB_CTD_MAX]; double conductivity; double temperature; double potentialtemperature; double depth; double salinity; double soundspeed; /* additional time variables */ int first_m = MB_YES; double time_d_ref; int first_u = MB_YES; time_t time_u; time_t time_u_ref; double seconds; /* course calculation variables */ double dlon, dlat, minutes; int degrees; char hemi; double headingx, headingy, mtodeglon, mtodeglat; double course, course_old; double time_d_old; double time_interval; double speed_made_good, speed_made_good_old; double navlon_old, navlat_old; double dx, dy; double b; int read_data; int ictd; int i, j; /* get current default values */ status = mb_defaults(verbose,&format,&pings,&lonflip,bounds, btime_i,etime_i,&speedmin,&timegap); pings = 1; bounds[0] = -360.0; bounds[1] = 360.0; bounds[2] = -90.0; bounds[3] = 90.0; ctd_count = 0; ctd_count_tot = 0; /* set default input to datalist.mb-1 */ strcpy (read_file, "datalist.mb-1"); /* set up the default list controls (Time, lon, lat, conductivity, temperature, depth, salinity, sound speed) */ list[0]='T'; list[1]='X'; list[2]='Y'; list[3]='H'; list[4]='C'; list[5]='c'; list[6]='^'; list[7]='c'; list[8]='S'; list[9]='s'; n_list = 10; sprintf(delimiter, "\t"); decimate = 1; /* process argument list */ while ((c = getopt(argc, argv, "AaDdF:f:G:g:I:i:L:l:O:o:Z:z:VvHh")) != -1) switch (c) { case 'H': case 'h': help++; break; case 'V': case 'v': verbose++; break; case 'A': case 'a': ascii = MB_NO; flag++; break; case 'D': case 'd': sscanf (optarg,"%d", &decimate); flag++; break; case 'F': case 'f': sscanf (optarg,"%d", &format); flag++; break; case 'G': case 'g': sscanf (optarg,"%s", delimiter); flag++; break; case 'I': case 'i': sscanf (optarg,"%s", read_file); flag++; break; case 'L': case 'l': sscanf (optarg,"%d", &lonflip); flag++; break; case 'O': case 'o': for(j=0,n_list=0;j<(int)strlen(optarg);j++,n_list++) if (n_list<MAX_OPTIONS) list[n_list] = optarg[j]; break; case 'Z': case 'z': segment = MB_YES; sscanf (optarg,"%s", segment_tag); flag++; break; case '?': errflg++; } /* if error flagged then print it and exit */ if (errflg) { fprintf(stderr,"usage: %s\n", usage_message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); error = MB_ERROR_BAD_USAGE; exit(error); } /* print starting message */ if (verbose == 1 || help) { fprintf(stderr,"\nProgram %s\n",program_name); fprintf(stderr,"Version %s\n",rcs_id); fprintf(stderr,"MB-system Version %s\n",MB_VERSION); } /* print starting debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Program <%s>\n",program_name); fprintf(stderr,"dbg2 Version %s\n",rcs_id); fprintf(stderr,"dbg2 MB-system Version %s\n",MB_VERSION); fprintf(stderr,"dbg2 Control Parameters:\n"); fprintf(stderr,"dbg2 verbose: %d\n",verbose); fprintf(stderr,"dbg2 help: %d\n",help); fprintf(stderr,"dbg2 format: %d\n",format); fprintf(stderr,"dbg2 pings: %d\n",pings); fprintf(stderr,"dbg2 lonflip: %d\n",lonflip); fprintf(stderr,"dbg2 decimate: %d\n",decimate); fprintf(stderr,"dbg2 bounds[0]: %f\n",bounds[0]); fprintf(stderr,"dbg2 bounds[1]: %f\n",bounds[1]); fprintf(stderr,"dbg2 bounds[2]: %f\n",bounds[2]); fprintf(stderr,"dbg2 bounds[3]: %f\n",bounds[3]); fprintf(stderr,"dbg2 btime_i[0]: %d\n",btime_i[0]); fprintf(stderr,"dbg2 btime_i[1]: %d\n",btime_i[1]); fprintf(stderr,"dbg2 btime_i[2]: %d\n",btime_i[2]); fprintf(stderr,"dbg2 btime_i[3]: %d\n",btime_i[3]); fprintf(stderr,"dbg2 btime_i[4]: %d\n",btime_i[4]); fprintf(stderr,"dbg2 btime_i[5]: %d\n",btime_i[5]); fprintf(stderr,"dbg2 btime_i[6]: %d\n",btime_i[6]); fprintf(stderr,"dbg2 etime_i[0]: %d\n",etime_i[0]); fprintf(stderr,"dbg2 etime_i[1]: %d\n",etime_i[1]); fprintf(stderr,"dbg2 etime_i[2]: %d\n",etime_i[2]); fprintf(stderr,"dbg2 etime_i[3]: %d\n",etime_i[3]); fprintf(stderr,"dbg2 etime_i[4]: %d\n",etime_i[4]); fprintf(stderr,"dbg2 etime_i[5]: %d\n",etime_i[5]); fprintf(stderr,"dbg2 etime_i[6]: %d\n",etime_i[6]); fprintf(stderr,"dbg2 speedmin: %f\n",speedmin); fprintf(stderr,"dbg2 timegap: %f\n",timegap); fprintf(stderr,"dbg2 ascii: %d\n",ascii); fprintf(stderr,"dbg2 segment: %d\n",segment); fprintf(stderr,"dbg2 segment_tag: %s\n",segment_tag); fprintf(stderr,"dbg2 delimiter: %s\n",delimiter); fprintf(stderr,"dbg2 file: %s\n",file); fprintf(stderr,"dbg2 n_list: %d\n",n_list); for (i=0;i<n_list;i++) fprintf(stderr,"dbg2 list[%d]: %c\n", i,list[i]); } /* if help desired then print it and exit */ if (help) { fprintf(stderr,"\n%s\n",help_message); fprintf(stderr,"\nusage: %s\n", usage_message); exit(error); } /* get format if required */ if (format == 0) mb_get_format(verbose,read_file,NULL,&format,&error); /* determine whether to read one file or a list of files */ if (format < 0) read_datalist = MB_YES; /**************************************************************************************/ /* section 1 - read all data and save nav etc for interpolation onto ctd data */ /* open file list */ if (read_datalist == MB_YES) { if ((status = mb_datalist_open(verbose,&datalist, read_file,look_processed,&error)) != MB_SUCCESS) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open data list file: %s\n", read_file); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } if ((status = mb_datalist_read(verbose,datalist, file,&format,&file_weight,&error)) == MB_SUCCESS) read_data = MB_YES; else read_data = MB_NO; } /* else copy single filename to be read */ else { strcpy(file, read_file); read_data = MB_YES; } /* loop over all files to be read */ while (read_data == MB_YES) { /* initialize reading the swath file */ if ((status = mb_read_init( verbose,file,format,pings,lonflip,bounds, btime_i,etime_i,speedmin,timegap, &mbio_ptr,&btime_d,&etime_d, &beams_bath,&beams_amp,&pixels_ss,&error)) != MB_SUCCESS) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error returned from function <mb_read_init>:\n%s\n",message); fprintf(stderr,"\nMultibeam File <%s> not initialized for reading\n",file); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* allocate memory for data arrays */ if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(char), (void **)&beamflag, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bath, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_AMPLITUDE, sizeof(double), (void **)&, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bathacrosstrack, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bathalongtrack, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&ss, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&ssacrosstrack, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&ssalongtrack, &error); /* if error initializing memory then quit */ if (error != MB_ERROR_NO_ERROR) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error allocating data arrays:\n%s\n", message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* output separator for GMT style segment file output */ if (segment == MB_YES && ascii == MB_YES) { printf("%s\n", segment_tag); } /* output info */ if (verbose >= 1) { fprintf(stderr, "\nSearching %s for survey records\n", file); } /* read and print data */ survey_count = 0; first = MB_YES; while (error <= MB_ERROR_NO_ERROR) { /* read a data record */ status = mb_get_all(verbose,mbio_ptr,&store_ptr,&kind, time_i,&time_d,&navlon,&navlat, &speed,&heading, &distance,&altitude,&sonardepth, &beams_bath,&beams_amp,&pixels_ss, beamflag,bath,amp,bathacrosstrack,bathalongtrack, ss,ssacrosstrack,ssalongtrack, comment,&error); /* print debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Ping read in program <%s>\n", program_name); fprintf(stderr,"dbg2 kind: %d\n",kind); fprintf(stderr,"dbg2 error: %d\n",error); fprintf(stderr,"dbg2 status: %d\n",status); } /* if survey data save the nav etc */ if (error <= MB_ERROR_NO_ERROR && kind == MB_DATA_DATA) { /* allocate memory for navigation/attitude arrays if needed */ if (nnav + 1 >= nnav_alloc) { nnav_alloc += MBCTDLIST_ALLOC_CHUNK; status = mb_reallocd(verbose,__FILE__,__LINE__,nnav_alloc*sizeof(double),(void **)&nav_time_d,&error); status = mb_reallocd(verbose,__FILE__,__LINE__,nnav_alloc*sizeof(double),(void **)&nav_lon,&error); status = mb_reallocd(verbose,__FILE__,__LINE__,nnav_alloc*sizeof(double),(void **)&nav_lat,&error); status = mb_reallocd(verbose,__FILE__,__LINE__,nnav_alloc*sizeof(double),(void **)&nav_speed,&error); status = mb_reallocd(verbose,__FILE__,__LINE__,nnav_alloc*sizeof(double),(void **)&nav_sonardepth,&error); status = mb_reallocd(verbose,__FILE__,__LINE__,nnav_alloc*sizeof(double),(void **)&nav_heading,&error); status = mb_reallocd(verbose,__FILE__,__LINE__,nnav_alloc*sizeof(double),(void **)&nav_altitude,&error); if (error != MB_ERROR_NO_ERROR) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error allocating data arrays:\n%s\n",message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } } /* save the nav etc */ if (nnav == 0 || time_d > nav_time_d[nnav-1]) { nav_time_d[nnav] = time_d; nav_lon[nnav] = navlon; nav_lat[nnav] = navlat; nav_speed[nnav] = speed; nav_sonardepth[nnav] = sonardepth; nav_heading[nnav] = heading; nav_altitude[nnav] = altitude; nnav++; } survey_count++; survey_count_tot++; } } /* close the swath file */ status = mb_close(verbose,&mbio_ptr,&error); /* output info */ if (verbose >= 1) { fprintf(stderr, "nav extracted from %d survey records\n", survey_count); } /* figure out whether and what to read next */ if (read_datalist == MB_YES) { if ((status = mb_datalist_read(verbose,datalist, file,&format,&file_weight,&error)) == MB_SUCCESS) read_data = MB_YES; else read_data = MB_NO; } else { read_data = MB_NO; } /* end loop over files in list */ } if (read_datalist == MB_YES) mb_datalist_close(verbose,&datalist,&error); /* output info */ if (verbose >= 1) { fprintf(stderr, "\nTotal %d survey records\n", survey_count_tot); } /**************************************************************************************/ /* section 2 - read data and output ctd data with time interpolation of nav etc */ /* open file list */ if (read_datalist == MB_YES) { if ((status = mb_datalist_open(verbose,&datalist, read_file,look_processed,&error)) != MB_SUCCESS) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open data list file: %s\n", read_file); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } if ((status = mb_datalist_read(verbose,datalist, file,&format,&file_weight,&error)) == MB_SUCCESS) read_data = MB_YES; else read_data = MB_NO; } /* else copy single filename to be read */ else { strcpy(file, read_file); read_data = MB_YES; } /* loop over all files to be read */ while (read_data == MB_YES) { /* initialize reading the swath file */ if ((status = mb_read_init( verbose,file,format,pings,lonflip,bounds, btime_i,etime_i,speedmin,timegap, &mbio_ptr,&btime_d,&etime_d, &beams_bath,&beams_amp,&pixels_ss,&error)) != MB_SUCCESS) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error returned from function <mb_read_init>:\n%s\n",message); fprintf(stderr,"\nMultibeam File <%s> not initialized for reading\n",file); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* allocate memory for data arrays */ if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(char), (void **)&beamflag, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bath, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_AMPLITUDE, sizeof(double), (void **)&, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bathacrosstrack, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bathalongtrack, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&ss, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&ssacrosstrack, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&ssalongtrack, &error); /* if error initializing memory then quit */ if (error != MB_ERROR_NO_ERROR) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error allocating data arrays:\n%s\n", message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* output info */ if (verbose >= 1) { fprintf(stderr, "\nSearching %s for CTD records\n", file); } /* read and print data */ ctd_count = 0; first = MB_YES; while (error <= MB_ERROR_NO_ERROR) { /* read a data record */ status = mb_get_all(verbose,mbio_ptr,&store_ptr,&kind, time_i,&time_d,&navlon,&navlat, &speed,&heading, &distance,&altitude,&sonardepth, &beams_bath,&beams_amp,&pixels_ss, beamflag,bath,amp,bathacrosstrack,bathalongtrack, ss,ssacrosstrack,ssalongtrack, comment,&error); /* print debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Ping read in program <%s>\n", program_name); fprintf(stderr,"dbg2 kind: %d\n",kind); fprintf(stderr,"dbg2 error: %d\n",error); fprintf(stderr,"dbg2 status: %d\n",status); } /* if ctd then extract data */ if (error <= MB_ERROR_NO_ERROR && (kind == MB_DATA_CTD || kind == MB_DATA_SSV)) { /* extract ctd */ status = mb_ctd(verbose, mbio_ptr, store_ptr, &kind, &nctd, ctd_time_d, ctd_conductivity, ctd_temperature, ctd_depth, ctd_salinity, ctd_soundspeed, &error); /* extract ancilliary sensor data */ status = mb_ancilliarysensor(verbose, mbio_ptr, store_ptr, &kind, &nsensor, sensor_time_d, sensor1, sensor2, sensor3, sensor4, sensor5, sensor6, sensor7, sensor8, &error); /* loop over the nctd ctd points, outputting each one */ if (error == MB_ERROR_NO_ERROR && nctd > 0) { for (ictd=0;ictd<nctd;ictd++) { /* get data */ time_d = ctd_time_d[ictd]; mb_get_date(verbose, time_d, time_i); conductivity = ctd_conductivity[ictd]; temperature = ctd_temperature[ictd]; depth = ctd_depth[ictd]; salinity = ctd_salinity[ictd]; soundspeed = ctd_soundspeed[ictd]; /* get navigation */ j = 0; speed = 0.0; interp_status = mb_linear_interp_longitude(verbose, nav_time_d-1, nav_lon-1, nnav, time_d, &navlon, &j, &error); if (interp_status == MB_SUCCESS) interp_status = mb_linear_interp_latitude(verbose, nav_time_d-1, nav_lat-1, nnav, time_d, &navlat, &j, &error); if (interp_status == MB_SUCCESS) interp_status = mb_linear_interp_heading(verbose, nav_time_d-1, nav_heading-1, nnav, time_d, &heading, &j, &error); if (interp_status == MB_SUCCESS) interp_status = mb_linear_interp(verbose, nav_time_d-1, nav_sonardepth-1, nnav, time_d, &sonardepth, &j, &error); if (interp_status == MB_SUCCESS) interp_status = mb_linear_interp(verbose, nav_time_d-1, nav_altitude-1, nnav, time_d, &altitude, &j, &error); if (interp_status == MB_SUCCESS) interp_status = mb_linear_interp(verbose, nav_time_d-1, nav_speed-1, nnav, time_d, &speed, &j, &error); /* only output if interpolation of nav etc has worked */ if (interp_status == MB_YES) { /* calculate course made good and distance */ mb_coor_scale(verbose,navlat, &mtodeglon, &mtodeglat); headingx = sin(DTR * heading); headingy = cos(DTR * heading); if (first == MB_YES) { time_interval = 0.0; course = heading; speed_made_good = 0.0; course_old = heading; speed_made_good_old = speed; distance = 0.0; } else { time_interval = time_d - time_d_old; dx = (navlon - navlon_old)/mtodeglon; dy = (navlat - navlat_old)/mtodeglat; distance = sqrt(dx*dx + dy*dy); if (distance > 0.0) course = RTD*atan2(dx/distance,dy/distance); else course = course_old; if (course < 0.0) course = course + 360.0; if (time_interval > 0.0) speed_made_good = 3.6*distance/time_interval; else speed_made_good = speed_made_good_old; } distance_total += 0.001 * distance; /* reset old values */ navlon_old = navlon; navlat_old = navlat; course_old = course; speed_made_good_old = speed_made_good; time_d_old = time_d; /* now loop over list of output parameters */ ctd_count++; ctd_count_tot++; if (nctd % decimate == 0) for (i=0; i<n_list; i++) { switch (list[i]) { case '/': /* Inverts next simple value */ invert_next_value = MB_YES; break; case '-': /* Flip sign on next simple value */ signflip_next_value = MB_YES; break; case '^': /* use mblist definitions of CcSsTt */ mblist_next_value = MB_YES; break; case '1': /* Sensor 1 - volts */ printsimplevalue(verbose, sensor1[ictd], 0, 3, ascii, &invert_next_value, &signflip_next_value, &error); break; case '2': /* Sensor 2 - volts */ printsimplevalue(verbose, sensor2[ictd], 0, 3, ascii, &invert_next_value, &signflip_next_value, &error); break; case '3': /* Sensor 3 - volts */ printsimplevalue(verbose, sensor3[ictd], 0, 3, ascii, &invert_next_value, &signflip_next_value, &error); break; case '4': /* Sensor 4 - volts */ printsimplevalue(verbose, sensor4[ictd], 0, 3, ascii, &invert_next_value, &signflip_next_value, &error); break; case '5': /* Sensor 5 - volts */ printsimplevalue(verbose, sensor5[ictd], 0, 3, ascii, &invert_next_value, &signflip_next_value, &error); break; case '6': /* Sensor 6 - volts */ printsimplevalue(verbose, sensor6[ictd], 0, 3, ascii, &invert_next_value, &signflip_next_value, &error); break; case '7': /* Sensor 7 - volts */ printsimplevalue(verbose, sensor7[ictd], 0, 3, ascii, &invert_next_value, &signflip_next_value, &error); break; case '8': /* Sensor 8 - volts */ printsimplevalue(verbose, sensor8[ictd], 0, 3, ascii, &invert_next_value, &signflip_next_value, &error); break; case 'C': /* Conductivity or Sonar altitude (m) */ if (mblist_next_value == MB_NO) printsimplevalue(verbose, conductivity, 0, 5, ascii, &invert_next_value, &signflip_next_value, &error); else { printsimplevalue(verbose, altitude, 0, 3, ascii, &invert_next_value, &signflip_next_value, &error); mblist_next_value = MB_NO; } break; case 'c': /* Temperature or sonar transducer depth (m) */ if (mblist_next_value == MB_NO) printsimplevalue(verbose, temperature, 0, 5, ascii, &invert_next_value, &signflip_next_value, &error); else { printsimplevalue(verbose, sonardepth, 0, 3, ascii, &invert_next_value, &signflip_next_value, &error); mblist_next_value = MB_NO; } break; case 'H': /* heading */ printsimplevalue(verbose, heading, 6, 2, ascii, &invert_next_value, &signflip_next_value, &error); break; case 'h': /* course */ printsimplevalue(verbose, course, 6, 2, ascii, &invert_next_value, &signflip_next_value, &error); break; case 'J': /* time string */ mb_get_jtime(verbose,time_i,time_j); seconds = time_i[5] + 0.000001 * time_i[6]; if (ascii == MB_YES) { printf("%.4d %.3d %.2d %.2d %9.6f", time_j[0],time_j[1], time_i[3],time_i[4], seconds); } else { b = time_j[0]; fwrite(&b, sizeof(double), 1, stdout); b = time_j[1]; fwrite(&b, sizeof(double), 1, stdout); b = time_i[3]; fwrite(&b, sizeof(double), 1, stdout); b = time_i[4]; fwrite(&b, sizeof(double), 1, stdout); b = time_i[5]; fwrite(&b, sizeof(double), 1, stdout); b = time_i[6]; fwrite(&b, sizeof(double), 1, stdout); } break; case 'j': /* time string */ mb_get_jtime(verbose,time_i,time_j); seconds = time_i[5] + 0.000001 * time_i[6]; if (ascii == MB_YES) { printf("%.4d %.3d %.4d %9.6f", time_j[0],time_j[1], time_j[2],seconds); } else { b = time_j[0]; fwrite(&b, sizeof(double), 1, stdout); b = time_j[1]; fwrite(&b, sizeof(double), 1, stdout); b = time_j[2]; fwrite(&b, sizeof(double), 1, stdout); b = time_j[3]; fwrite(&b, sizeof(double), 1, stdout); b = time_j[4]; fwrite(&b, sizeof(double), 1, stdout); } break; case 'L': /* along-track distance (km) */ printsimplevalue(verbose, distance_total, 7, 3, ascii, &invert_next_value, &signflip_next_value, &error); break; case 'l': /* along-track distance (m) */ printsimplevalue(verbose, 1000.0 * distance_total, 7, 3, ascii, &invert_next_value, &signflip_next_value, &error); break; case 'M': /* Decimal unix seconds since 1/1/70 00:00:00 */ printsimplevalue(verbose, time_d, 0, 6, ascii, &invert_next_value, &signflip_next_value, &error); break; case 'm': /* time in decimal seconds since first record */ if (first_m == MB_YES) { time_d_ref = time_d; first_m = MB_NO; } b = time_d - time_d_ref; printsimplevalue(verbose, b, 0, 6, ascii, &invert_next_value, &signflip_next_value, &error); break; case 'P': /* potential temperature (degrees) */ /* approximation taken from http://mason.gmu.edu/~bklinger/seawater.pdf on 4/25/2012 - to be replaced by a better calculation at some point */ potentialtemperature = temperature - 0.04 * (1.0 + 0.185 * temperature + 0.35 * (salinity - 35.0)) * (sonardepth / 1000.0) - 0.0075 * (1.0 - temperature / 30.0) * (sonardepth * sonardepth / 1000000.0); printsimplevalue(verbose, potentialtemperature, 0, 5, ascii, &invert_next_value, &signflip_next_value, &error); break; case 'S': /* salinity or speed */ if (mblist_next_value == MB_NO) printsimplevalue(verbose, salinity, 0, 5, ascii, &invert_next_value, &signflip_next_value, &error); else { printsimplevalue(verbose, speed, 5, 2, ascii, &invert_next_value, &signflip_next_value, &error); mblist_next_value = MB_NO; } break; case 's': /* speed made good */ if (mblist_next_value == MB_NO) printsimplevalue(verbose, soundspeed, 0, 3, ascii, &invert_next_value, &signflip_next_value, &error); else { printsimplevalue(verbose, speed_made_good, 5, 2, ascii, &invert_next_value, &signflip_next_value, &error); mblist_next_value = MB_NO; } break; case 'T': /* yyyy/mm/dd/hh/mm/ss time string */ seconds = time_i[5] + 1e-6 * time_i[6]; if (ascii == MB_YES) printf("%.4d/%.2d/%.2d/%.2d/%.2d/%9.6f", time_i[0],time_i[1],time_i[2], time_i[3],time_i[4],seconds); else { b = time_i[0]; fwrite(&b, sizeof(double), 1, stdout); b = time_i[1]; fwrite(&b, sizeof(double), 1, stdout); b = time_i[2]; fwrite(&b, sizeof(double), 1, stdout); b = time_i[3]; fwrite(&b, sizeof(double), 1, stdout); b = time_i[4]; fwrite(&b, sizeof(double), 1, stdout); b = seconds; fwrite(&b, sizeof(double), 1, stdout); } break; case 't': /* yyyy mm dd hh mm ss time string */ seconds = time_i[5] + 1e-6 * time_i[6]; if (ascii == MB_YES) printf("%.4d %.2d %.2d %.2d %.2d %9.6f", time_i[0],time_i[1],time_i[2], time_i[3],time_i[4],seconds); else { b = time_i[0]; fwrite(&b, sizeof(double), 1, stdout); b = time_i[1]; fwrite(&b, sizeof(double), 1, stdout); b = time_i[2]; fwrite(&b, sizeof(double), 1, stdout); b = time_i[3]; fwrite(&b, sizeof(double), 1, stdout); b = time_i[4]; fwrite(&b, sizeof(double), 1, stdout); b = seconds; fwrite(&b, sizeof(double), 1, stdout); } break; case 'U': /* unix time in seconds since 1/1/70 00:00:00 */ time_u = (int) time_d; if (ascii == MB_YES) printf("%ld",time_u); else { b = time_u; fwrite(&b, sizeof(double), 1, stdout); } break; case 'u': /* time in seconds since first record */ time_u = (int) time_d; if (first_u == MB_YES) { time_u_ref = time_u; first_u = MB_NO; } if (ascii == MB_YES) printf("%ld",time_u - time_u_ref); else { b = time_u - time_u_ref; fwrite(&b, sizeof(double), 1, stdout); } break; case 'V': /* time in seconds since last value */ case 'v': if (ascii == MB_YES) { if ( fabs(time_interval) > 100. ) printf("%g",time_interval); else printf("%7.3f",time_interval); } else { fwrite(&time_interval, sizeof(double), 1, stdout); } break; case 'X': /* longitude decimal degrees */ dlon = navlon; printsimplevalue(verbose, dlon, 11, 6, ascii, &invert_next_value, &signflip_next_value, &error); break; case 'x': /* longitude degress + decimal minutes */ dlon = navlon; if (dlon < 0.0) { hemi = 'W'; dlon = -dlon; } else hemi = 'E'; degrees = (int) dlon; minutes = 60.0*(dlon - degrees); if (ascii == MB_YES) { printf("%3d %8.5f%c", degrees, minutes, hemi); } else { b = degrees; if (hemi == 'W') b = -b; fwrite(&b, sizeof(double), 1, stdout); b = minutes; fwrite(&b, sizeof(double), 1, stdout); } break; case 'Y': /* latitude decimal degrees */ dlat = navlat; printsimplevalue(verbose, dlat, 11, 6, ascii, &invert_next_value, &signflip_next_value, &error); break; case 'y': /* latitude degrees + decimal minutes */ dlat = navlat; if (dlat < 0.0) { hemi = 'S'; dlat = -dlat; } else hemi = 'N'; degrees = (int) dlat; minutes = 60.0*(dlat - degrees); if (ascii == MB_YES) { printf("%3d %8.5f%c", degrees, minutes, hemi); } else { b = degrees; if (hemi == 'S') b = -b; fwrite(&b, sizeof(double), 1, stdout); b = minutes; fwrite(&b, sizeof(double), 1, stdout); } break; default: if (ascii == MB_YES) printf("<Invalid Option: %c>", list[i]); break; } if (ascii == MB_YES) { if (i<(n_list-1)) printf ("%s", delimiter); else printf ("\n"); } } first = MB_NO; } } } } /* else if survey data ignore */ else if (error <= MB_ERROR_NO_ERROR && kind == MB_DATA_DATA) { } } /* close the swath file */ status = mb_close(verbose,&mbio_ptr,&error); /* output info */ if (verbose >= 1) { fprintf(stderr, "%d CTD records\n", ctd_count); } /* figure out whether and what to read next */ if (read_datalist == MB_YES) { if ((status = mb_datalist_read(verbose,datalist, file,&format,&file_weight,&error)) == MB_SUCCESS) read_data = MB_YES; else read_data = MB_NO; } else { read_data = MB_NO; } /* end loop over files in list */ } if (read_datalist == MB_YES) mb_datalist_close(verbose,&datalist,&error); /* output info */ if (verbose >= 1) { fprintf(stderr, "\nTotal %d CTD records\n", ctd_count_tot); } /* deallocate navigation arrays */ if (nnav > 0) { status = mb_freed(verbose,__FILE__,__LINE__,(void **)&nav_time_d,&error); status = mb_freed(verbose,__FILE__,__LINE__,(void **)&nav_lon,&error); status = mb_freed(verbose,__FILE__,__LINE__,(void **)&nav_lat,&error); status = mb_freed(verbose,__FILE__,__LINE__,(void **)&nav_speed,&error); status = mb_freed(verbose,__FILE__,__LINE__,(void **)&nav_sonardepth,&error); status = mb_freed(verbose,__FILE__,__LINE__,(void **)&nav_heading,&error); status = mb_freed(verbose,__FILE__,__LINE__,(void **)&nav_altitude,&error); } /* check memory */ if (verbose >= 4) status = mb_memory_list(verbose,&error); /* print output debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Program <%s> completed\n", program_name); fprintf(stderr,"dbg2 Ending status:\n"); fprintf(stderr,"dbg2 status: %d\n",status); } /* end it all */ exit(error); }
int main (int argc, char **argv) { char program_name[] = "MBroutetime"; char help_message[] = "MBroutetime outputs a list of the times when a survey hit the waypoints\nof a planned survey route. This (lon lat time_d) list can then be used by mbextractsegy\nor mb7k2ss to extract subbottom (or sidescan) data into files corresponding\nto the lines between waypoints."; char usage_message[] = "mbroutetime -Rroutefile [-Fformat -Ifile -Owaypointtimefile -Urangethreshold -H -V]"; extern char *optarg; int errflg = 0; int c; int help = 0; int flag = 0; /* MBIO status variables */ int status = MB_SUCCESS; int verbose = 0; int error = MB_ERROR_NO_ERROR; char *message; /* MBIO read control parameters */ int read_datalist = MB_NO; char read_file[MB_PATH_MAXLINE]; char output_file[MB_PATH_MAXLINE]; int output_file_set = MB_NO; void *datalist; int look_processed = MB_DATALIST_LOOK_UNSET; double file_weight; int format; int pings; int lonflip; double bounds[4]; int btime_i[7]; int etime_i[7]; double btime_d; double etime_d; double speedmin; double timegap; char file[MB_PATH_MAXLINE]; int beams_bath; int beams_amp; int pixels_ss; /* MBIO read values */ void *mbio_ptr = NULL; void *store_ptr = NULL; int kind; int time_i[7]; double time_d; double navlon; double navlat; double speed; double heading; double distance; double altitude; double sonardepth; char *beamflag = NULL; double *bath = NULL; double *bathacrosstrack = NULL; double *bathalongtrack = NULL; double *amp = NULL; double *ss = NULL; double *ssacrosstrack = NULL; double *ssalongtrack = NULL; char comment[MB_COMMENT_MAXLINE]; /* route and auto-line data */ char route_file[MB_PATH_MAXLINE]; int rawroutefile = MB_NO; int nroutepoint = 0; int nroutepointfound = 0; int nroutepointalloc = 0; double lon; double lat; double topo; int waypoint; double *routelon = NULL; double *routelat = NULL; double *routeheading = NULL; int *routewaypoint = NULL; double *routetime_d = NULL; double range; double rangethreshold = 25.0; double rangelast; int activewaypoint = 0; double mtodeglon, mtodeglat; double lastlon; double lastlat; double lastheading; double lasttime_d; double dx, dy; FILE *fp = NULL; char *result; int nget; int point_ok; int read_data; int nread; int i; /* get current default values */ status = mb_defaults(verbose,&format,&pings,&lonflip,bounds, btime_i,etime_i,&speedmin,&timegap); /* set default input to datalist.mb-1 */ strcpy (read_file, "datalist.mb-1"); /* process argument list */ while ((c = getopt(argc, argv, "F:f:I:i:O:o:R:r:U:u:VvHh")) != -1) switch (c) { case 'H': case 'h': help++; break; case 'V': case 'v': verbose++; break; case 'F': case 'f': sscanf (optarg,"%d", &format); flag++; break; case 'I': case 'i': sscanf (optarg,"%s", read_file); flag++; break; case 'O': case 'o': sscanf (optarg,"%s", output_file); output_file_set = MB_YES; flag++; break; case 'R': case 'r': sscanf (optarg,"%s", route_file); flag++; break; case 'U': case 'u': sscanf (optarg,"%lf", &rangethreshold); flag++; break; case '?': errflg++; } /* if error flagged then print it and exit */ if (errflg) { fprintf(stderr,"usage: %s\n", usage_message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); error = MB_ERROR_BAD_USAGE; exit(error); } /* print starting message */ if (verbose == 1 || help) { fprintf(stderr,"\nProgram %s\n",program_name); fprintf(stderr,"Version %s\n",rcs_id); fprintf(stderr,"MB-system Version %s\n",MB_VERSION); } /* print starting debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Program <%s>\n",program_name); fprintf(stderr,"dbg2 Version %s\n",rcs_id); fprintf(stderr,"dbg2 MB-system Version %s\n",MB_VERSION); fprintf(stderr,"dbg2 Control Parameters:\n"); fprintf(stderr,"dbg2 verbose: %d\n",verbose); fprintf(stderr,"dbg2 help: %d\n",help); fprintf(stderr,"dbg2 format: %d\n",format); fprintf(stderr,"dbg2 pings: %d\n",pings); fprintf(stderr,"dbg2 lonflip: %d\n",lonflip); fprintf(stderr,"dbg2 bounds[0]: %f\n",bounds[0]); fprintf(stderr,"dbg2 bounds[1]: %f\n",bounds[1]); fprintf(stderr,"dbg2 bounds[2]: %f\n",bounds[2]); fprintf(stderr,"dbg2 bounds[3]: %f\n",bounds[3]); fprintf(stderr,"dbg2 btime_i[0]: %d\n",btime_i[0]); fprintf(stderr,"dbg2 btime_i[1]: %d\n",btime_i[1]); fprintf(stderr,"dbg2 btime_i[2]: %d\n",btime_i[2]); fprintf(stderr,"dbg2 btime_i[3]: %d\n",btime_i[3]); fprintf(stderr,"dbg2 btime_i[4]: %d\n",btime_i[4]); fprintf(stderr,"dbg2 btime_i[5]: %d\n",btime_i[5]); fprintf(stderr,"dbg2 btime_i[6]: %d\n",btime_i[6]); fprintf(stderr,"dbg2 etime_i[0]: %d\n",etime_i[0]); fprintf(stderr,"dbg2 etime_i[1]: %d\n",etime_i[1]); fprintf(stderr,"dbg2 etime_i[2]: %d\n",etime_i[2]); fprintf(stderr,"dbg2 etime_i[3]: %d\n",etime_i[3]); fprintf(stderr,"dbg2 etime_i[4]: %d\n",etime_i[4]); fprintf(stderr,"dbg2 etime_i[5]: %d\n",etime_i[5]); fprintf(stderr,"dbg2 etime_i[6]: %d\n",etime_i[6]); fprintf(stderr,"dbg2 speedmin: %f\n",speedmin); fprintf(stderr,"dbg2 timegap: %f\n",timegap); fprintf(stderr,"dbg2 read_file: %s\n",read_file); fprintf(stderr,"dbg2 route_file: %s\n",route_file); fprintf(stderr,"dbg2 output_file_set: %d\n",output_file_set); fprintf(stderr,"dbg2 output_file: %s\n",output_file); fprintf(stderr,"dbg2 rangethreshold: %f\n",rangethreshold); } /* if help desired then print it and exit */ if (help) { fprintf(stderr,"\n%s\n",help_message); fprintf(stderr,"\nusage: %s\n", usage_message); exit(error); } /* read route file */ if ((fp = fopen(route_file, "r")) == NULL) { error = MB_ERROR_OPEN_FAIL; status = MB_FAILURE; fprintf(stderr,"\nUnable to open route file <%s> for reading\n",route_file); exit(status); } rawroutefile = MB_NO; while ((result = fgets(comment,MB_PATH_MAXLINE,fp)) == comment) { if (comment[0] == '#') { if (strncmp(comment,"## Route File Version", 21) == 0) { rawroutefile = MB_NO; } } else { nget = sscanf(comment,"%lf %lf %lf %d %lf", &lon, &lat, &topo, &waypoint, &heading); if (comment[0] == '#') { fprintf(stderr,"buffer:%s",comment); if (strncmp(comment,"## Route File Version", 21) == 0) { rawroutefile = MB_NO; } } if ((rawroutefile == MB_YES && nget >= 2) || (rawroutefile == MB_NO && nget >= 3 && waypoint > MBES_ROUTE_WAYPOINT_TRANSIT)) point_ok = MB_YES; else point_ok = MB_NO; /* if good data check for need to allocate more space */ if (point_ok == MB_YES && nroutepoint + 2 > nroutepointalloc) { nroutepointalloc += MBES_ALLOC_NUM; status = mb_reallocd(verbose, __FILE__, __LINE__, nroutepointalloc * sizeof(double), (void **)&routelon, &error); status = mb_reallocd(verbose, __FILE__, __LINE__, nroutepointalloc * sizeof(double), (void **)&routelat, &error); status = mb_reallocd(verbose, __FILE__, __LINE__, nroutepointalloc * sizeof(double), (void **)&routeheading, &error); status = mb_reallocd(verbose, __FILE__, __LINE__, nroutepointalloc * sizeof(int), (void **)&routewaypoint, &error); status = mb_reallocd(verbose, __FILE__, __LINE__, nroutepointalloc * sizeof(double), (void **)&routetime_d, &error); if (status != MB_SUCCESS) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error allocating data arrays:\n%s\n", message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } } /* add good point to route */ if (point_ok == MB_YES && nroutepointalloc > nroutepoint) { routelon[nroutepoint] = lon; routelat[nroutepoint] = lat; routeheading[nroutepoint] = heading; routewaypoint[nroutepoint] = waypoint; routetime_d[nroutepoint] = 0.0; nroutepoint++; } } } /* close the file */ fclose(fp); fp = NULL; /* Check that there are valid waypoints in memory */ if (nroutepoint < 1) { error = MB_ERROR_EOF; status = MB_FAILURE; fprintf(stderr,"\nNo line start or line end waypoints read from route file: <%s>\n",route_file); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } else if (nroutepoint < 2) { error = MB_ERROR_EOF; status = MB_FAILURE; fprintf(stderr,"\nOnly one line start or line end waypoint read from route file: <%s>\n",route_file); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* set starting values */ activewaypoint = 0; mb_coor_scale(verbose,routelat[activewaypoint], &mtodeglon, &mtodeglat); rangelast = 1000 * rangethreshold; /* output status */ if (verbose > 0) { /* output info on file output */ fprintf(stderr,"Read %d waypoints from route file: %s\n", nroutepoint, route_file); } /* get format if required */ if (format == 0) mb_get_format(verbose,read_file,NULL,&format,&error); /* determine whether to read one file or a list of files */ if (format < 0) read_datalist = MB_YES; /* open file list */ if (read_datalist == MB_YES) { if ((status = mb_datalist_open(verbose,&datalist, read_file,look_processed,&error)) != MB_SUCCESS) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open data list file: %s\n", read_file); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } if ((status = mb_datalist_read(verbose,datalist, file,&format,&file_weight,&error)) == MB_SUCCESS) read_data = MB_YES; else read_data = MB_NO; } /* else copy single filename to be read */ else { strcpy(file, read_file); read_data = MB_YES; } /* loop over all files to be read */ while (read_data == MB_YES) { /* read fnv file if possible */ mb_get_fnv(verbose, file, &format, &error); /* initialize reading the swath file */ if ((status = mb_read_init( verbose,file,format,pings,lonflip,bounds, btime_i,etime_i,speedmin,timegap, &mbio_ptr,&btime_d,&etime_d, &beams_bath,&beams_amp,&pixels_ss,&error)) != MB_SUCCESS) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error returned from function <mb_read_init>:\n%s\n",message); fprintf(stderr,"\nMultibeam File <%s> not initialized for reading\n",file); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* allocate memory for data arrays */ if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(char), (void **)&beamflag, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bath, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_AMPLITUDE, sizeof(double), (void **)&, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bathacrosstrack, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bathalongtrack, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&ss, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&ssacrosstrack, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&ssalongtrack, &error); /* if error initializing memory then quit */ if (error != MB_ERROR_NO_ERROR) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error allocating data arrays:\n%s\n", message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* read and use data */ nread = 0; while (error <= MB_ERROR_NO_ERROR && activewaypoint < nroutepoint) { /* reset error */ error = MB_ERROR_NO_ERROR; /* read next data record */ status = mb_get_all(verbose,mbio_ptr,&store_ptr,&kind, time_i,&time_d,&navlon,&navlat, &speed,&heading, &distance,&altitude,&sonardepth, &beams_bath,&beams_amp,&pixels_ss, beamflag,bath,amp,bathacrosstrack,bathalongtrack, ss,ssacrosstrack,ssalongtrack, comment,&error); /* deal with nav and time from survey data only - not nav, sidescan, or subbottom */ if (error <= MB_ERROR_NO_ERROR && kind == MB_DATA_DATA) { /* increment counter */ nread++; /* save last nav and heading */ if (navlon != 0.0) lastlon = navlon; if (navlat != 0.0) lastlat = navlat; if (heading != 0.0) lastheading = heading; if (time_d != 0.0) lasttime_d = time_d; /* check survey data position against waypoints */ if (navlon != 0.0 && navlat != 0.0) { dx = (navlon - routelon[activewaypoint]) / mtodeglon; dy = (navlat - routelat[activewaypoint]) / mtodeglat; range = sqrt(dx * dx + dy * dy); if (verbose > 0) fprintf(stderr,"> activewaypoint:%d time_d:%f range:%f lon: %f %f lat: %f %f\n", activewaypoint, time_d, range, navlon, routelon[activewaypoint], navlat, routelat[activewaypoint]); if (range < rangethreshold && (activewaypoint == 0 || range > rangelast) && activewaypoint < nroutepoint) { fprintf(stderr,"Waypoint %d of %d found with range %f m\n", activewaypoint, nroutepoint, range); routetime_d[activewaypoint] = time_d; activewaypoint++; nroutepointfound++; mb_coor_scale(verbose,routelat[activewaypoint], &mtodeglon, &mtodeglat); rangelast = 1000 * rangethreshold; } else rangelast = range; } } /* print debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Ping read in program <%s>\n", program_name); fprintf(stderr,"dbg2 kind: %d\n",kind); fprintf(stderr,"dbg2 error: %d\n",error); fprintf(stderr,"dbg2 status: %d\n",status); } } /* close the swath file */ status = mb_close(verbose,&mbio_ptr,&error); /* output read statistics */ fprintf(stderr,"%d records read from %s\n", nread, file); /* figure out whether and what to read next */ if (read_datalist == MB_YES) { if ((status = mb_datalist_read(verbose,datalist, file,&format,&file_weight,&error)) == MB_SUCCESS) read_data = MB_YES; else read_data = MB_NO; } else { read_data = MB_NO; } /* end loop over files in list */ } if (read_datalist == MB_YES) mb_datalist_close(verbose,&datalist,&error); /* if the last route point was not reached, add one last waypoint */ if (nroutepointfound < nroutepoint) { fprintf(stderr,"Waypoint %d of %d set at end of data with range %f m to next specified waypoint\n", activewaypoint, nroutepoint, range); routelon[nroutepointfound] = lastlon; routelat[nroutepointfound] = lastlat; routeheading[nroutepointfound] = lastheading; routetime_d[nroutepointfound] = lasttime_d; routewaypoint[nroutepointfound] = MBES_ROUTE_WAYPOINT_ENDLINE; nroutepointfound++; } /* output time list for the route */ if (output_file_set == MB_NO) { sprintf(output_file, "%s_wpttime_d.txt", read_file); } if ((fp = fopen(output_file, "w")) == NULL) { error = MB_ERROR_OPEN_FAIL; status = MB_FAILURE; fprintf(stderr,"\nUnable to open output waypoint time list file <%s> for writing\n",output_file); exit(status); } for (i=0;i<nroutepointfound;i++) { fprintf(fp,"%3d %3d %11.6f %10.6f %10.6f %.6f\n", i, routewaypoint[i], routelon[i], routelat[i], routeheading[i], routetime_d[i]); if (verbose > 0) fprintf(stderr,"%3d %3d %11.6f %10.6f %10.6f %.6f\n", i, routewaypoint[i], routelon[i], routelat[i], routeheading[i], routetime_d[i]); } fclose(fp); /* deallocate route arrays */ status = mb_freed(verbose,__FILE__,__LINE__, (void **)&routelon, &error); status = mb_freed(verbose,__FILE__,__LINE__, (void **)&routelat, &error); status = mb_freed(verbose,__FILE__,__LINE__, (void **)&routeheading, &error); status = mb_freed(verbose,__FILE__,__LINE__, (void **)&routewaypoint, &error); status = mb_freed(verbose,__FILE__,__LINE__, (void **)&routetime_d, &error); /* check memory */ if (verbose >= 4) status = mb_memory_list(verbose,&error); /* print output debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Program <%s> completed\n", program_name); fprintf(stderr,"dbg2 Ending status:\n"); fprintf(stderr,"dbg2 status: %d\n",status); } /* end it all */ exit(error); }
/*------------------------------------------------------------------------------*/ int mbview_allocprofilearrays(int verbose, int npoints, double **distance, double **zdata, int **boundary, double **xlon, double **ylat, double **distovertopo, double **bearing, double **slope, int *error) { /* local variables */ char *function_name = "mbview_allocprofilearrays"; int status = MB_SUCCESS; /* print starting debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBIO function <%s> called\n", function_name); fprintf(stderr,"dbg2 MB-system Version %s\n",MB_VERSION); fprintf(stderr,"dbg2 Input arguments:\n"); fprintf(stderr,"dbg2 verbose: %d\n", verbose); fprintf(stderr,"dbg2 npoints: %d\n", npoints); fprintf(stderr,"dbg2 distance: %lu\n", (size_t)*distance); fprintf(stderr,"dbg2 zdata: %lu\n", (size_t)*zdata); fprintf(stderr,"dbg2 boundary: %lu\n", (size_t)*boundary); fprintf(stderr,"dbg2 xlon: %lu\n", (size_t)*xlon); fprintf(stderr,"dbg2 ylat: %lu\n", (size_t)*ylat); fprintf(stderr,"dbg2 distovertopo: %lu\n", (size_t)*distovertopo); fprintf(stderr,"dbg2 bearing: %lu\n", (size_t)*bearing); fprintf(stderr,"dbg2 slope: %lu\n", (size_t)*slope); } /* allocate the arrays using mb_realloc */ status = mb_reallocd(verbose, __FILE__, __LINE__, npoints * sizeof(double), (void **)distance,error); status = mb_reallocd(verbose, __FILE__, __LINE__, npoints * sizeof(double), (void **)zdata,error); status = mb_reallocd(verbose, __FILE__, __LINE__, npoints * sizeof(double), (void **)boundary,error); status = mb_reallocd(verbose, __FILE__, __LINE__, npoints * sizeof(double), (void **)xlon,error); status = mb_reallocd(verbose, __FILE__, __LINE__, npoints * sizeof(double), (void **)ylat,error); status = mb_reallocd(verbose, __FILE__, __LINE__, npoints * sizeof(double), (void **)distovertopo,error); status = mb_reallocd(verbose, __FILE__, __LINE__, npoints * sizeof(double), (void **)bearing,error); status = mb_reallocd(verbose, __FILE__, __LINE__, npoints * sizeof(double), (void **)slope,error); /* print output debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBIO function <%s> completed\n", function_name); fprintf(stderr,"dbg2 Return values:\n"); fprintf(stderr,"dbg2 distance: %lu\n", (size_t)*distance); fprintf(stderr,"dbg2 zdata: %lu\n", (size_t)*zdata); fprintf(stderr,"dbg2 boundary: %lu\n", (size_t)*boundary); fprintf(stderr,"dbg2 xlon: %lu\n", (size_t)*xlon); fprintf(stderr,"dbg2 ylat: %lu\n", (size_t)*ylat); fprintf(stderr,"dbg2 distovertopo: %lu\n", (size_t)*distovertopo); fprintf(stderr,"dbg2 bearing: %lu\n", (size_t)*bearing); fprintf(stderr,"dbg2 slope: %lu\n", (size_t)*slope); fprintf(stderr,"dbg2 error: %d\n", *error); fprintf(stderr,"dbg2 Return status:\n"); fprintf(stderr,"dbg2 status: %d\n", status); } /* return */ return(status); }
/*--------------------------------------------------------------------*/ int mbsys_stereopair_insert(int verbose, void *mbio_ptr, void *store_ptr, int kind, int time_i[7], double time_d, double navlon, double navlat, double speed, double heading, int nbath, int namp, int nss, char *beamflag, double *bath, double *amp, double *bathacrosstrack, double *bathalongtrack, double *ss, double *ssacrosstrack, double *ssalongtrack, char *comment, int *error) { char *function_name = "mbsys_stereopair_insert"; int status = MB_SUCCESS; struct mb_io_struct *mb_io_ptr; struct mbsys_stereopair_struct *store; struct mbsys_stereopair_sounding_struct *sounding; int i; /* print input debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBIO function <%s> called\n",function_name); fprintf(stderr,"dbg2 Revision id: %s\n",version_id); fprintf(stderr,"dbg2 Input arguments:\n"); fprintf(stderr,"dbg2 verbose: %d\n",verbose); fprintf(stderr,"dbg2 mbio_ptr: %p\n",(void *)mbio_ptr); fprintf(stderr,"dbg2 store_ptr: %p\n",(void *)store_ptr); fprintf(stderr,"dbg2 kind: %d\n",kind); } if (verbose >= 2 && kind == MB_DATA_COMMENT) { fprintf(stderr,"dbg2 comment: \ndbg2 %s\n", comment); } if (verbose >= 2 && (kind != MB_DATA_COMMENT)) { fprintf(stderr,"dbg2 time_i[0]: %d\n",time_i[0]); fprintf(stderr,"dbg2 time_i[1]: %d\n",time_i[1]); fprintf(stderr,"dbg2 time_i[2]: %d\n",time_i[2]); fprintf(stderr,"dbg2 time_i[3]: %d\n",time_i[3]); fprintf(stderr,"dbg2 time_i[4]: %d\n",time_i[4]); fprintf(stderr,"dbg2 time_i[5]: %d\n",time_i[5]); fprintf(stderr,"dbg2 time_i[6]: %d\n",time_i[6]); fprintf(stderr,"dbg2 time_d: %f\n",time_d); } if (verbose >= 2 && (kind == MB_DATA_DATA || kind == MB_DATA_NAV)) { fprintf(stderr,"dbg2 navlon: %f\n",navlon); fprintf(stderr,"dbg2 navlat: %f\n",navlat); fprintf(stderr,"dbg2 speed: %f\n",speed); fprintf(stderr,"dbg2 heading: %f\n",heading); } if (verbose >= 2 && kind == MB_DATA_DATA) { fprintf(stderr,"dbg2 nbath: %d\n",nbath); if (verbose >= 3) for (i=0;i<nbath;i++) fprintf(stderr,"dbg3 beam:%d flag:%3d bath:%f acrosstrack:%f alongtrack:%f\n", i,beamflag[i],bath[i], bathacrosstrack[i],bathalongtrack[i]); fprintf(stderr,"dbg2 namp: %d\n",namp); if (verbose >= 3) for (i=0;i<namp;i++) fprintf(stderr,"dbg3 beam:%d amp:%f acrosstrack:%f alongtrack:%f\n", i,amp[i],bathacrosstrack[i],bathalongtrack[i]); fprintf(stderr,"dbg2 nss: %d\n",nss); if (verbose >= 3) for (i=0;i<nss;i++) fprintf(stderr,"dbg3 beam:%d ss:%f acrosstrack:%f alongtrack:%f\n", i,ss[i],ssacrosstrack[i],ssalongtrack[i]); } /* get mbio descriptor */ mb_io_ptr = (struct mb_io_struct *) mbio_ptr; /* get data structure pointer */ store = (struct mbsys_stereopair_struct *) store_ptr; /* set data kind */ store->kind = kind; /* insert data in structure */ if (store->kind == MB_DATA_DATA) { /* get time */ store->time_d = time_d; /* get navigation */ store->longitude = navlon; store->latitude = navlat; /* get heading */ store->heading = heading; /* get speed */ store->speed = speed / 3.6; /* allocate space for soundings if required */ if (nbath > store->num_soundings_alloc) { /* allocate memory for data structure */ status = mb_reallocd(verbose, __FILE__, __LINE__, nbath * sizeof(struct mbsys_stereopair_sounding_struct), (void **)(&store->soundings), error); if (status == MB_SUCCESS) store->num_soundings_alloc = nbath; else store->num_soundings_alloc = 0; } /* read distance and depth values into storage arrays */ store->num_soundings = nbath; for (i=0;i<store->num_soundings;i++) { sounding = (struct mbsys_stereopair_sounding_struct *) &store->soundings[i]; sounding->depth = bath[i] - store->sensordepth; sounding->beamflag = beamflag[i]; sounding->acrosstrack = bathacrosstrack[i]; sounding->alongtrack = bathalongtrack[i]; sounding->red = 0; sounding->green = 0; sounding->blue = 0; } /* insert the sidescan */ } /* insert data in nav structure */ else if (store->kind == MB_DATA_NAV) { /* get time */ store->time_d = time_d; /* get navigation */ store->longitude = navlon; store->latitude = navlat; /* get heading */ store->heading = heading; /* get speed */ store->speed = speed / 3.6; } /* insert comment in structure */ else if (store->kind == MB_DATA_COMMENT) { strncpy(store->comment, comment, MB_COMMENT_MAXLINE); store->comment_len = strlen(store->comment) + 1; store->comment_len += 4 - (store->comment_len % 4); } /* print output debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBIO function <%s> completed\n",function_name); fprintf(stderr,"dbg2 Return value:\n"); fprintf(stderr,"dbg2 error: %d\n",*error); fprintf(stderr,"dbg2 Return status:\n"); fprintf(stderr,"dbg2 status: %d\n",status); } /* return status */ return(status); }
/*--------------------------------------------------------------------*/ int mbr_rt_swplssxi(int verbose, void *mbio_ptr, void *store_ptr, int *error) { char *function_name = "mbr_rt_swplssxi"; int status = MB_SUCCESS; struct mb_io_struct *mb_io_ptr; struct mbsys_swathplus_struct *store; swpls_projection *projection; /* print input debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> called\n", function_name); fprintf(stderr, "dbg2 Input arguments:\n"); fprintf(stderr, "dbg2 verbose: %d\n", verbose); fprintf(stderr, "dbg2 mbio_ptr: %p\n", (void *)mbio_ptr); fprintf(stderr, "dbg2 store_ptr: %p\n", (void *)store_ptr); } /* get pointers to mbio descriptor */ mb_io_ptr = (struct mb_io_struct *)mbio_ptr; /* read next data from file */ status = mbr_swplssxi_rd_data(verbose, mbio_ptr, store_ptr, error); /* get pointers to data structures */ store = (struct mbsys_swathplus_struct *)store_ptr; projection = &store->projection; /* check if projection has been set from *.prj file, if so, copy into projection structure */ if ((store->projection_set == MB_NO) && (mb_io_ptr->projection_initialized == MB_YES)) { projection->time_d = time(NULL); projection->microsec = 0; projection->nchars = strnlen(mb_io_ptr->projection_id, MB_NAME_LENGTH); if (projection->projection_alloc < projection->nchars) { status = mb_reallocd(verbose, __FILE__, __LINE__, (size_t)projection->nchars, (void **)&(projection->projection_id), error); if (status != MB_SUCCESS) { projection->projection_alloc = 0; } else { projection->projection_alloc = projection->nchars; } } if (status == MB_SUCCESS) { strncpy(projection->projection_id, mb_io_ptr->projection_id, (size_t)projection->nchars); store->projection_set = MB_YES; } } /* check if projection has been read from *mb222 file, if so, tell mb system */ else if ((store->projection_set == MB_YES) && (mb_io_ptr->projection_initialized == MB_NO)) { mb_proj_init(verbose, projection->projection_id, &(mb_io_ptr->pjptr), error); strncpy(mb_io_ptr->projection_id, projection->projection_id, MB_NAME_LENGTH); mb_io_ptr->projection_initialized = MB_YES; } /* throw away multibeam data if the time stamp makes no sense */ if ((status == MB_SUCCESS) && (store->kind == MB_DATA_DATA) && (store->time_i[0] < 2003)) { status = MB_FAILURE; *error = MB_ERROR_UNINTELLIGIBLE; } /* save geographic position fix data */ else if ((status == MB_SUCCESS) && (store->kind == MB_DATA_NAV) && (store->projection_set == MB_NO)) { mb_navint_add(verbose, mbio_ptr, store->time_d, store->posll.longitude, store->posll.latitude, error); } /* save projected position fix data */ else if ((status == MB_SUCCESS) && (store->kind == MB_DATA_NAV1) && (store->projection_set == MB_YES)) { mb_navint_add(verbose, mbio_ptr, store->time_d, store->posen.easting, store->posen.northing, error); } /* save heading and attitude fix data */ else if ((status == MB_SUCCESS) && (store->kind == MB_DATA_ATTITUDE)) { mb_attint_add(verbose, mbio_ptr, store->time_d, store->attitude.height, store->attitude.roll, store->attitude.pitch, error); mb_hedint_add(verbose, mbio_ptr, store->time_d, store->attitude.heading, error); } /* save tide data (as altitude) */ else if ((status == MB_SUCCESS) && (store->kind == MB_DATA_TIDE)) { mb_altint_add(verbose, mbio_ptr, store->time_d, store->tide.tide, error); } /* set error and kind in mb_io_ptr */ mb_io_ptr->new_error = *error; mb_io_ptr->new_kind = store->kind; /* print output debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> completed\n", function_name); fprintf(stderr, "dbg2 Return values:\n"); fprintf(stderr, "dbg2 error: %d\n", *error); fprintf(stderr, "dbg2 Return status:\n"); fprintf(stderr, "dbg2 status: %d\n", status); } return (status); } /* mbr_rt_swplssxi */
/*--------------------------------------------------------------------*/ int mbr_alm_swplssxi(int verbose, void *mbio_ptr, int *error) { char *function_name = "mbr_alm_swplssxi"; int status = MB_SUCCESS; struct mb_io_struct *mb_io_ptr; int *current_ping; int *last_ping; int *save_flag; int *recordid; int *recordidlast; char **bufferptr; char *buffer; int *bufferalloc; int *size; int *nbadrec; int *deviceid; int *projection_file_created; /* print input debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> called\n", function_name); fprintf(stderr, "dbg2 Input arguments:\n"); fprintf(stderr, "dbg2 verbose: %d\n", verbose); fprintf(stderr, "dbg2 mbio_ptr: %p\n", (void *)mbio_ptr); } /* get pointer to mbio descriptor */ mb_io_ptr = (struct mb_io_struct *)mbio_ptr; /* set initial status */ status = MB_SUCCESS; /* allocate memory for data structure */ mb_io_ptr->structure_size = 0; mb_io_ptr->data_structure_size = 0; status = mbsys_swathplus_alloc(verbose, mbio_ptr, &mb_io_ptr->store_data, error); save_flag = (int *)&mb_io_ptr->save_flag; current_ping = (int *)&mb_io_ptr->save14; last_ping = (int *)&mb_io_ptr->save1; recordid = (int *)&mb_io_ptr->save3; recordidlast = (int *)&mb_io_ptr->save4; bufferptr = (char **)&mb_io_ptr->saveptr1; buffer = (char *)*bufferptr; bufferalloc = (int *)&mb_io_ptr->save6; size = (int *)&mb_io_ptr->save8; nbadrec = (int *)&mb_io_ptr->save9; deviceid = (int *)&mb_io_ptr->save10; projection_file_created = (int *)&mb_io_ptr->save5; *current_ping = -1; *last_ping = -1; *save_flag = MB_NO; *recordid = SWPLS_ID_NONE; *recordidlast = SWPLS_ID_NONE; *bufferptr = NULL; *bufferalloc = 0; *size = 0; *nbadrec = 0; *deviceid = 0; *projection_file_created = MB_NO; /* allocate memory if necessary */ if (status == MB_SUCCESS) { status = mb_reallocd(verbose, __FILE__, __LINE__, SWPLS_BUFFER_STARTSIZE, (void **)bufferptr, error); if (status == MB_SUCCESS) { *bufferalloc = SWPLS_BUFFER_STARTSIZE; } } /* print output debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> completed\n", function_name); fprintf(stderr, "dbg2 Return values:\n"); fprintf(stderr, "dbg2 error: %d\n", *error); fprintf(stderr, "dbg2 Return status:\n"); fprintf(stderr, "dbg2 status: %d\n", status); } return (status); } /* mbr_alm_swplssxi */
int main (int argc, char **argv) { #ifdef MBCONTOURFILTER char program_name[] = "MBCONTOURFILTER"; char help_message[] = "MBCONTOURFILTER is a utility which creates a pen plot \ncontour map of multibeam swath bathymetry. \nThe primary purpose of this program is to serve as \npart of a real-time plotting system. The contour \nlevels and colors can be controlled \ndirectly or set implicitly using contour and color change intervals. \nContours can also be set to have ticks pointing downhill."; char usage_message[] = "mbcontourfilter -Jparameters -Rwest/east/south/north \n\t[-Acontour_int/color_int/tick_int/label_int/tick_len/label_hgt/label_spacing \n\t-Btickinfo -byr/mon/day/hour/min/sec -Ccontourfile \n\t-Dtime_tick/time_annot/date_annot/time_tick_len -Eyr/mon/day/hour/min/sec \n\t-fformat -Fred/green/blue -Idatalist -K -Llonflip -M -O -Nnplot \n\t-P -ppings -Q -Ttimegap -U -Xx-shift -Yy-shift -Zalgorithm -#copies -V -H]"; #else char program_name[] = "MBCONTOUR"; char help_message[] = "MBCONTOUR is a GMT compatible utility which creates a color postscript \ncontour map of multibeam swath bathymetry. \nComplete maps are made by using MBCONTOUR in conjunction with the \nusual GMT programs. The contour levels and colors can be controlled \ndirectly or set implicitly using contour and color change intervals. \nContours can also be set to have ticks pointing downhill."; char usage_message[] = "mbcontour -Jparameters -Rwest/east/south/north \n\t[-Acontour_int/color_int/tick_int/label_int/tick_len/label_hgt/label_spacing \n\t-Btickinfo -byr/mon/day/hour/min/sec -Ccontourfile -ccopies \n\t-Dtime_tick/time_annot/date_annot/time_tick_len \n\t-Eyr/mon/day/hour/min/sec \n\t-fformat -Fred/green/blue -Idatalist -K -Llonflip -Nnplot -O \n\t-P -ppings -U -Xx-shift -Yy-shift -Zalgorithm -V -H]"; #endif extern char *optarg; int argc_gmt = 0; char *argv_gmt[MBCONTOUR_GMT_ARG_MAX]; int errflg = 0; int c; int help = 0; int flag = 0; /* MBIO status variables */ int status = MB_SUCCESS; int verbose = 0; int error = MB_ERROR_NO_ERROR; char *message = NULL; /* MBIO read control parameters */ char read_file[MBCONTOUR_LABEL_LEN]; int read_datalist; int read_data; void *datalist; int look_processed = MB_DATALIST_LOOK_UNSET; double file_weight; FILE *fp; int format; int pings; int lonflip; int lonflip_set = MB_NO; double bounds[4]; double mb_bounds[4]; int btime_i[7]; int etime_i[7]; double btime_d; double etime_d; double speedmin; double timegap; char file[MB_PATH_MAXLINE]; int file_in_bounds; int beams_bath; int beams_amp; int pixels_ss; void *mbio_ptr = NULL; /* mbio read values */ struct swath *swath_plot = NULL; struct ping *pingcur = NULL; int kind; int pings_read; int time_i[7]; double time_d; double navlon; double navlat; double speed; double heading; double distance; double altitude; double sonardepth; char *beamflag = NULL; double *bath = NULL; double *bathlon = NULL; double *bathlat = NULL; double *amp = NULL; double *ss = NULL; double *sslon = NULL; double *sslat = NULL; char comment[256]; int pingnumber; /* plot control variables */ int contour_algorithm; char contourfile[MB_PATH_MAXLINE]; int plot; int done; int flush; int save_new; int *npings = NULL; int nping_read; int nplot; int plot_contours; int plot_triangles; int set_contours; double cont_int; double col_int; double tick_int; double label_int; double tick_len; double label_hgt; double label_spacing; double tick_len_map; double label_hgt_map; double label_spacing_map; int plot_name; int plotted_name; int plot_track; double time_tick_int; double time_annot_int; double date_annot_int; double time_tick_len; double time_tick_len_map; double name_hgt; double name_hgt_map; int name_perp; double scale; int bathy_in_feet; int plot_pingnumber; int pingnumber_tick_int; int pingnumber_annot_int; double pingnumber_tick_len; double pingnumber_tick_len_map; /* pen variables */ int ncolor; int nlevel; double *level = NULL; int *red = NULL; int *green = NULL; int *blue = NULL; int *label = NULL; int *tick = NULL; /* inch to map scale */ double inchtolon; /* other variables */ char line[MBCONTOUR_LABEL_LEN]; char labelstr[MBCONTOUR_LABEL_LEN], tickstr[MBCONTOUR_LABEL_LEN]; int count; int setcolors; double navlon_old; double navlat_old; int i1, i2; double d1, d2, d3, d4, d5, d6, d7; int nscan; int i; /* get current mb default values */ status = mb_defaults(verbose,&format,&pings,&lonflip,bounds, btime_i,etime_i,&speedmin,&timegap); /* set default input to stdin */ strcpy (read_file, "stdin"); /* initialize some values */ format = -1; read_datalist = MB_NO; contour_algorithm = MB_CONTOUR_OLD; strcpy (contourfile,"\0"); set_contours = MB_NO; bounds[0] = 0.0; bounds[1] = 0.0; bounds[2] = 0.0; bounds[3] = 0.0; scale = 0.0; nplot = 0; cont_int = 25.; col_int = 100.; tick_int = 100.; label_int = 100.; label_hgt = 0.1; label_spacing = 0.0; tick_len = 0.05; plot_name = MB_NO; plot_track = MB_NO; time_tick_int = 0.25; time_annot_int = 1.0; date_annot_int = 4.0; time_tick_len = 0.1; name_hgt = 0.1; name_perp = MB_NO; ncolor = 4; nlevel = 0; plot_contours = MB_NO; plot_triangles = MB_NO; bathy_in_feet = MB_NO; plot_pingnumber = MB_NO; pingnumber_tick_int = 50; pingnumber_annot_int = 100; pingnumber_tick_len = 0.1; /* get GMT options into separate argv */ argv_gmt[0] = argv[0]; argc_gmt = 1; for (i=1;i<argc;i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'B': case 'F': case 'J': case 'j': case 'K': case 'k': case 'O': case 'o': case 'P': case 'R': case 'r': case 'U': case 'u': case 'V': case 'v': case 'X': case 'x': case 'Y': case 'y': case '#': if (argc_gmt < MBCONTOUR_GMT_ARG_MAX) { argv_gmt[argc_gmt] = argv[i]; argc_gmt++; break; } } } } /* deal with mb options */ while ((c = getopt(argc, argv, "VvHhA:a:B:b:C:c:D:d:E:e:F:f:G:g:I:i:J:j:KkL:l:M:m:N:n:OoPp:QqR:r:S:s:T:t:UuWwX:x:Y:y:Z:z:")) != -1) switch (c) { case 'A': case 'a': nscan = sscanf (optarg, "%lf/%lf/%lf/%lf/%lf/%lf/%lf", &d1,&d2,&d3,&d4,&d5,&d6,&d7); if (nscan >= 1) cont_int = d1; if (nscan >= 2) col_int = d2; if (nscan >= 3) tick_int = d3; if (nscan >= 4) label_int = d4; if (nscan >= 5) tick_len = d5; if (nscan >= 6) label_hgt = d6; if (nscan >= 7) label_spacing = d7; if (nscan >= 1) plot_contours = MB_YES; break; case 'b': sscanf (optarg, "%d/%d/%d/%d/%d/%d", &btime_i[0],&btime_i[1],&btime_i[2], &btime_i[3],&btime_i[4],&btime_i[5]); btime_i[6] = 0; break; case 'C': sscanf (optarg,"%s", contourfile); plot_contours = MB_YES; set_contours = MB_YES; break; case 'D': case 'd': sscanf (optarg, "%lf/%lf/%lf/%lf", &time_tick_int,&time_annot_int, &date_annot_int,&time_tick_len); plot_track = MB_YES; break; case 'E': case 'e': sscanf (optarg, "%d/%d/%d/%d/%d/%d", &etime_i[0],&etime_i[1],&etime_i[2], &etime_i[3],&etime_i[4],&etime_i[5]); etime_i[6] = 0; break; case 'f': sscanf (optarg, "%d",&format); break; case 'G': case 'g': nscan = sscanf (optarg, "%lf/%d", &name_hgt, &name_perp); plot_name = MB_YES; if (nscan < 1) name_hgt = 0.1; if (nscan < 2) name_perp = MB_NO; break; case 'H': case 'h': help++; break; case 'I': case 'i': sscanf (optarg,"%s", read_file); flag++; break; case 'J': if (optarg[0] == 'm') sscanf (&optarg[1],"%lf", &scale); flag++; break; case 'L': case 'l': sscanf (optarg,"%d", &lonflip); lonflip_set = MB_YES; flag++; break; case 'M': case 'm': nscan = sscanf (optarg, "%d/%d/%lf", &i1,&i2,&d3); if (nscan >= 1) pingnumber_tick_int = i1; if (nscan >= 2) pingnumber_annot_int = i2; if (nscan >= 3) pingnumber_tick_len = d3; if (nscan >= 1) plot_pingnumber = MB_YES; break; case 'N': case 'n': sscanf (optarg,"%d", &nplot); if (nplot < 3) nplot = 3; break; case 'p': sscanf (optarg,"%d", &pings); flag++; break; case 'Q': case 'q': plot_triangles = MB_YES; break; case 'R': case 'r': sscanf(optarg,"%lf/%lf/%lf/%lf", &bounds[0],&bounds[1], &bounds[2],&bounds[3]); break; case 'S': case 's': sscanf (optarg, "%lf", &speedmin); break; case 'T': case 't': sscanf (optarg,"%lf", &timegap); flag++; break; case 'V': case 'v': verbose++; break; case 'W': case 'w': bathy_in_feet = MB_YES; break; case 'Z': case 'z': sscanf (optarg,"%d", &contour_algorithm); flag++; break; case 'B': case 'F': case 'K': case 'O': case 'P': case 'U': case 'X': case 'x': case 'Y': case 'y': case '#': break; case '?': errflg++; } /* if error flagged then print it and exit */ if (errflg) { fprintf(stderr,"usage: %s\n", usage_message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); error = MB_ERROR_BAD_USAGE; exit(error); } /* set number of pings to be plotted if not set */ if (nplot == 0 && contour_algorithm == MB_CONTOUR_TRIANGLES) nplot = 5; else if (nplot == 0) nplot = 50; /* if nothing set to be plotted, plot contours and track */ if (plot_contours == MB_NO && plot_triangles == MB_NO && plot_track == MB_NO && plot_pingnumber == MB_NO) { plot_contours = MB_YES; plot_track = MB_YES; } if (plot_name == MB_YES && plot_track == MB_NO && plot_pingnumber == MB_NO) { plot_track = MB_YES; } if (plot_track == MB_NO && plot_pingnumber == MB_YES) { plot_track = MB_YES; time_tick_int = 10000000.0; time_annot_int = 10000000.0; date_annot_int = 10000000.0; } /* print starting message */ if (verbose == 1 || help) { fprintf(stderr,"\nProgram %s\n",program_name); fprintf(stderr,"MB-system Version %s\n",MB_VERSION); } /* if help desired then print it and exit */ if (help) { fprintf(stderr,"\n%s\n",help_message); fprintf(stderr,"\nusage: %s\n", usage_message); exit(error); } /* initialize plotting */ status = plot_init(verbose,argc_gmt,argv_gmt,bounds,&scale,&inchtolon,&error); /* if error flagged then print it and exit */ if (status == MB_FAILURE) { fprintf(stderr,"usage: %s\n", usage_message); fprintf(stderr,"GMT option error\n"); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); error = MB_ERROR_BAD_USAGE; exit(error); } /* print starting debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Program <%s>\n",program_name); fprintf(stderr,"dbg2 MB-system Version %s\n",MB_VERSION); fprintf(stderr,"dbg2 Control Parameters:\n"); fprintf(stderr,"dbg2 verbose: %d\n",verbose); fprintf(stderr,"dbg2 help: %d\n",help); fprintf(stderr,"dbg2 format: %d\n",format); fprintf(stderr,"dbg2 pings: %d\n",pings); fprintf(stderr,"dbg2 lonflip: %d\n",lonflip); fprintf(stderr,"dbg2 btime_i[0]: %d\n",btime_i[0]); fprintf(stderr,"dbg2 btime_i[1]: %d\n",btime_i[1]); fprintf(stderr,"dbg2 btime_i[2]: %d\n",btime_i[2]); fprintf(stderr,"dbg2 btime_i[3]: %d\n",btime_i[3]); fprintf(stderr,"dbg2 btime_i[4]: %d\n",btime_i[4]); fprintf(stderr,"dbg2 btime_i[5]: %d\n",btime_i[5]); fprintf(stderr,"dbg2 btime_i[6]: %d\n",btime_i[6]); fprintf(stderr,"dbg2 etime_i[0]: %d\n",etime_i[0]); fprintf(stderr,"dbg2 etime_i[1]: %d\n",etime_i[1]); fprintf(stderr,"dbg2 etime_i[2]: %d\n",etime_i[2]); fprintf(stderr,"dbg2 etime_i[3]: %d\n",etime_i[3]); fprintf(stderr,"dbg2 etime_i[4]: %d\n",etime_i[4]); fprintf(stderr,"dbg2 etime_i[5]: %d\n",etime_i[5]); fprintf(stderr,"dbg2 etime_i[6]: %d\n",etime_i[6]); fprintf(stderr,"dbg2 speedmin: %f\n",speedmin); fprintf(stderr,"dbg2 timegap: %f\n",timegap); fprintf(stderr,"dbg2 read file: %s\n",read_file); fprintf(stderr,"dbg2 bounds[0]: %f\n",bounds[0]); fprintf(stderr,"dbg2 bounds[1]: %f\n",bounds[1]); fprintf(stderr,"dbg2 bounds[2]: %f\n",bounds[2]); fprintf(stderr,"dbg2 bounds[3]: %f\n",bounds[3]); fprintf(stderr,"dbg2 contour algorithm: %d\n",contour_algorithm); fprintf(stderr,"dbg2 plot contours: %d\n",plot_contours); fprintf(stderr,"dbg2 plot triangles: %d\n",plot_triangles); fprintf(stderr,"dbg2 plot track: %d\n",plot_track); fprintf(stderr,"dbg2 plot_pingnumber: %d\n",plot_pingnumber); fprintf(stderr,"dbg2 plot name: %d\n",plot_name); fprintf(stderr,"dbg2 contour interval: %f\n",cont_int); fprintf(stderr,"dbg2 color interval: %f\n",col_int); fprintf(stderr,"dbg2 tick interval: %f\n",tick_int); fprintf(stderr,"dbg2 label interval: %f\n",label_int); fprintf(stderr,"dbg2 tick length: %f\n",tick_len); fprintf(stderr,"dbg2 label height: %f\n",label_hgt); fprintf(stderr,"dbg2 label spacing: %f\n",label_spacing); fprintf(stderr,"dbg2 number contoured: %d\n",nplot); fprintf(stderr,"dbg2 time tick int: %f\n",time_tick_int); fprintf(stderr,"dbg2 time interval: %f\n",time_annot_int); fprintf(stderr,"dbg2 date interval: %f\n",date_annot_int); fprintf(stderr,"dbg2 time tick length: %f\n",time_tick_len); fprintf(stderr,"dbg2 name height: %f\n",name_hgt); fprintf(stderr,"dbg2 pingnumber tick int: %d\n",pingnumber_tick_int); fprintf(stderr,"dbg2 pingnumber annot int: %d\n",pingnumber_annot_int); fprintf(stderr,"dbg2 pingnumber tick len: %f\n",pingnumber_tick_len); fprintf(stderr,"dbg2 bathy_in_feet: %d\n\n",bathy_in_feet); } /* if bounds not specified then quit */ if (bounds[0] >= bounds[1] || bounds[2] >= bounds[3] || bounds[2] <= -90.0 || bounds[3] >= 90.0) { fprintf(stderr,"\nRegion bounds not properly specified:\n\t%f %f %f %f\n",bounds[0],bounds[1],bounds[2],bounds[3]); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); error = MB_ERROR_BAD_PARAMETER; exit(error); } /* scale label and tick sizes */ label_hgt_map = inchtolon * label_hgt; label_spacing_map = inchtolon * label_spacing; tick_len_map = inchtolon * tick_len; time_tick_len_map = inchtolon * time_tick_len; name_hgt_map = inchtolon * name_hgt; pingnumber_tick_len_map = inchtolon * pingnumber_tick_len; /* read contours from file */ if (set_contours == MB_YES) { /* open contour file */ if ((fp = fopen(contourfile,"r")) == NULL) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open contour file: %s\n", contourfile); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* count lines in file */ nlevel = 0; while (fgets(line,MBCONTOUR_LABEL_LEN,fp) != NULL) nlevel++; fclose(fp); /* set number of colors equal to levels */ ncolor = nlevel; /* allocate memory */ status = mb_mallocd(verbose, __FILE__, __LINE__, nlevel*sizeof(double), (void **)&level,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, nlevel*sizeof(int), (void **)&label,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, nlevel*sizeof(int), (void **)&tick,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, ncolor*sizeof(int), (void **)&red,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, ncolor*sizeof(int), (void **)&green,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, ncolor*sizeof(int), (void **)&blue,&error); /* reopen contour file */ if ((fp = fopen(contourfile,"r")) == NULL) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open contour file: %s\n", contourfile); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* read contour levels from file */ nlevel = 0; while (fgets(line,MBCONTOUR_LABEL_LEN,fp) != NULL) { count = sscanf(line,"%lf %s %s %d %d %d", &level[nlevel],labelstr,tickstr, &red[nlevel],&green[nlevel],&blue[nlevel]); setcolors = MB_YES; if (count >= 2 && labelstr[0] == 'a') label[nlevel] = 1; else if (count >= 2 && labelstr[0] == 'n') label[nlevel] = 0; else { label[nlevel] = 0; setcolors = MB_NO; } if (count >= 3 && tickstr[0] == 't') tick[nlevel] = 1; else if (count >= 3 && tickstr[0] == 'n') tick[nlevel] = 0; else { tick[nlevel] = 0; setcolors = MB_NO; } if (count < 6 || setcolors == MB_NO) { red[nlevel] = 0; green[nlevel] = 0; blue[nlevel] = 0; } if (count > 0) nlevel++; } fclose(fp); } /* else set default colors and use contour intervals */ else { /* set defaults */ nlevel = 0; ncolor = 4; /* allocate memory */ status = mb_mallocd(verbose, __FILE__, __LINE__, ncolor*sizeof(int), (void **)&red,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, ncolor*sizeof(int), (void **)&green,&error); status = mb_mallocd(verbose, __FILE__, __LINE__, ncolor*sizeof(int), (void **)&blue,&error); /* set colors */ red[0] = 0; green[0] = 0; blue[0] = 0; /* black */ red[1] = 255; green[1] = 0; blue[1] = 0; /* red */ red[2] = 0; green[2] = 200; blue[2] = 0; /* green */ red[3] = 0; green[3] = 0; blue[3] = 255; /* blue */ } /* set colors */ set_colors(ncolor,red,green,blue); /* set bounds for multibeam reading larger than map borders */ mb_bounds[0] = bounds[0] - 0.25*(bounds[1] - bounds[0]); mb_bounds[1] = bounds[1] + 0.25*(bounds[1] - bounds[0]); mb_bounds[2] = bounds[2] - 0.25*(bounds[3] - bounds[2]); mb_bounds[3] = bounds[3] + 0.25*(bounds[3] - bounds[2]); /* set lonflip if possible */ if (lonflip_set == MB_NO) { if (mb_bounds[0] < -180.0) lonflip = -1; else if (mb_bounds[1] > 180.0) lonflip = 1; else if (lonflip == -1 && mb_bounds[1] > 0.0) lonflip = 0; else if (lonflip == 1 && mb_bounds[0] < 0.0) lonflip = 0; } /* determine whether to read one file or a list of files */ if (format < 0) read_datalist = MB_YES; /* open file list */ nping_read = 0; if (read_datalist == MB_YES) { if ((status = mb_datalist_open(verbose,&datalist, read_file,look_processed,&error)) != MB_SUCCESS) { error = MB_ERROR_OPEN_FAIL; fprintf(stderr,"\nUnable to open data list file: %s\n", read_file); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } if ((status = mb_datalist_read(verbose,datalist, file,&format,&file_weight,&error)) == MB_SUCCESS) read_data = MB_YES; else read_data = MB_NO; } else { strcpy(file,read_file); read_data = MB_YES; } /* loop over files in file list */ if (verbose == 1) fprintf(stderr,"\n"); while (read_data == MB_YES) { /* check for mbinfo file - get file bounds if possible */ status = mb_check_info(verbose, file, lonflip, bounds, &file_in_bounds, &error); if (status == MB_FAILURE) { file_in_bounds = MB_YES; status = MB_SUCCESS; error = MB_ERROR_NO_ERROR; } /* read if data may be in bounds */ if (file_in_bounds == MB_YES) { /* check for "fast bathymetry" or "fbt" file */ if (plot_contours == MB_YES) { mb_get_fbt(verbose, file, &format, &error); } /* else check for "fast nav" or "fnv" file */ else if (plot_track == MB_YES || plot_pingnumber == MB_YES) { mb_get_fnv(verbose, file, &format, &error); } /* call mb_read_init() */ if ((status = mb_read_init( verbose,file,format,pings,lonflip,mb_bounds, btime_i,etime_i,speedmin,timegap, &mbio_ptr,&btime_d,&etime_d, &beams_bath,&beams_amp,&pixels_ss,&error)) != MB_SUCCESS) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error returned from function <mb_read_init>:\n%s\n",message); fprintf(stderr,"\nMultibeam File <%s> not initialized for reading\n",file); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* allocate memory for data arrays */ if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(char), (void **)&beamflag, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bath, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_AMPLITUDE, sizeof(double), (void **)&, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bathlon, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY, sizeof(double), (void **)&bathlat, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&ss, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&sslon, &error); if (error == MB_ERROR_NO_ERROR) status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN, sizeof(double), (void **)&sslat, &error); /* if error initializing memory then quit */ if (error != MB_ERROR_NO_ERROR) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error allocating data arrays:\n%s\n",message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* initialize contour controls */ status = mb_contour_init(verbose,&swath_plot,nplot,beams_bath, contour_algorithm, plot_contours,plot_triangles, plot_track,plot_name,plot_pingnumber, cont_int,col_int,tick_int,label_int, tick_len_map,label_hgt_map,label_spacing_map, ncolor,nlevel,level,label,tick, time_tick_int,time_annot_int, date_annot_int,time_tick_len_map,name_hgt_map, pingnumber_tick_int,pingnumber_annot_int, pingnumber_tick_len_map, &error); swath_plot->beams_bath = beams_bath; /* if error initializing memory then quit */ if (error != MB_ERROR_NO_ERROR) { mb_error(verbose,error,&message); fprintf(stderr,"\nMBIO Error allocating contour control structure:\n%s\n",message); fprintf(stderr,"\nProgram <%s> Terminated\n", program_name); exit(error); } /* print message */ if (verbose >= 2) fprintf(stderr,"\n"); if (verbose >= 1) fprintf(stderr,"processing data in %s...\n",file); /* loop over reading */ npings = &swath_plot->npings; *npings = 0; done = MB_NO; plotted_name = MB_NO; while (done == MB_NO) { /* read the next ping */ status = mb_read(verbose,mbio_ptr,&kind, &pings_read,time_i,&time_d, &navlon,&navlat, &speed,&heading, &distance,&altitude,&sonardepth, &beams_bath,&beams_amp,&pixels_ss, beamflag,bath,amp,bathlon,bathlat, ss,sslon,sslat, comment,&error); /* get pingnumber */ if (status == MB_SUCCESS) { status = mb_pingnumber(verbose,mbio_ptr,&pingnumber,&error); } /* copy data to swath_plot */ if (status == MB_SUCCESS || error == MB_ERROR_TIME_GAP) { pingcur = &swath_plot->pings[*npings]; /* make sure enough memory is allocated */ if (pingcur->beams_bath_alloc < beams_bath) { status = mb_reallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(char), (void **)&(pingcur->beamflag),&error); status = mb_reallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(double), (void **)&(pingcur->bath),&error); status = mb_reallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(double), (void **)&(pingcur->bathlon),&error); status = mb_reallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(double), (void **)&(pingcur->bathlat),&error); status = mb_reallocd(verbose,__FILE__,__LINE__,beams_bath*sizeof(int), (void **)&(pingcur->bflag[0]),&error); status = mb_reallocd(verbose,__FILE__,__LINE__,beams_bath*sizeof(int), (void **)&(pingcur->bflag[1]),&error); pingcur->beams_bath_alloc = beams_bath; } /* insert the data */ for (i=0;i<7;i++) pingcur->time_i[i] = time_i[i]; pingcur->time_d = time_d; pingcur->navlon = navlon; pingcur->navlat = navlat; pingcur->heading = heading; pingcur->beams_bath = beams_bath; pingcur->pingnumber = pingnumber; for (i=0;i<beams_bath;i++) { pingcur->beamflag[i] = beamflag[i]; pingcur->bath[i] = bath[i]; pingcur->bathlon[i] = bathlon[i]; pingcur->bathlat[i] = bathlat[i]; pingcur->bflag[0][i] = 0; pingcur->bflag[1][i] = 0; } } /* null out any unused beams for formats with variable numbers of beams */ for (i=beams_bath;i<swath_plot->beams_bath;i++) beamflag[i] = MB_FLAG_NULL; /* print debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Ping read in program <%s>\n", program_name); fprintf(stderr,"dbg2 kind: %d\n", kind); fprintf(stderr,"dbg2 npings: %d\n", *npings); fprintf(stderr,"dbg2 time: %4d %2d %2d %2d %2d %2d %6.6d\n", time_i[0],time_i[1],time_i[2], time_i[3],time_i[4],time_i[5],time_i[6]); fprintf(stderr,"dbg2 navigation: %f %f\n", navlon, navlat); fprintf(stderr,"dbg2 beams_bath: %d\n", beams_bath); fprintf(stderr,"dbg2 beams_amp: %d\n", beams_amp); fprintf(stderr,"dbg2 pixels_ss: %d\n", pixels_ss); fprintf(stderr,"dbg2 error: %d\n", error); fprintf(stderr,"dbg2 status: %d\n", status); } /* scale bathymetry if necessary */ if (error == MB_ERROR_NO_ERROR && bathy_in_feet == MB_YES) { for (i=0;i<beams_bath;i++) { bath[i] = 3.2808399 * bath[i]; } } /* update bookkeeping */ if (error == MB_ERROR_NO_ERROR) { /*if (*npings == 0 || (*npings > 0 && contour_algorithm == MB_CONTOUR_TRIANGLES) || (*npings > 0 && (navlon != navlon_old || navlat != navlat_old)))*/ { nping_read += pings_read; (*npings)++; navlon_old = navlon; navlat_old = navlat; } } /* decide whether to plot, whether to save the new ping, and if done */ plot = MB_NO; flush = MB_NO; if (*npings >= nplot) plot = MB_YES; if (*npings > 0 && (error > MB_ERROR_NO_ERROR || error == MB_ERROR_TIME_GAP || error == MB_ERROR_OUT_BOUNDS || error == MB_ERROR_OUT_TIME || error == MB_ERROR_SPEED_TOO_SMALL)) { plot = MB_YES; flush = MB_YES; } save_new = MB_NO; if (error == MB_ERROR_TIME_GAP) save_new = MB_YES; if (error > MB_ERROR_NO_ERROR) done = MB_YES; /* if enough pings read in, plot them */ if (plot == MB_YES) { /* print debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Plotting %d pings in program <%s>\n", *npings,program_name); for (i=0;i<*npings;i++) { pingcur = &swath_plot->pings[i]; fprintf(stderr,"dbg2 %4d %4d %2d %2d %2d %2d %2d %6.6d\n", i,pingcur->time_i[0], pingcur->time_i[1], pingcur->time_i[2], pingcur->time_i[3], pingcur->time_i[4], pingcur->time_i[5], pingcur->time_i[6]); } } /* plot data */ if (plot_contours == MB_YES || plot_triangles == MB_YES) mb_contour(verbose,swath_plot,&error); /* plot nav track */ if (plot_track == MB_YES) mb_track(verbose,swath_plot,&error); /* annotate pingnumber */ if (plot_pingnumber == MB_YES) { mb_trackpingnumber(verbose,swath_plot,&error); } if (plot_name == MB_YES && plotted_name == MB_NO) { mb_trackname(verbose,name_perp,swath_plot,file,&error); plotted_name = MB_YES; } /* reorganize data */ if (flush == MB_YES && save_new == MB_YES) { status = ping_copy(verbose,0,*npings, swath_plot,&error); *npings = 1; } else if (flush == MB_YES) { *npings = 0; } else if (*npings > 1) { status = ping_copy(verbose,0,*npings-1, swath_plot,&error); *npings = 1; } } } status = mb_close(verbose,&mbio_ptr,&error); /* deallocate memory for data arrays */ status = mb_contour_deall(verbose,swath_plot,&error); } /* end if file in bounds */ /* figure out whether and what to read next */ if (read_datalist == MB_YES) { if ((status = mb_datalist_read(verbose,datalist, file,&format,&file_weight,&error)) == MB_SUCCESS) read_data = MB_YES; else read_data = MB_NO; } else { read_data = MB_NO; } /* end loop over files in list */ } if (read_datalist == MB_YES) mb_datalist_close(verbose,&datalist,&error); /* end plot */ plot_end(verbose,&error); /* deallocate memory for data arrays */ mb_freed(verbose,__FILE__, __LINE__, (void **)&level,&error); mb_freed(verbose,__FILE__, __LINE__, (void **)&label,&error); mb_freed(verbose,__FILE__, __LINE__, (void **)&tick,&error); mb_freed(verbose,__FILE__, __LINE__, (void **)&red,&error); mb_freed(verbose,__FILE__, __LINE__, (void **)&green,&error); mb_freed(verbose,__FILE__, __LINE__, (void **)&blue,&error); /* print ending info */ if (verbose >= 1) fprintf(stderr,"\n%d pings read and plotted\n", nping_read); /* check memory */ if (verbose >= 2) status = mb_memory_list(verbose,&error); /* print output debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 Program <%s> completed\n", program_name); fprintf(stderr,"dbg2 Ending status:\n"); fprintf(stderr,"dbg2 status: %d\n",status); } /* end it all */ plot_exit(argc,argv); exit(status); }
/*--------------------------------------------------------------------*/ int ping_copy(int verbose, int one, int two, struct swath *swath, int *error) { char *function_name = "ping_copy"; int status = MB_SUCCESS; struct ping *ping1; struct ping *ping2; int i; /* print input debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBSWATH function <%s> called\n", function_name); fprintf(stderr,"dbg2 Input arguments:\n"); fprintf(stderr,"dbg2 verbose: %d\n",verbose); fprintf(stderr,"dbg2 one: %d\n",one); fprintf(stderr,"dbg2 two: %d\n",two); fprintf(stderr,"dbg2 swath: %lu\n",(size_t)swath); fprintf(stderr,"dbg2 pings: %d\n",swath->npings); fprintf(stderr,"dbg2 time_i[two]:%4d %4d %2d %2d %2d %2d %2d %6.6d\n", two,swath->pings[two].time_i[0], swath->pings[two].time_i[1], swath->pings[two].time_i[2], swath->pings[two].time_i[3], swath->pings[two].time_i[4], swath->pings[two].time_i[5], swath->pings[two].time_i[6]); } /* get ping structures */ ping1 = &swath->pings[one]; ping2 = &swath->pings[two]; /* make sure enough memory is allocated */ if (ping1->beams_bath_alloc < ping2->beams_bath) { status = mb_reallocd(verbose, __FILE__, __LINE__, ping2->beams_bath*sizeof(char), (void **)&(ping1->beamflag),error); status = mb_reallocd(verbose, __FILE__, __LINE__, ping2->beams_bath*sizeof(double), (void **)&(ping1->bath),error); status = mb_reallocd(verbose, __FILE__, __LINE__, ping2->beams_bath*sizeof(double), (void **)&(ping1->bathlon),error); status = mb_reallocd(verbose, __FILE__, __LINE__, ping2->beams_bath*sizeof(double), (void **)&(ping1->bathlat),error); status = mb_reallocd(verbose, __FILE__, __LINE__, ping2->beams_bath*sizeof(int), (void **)&(ping1->bflag[0]),error); status = mb_reallocd(verbose, __FILE__, __LINE__, ping2->beams_bath*sizeof(int), (void **)&(ping1->bflag[1]),error); ping1->beams_bath_alloc = ping2->beams_bath; } /* copy things */ for (i=0;i<7;i++) ping1->time_i[i] = ping2->time_i[i]; ping1->time_d = ping2->time_d; ping1->navlon = ping2->navlon; ping1->navlat = ping2->navlat; ping1->heading = ping2->heading; ping1->pingnumber = ping2->pingnumber; ping1->beams_bath = ping2->beams_bath; for (i=0;i<ping2->beams_bath;i++) { ping1->beamflag[i] = ping2->beamflag[i]; ping1->bath[i] = ping2->bath[i]; ping1->bathlon[i] = ping2->bathlon[i]; ping1->bathlat[i] = ping2->bathlat[i]; ping1->bflag[0][i] = ping2->bflag[1][i]; } /* assume success */ *error = MB_ERROR_NO_ERROR; status = MB_SUCCESS; /* print output debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBSWATH function <%s> completed\n", function_name); fprintf(stderr,"dbg2 Return values:\n"); fprintf(stderr,"dbg2 error: %d\n",*error); fprintf(stderr,"dbg2 Return status:\n"); fprintf(stderr,"dbg2 status: %d\n",status); } /* return status */ return(status); }