/*--------------------------------------------------------------------*/ int mb_put_comment(int verbose, void *mbio_ptr, char *comment, int *error) { static char rcs_id[]="$Id $"; char *function_name = "mb_put_comment"; int status; struct mb_io_struct *mb_io_ptr; int time_i[7] = {0, 0, 0, 0, 0, 0, 0}; double time_d = 0.0; double navlon = 0.0; double navlat = 0.0; double speed = 0.0; double heading = 0.0; 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 mb_ptr: %p\n",(void *)mbio_ptr); fprintf(stderr,"dbg2 comment: %s\n",comment); } /* get mbio descriptor */ mb_io_ptr = (struct mb_io_struct *) mbio_ptr; /* insert comment using mb_insert */ for (i=0;i<7;i++) time_i[i] = 0; time_d = 0.0; navlon = 0.0; status = mb_insert(verbose,mbio_ptr,mb_io_ptr->store_data, MB_DATA_COMMENT, time_i,time_d,navlon,navlat,speed,heading, 0,0,0, NULL,NULL,NULL, NULL,NULL, NULL,NULL,NULL, comment,error); /* write the data */ status = mb_write_ping(verbose,mbio_ptr,mb_io_ptr->store_data,error); /* print output debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBIO function <%s> completed\n",function_name); fprintf(stderr,"dbg2 Revision id: %s\n",rcs_id); 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 mb_put_all(int verbose, void *mbio_ptr, void *store_ptr, int usevalues, 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 = "mb_put_all"; int status = MB_SUCCESS; struct mb_io_struct *mb_io_ptr; int i; /* 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: %lu\n",(size_t)mbio_ptr); fprintf(stderr,"dbg2 store_ptr: %lu\n",(size_t)store_ptr); fprintf(stderr,"dbg2 usevalues: %d\n",usevalues); fprintf(stderr,"dbg2 kind: %d\n",kind); } if (verbose >= 2 && usevalues == MB_YES && 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); 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 && usevalues == MB_YES && kind == MB_DATA_DATA) { fprintf(stderr,"dbg2 nbath: %d\n",nbath); if (verbose >= 3 && nbath > 0) { fprintf(stderr,"dbg3 beam flag bath crosstrack alongtrack\n"); for (i=0;i<nbath;i++) fprintf(stderr,"dbg3 %4d %3d %f %f %f\n", i,beamflag[i],bath[i], bathacrosstrack[i],bathalongtrack[i]); } fprintf(stderr,"dbg2 namp: %d\n",namp); if (verbose >= 3 && namp > 0) { fprintf(stderr,"dbg3 beam amp crosstrack alongtrack\n"); for (i=0;i<namp;i++) fprintf(stderr,"dbg3 %4d %f %f %f\n", i,amp[i], bathacrosstrack[i],bathalongtrack[i]); } fprintf(stderr,"dbg2 nss: %d\n",nss); if (verbose >= 3 && nss > 0) { fprintf(stderr,"dbg3 pixel sidescan crosstrack alongtrack\n"); for (i=0;i<nss;i++) fprintf(stderr,"dbg3 %4d %f %f %f\n", i,ss[i], ssacrosstrack[i],ssalongtrack[i]); } } if (verbose >= 2 && usevalues == MB_YES && kind == MB_DATA_COMMENT) { fprintf(stderr,"dbg2 comment: %s\n",comment); } /* get mbio descriptor */ mb_io_ptr = (struct mb_io_struct *) mbio_ptr; /* insert values into structure if requested */ if (usevalues == MB_YES) { status = mb_insert(verbose,mbio_ptr,store_ptr, kind,time_i,time_d,navlon,navlat,speed,heading, nbath,namp,nss, beamflag,bath,amp, bathacrosstrack,bathalongtrack, ss,ssacrosstrack,ssalongtrack, comment,error); } /* write the data */ status = mb_write_ping(verbose,mbio_ptr,store_ptr,error); /* increment counters */ if (status == MB_SUCCESS) { if (kind == MB_DATA_DATA) mb_io_ptr->ping_count++; else if (kind == MB_DATA_NAV) mb_io_ptr->nav_count++; else if (kind == MB_DATA_COMMENT) mb_io_ptr->comment_count++; } /* 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); }
/*---------------------------------------------------------------*/ static int process_output(int verbose, mbdefaults *mbdflts, options *opts, mb_path ifile, counts *recs, int *error) { char *function_name = "scan_input_heights"; int status = MB_SUCCESS; int i; void *imbio_ptr = NULL; double btime_d, etime_d; int beams_bath_alloc, beams_amp_alloc, pixels_ss_alloc; void *ombio_ptr[SWPLS_MAX_TXERS]; struct mb_io_struct *imb_io_ptr = NULL; void *istore_ptr = NULL; int ofile_init[SWPLS_MAX_TXERS]; mb_path ofile[SWPLS_MAX_TXERS]; struct mbsys_swathplus_struct *istore = NULL; /* print input debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 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 options: %p\n", (void *)opts); } /* open the input file */ if ((status = mb_read_init(opts->verbose, ifile, opts->format, mbdflts->pings_get, mbdflts->lonflip, mbdflts->bounds, mbdflts->btime_i, mbdflts->etime_i, mbdflts->speedmin, mbdflts->timegap, &imbio_ptr, &btime_d, &etime_d, &beams_bath_alloc, &beams_amp_alloc, &pixels_ss_alloc, error)) != MB_SUCCESS) { char message[MAX_ERROR_STRING] = {0}; sprintf(message, "Swath File <%s> not initialized for reading\n", ifile); error_exit(opts->verbose, *error, "mb_read_init", message); } /* get mbio and data structure descriptors */ imb_io_ptr = (struct mb_io_struct *)imbio_ptr; istore_ptr = imb_io_ptr->store_data; /* set the projection for nav data */ if (opts->projection_set == MB_YES) { mb_proj_init(opts->verbose, opts->proj4command, &(imb_io_ptr->pjptr), error); strncpy(imb_io_ptr->projection_id, opts->proj4command, MB_NAME_LENGTH); imb_io_ptr->projection_initialized = MB_YES; } /* setup the output filename(s) for writing */ status = set_outfile_names(opts->verbose, ofile, ifile, &opts->basename, opts->ofile_set, opts->split_txers, error); for (i = 0; i < SWPLS_MAX_TXERS; i++) { ombio_ptr[i] = NULL; ofile_init[i] = MB_NO; } /* start looping over data records */ while (*error <= MB_ERROR_NO_ERROR) { int kind = MB_DATA_NONE; /* read the next record */ status = mb_read_ping(opts->verbose, imbio_ptr, istore_ptr, &kind, error); /* some nonfatal errors do not matter */ if ((*error < MB_ERROR_NO_ERROR) && (MB_ERROR_UNINTELLIGIBLE < *error)) { error = MB_ERROR_NO_ERROR; status = MB_SUCCESS; } istore = (struct mbsys_swathplus_struct *)istore_ptr; if (status == MB_SUCCESS) { status = count_record(opts->verbose, recs, istore, error); } if ((status == MB_SUCCESS) && (opts->print_ascii == MB_YES)) { status = print_latest_record(opts->verbose, istore, error); } /* process the sxp ping data to file */ if ((status == MB_SUCCESS) && (istore->kind == MB_DATA_DATA) && ((istore->type == SWPLS_ID_PROCESSED_PING) || (istore->type == SWPLS_ID_PROCESSED_PING2))) { int obeams_bath, obeams_amp, opixels_ss; struct mb_io_struct *omb_io_ptr = NULL; void *ostore_ptr = NULL; struct mbsys_swathplus_struct *ostore = NULL; int txno = 0; int txidx = 0; if ((status == MB_SUCCESS) && (opts->flip_rejected == MB_YES)) { status = flip_sample_flags(opts->verbose, &(istore->sxp_ping), error); } if ((status == MB_SUCCESS) && (opts->remove_rejected == MB_YES)) { status = remove_rejected_samps(opts->verbose, &(istore->sxp_ping), error); } if ((status == MB_SUCCESS) && (opts->copy_rawamp == MB_YES)) { status = copy_rawamp(opts->verbose, &(istore->sxp_ping), error); } if ((status == MB_SUCCESS) && (opts->write_output == MB_YES)) { /* select the output file based on the txer channel */ status = ping_txno(opts->verbose, istore, &txno, error); txidx = (opts->split_txers == MB_YES) ? txno - 1 : 0; /* initialize the output file if necessary */ if (ofile_init[txidx] == MB_NO) { status = mb_write_init(opts->verbose, ofile[txidx], opts->format, &ombio_ptr[txidx], &obeams_bath, &obeams_amp, &opixels_ss, error); if (status != MB_SUCCESS) { char message[MAX_ERROR_STRING] = {0}; sprintf(message, "SWATHplus file <%s> not initialized for writing.\n", ofile[txidx]); error_exit(verbose, *error, "mb_write_init", message); } if (status == MB_SUCCESS) { ofile_init[txidx] = MB_YES; } } /* assign output pointers based on txer channel */ omb_io_ptr = (struct mb_io_struct *)ombio_ptr[txidx]; ostore_ptr = omb_io_ptr->store_data; ostore = (struct mbsys_swathplus_struct *)ostore_ptr; /* copy the ping from istore to ostore */ if (status == MB_SUCCESS) { status = mbsys_swathplus_copy(opts->verbose, imbio_ptr, istore_ptr, ostore_ptr, error); } /* write the ping to file */ if (status == MB_SUCCESS) { ostore->kind = MB_DATA_DATA; ostore->type = SWPLS_ID_PROCESSED_PING2; status = mb_write_ping(opts->verbose, ombio_ptr[txidx], ostore, error); } /* check for error writing here */ if (status != MB_SUCCESS) { char message[MAX_ERROR_STRING] = {0}; sprintf(message, "Data not written to file <%s>\n", ofile[txidx]); error_exit(opts->verbose, *error, "mb_write_ping", message); } } /* end write sxp data to file */ } /* end processing sxp data */ } /* end looping over all records in file */ /* close the files */ status = mb_close(opts->verbose, &imbio_ptr, error); for (i = 0; i < SWPLS_MAX_TXERS; i++) { if (ofile_init[i] == MB_YES) { status = mb_close(opts->verbose, &ombio_ptr[i], error); ofile_init[i] = MB_NO; } } if (verbose >= 2) { fprintf(stderr, "\ndbg2 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); } /* process_output */
/*--------------------------------------------------------------------*/ int mb_buffer_dump(int verbose, void *buff_ptr, void *mbio_ptr, void *ombio_ptr, int nhold, int *ndump, int *nbuff, int *error) { char *function_name = "mb_buffer_dump"; int status = MB_SUCCESS; struct mb_buffer_struct *buff; struct mb_io_struct *mb_io_ptr; 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 buff_ptr: %p\n",(void *)buff_ptr); fprintf(stderr,"dbg2 mb_ptr: %p\n",(void *)mbio_ptr); fprintf(stderr,"dbg2 omb_ptr: %p\n",(void *)ombio_ptr); fprintf(stderr,"dbg2 nhold: %d\n",nhold); } /* get buffer structure */ buff = (struct mb_buffer_struct *) buff_ptr; /* get mbio descriptor */ mb_io_ptr = (struct mb_io_struct *) mbio_ptr; /* figure out how much to dump */ *ndump = buff->nbuffer - nhold; if (buff->nbuffer <= 0) { status = MB_FAILURE; *error = MB_ERROR_BUFFER_EMPTY; *ndump = 0; } else if (*ndump <= 0) { status = MB_FAILURE; *error = MB_ERROR_NO_DATA_DUMPED; *ndump = 0; } /* print debug statements */ if (verbose >= 4) { fprintf(stderr,"\ndbg4 Buffer list in MBIO function <%s>\n", function_name); fprintf(stderr,"dbg4 nbuffer: %d\n",buff->nbuffer); for (i=0;i<buff->nbuffer;i++) { fprintf(stderr,"dbg4 i:%d kind:%d ptr:%p\n", i,buff->buffer_kind[i],(void *)buff->buffer[i]); } } /* dump records from buffer */ if (status == MB_SUCCESS) { for (i=0;i<*ndump;i++) { /* print debug statements */ if (verbose >= 4) { fprintf(stderr,"\ndbg4 Dumping record in MBIO function <%s>\n",function_name); fprintf(stderr,"dbg4 record: %d\n",i); fprintf(stderr,"dbg4 ptr: %p\n",(void *)buff->buffer[i]); fprintf(stderr,"dbg4 kind: %d\n",buff->buffer_kind[i]); } /* only write out data if output defined */ if (ombio_ptr != NULL) status = mb_write_ping(verbose,ombio_ptr,buff->buffer[i],error); /* print debug statements */ if (verbose >= 4) { fprintf(stderr,"\ndbg4 Deallocating record in MBIO function <%s>\n",function_name); fprintf(stderr,"dbg4 record: %d\n",i); fprintf(stderr,"dbg4 ptr: %p\n",(void *)buff->buffer[i]); fprintf(stderr,"dbg4 kind: %d\n",buff->buffer_kind[i]); } status = mb_deall(verbose,mbio_ptr, &buff->buffer[i],error); buff->buffer[i] = NULL; /* print debug statements */ if (verbose >= 4) { fprintf(stderr,"\ndbg4 Done dumping record in MBIO function <%s>\n",function_name); fprintf(stderr,"dbg4 record: %d\n",i); fprintf(stderr,"dbg4 ptr: %p\n",(void *)buff->buffer[i]); fprintf(stderr,"dbg4 kind: %d\n",buff->buffer_kind[i]); } } for (i=0;i<nhold;i++) { /* print debug statements */ if (verbose >= 4) { fprintf(stderr,"\ndbg4 Moving buffer record in MBIO function <%s>\n",function_name); fprintf(stderr,"dbg4 old: %d\n",*ndump + i); fprintf(stderr,"dbg4 new: %d\n",i); fprintf(stderr,"dbg4 old ptr: %p\n",(void *)buff->buffer[*ndump + i]); fprintf(stderr,"dbg4 new ptr: %p\n",(void *)buff->buffer[i]); fprintf(stderr,"dbg4 old kind: %d\n",buff->buffer_kind[*ndump + i]); fprintf(stderr,"dbg4 new kind: %d\n",buff->buffer_kind[i]); } buff->buffer[i] = buff->buffer[*ndump + i]; buff->buffer_kind[i] = buff->buffer_kind[*ndump + i]; buff->buffer[*ndump + i] = NULL; buff->buffer_kind[*ndump + i] = 0; /* print debug statements */ if (verbose >= 4) { fprintf(stderr,"\ndbg4 Done moving buffer record in MBIO function <%s>\n",function_name); fprintf(stderr,"dbg4 old: %d\n",*ndump + i); fprintf(stderr,"dbg4 new: %d\n",i); fprintf(stderr,"dbg4 old ptr: %p\n",(void *)buff->buffer[*ndump + i]); fprintf(stderr,"dbg4 new ptr: %p\n",(void *)buff->buffer[i]); fprintf(stderr,"dbg4 old kind: %d\n",buff->buffer_kind[*ndump + i]); fprintf(stderr,"dbg4 new kind: %d\n",buff->buffer_kind[i]); } } buff->nbuffer = buff->nbuffer - *ndump; } /* print debug statements */ if (verbose >= 4) { fprintf(stderr,"\ndbg4 Buffer list at end of MBIO function <%s>\n",function_name); fprintf(stderr,"dbg4 nbuffer: %d\n",buff->nbuffer); for (i=0;i<buff->nbuffer;i++) { fprintf(stderr,"dbg4 i:%d kind:%d ptr:%p\n", i,buff->buffer_kind[i],(void *)buff->buffer[i]); } } /* set return value */ *nbuff = buff->nbuffer; /* print output debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBIO function <%s> completed\n",function_name); fprintf(stderr,"dbg2 Revision id: %s\n",rcs_id); fprintf(stderr,"dbg2 Return values:\n"); fprintf(stderr,"dbg2 ndump: %d\n",*ndump); fprintf(stderr,"dbg2 nbuff: %d\n",*nbuff); fprintf(stderr,"dbg2 error: %d\n",*error); fprintf(stderr,"dbg2 Return status:\n"); fprintf(stderr,"dbg2 status: %d\n",status); } /* return status */ return(status); }