Coder Social home page Coder Social logo

dwcaress / mb-system Goto Github PK

View Code? Open in Web Editor NEW
123.0 21.0 42.0 112.48 MB

MB-System is an open source software package for the processing and display of bathymetry and backscatter imagery data derived from multibeam, interferometry, and sidescan sonars.

Home Page: https://www.mbari.org/products/research-software/mb-system/

License: Other

Makefile 2.56% Shell 1.74% Batchfile 0.04% M4 0.27% Roff 5.27% C 57.40% HTML 12.17% JavaScript 0.10% GLSL 0.02% Perl 1.55% C++ 18.00% Python 0.23% DIGITAL Command Language 0.01% Fortran 0.01% PostScript 0.14% Dockerfile 0.03% CSS 0.01% QML 0.15% QMake 0.02% CMake 0.30%

mb-system's Issues

Need to build my own ubuntu image

The ubuntu 19.04 docker image apt-get upgrade is taking the majority of the test time and is the most frequent cause of failure. I really need to setup my own docker image and a cron job to push an updated image. Or is there an already up-to-date docker image of disco dingo?

Using status for things other than status

status should only be used for MB_SUCCESS or MB_FAILURE. Other uses make the code less straight forward.

e.g. from https://github.com/dwcaress/MB-System/blob/master/src/mbio/mbr_dsl120pf.c:

	int status = MB_SUCCESS;
	// SNIP
	status = fread(buffer, 1, 124, mbfp);
	if (status == 124) {
		status = MB_SUCCESS;
		*error = MB_ERROR_NO_ERROR;
	}
	else {
		status = MB_FAILURE;
		*error = MB_ERROR_EOF;
	}

fread returns size_t and the man page for fread says:

RETURN VALUES
     The functions fread() and fwrite() advance the file position indicator
     for the stream by the number of bytes read or written.  They return the
     number of objects read or written.  If an error occurs, or the end-of-
     file is reached, the return value is a short object count (or zero).

     The function fread() does not distinguish between end-of-file and error;
     callers must use feof(3) and ferror(3) to determine which occurred.  The
     function fwrite() returns a value less than nitems only if a write error
     has occurred.

It's possible that the error wasn't an EOF. Ignoring that, this code should be something like:

	const size_t bytes_expected = 124;
	const size_t num_read = fread(buffer, 1, bytes_expected, mbfp);
	const int status = num_read == bytes_expected ? MB_SUCCESS : MB_FAILURE;
	*error = status ? MB_ERROR_NO_ERROR : MB_ERROR_EOF;
	/* TODO(schwehr): Check for error conditions other than EOF. */

It would be nice if mb status and error become enums to flush out more of these beyond these:

egrep 'status = f(read|write)' *.c | wc -l
318

--enable-mbtrn broken

Sorry for the breakage. I didn't realize that mbtrn is embedded in mb_io.h and used in src/utilities/mbtrnpreprocess.c. I thought src/mbtrn was totally standalone. I'm working on getting it back into shape.

Along with that, there is something wrong with MBF_ELMK2UNB

mb_get_time global-buffer-overflow

Giving a month of 0 causes a buffer overflow.

int mb_get_time(int verbose, int time_i[7], double *time_d) {
	// SNIP
	int yearday = yday[time_i[1] - 1];
	// SNIP

All the time args should be range checked. min is easy. max is harder.

e.g. month:

  if (time_i[1] < 1) {
    fprintf(stderr, "ERROR: month < 1: %d\n", time_i[1]);
    return MB_FAILURE;
  }

Found with:

TEST(MbReadInitTest, doesNotExist) {
  int verbose = 0;
  int format = 0;
  int pings_get = 1;
  int lonflip = 0;
  double bounds[4] = {0.0, 0.0, 0.0, 0.0};
  int btime_i[7] = {0, 0, 0, 0, 0, 0, 0};
  int etime_i[7] = {0, 0, 0, 0, 0, 0, 0};
  double speedmin = 0.0;
  double timegap = 0.0;
  char file[MB_PATH_MAXLINE] = "/does/not/exist";
  void *mbio_ptr = nullptr;
  double btime_d;
  double etime_d;
  int beams_bath_alloc = 0;
  int beams_amp_alloc = 0;
  int pixels_ss_alloc = 0;
  int error = MB_ERROR_NO_ERROR;

  ASSERT_EQ(MB_FAILURE,
            mb_read_init(verbose, file, format, pings_get, lonflip, bounds,
                         btime_i, etime_i, speedmin, timegap, &mbio_ptr,
                         &btime_d, &etime_d, &beams_bath_alloc,
                         &beams_amp_alloc, &pixels_ss_alloc, &error));
  ASSERT_EQ(MB_ERROR_BAD_FORMAT, error);
  error = MB_ERROR_NO_ERROR;

  mbio_ptr = nullptr;
  format = MBF_SBSIOMRG;
  ASSERT_EQ(MB_FAILURE,
            mb_read_init(verbose, file, format, pings_get, lonflip, bounds,
                         btime_i, etime_i, speedmin, timegap, &mbio_ptr,
                         &btime_d, &etime_d, &beams_bath_alloc,
                         &beams_amp_alloc, &pixels_ss_alloc, &error));
  ASSERT_EQ(MB_ERROR_OPEN_FAIL, error);
  error = MB_ERROR_NO_ERROR;
}

asan details:

dbg2  MBIO function <mb_get_time> called
dbg2  Input arguments:
dbg2       verbose: 0
dbg2       year:    0
dbg2       month:   0
dbg2       day:     0
dbg2       hour:    0
dbg2       minute:  0
dbg2       second:  0
dbg2       microsec:0
dbg2       time_d:  0x7fef3f9cc580
dbg2       *time_d: 0.000000
=================================================================
==2736==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7fef4a83e17c at pc 0x7fef4ab3ac3d bp 0x7ffec2b9af00 sp 0x7ffec2b9aef8
READ of size 4 at 0x7fef4a83e17c thread T0
    #0 0x7fef4ab3ac3c in mb_get_time third_party/mbsystem/mbio/mb_time.c:58:16
    #1 0x7fef4ab1a68e in mb_read_init third_party/mbsystem/mbio/mb_read_init.c:152:11
    #2 0x7fef4b9f2ee8 in (anonymous namespace)::MbReadInitTest_doesNotExist_Test::TestBody() third_party/mbsystem/test/mbio/mb_read_init_test.cc:53:3

0x7fef4a83e17c is located 4 bytes to the left of global variable 'yday' defined in 'third_party/mbsystem/mbio/mb_time.c:30:18' (0x7fef4a83e180) of size 48
0x7fef4a83e17c is located 36 bytes to the right of global variable '<string literal>' defined in 'third_party/mbsystem/mbio/mb_time.c:49:19' (0x7fef4a83e140) of size 24
  '<string literal>' is ascii string 'dbg2       *time_d: %f
'
SUMMARY: AddressSanitizer: global-buffer-overflow third_party/mbsystem/mbio/mb_time.c:58:16 in mb_get_time
Shadow bytes around the buggy address:
  0x0ffe694ffbd0: 00 04 f9 f9 f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9
  0x0ffe694ffbe0: 00 00 00 f9 f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9
  0x0ffe694ffbf0: 00 00 00 f9 f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9
  0x0ffe694ffc00: 00 00 00 f9 f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9
  0x0ffe694ffc10: 00 00 00 f9 f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9
=>0x0ffe694ffc20: 00 00 00 f9 f9 f9 f9 f9 00 00 00 f9 f9 f9 f9[f9]
  0x0ffe694ffc30: 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9 00 00 00 00
  0x0ffe694ffc40: 00 00 00 00 05 f9 f9 f9 f9 f9 f9 f9 00 00 05 f9
  0x0ffe694ffc50: f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9 00 00 06 f9
  0x0ffe694ffc60: f9 f9 f9 f9 00 00 00 f9 f9 f9 f9 f9 00 04 f9 f9
  0x0ffe694ffc70: f9 f9 f9 f9 00 00 00 00 00 00 00 07 f9 f9 f9 f9
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc

Make README.md file and replace old README

I've made a pull request of making a README.md to make it in markdown. I think this should replace the original README. Markdown is as good as old school (no offence) README's.

GSF 3.09

Leidos has GSF 3.09 available on their site.

We could really use something in the makefile to force Unix formatted files (dos2unix) with the correct bits set and a few patches be applied on updating. The 3.08 update looks to have stepped on a few of those things.

Also, still no sign of tests, test files, or real revision history in upstream. We should be extra wary of regressions with this style of code.

Zip is here:
https://www.leidos.com/products/ocean-marine

I have not checked to see if any of the issues in my fork if GSF were addressed in upstream. Many of the issues are related to extra testing of GSF that could be move to MB-System. That testing could/should be copied to MB-System.

https://github.com/schwehr/generic-sensor-format/issues

Build error: "BUILD_GL" was never defined.

During the configuration process, I get the following error:

About to create Makefiles...
checking that generated files are newer than configure... done
configure: error: conditional "BUILD_GL" was never defined.
Usually this means the macro was only invoked conditionally.

Write a test for mb_format.c

mb_format looks like a good place to start writing tests for the core of mb_system for multiple reasons:

  1. The code is core to the operation of mbsystem
  2. Functions don't have documentation, so it's a chance to add it
  3. Demonstrates cleanup of headers
  4. A chance to show more ways that tests can be written that leverage C++11.
    e.g. the following example
TEST(MbFormatMbGetBasenameTest, SpecialExtension) {
  for (const auto initial : {"a.fbt", "a.fnv", "a.inf", "a.esf"}) {
    int verbose = 0;
    int error = -999;  // Not one of MB_ERROR_*
    char *path = strdup(initial);
    EXPECT_EQ(MB_SUCCESS, mb_get_basename(verbose, path, &error));
    EXPECT_EQ(MB_ERROR_NO_ERROR, error);
    EXPECT_STREQ("a", path);
    free(path);
  }
}

Be able to disable sonar format drivers

It would be nice to be able to control which formats are built into mb-system for several reasons:

  • Decrease build time while developing
  • Be able to focus fuzzing more tightly
  • Leave out drivers if you are worried about their security implications. e.g. GSF

For a note on GSF: I reported a number of issues with GSF (some more than 10 years ago) and have gotten no acknowledgements or fixes. Many of these issues are with improper handling of pointers. The GSF development process happens behind closed doors. It isn't clear how testing is done and if any code auditing is done. c.f. https://github.com/schwehr/generic-sensor-format/issues

sprintf buffer overflows

Describe the bug

clang runs in travis are detecting potential buffer overflows with sprintf. Additionally, sprintf is generally dangerous and only snprintf should be used.

The warning messages can be seen here https://travis-ci.org/schwehr/MB-System/builds/518381044

gcc -DHAVE_CONFIG_H -I. -I../../src/mbio  -I../../src/mbio -I../../src/mbaux -I../../src/mbview -I../../src/gsf  -I/usr/include      -g -O2 -MT mbnavadjust_creation.o -MD -MP -MF .deps/mbnavadjust_creation.Tpo -c -o mbnavadjust_creation.o mbnavadjust_creation.c
mbnavadjust_callbacks.c: In function ‘do_update_status’:
mbnavadjust_callbacks.c:646:26: warning: ‘%s’ directive writing up to 1023 bytes into a region of size 1010 [-Wformat-overflow=]
          ":::t\"Project: %s\":t\"Number of Files:                             %4d     Selected Survey:%4d\":t\"Number of "
                          ^~
mbnavadjust_callbacks.c:650:10:
          project.name, project.num_files, mbna_survey_select, project.num_crossings, mbna_file_select,
          ~~~~~~~~~~~~     
In file included from /usr/include/stdio.h:867,
                 from mbnavadjust_callbacks.c:29:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 426 and 1529 bytes into a destination of size 1024
   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       __bos (__s), __fmt, __va_arg_pack ());
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mbnavadjust_callbacks.c:668:59: warning: ‘%s’ directive writing up to 1023 bytes into a region of size 977 [-Wformat-overflow=]
           "Project:                                       %s\nNumber of Files:                           %d\nNumber of "
                                                           ^~
mbnavadjust_callbacks.c:671:11:
           project.name, project.num_files, project.num_crossings, project.num_crossings_analyzed, project.num_truecrossings,
           ~~~~~~~~~~~~                                     
In file included from /usr/include/stdio.h:867,
                 from mbnavadjust_callbacks.c:29:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 280 and 1363 bytes into a destination of size 1024
   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       __bos (__s), __fmt, __va_arg_pack ());
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mbnavadjust_callbacks.c:887:54: warning: ‘%s’ directive writing up to 1023 bytes into a region of size between 354 and 993 [-Wformat-overflow=]
      sprintf(string, "%4.4d:%2.2d %s %4d %4.1f %4.1f %s", file->id, file->block, filestatus, file->num_sections,
                                                      ^~
In file included from /usr/include/stdio.h:867,
                 from mbnavadjust_callbacks.c:29:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 32 and 1694 bytes into a destination of size 1024

To Reproduce

Build with a recent clang (e.g. version 8). e.g. a travis-ci build

Expected behavior

No potential for buffer overflows

Computing context (please complete the following information):

  • OS: Probably all
  • GIT head e.g. 8fcb617

Make the README more inviting to new users

The README for this repository is not very welcoming to new users.

Could you all clean it up and make it human-readable (new-user-readable) in a markup language like Markdown such that it is more inviting to a new user?

5.7.6beta22 build fail on CentOs

My initial take at the 5.7.6beta22 release is failing to build on CentOs 7.6 w/ gcc 4.8.5

The autoconf macro I invoke results in the use of -std=gnu++11 compile flags.

It doesn’t like a c++ structure defined in src/utilities/mbprocess.cc , failing at the line including "data(nullptr) {}”. The error message is below. The same code builds fine on MacOs and Ubuntu.

struct mbprocess_grid_struct {
mbprocess_grid_struct() :
file(""),
projectionname(""),
projection_mode(0),
projection_id(""),
nodatavalue(0.0f),
nxy(0),
n_columns(0),
n_rows(0),
min(0.0),
max(0.0),
xmin(0.0),
xmax(0.0),
ymin(0.0),
ymax(0.0),
dx(0.0),
dy(0.0),
data(nullptr) {}

public:
mb_path file;
mb_path projectionname;
int projection_mode;
mb_path projection_id;
float nodatavalue;
int nxy;
int n_columns;
int n_rows;
double min;
double max;
double xmin;
double xmax;
double ymin;
double ymax;
double dx;
double dy;
float *data;
};

/bin/sh ../../libtool --tag=CXX --mode=link g++ -std=gnu++11 -g -O2 -m64 -o mbpreprocess mbpreprocess.o ../../src/mbaux/libmbaux.la ../../src/mbio/libmbio.la -L/usr/local/lib64 -R /usr/local/lib64 -lgmt -lpostscriptlight -lnetcdf -lproj -lm
libtool: link: g++ -std=gnu++11 -g -O2 -m64 -o .libs/mbpreprocess mbpreprocess.o ../../src/mbaux/.libs/libmbaux.so -L/usr/local/lib64 -L/usr/lib64 /usr/local/src/MB-System-5.7.6beta22/src/mbio/.libs/libmbio.so -lgdal ../../src/mbio/.libs/libmbio.so /usr/local/src/MB-System-5.7.6beta22/src/bsio/.libs/libmbbsio.so /usr/local/src/MB-System-5.7.6beta22/src/surf/.libs/libmbsapi.so /usr/local/src/MB-System-5.7.6beta22/src/gsf/.libs/libmbgsf.so /usr/local/src/MB-System-5.7.6beta22/src/mbtrn/.libs/libr7kr.so /usr/local/src/MB-System-5.7.6beta22/src/mbtrn/.libs/libmframe.so -lpthread -lgmt -lpostscriptlight -lnetcdf -lproj -lm -Wl,-rpath -Wl,/usr/local/lib64
depbase=echo mbprocess.o | sed 's|[^/]*$|.deps/&|;s|\.o$||';
g++ -std=gnu++11 -DHAVE_CONFIG_H -I. -I../../src/mbio -I../../src/mbio -I../../src/mbaux -I../../src/gsf -I../../src/mbtrn/r7kr -I../../src/mbtrn/utils -I../../src/mbtrn/mframe/src -I/usr/local/include/gmt -I/usr/include -g -O2 -MT mbprocess.o -MD -MP -MF $depbase.Tpo -c -o mbprocess.o mbprocess.cc &&
mv -f $depbase.Tpo $depbase.Po
mbprocess.cc: In constructor \u2018mbprocess_grid_struct::mbprocess_grid_struct()\u2019:
mbprocess.cc:87:19: error: incompatible types in assignment of \u2018const char [1]\u2019 to \u2018mb_path {aka char [1024]}\u2019
data(nullptr) {}
^
mbprocess.cc:87:19: error: incompatible types in assignment of \u2018const char [1]\u2019 to \u2018mb_path {aka char [1024]}\u2019
mbprocess.cc:87:19: error: incompatible types in assignment of \u2018const char [1]\u2019 to \u2018mb_path {aka char [1024]}\u2019
make[3]: *** [mbprocess.o] Error 1
make[3]: Leaving directory /usr/local/src/MB-System-5.7.6beta22/src/utilities' make[2]: *** [all] Error 2 make[2]: Leaving directory /usr/local/src/MB-System-5.7.6beta22/src/utilities'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/MB-System-5.7.6beta22/src'
make: *** [all-recursive] Error 1
bash-4.2$ gedit src/utilities/mbprocess.cc &
[2] 115479

bash-4.2$ cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)

bash-4.2$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)

Expand travis tests to multiple Linux distros

I'd like to help expand MB-System's automated tests to more Linux variants. Getting automated builds for MacOSX or Windows would be out of scope for this effort, but the result should not prevent making those targets available in the future.

Desired coverage

We shouldn't look to cover every distribution under the sun for tests. Given the little traffic I've paid attention to I have seen at least the desire for the following:

  • Tests with distrubtion-standard versions
    • Ubuntu 19.04 (Disco) with default versions of gcc, gdal, gmt
    • Ubuntu 18.04 (Bionic) with default versions of gcc, gdal, gmt
    • Ubuntu 16.04 (Xenial) with default versions of gcc, gdal. GMT built from 6.0.0 sources
    • CentoOS 7 with default versions of gcc, gdal, gmt.
  • Tests with "latest" versions of PROJ (6.3) and GMT (6.0)
    • Ubuntu 18.04 (Bionic)
    • CentOS 8 (CentOS 7 sqlite3 version too old for PROJ 6)
  • Other test targets
    • Some distro with clang?

If there are other targets or combinations (such as building against packages available in ubuntugis) they can be added.

Approach

We'll need to use docker images since some of the desired linux targets are not provided as built-in distributions for travis-ci. Using docker images will also help automate keeping efforts such as #807 up to date.

Create a separate repository for MB-System dockerfiles

This would be the simplest way forward. Docker Hub can monitor a repo and automatically build multiple docker images any time the repo changes. A standard README file will also be used for Docker Hub's landing page for the images to help users decide which image is right for their use.

However, making tagged releases would require coordination between this separate repo and the main MB-System code repo.

Keep Docker files in main MB-System repo

Keeping everything in the same repo eliminates the need for extra coordination but is more complex. QGIS follows this model and I've been able to replicate something similar for MB-System. The travis-ci machinery to get this working is more complex, but nothing a detailed README shouldn't be able to cover. The current workflow looks like this:

  • Docker images with MB-System build dependencies are built weekly as travis-ci cron jobs and pushed to hub.docker.com
  • MB-System build tests run on every push on master (or PR, etc.) and pull the docker images with all the build dependencies from hub.docker.com

Discussion Points

  • What build targets do we want?
  • Which approach is most appropriate
  • How to hand over/test hub.docker.com credentials during PR

Testing for surf library's xdr encode/decode

Trying to sketch out how to do testing of xdr_surf.[ch]. Should be able to do it without having to touch files on disk... here is a sketch of how I think it should be done. I used xdr_int to stand in for calls from the API.

#include "xdr_surf.h"

#include <rpc/xdr.h>
#include <cstdint>
#include <cstdio>
#include <vector>

#include "testing/base/public/gunit.h"

namespace {

TEST(SurfTest, WriteRead) {
  std::vector<char> buf(8, 0);
  int expected = -123;
  {
    FILE *out = fmemopen(buf.data(), 8, "w");
    XDR xdrs;
    xdrstdio_create(&xdrs, out, XDR_ENCODE);
    int value = expected;
    EXPECT_TRUE(xdr_int(&xdrs, &value));
    xdr_destroy(&xdrs);
    EXPECT_EQ(0, fclose(out));
  }

  {
    FILE *in = fmemopen(buf.data(), 8, "r");
    XDR xdrs;
    xdrstdio_create(&xdrs, in, XDR_DECODE);
    int value = 0;
    EXPECT_TRUE(xdr_int(&xdrs, &value));
    EXPECT_EQ(expected, value);
    xdr_destroy(&xdrs);
    EXPECT_EQ(0, fclose(in));
  }
}

}  // namespace

Running mbcontour - module not found

I'm very new to MB-system so pardon my newbie questions. Anyway, I've finally been able to compile and follow the cookbook. When I get to

mbm_plot -F-1 -I datalist-1 -N

the datalist-1.cmd is made. Running datalist-1.cmd gives

$ bash datalist-1.cmd
Setting temporary GMT defaults...
Running mbcontour...

        GMT - The Generic Mapping Tools, Version 5.4.0 (r18194) [64-bit] [MP] [4 cores]
(c) 1991-2017 Paul Wessel, Walter H. F. Smith, Remko Scharroo, Joaquim Luis, and Florian Wobbe

Supported in part by the US National Science Foundation (http://www.nsf.gov/)
and volunteers from around the world (see http://gmt.soest.hawaii.edu/).

This program comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of this program under the terms of the
GNU Lesser General Public License (http://www.gnu.org/licenses/lgpl.html).
For more information about legal matters, see the file named LICENSE.TXT.

usage: gmt [options]
       gmt <module name> [<module-options>]

Session management:
  gmt clear history | conf | cache | all
                    Deletes gmt.history, gmt.conf, the user cache dir, or all of them

options:
  --help            List descriptions of available GMT modules.
  --show-bindir     Show directory with GMT executables.
  --show-cores      Print number of available cores.
  --show-datadir    Show directory/ies with user data.
  --show-modules    List all module names.
  --show-library    Show path of the shared GMT library.
  --show-plugindir  Show directory for plug-ins.
  --show-sharedir   Show directory for shared GMT resources.
  --version         Print GMT version number.

if <module-options> is '=' we call exit (0) if module exist and non-zero otherwise.

ERROR: No module named mbcontour was found.  This could mean one of three cases:
  1. There actually is no such module; please check your spelling.
  2. Module exists in the GMT supplemental library, but the library could not be found.
  3. Module exists in a GMT custom library, but none was specified via GMT_CUSTOM_LIBS.
Shared libraries must be in standard system paths or set via environmental parameter LD_LIBRARY_PATH.

Running psbasemap...
psbasemap: Constructing the basemap
Deleting surplus files...
Attempting to display the Postscript plot...
Displaying using system default program through gio open...
gio: file:///home/user/mbes/datalist-1.ps: No application is registered as handling this file
All done!

The problem seems to be (taken from the output above):

ERROR: No module named mbcontour was found.  This could mean one of three cases:
  1. There actually is no such module; please check your spelling.
  2. Module exists in the GMT supplemental library, but the library could not be found.
  3. Module exists in a GMT custom library, but none was specified via GMT_CUSTOM_LIBS.
Shared libraries must be in standard system paths or set via environmental parameter LD_LIBRARY_PATH.

I've built GMT 5.4.0 and 5.4.5 in an attempt to fix it, without luck. Any tips?

Mac OSX Travis build failing for homebrew gmt

Taken from #971

Mac OSX homebrew gmt-config failure... https://travis-ci.com/dwcaress/MB-System/jobs/289317256 that also occurred on ffe686f

Therefore, I'm going to go ahead and commit. Looks like homebrew has an issue or the mbsystem config.

There have been no changes in:

InstalledDir: /Applications/Xcode-9.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Configured with: --prefix=/Applications/Xcode-9.4.1.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode-9.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
PROJ info:
Rel. 6.2.1, November 1st, 2019
usage: proj [-bdeEfiIlmorsStTvVwW [args]] [+opt[=arg] ...] [file ...]
GDAL info:
2.4.2
GMT info:
./ci/travis/build_osx/before_script.sh: line 18: gmt-config: command not found
The command "./ci/travis/${TRAVIS_CONFIG}/before_script.sh" failed and exited with 127 during .

make install should not try to install anything in the third_party tree

@dwcaress saw this on his mac:

libtool: install: /usr/bin/install -c .libs/mbnavadjust /usr/local/bin/mbnavadjust
libtool: install: /usr/bin/install -c .libs/mbnavadjustmerge /usr/local/bin/mbnavadjustmerge
make[3]: Nothing to be done for `install-data-am'.
make[3]: Nothing to be done for `install-exec-am'.
make[3]: Nothing to be done for `install-data-am'.
Making install in third_party
Making install in googletest
echo "'make install' is dangerous and not supported. Instead, see README for how to integrate Google Test into your build system."
'make install' is dangerous and not supported. Instead, see README for how to integrate Google Test into your build system.
false
make[3]: *** [install-exec-local] Error 1
make[2]: *** [install-am] Error 2
make[1]: *** [install-recursive] Error 1
make: *** [install-recursive] Error 1

I didn't think to try installing when I setup googletest/googlemock.

So the tasks here are:

  • cause make install do nothing in third_party
  • make travis-ci try to install mb-system someplace

mb_readwritegrd.c: Probable bug with kx2 in mb_read_gmt_grd

I found this because of:

mb_readwritegrd.c: In function ‘mb_read_gmt_grd’:
mb_readwritegrd.c:247:39: warning: ‘kx2’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  247 |             (*data_dzdx)[k] = ((*data)[kx2] - (*data)[kx0]) / (((double)ii) * ddx);
      |                                       ^

I did cleanup in #1028 - 8471b91

      for (int i = 0; i < *n_columns; i++)
        for (int j = 0; j < *n_rows; j++) {
          const int k = i * (*n_rows) + j;
          int ii = 0;

          int kx0;
          if (i > 0) {
            kx0 = (i - 1) * (*n_rows) + j;
            ii++;
          } else {
            kx0 = k;
          }

          int kx2 = 0;
          if (i < *n_columns - 1) {
            kx2 = (i + 1) * (*n_rows) + j;
            ii++;
          } else {
            kx0 = k;  // TODO(schwehr): Should this be kx2?
          }

          int jj = 0;

          int ky0;
          if (j > 0) {
            ky0 = i * (*n_rows) + j + 1;
            jj++;
          } else {
            ky0 = k;
          }

PKGBUILD for Archlinux

I am working on a PKGBUILD for Archlinux (user-repository recipe for building and packaging). This is my current state, am I missing any important configure or build flags? Are there some important optimisations I should include?

pkgname=mb-system-git
pkgver=r2713.931988a4
pkgrel=1
_pkgname=mb-system
pkgdesc="An open source software package for the processing and display of bathymetry and backscatter imagery data derived from multibeam, interferometry, and sidescan sonars- Git version."
arch=('i686' 'x86_64')  # TODO i686 is untested
url="https://www.mbari.org/products/research-software/mb-system/"
license=('GPL3')
depends=('glu' 'gmt' 'openmotif')
makedepends=('git')
provides=('mb-system')
sha1sums=('SKIP')

source=("$_pkgname::git+https://github.com/dwcaress/MB-System.git")

pkgver() {
  cd "${srcdir}"/$_pkgname
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}"/$_pkgname
  # tirpc via https://cygwin.cygwin.narkive.com/Ob5WL6zw/cygwin-configure-error-required-header-rpc-types-h-not-found
  export CPPFLAGS="$CPPFLAGS -I/usr/include/tirpc"
  ./configure --prefix=/usr
}

build() {
  cd "${srcdir}"/$_pkgname
  make
}

package() {
  # all the warnings like below are irrelevant, the packaging works fine:
  #   libtool: warning: remember to run 'libtool --finish /usr/lib'
  #   libtool: warning: 'libmbgsf.la' has not been installed in '/usr/lib'
  cd "${srcdir}"/$_pkgname
  make DESTDIR="$pkgdir/" install
}


UB in mbsys_reson7k.c

mbsys_reson7k.c: In function ‘mbsys_reson7k_alloc’:
mbsys_reson7k.c:988:36: warning: iteration 6 invokes undefined behavior [-Waggressive-loop-optimizations]
  988 |     calibratedsnippet->reserved[i] = 0;
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
mbsys_reson7k.c:987:3: note: within this loop
  987 |   for (int i = 0; i < 28; i++)
      |   ^~~

Environment: debian testing

gcc --version
gcc (Debian 9.2.1-8) 9.2.1 20190909

build:

./autogen.sh
CFLAGS='-g -O2 -Wno-format -Wno-stringop-truncation -Wno-stringop-overflow -Wall -Wextra -Wno-sign-compare -Wno-maybe-uninitialized -Wno-format-overflow' ./configure --enable-static --disable-shared --enable-test --prefix=`pwd`/inst
make clean -j 50
make -j 50 check

The code:

  /* Reson 7k calibrated snippet (record 7058) */
  s7kr_calibratedsnippet *calibratedsnippet = &store->calibratedsnippet;
  mbsys_reson7k_zero7kheader(verbose, &calibratedsnippet->header, error);
  calibratedsnippet->serial_number = 0;
  calibratedsnippet->ping_number = 0;
  calibratedsnippet->multi_ping = 0;
  calibratedsnippet->number_beams = 0;
  calibratedsnippet->error_flag = 0;
  calibratedsnippet->control_flags = 0;
  for (int i = 0; i < 28; i++)
    calibratedsnippet->reserved[i] = 0;   //. <-------- Issue is here
  for (int i = 0; i < MBSYS_RESON7K_MAX_BEAMS; i++) {
    s7kr_calibratedsnippettimeseries *calibratedsnippettimeseries =
        &calibratedsnippet->calibratedsnippettimeseries[i];
    calibratedsnippettimeseries->beam_number = 0;
    calibratedsnippettimeseries->begin_sample = 0;
    calibratedsnippettimeseries->detect_sample = 0;
    calibratedsnippettimeseries->end_sample = 0;
    calibratedsnippettimeseries->nalloc = 0;
    calibratedsnippettimeseries->amplitude = NULL;
  }

Whoops.... s7kr_calibratedsnippet in mbsys_reson7k.h. 28 is a lot more than 6.

  unsigned int reserved[6];  // Reserved for future use

GMT 6.x.x and MB-System issues

Hi MB-System developers. The GMT developers have decided to be more proactive in making sure MB-system works well with GMT 6.x and future releases. I have therefore forked your repo and trying to build and fix anything so I can submit a pull request. This is on macOS Catalina with macports. Since I rarely build MB it is likely I am running into trivial issues but they are preventing me from doing my testing. Here is my status:

  1. Your list of prerequisites seems incomplete: proj is not mentioned, and GDAL is missing from your README.md (but mentioned on the MBARI list).
  2. I have a configure script that has worked in the past, and works (up to a point) with 5.7.5. The problem is that despite configuring with --with-proj-lib=/opt/local/lib/proj6/lib --with-proj-include=/opt/local/lib/proj6/include, the master build fails with
g++ -std=gnu++11 -DHAVE_CONFIG_H -I. -I../../src/mbio  -I../../src/mbio -I../../src/mbaux -I../../src/gsf  -I/Users/pwessel/GMTdev/gmt-dev/dbuild/gmt6/include/gmt -I/opt/local/include -I/opt/local/include   -g -O2 -MT mbsvpselect.o -MD -MP -MF $depbase.Tpo -c -o mbsvpselect.o mbsvpselect.cc &&\
	mv -f $depbase.Tpo $depbase.Po
mbsvpselect.cc:193:10: fatal error: 'geodesic.h' file not found
#include <geodesic.h>

That file exists, so I am not sure why my includes are not honored for this makefile. I see there is now lots of C++ files that have been added so perhaps the build for these are not robust yet. So I try the 5.7.5 tarball instead. This works until we hit src/gmt. This step fail because the precompiler directives to check for GMT 5 versions fail on 6.0.0 and think it is < 5.2.1, and chaos ensues. Specifically,

#if GMT_MINOR_VERSION == 1 && GMT_RELEASE_VERSION < 2
			if (gmt_check_filearg(GMT, '<', opt->arg, GMT_IN)) {
#else
			if (gmt_check_filearg(GMT, '<', opt->arg, GMT_IN, GMT_IS_DATASET)) {
#endif

needs to be

#if GMT_MAJOR_VERSION == 5 && GMT_MINOR_VERSION == 1 && GMT_RELEASE_VERSION < 2
			if (gmt_check_filearg(GMT, '<', opt->arg, GMT_IN)) {
#else
			if (gmt_check_filearg(GMT, '<', opt->arg, GMT_IN, GMT_IS_DATASET)) {
#endif

Same for mbcontour.c and mbgrdtiff.c. Similarly, the two latter tools also need

#if GMT_MAJOR_VERSION == 6 || (GMT_MAJOR_VERSION == 5 && GMT_MINOR_VERSION > 3)
	n_errors += gmt_M_check_condition(GMT, !GMT->common.R.active[RSET], "Syntax error: Must specify -R option\n");
#else
	n_errors += gmt_M_check_condition(GMT, !GMT->common.R.active, "Syntax error: Must specify -R option\n");
#endif

to compile. With these edits, mb-system builds with GMT 6.x. I note your instructions state you require GMT 5.4 or later. If so, you could have configure check for that (via gmt --version) and stop if that is not true - you could then remove all those #ifdefs that deal with things older than 5.4. In fact, you have lots of defines at the top of each of these three C codes that deal with 5.2 and older. You could yank all that if you stick to your 5.4 cutoff. Even Ubuntu seems to have managed to move up to 5.4.5.

However, if you can address the build issues with g++ above (or tell me how to circumvent it) then I am happy to submit a pull request.

Should only have one declaration per function

There should be only one prototype / declarations for each function. The register functions have a declaration in both mb_format.h and mbr_*.c. e.g.

grep mbr_register_hysw *.[ch]
mb_format.c:            status = mbr_register_hysweep1(verbose, mbio_ptr, error);
mb_format.h:int mbr_register_hysweep1(int verbose, void *mbio_ptr, int *error);
mbr_hysweep1.c:int mbr_register_hysweep1(int verbose, void *mbio_ptr, int *error);
mbr_hysweep1.c:int mbr_register_hysweep1(int verbose, void *mbio_ptr, int *error) {
mbr_hysweep1.c: char *function_name = "mbr_register_hysweep1";

I think the format drivers like mbr_hysweep1.c should include mb_format.h and use that declaration.

Provide docker based installation

@dwcaress, as we recently talked, I'm starting this ticket by just capturing various aspects mentioned in our email thread started a few months ago. We can elaborate on details as this progresses.

Status here last updated: 2020-05-27

  • Docker release: set up a mechanism to automatically build an MB-System Docker package with each major release from Github.

    The mechanism exists and has been tested in a fork. All it remains is to enable it for this repo at Docker Hub.

  • Base image: no particular preference for which Linux to use as base image.

    We agreed on using CentOS 7 as base image.

  • GMT: docker image will have to have a current GMT built from source just as it does MB-System.

  • GUIs: existing visualization tools use X11/Motif/OpenGL

    • All of them seem to be working on CentOS7
    • MacOS: X11-only graphical tools are working
    • MacOS OpenGL (thanks Dave for the solution)
  • Other: there needs to be a way to display postscript and images, and to edit text files.

    evince, gedit, vim are included in the image.

  • Other: Access to network shares from the container.

    This only needs some rather minor customization to the image regarding proper user permissions.

Update Kongsberg kmall format to rev. G

The Kongsberg kmall format has been revised and is now in rev G (01.11.2019). As far as I can tell the implementation of the KMall-format in MB-System is based on rev. F of the datagram description.

I've tried to use MB-System 5.7.6beta31 with kmall-files in presumably rev. G, and getting into trouble. Sample file can be supplied if necessary.

E.g. 1

$ mbnavlist -I file.kmall

The MBF_KEMKMALL module skipped data between identified
data records. Something is broken, most likely the data...
However, the data may include a data record type that we
haven't seen yet, or there could be an error in the code.
If skipped data are reported multiple times, we recommend
you post a problem description through the discussion list
available at https://listserver.mbari.org/sympa/arc/mbsystem
and make a data sample available.
Have a nice day...
MBF_KEMKMALL skipped 25568 bytes before record #CHE at file pos 28818
Segmentation fault (core dumped)

e.g. 2

$ mbnavlist -I file2.kmall

The MBF_KEMKMALL module skipped data between identified
data records. Something is broken, most likely the data...
However, the data may include a data record type that we
haven't seen yet, or there could be an error in the code.
If skipped data are reported multiple times, we recommend
you post a problem description through the discussion list
available at https://listserver.mbari.org/sympa/arc/mbsystem
and make a data sample available.
Have a nice day...
MBF_KEMKMALL skipped 45870 bytes before record #SKM at file pos 52582

The datagram description may be downloaded from Kongsbergs website; https://www.kongsberg.com/maritime/support/document-and-downloads/software-downloads/; "KMALL - Datagram description Rev:G". The changes between rev. F to rev. G is (quote from the document):

Rev G. 01 NOV 2019
Code changes:

#FCF datagram, new datagram for backscatter calibration

#MRZ datagram, updated to version 1
Line 880: float bsCorrectionOffset_dB - Backscatter offset set in the installation menu.
Line 881: uint8_t lambertsLawApplied - Beam intensity data corrected as seabed image data (Lambert and normal incidence corrections).
Line 882: uint8_t iceWindow - Ice window installed.
Line 883: uint16_t padding4 - Padding for byte alignment.
Line 905: Description changed: float txNominalSourceLevel_dB; - Actual SL = txNominalSourceLevel_dB + highVoltageLevel_dB. Unit dB re 1 microPascal.
Line 916: float highVoltageLevel_dB - 20log(Measured high voltage power level at TX pulse or Nominal high voltage power level). This parameter will also include the effect of user selected transmit power reduction (transmitPower_dB) and mammal protection. Actual SL = txNominalSourceLevel_dB + highVoltageLevel_dB. Unit dB.
Line 917: float sectorTrackingCorr_dB - Backscatter correction added in sector tracking mode. Unit dB.
Line 918: float effectiveSignalLength_sec - Signal length used for backscatter footprint calculation. This compensates for the TX pulse tapering and the RX filter bandwidths. Unit second.

#MWC datagram, updated to version 1
Line 1163: float detectedRangeInSamplesHighResolution - The same information as in detectedRangeInSamples with higher resolution. Two way range in samples. Approximation to calculated distance from tx to bottom detection [meters] = soundVelocity_mPerSec * detectedRangeInSamples / (sampleFreq_Hz * 2). The detected range is set to zero when the beam has no bottom detection.

#SVT datagram
Line 515, 516: Kongsberg sound velocity datagrams KSSIS 80 and KSSIS 43 added.

Issues with RSET on mbcontour.c and mbgrdtiff.c

Had some troubles while building latest release on debian stable.
while doing a make, got:

In file included from /usr/include/gmt/gmt_dev.h:136:0, from mbcontour.c:43: mbcontour.c: In function ‘GMT_mbcontour_parse’: mbcontour.c:538:63: error: ‘RSET’ undeclared (first use in this function) n_errors += gmt_M_check_condition(GMT, !GMT->common.R.active[RSET], "Syntax error: Must specify -R option\n");

commented the usage of RSET in mbcontour.c , cleaned the build, restarted the make and got a

mbgrdtiff.c: In function ‘GMT_mbgrdtiff’: mbgrdtiff.c:852:28: error: ‘RSET’ undeclared (first use in this function) if (!GMT->common.R.active[RSET] && n_grids) ^~~~

Followed the same strategy, and commented the block with the if condition.
Built correctly after that...

Better tests for mb_absorption.c and parameter checks

3eee9cd added mb_absorption_test.py that has some quick checks that capture the output that I found with mb_absorption.

To better characterize the functions in mb_absorption.c, I made a quick proto based llvm fuzzer and ran it in asan mode. I found 136 cases and no crashes. This shows that non-sensical values don't trigger trouble or complaints from the function.

It would be good to have a mb_absorption_test.cc with:

  • some key corner cases
  • out of bounds values and range checks added to mb_absorption.c

e.g.

absorption: 0
algorithm: 1
conductivity: 6
density: 0
depth: 0
frequency: 0
latitude: 0
ph: 6
potential_temperature: 0
pressure: inf
salinity: 0
soundspeed: 0
temperature: 6
verbose: 0

and

absorption: 10174880603439102
algorithm: 268435460
conductivity: 10174880603439102
density: 10174880603439102
depth: 10174880603439102
frequency: 1.1125375509644342e-308
latitude: 4.9390607875555734e+257
ph: 8.9002954340290051e-308
potential_temperature: 4.9390607875556022e+257
pressure: 10174880603439102
salinity: 10174880603439102
soundspeed: 1.1125369292536007e-308
temperature: 1.1125369292536007e-308
verbose: 272629764
// Copyright 2019 Google Inc. All Rights Reserved.

#include "base/logging.h"
#include "proto_message_mutator.h"
#include "third_party/mbsystem/mbio/mb_absorption_fuzzer.pb.h"
#include "third_party/mbsystem/mbio/mb_absorption_fuzzer.proto.h"
#include "third_party/mbsystem/mbio/mb_define.h"
#include "third_party/mbsystem/mbio/mb_status.h"

using third_party::mbsystem::mbio::MbAbsorption;

DEFINE_PROTO_FUZZER(const MbAbsorption &a) {
  {
    double absorption = a.absorption();
    int error = a.error();

    const int result =
        mb_absorption(a.verbose(), a.frequency(), a.temperature(), a.salinity(),
                      a.depth(), a.ph(), a.soundspeed(), &absorption, &error);
    CHECK(result == MB_SUCCESS || result == MB_FAILURE);
    CHECK(error >= MB_ERROR_SIDESCAN_IGNORED && error <= MB_ERROR_MISSING_DATA);
  }
  {
    double absorption;
    int error;

    const int result =
        mb_absorption(a.verbose(), a.frequency(), a.temperature(), a.salinity(),
                      a.depth(), a.ph(), a.soundspeed(), &absorption, &error);
    CHECK(result == MB_SUCCESS || result == MB_FAILURE);
    CHECK(error >= MB_ERROR_SIDESCAN_IGNORED && error <= MB_ERROR_MISSING_DATA);
  }
  {
    double potential_temperature = a.potential_temperature();
    int error;
    const int result =
        mb_potential_temperature(a.verbose(), a.temperature(), a.salinity(),
                                 a.pressure(), &potential_temperature, &error);
    CHECK(result == MB_SUCCESS || result == MB_FAILURE);
    CHECK(error >= MB_ERROR_SIDESCAN_IGNORED && error <= MB_ERROR_MISSING_DATA);
  }
  {
    int error;
    double density = a.density();
    const int result =
        mb_seabird_density(a.verbose(), a.salinity(), a.temperature(),
                           a.pressure(), &density, &error);
    CHECK(result == MB_SUCCESS || result == MB_FAILURE);
    CHECK(error >= MB_ERROR_SIDESCAN_IGNORED && error <= MB_ERROR_MISSING_DATA);
  }
  {
    int error;
    double depth = a.depth();
    const int result = mb_seabird_depth(a.verbose(), a.pressure(), a.latitude(),
                                        &depth, &error);
    CHECK(result == MB_SUCCESS || result == MB_FAILURE);
    CHECK(error >= MB_ERROR_SIDESCAN_IGNORED && error <= MB_ERROR_MISSING_DATA);
  }
  {
    double salinity = a.salinity();
    int error;
    const int result =
        mb_seabird_salinity(a.verbose(), a.conductivity(), a.temperature(),
                            a.pressure(), &salinity, &error);
    CHECK(result == MB_SUCCESS || result == MB_FAILURE);
    CHECK(error >= MB_ERROR_SIDESCAN_IGNORED && error <= MB_ERROR_MISSING_DATA);
  }
  {
    double soundspeed = a.soundspeed();
    int error;
    const int result = mb_seabird_soundspeed(a.verbose(), a.algorithm(),
                                             a.salinity(), a.temperature(),
                                             a.pressure(), &soundspeed, &error);
    CHECK(result == MB_SUCCESS || result == MB_FAILURE);
    CHECK(error >= MB_ERROR_SIDESCAN_IGNORED && error <= MB_ERROR_MISSING_DATA);
  }
}

The proto:

// Copyright 2019 Google Inc. All Rights Reserved.

syntax = "proto2";

package third_party.mbsystem.mbio;

option cc_api_version = 2;

message MbAbsorption {
  required double absorption = 1;
  required int32 algorithm = 2;
  required double conductivity = 3;
  required double density = 4;
  required double depth = 5;
  required double frequency = 6;
  required double latitude = 7;
  required double ph = 8;
  required double potential_temperature = 9;
  required double pressure = 10;
  required double salinity = 11;
  required double soundspeed = 12;
  required double temperature = 13;
  required int32 verbose = 14;
  required int32 error = 15;
}

mb_absorption_corpus.zip

Remove redundant comments

/* return status */
	return (status);

Can we remove these? There are other similar comments, but this is the most glaring one. It eats up tons of lines without adding the reader. If you are ok with this o e, I will send a pull request

Create a first C++ test of a format driver - hydrosweep raw

Is your feature request related to a problem? Please describe.

Understanding and modifying a format driver is currently difficult for someone new to the project. Some older drivers crash (e.g. the old cookbook). A test suite would also give something simple to run ASAN and MSAN on to look for additional issues. It would also provide examples that would be useful as examples when writing fuzzers.

Describe the solution you'd like

A series of tests for both reading and writing the format. I think raw hydrosweep might be a good place to start as the format is text based, I have samples from one of my own cruises, and I used one of those files for an initial mbinfo test. Additionally, this is a format that is not in active development, so the risks to other peoples' mb-system development is lower.

           MBIO Data Format ID:  21
           Format name:          MBF_HSATLRAW
           Informal Description: Raw Hydrosweep
           Attributes:           Hydrosweep DS, bathymetry and
                                 amplitude, 59 beams, ascii,
                                 Atlas Electronik.

Describe alternatives you've considered

Binary formats are much more confusing when it comes to test file contents, so I want to avoid those when starting.

There are lots of other ASCII formats like this one, but I don't have my own samples.

           MBIO Data Format ID:  161
           Format name:          MBF_MGD77DAT
           Informal Description: NGDC MGD77 underway geophysics
                                 format
           Attributes:           single beam bathymetry, nav,
                                 magnetics, gravity, ascii,
                                 NOAA NGDC

Additional context

I am having trouble getting started looking at the source files:

wc -l *hsat*.[ch]
   232 mbf_hsatlraw.h
  3123 mbr_hsatlraw.c
  3355 total

I am having to move the function prototypes header, but don't follow what the pattern is to read a file.

egrep 'int mbr_' mbf_hsatlraw.h | egrep -v '_(wr|wt|write)_'
int mbr_register_hsatlraw(int verbose, void *mbio_ptr, int *error);
int mbr_info_hsatlraw(int verbose, int *system, int *beams_bath_max, int *beams_amp_max, int *pixels_ss_max, char *format_name,
int mbr_alm_hsatlraw(int verbose, void *mbio_ptr, int *error);
int mbr_dem_hsatlraw(int verbose, void *mbio_ptr, int *error);
int mbr_zero_hsatlraw(int verbose, void *data_ptr, int mode, int *error);
int mbr_rt_hsatlraw(int verbose, void *mbio_ptr, void *store_ptr, int *error);
int mbr_hsatlraw_rd_label(int verbose, FILE *mbfp, char *line, int *type, int *shift, int *error);
int mbr_hsatlraw_read_line(int verbose, FILE *mbfp, int minimum_size, char *line, int *error);
int mbr_hsatlraw_rd_ergnhydi(int verbose, FILE *mbfp, struct mbf_hsatlraw_struct *data, int shift, int *error);
int mbr_hsatlraw_rd_ergnpara(int verbose, FILE *mbfp, struct mbf_hsatlraw_struct *data, int shift, int *error);
int mbr_hsatlraw_rd_ergnposi(int verbose, FILE *mbfp, struct mbf_hsatlraw_struct *data, int shift, int *error);
int mbr_hsatlraw_rd_ergneich(int verbose, FILE *mbfp, struct mbf_hsatlraw_struct *data, int shift, int *error);
int mbr_hsatlraw_rd_ergnmess(int verbose, FILE *mbfp, struct mbf_hsatlraw_struct *data, int shift, int *error);
int mbr_hsatlraw_rd_ergnslzt(int verbose, FILE *mbfp, struct mbf_hsatlraw_struct *data, int shift, int *error);
int mbr_hsatlraw_rd_ergnctds(int verbose, FILE *mbfp, struct mbf_hsatlraw_struct *data, int shift, int *error);
int mbr_hsatlraw_rd_ergnampl(int verbose, FILE *mbfp, struct mbf_hsatlraw_struct *data, int shift, int *error);
int mbr_hsatlraw_rd_ldeocmnt(int verbose, FILE *mbfp, struct mbf_hsatlraw_struct *data, int shift, int *error);
int mbr_hsatlraw_rd_data(int verbose, void *mbio_ptr, int *error);

I will probably need to do a trace of a utility program reading a sample file so I can see how these all fit together and how to assemble tests that test just one component. Perhaps I can make files with just one packet type to test things individually like mbr_hsatlraw_rd_ergnhydi. Things like mbinfo are great for writing tests that give quick coverage of a large swath of the code, but they are not going to be very helpful for quickly narrowing down bugs / regressions.

mbsys_simrad3_zero_ss had for i inside of for i

Definitely not going to zero all the things

for (int i = 0; i < MBSYS_SIMRAD3_NUM_PING_STRUCTURES; i++) {
  // ...
  for (int i = 0; i < MBSYS_SIMRAD3_MAXBEAMS; i++) {
    //
  }
  for (int i = 0; i < MBSYS_SIMRAD3_MAXRAWPIXELS; i++) {
    //
  }
  for (int i = 0; i < MBSYS_SIMRAD3_MAXPIXELS; i++) {
     //
  }
}

trn code has lots of typos and trailing whitespace

Using:

codespell *trn* | egrep -v 'reson|OBJEXT| BA |leapYear|AddDS|NED|gctp|indexS| OT |Reson

There is a long list of probable typos:

mbtrn/emu7k.sh:147: processsing  ==> processing
mbtrn/emu7k.sh:149: paramters  ==> parameters
mbtrn/emu7k.sh:190: Comand  ==> Command
mbtrn/emu7k.sh:354: intialize  ==> initialize
mbtrn/mbtrnpp.sh:38: overriden  ==> overridden
mbtrn/mbtrnpp.sh:292: processsing  ==> processing
mbtrn/mbtrnpp.sh:294: paramters  ==> parameters
mbtrn/mbtrnpp.sh:341: Comand  ==> Command
mbtrn/mbtrnpp.sh:679: intialize  ==> initialize
mbtrn/utils/stream7k.c:356: connnect  ==> connect
mbtrn/utils/tbinx.c:747: initialze  ==> initialize
mbtrn/utils/tbinx.c:782: availble  ==> available
mbtrn/r7kr/r7k-reader.c:529: tim  ==> time, tim  | disabled due to being a person's name
mbtrn/r7kr/r7kc.c:373: unsufficient  ==> insufficient
mbtrn/r7kr/r7kc.c:1424: explicitely  ==> explicitly
mbtrn/r7kr/r7kc.c:1608: OD  ==> OF
mbtrn/r7kr/r7kc.c:1616: od  ==> of
mbtrn/mframe/src/mmdebug.h:237: messsage  ==> message
mbtrn/mframe/src/mlog.h:181: te  ==> the, be
mbtrn/mframe/src/mlog.h:183: te  ==> the, be
mbtrn/mframe/src/mlog.h:199: extention  ==> extension
mbtrn/mframe/src/mtime.h:241: specied  ==> specified
mbtrn/mframe/src/mtime.h:246: specied  ==> specified
mbtrn/mframe/src/medebug.h:16: argment  ==> argument
mbtrn/mframe/src/mlog.c:397: te  ==> the, be
mbtrn/mframe/src/mlog.c:397: te  ==> the, be
mbtrn/mframe/src/mlog.c:399: te  ==> the, be
mbtrn/mframe/src/mlog.c:401: te  ==> the, be
mbtrn/mframe/src/mlog.c:610: te  ==> the, be
mbtrn/mframe/src/mlog.c:792: te  ==> the, be
mbtrn/mframe/src/mlog.c:792: te  ==> the, be
mbtrn/mframe/src/mlog.c:1700: alog  ==> along
mbtrn/mframe/src/mlog.c:1702: alog  ==> along
mbtrn/mframe/src/mlog.c:1759: alog  ==> along
mbtrn/mframe/src/msocket.c:623: ohterwise  ==> otherwise
mbtrn/mframe/src/mlist.c:104: partioning  ==> partitioning
mbtrn/mframe/src/mlist.c:442: ith  ==> with
mbtrnav/terrain-nav/TNavExtendKalmanFilter.h:48: Initalize  ==> Initialize
mbtrnav/terrain-nav/TNavExtendKalmanFilter.h:157: measurment  ==> measurement
mbtrnav/terrain-nav/TNavExtendKalmanFilter.h:167: measurment  ==> measurement
mbtrnav/terrain-nav/mapio.cpp:8: formated  ==> formatted
mbtrnav/terrain-nav/TNavPointMassFilter.h:70: conatins  ==> contains
mbtrnav/terrain-nav/TNavPointMassFilter.h:74: Initalize  ==> Initialize
mbtrnav/terrain-nav/TNavPointMassFilter.h:214: measurment  ==> measurement
mbtrnav/terrain-nav/TerrainNav.cpp:430: thta  ==> that
mbtrnav/terrain-nav/TerrainNav.cpp:613: incoporate  ==> incorporate
mbtrnav/terrain-nav/TerrainNav.cpp:894: intialized  ==> initialized
mbtrnav/terrain-nav/TerrainNav.cpp:894: intialize  ==> initialize
mbtrnav/terrain-nav/TerrainNav.cpp:981: beacause  ==> because
mbtrnav/terrain-nav/TerrainNav.cpp:1081: recevied  ==> received
mbtrnav/terrain-nav/TerrainNav.cpp:1120: Fitler  ==> Filter
mbtrnav/terrain-nav/TerrainNav.cpp:1207: fitler  ==> filter
mbtrnav/terrain-nav/matrixArrayCalcs.h:344: specificied  ==> specified
mbtrnav/terrain-nav/OctreeNode.cpp:117: assignes  ==> assigns
mbtrnav/terrain-nav/OctreeNode.cpp:276: actualy  ==> actually
mbtrnav/terrain-nav/OctreeNode.cpp:295: dynamicaly  ==> dynamically
mbtrnav/terrain-nav/OctreeNode.cpp:313: dynamicaly  ==> dynamically
mbtrnav/terrain-nav/OctreeNode.cpp:339: dynamicaly  ==> dynamically
mbtrnav/terrain-nav/TNavParticleFilter.h:52: triggerd  ==> triggered
mbtrnav/terrain-nav/TNavParticleFilter.h:58: tho  ==> though, to, thou
mbtrnav/terrain-nav/TNavParticleFilter.h:59: tho  ==> though, to, thou
mbtrnav/terrain-nav/TNavParticleFilter.h:139: Initalize  ==> Initialize
mbtrnav/terrain-nav/TNavParticleFilter.h:317: funciton  ==> function
mbtrnav/terrain-nav/TNavParticleFilter.h:348: distibution  ==> distribution
mbtrnav/terrain-nav/TNavParticleFilter.h:381: defind  ==> defined, defund
mbtrnav/terrain-nav/TNavParticleFilter.h:465: hist  ==> heist, his
mbtrnav/terrain-nav/TNavParticleFilter.h:485: distrubtion  ==> distribution
mbtrnav/terrain-nav/OctreeSupport.hpp:80: indicies  ==> indices
mbtrnav/terrain-nav/mapio.h:46: tRun  ==> turn
mbtrnav/terrain-nav/mapio.h:253: exaclty  ==> exactly
mbtrnav/terrain-nav/mapio.h:254: definining  ==> defining
mbtrnav/terrain-nav/mapio.h:258: retrive  ==> retrieve
mbtrnav/terrain-nav/mapio.h:261: fo  ==> of, for
mbtrnav/terrain-nav/mapio.h:322: stucture  ==> structure
mbtrnav/terrain-nav/mapio.h:325: meaninful  ==> meaningful
mbtrnav/terrain-nav/TerrainMap.h:21: parrent  ==> parent
mbtrnav/terrain-nav/Octree.hpp:33: maping  ==> mapping
mbtrnav/terrain-nav/Octree.hpp:37: accesed  ==> accessed
mbtrnav/terrain-nav/Octree.hpp:55: funcitons  ==> functions
mbtrnav/terrain-nav/Octree.hpp:56: useing  ==> using
mbtrnav/terrain-nav/Octree.hpp:65: implimentation  ==> implementation
mbtrnav/terrain-nav/Octree.hpp:95: Literaly  ==> Literally
mbtrnav/terrain-nav/Octree.hpp:98: capible  ==> capable
mbtrnav/terrain-nav/TNavParticleFilter.cpp:106: correspondance  ==> correspondence
mbtrnav/terrain-nav/TNavParticleFilter.cpp:142: Correspondances  ==> Correspondences
mbtrnav/terrain-nav/TNavParticleFilter.cpp:314: indicies  ==> indices
mbtrnav/terrain-nav/TNavParticleFilter.cpp:318: indicies  ==> indices
mbtrnav/terrain-nav/TNavParticleFilter.cpp:318: handeling  ==> handling
mbtrnav/terrain-nav/TNavParticleFilter.cpp:490: thats  ==> that's
mbtrnav/terrain-nav/TNavParticleFilter.cpp:493: informaiton  ==> information
mbtrnav/terrain-nav/TNavParticleFilter.cpp:504: normaly  ==> normally
mbtrnav/terrain-nav/TNavParticleFilter.cpp:537: likelyhood  ==> likelihood
mbtrnav/terrain-nav/TNavParticleFilter.cpp:580: chack  ==> check, chalk
mbtrnav/terrain-nav/TNavParticleFilter.cpp:605: betweeen  ==> between
mbtrnav/terrain-nav/TNavParticleFilter.cpp:904: guassian  ==> gaussian
mbtrnav/terrain-nav/TNavParticleFilter.cpp:978: Maxiumum  ==> Maximum
mbtrnav/terrain-nav/TNavParticleFilter.cpp:1396: intial  ==> initial
mbtrnav/terrain-nav/TNavParticleFilter.cpp:1660: indicies  ==> indices
mbtrnav/terrain-nav/TNavParticleFilter.cpp:1788: IFF  ==> IF  | disabled due to valid mathematical concept
mbtrnav/terrain-nav/TNavParticleFilter.cpp:2162: guassian  ==> gaussian
mbtrnav/terrain-nav/Octree.cpp:492: ot  ==> to, of, or
mbtrnav/terrain-nav/Octree.cpp:518: recomended  ==> recommended
mbtrnav/terrain-nav/Octree.cpp:582: datas  ==> data
mbtrnav/terrain-nav/structDefs.h:79: measurment  ==> measurement
mbtrnav/terrain-nav/TNavBankFilter.h:91: triggerd  ==> triggered
mbtrnav/terrain-nav/TNavBankFilter.h:97: tho  ==> though, to, thou
mbtrnav/terrain-nav/TNavBankFilter.h:98: tho  ==> though, to, thou
mbtrnav/terrain-nav/TNavBankFilter.h:179: Initalize  ==> Initialize
mbtrnav/terrain-nav/TNavBankFilter.h:395: funciton  ==> function
mbtrnav/terrain-nav/TNavBankFilter.h:425: distibution  ==> distribution
mbtrnav/terrain-nav/TNavBankFilter.h:458: defind  ==> defined, defund
mbtrnav/terrain-nav/TNavBankFilter.h:542: hist  ==> heist, his
mbtrnav/terrain-nav/TNavBankFilter.h:562: distrubtion  ==> distribution
mbtrnav/terrain-nav/TerrainNav.h:104: substitude  ==> substitute
mbtrnav/terrain-nav/TerrainNav.h:486: initalization  ==> initialization
mbtrnav/terrain-nav/TerrainNav.h:601: incoporated  ==> incorporated
mbtrnav/terrain-nav/TerrainNav.h:661: indiating  ==> indicating
mbtrnav/terrain-nav/TNavSigmaPointFilter.h:100: Initalize  ==> Initialize
mbtrnav/terrain-nav/OctreeSupport.cpp:81: funciton  ==> function
mbtrnav/terrain-nav/OctreeSupport.cpp:111: funcion  ==> function
mbtrnav/terrain-nav/OctreeSupport.cpp:136: indicies  ==> indices
mbtrnav/terrain-nav/OctreeSupport.cpp:141: indicies  ==> indices
mbtrnav/terrain-nav/trn_log.cpp:51: pring  ==> print, bring, ping, spring
mbtrnav/terrain-nav/trn_log.cpp:123: pring  ==> print, bring, ping, spring
mbtrnav/terrain-nav/trn_log.cpp:125: pring  ==> print, bring, ping, spring
mbtrnav/terrain-nav/trn_log.cpp:131: pring  ==> print, bring, ping, spring
mbtrnav/terrain-nav/trn_log.cpp:163: pring  ==> print, bring, ping, spring
mbtrnav/terrain-nav/trn_log.cpp:169: pring  ==> print, bring, ping, spring
mbtrnav/terrain-nav/trn_log.cpp:174: pring  ==> print, bring, ping, spring
mbtrnav/terrain-nav/trn_log.cpp:178: pring  ==> print, bring, ping, spring
mbtrnav/terrain-nav/trn_log.cpp:182: pring  ==> print, bring, ping, spring
mbtrnav/terrain-nav/trn_log.cpp:183: pring  ==> print, bring, ping, spring
mbtrnav/terrain-nav/TNavSigmaPointFilter.cpp:126: sucessful  ==> successful
mbtrnav/terrain-nav/TNavSigmaPointFilter.cpp:560: dont'  ==> don't
mbtrnav/terrain-nav/TNavFilter.h:307: representating  ==> representing
mbtrnav/terrain-nav/TNavFilter.h:357: measurment  ==> measurement
mbtrnav/terrain-nav/TNavFilter.h:448: correspondance  ==> correspondence
mbtrnav/terrain-nav/TNavFilter.h:461: correspondance  ==> correspondence
mbtrnav/terrain-nav/TNavFilter.h:497: vincinity  ==> vicinity
mbtrnav/terrain-nav/TNavBankFilter.cpp:216: correspondance  ==> correspondence
mbtrnav/terrain-nav/TNavBankFilter.cpp:252: Correspondances  ==> Correspondences
mbtrnav/terrain-nav/TNavBankFilter.cpp:566: indicies  ==> indices
mbtrnav/terrain-nav/TNavBankFilter.cpp:570: indicies  ==> indices
mbtrnav/terrain-nav/TNavBankFilter.cpp:570: handeling  ==> handling
WARNING: Binary file: mbtrnav/gctp/source/nad83sp 
mbtrnav/terrain-nav/TNavBankFilter.cpp:765: thats  ==> that's
mbtrnav/terrain-nav/TNavBankFilter.cpp:768: informaiton  ==> information
mbtrnav/terrain-nav/TNavBankFilter.cpp:779: normaly  ==> normally
mbtrnav/terrain-nav/TNavBankFilter.cpp:812: likelyhood  ==> likelihood
mbtrnav/terrain-nav/TNavBankFilter.cpp:856: chack  ==> check, chalk
mbtrnav/terrain-nav/TNavBankFilter.cpp:875: betweeen  ==> between
mbtrnav/terrain-nav/TNavBankFilter.cpp:1151: guassian  ==> gaussian
mbtrnav/terrain-nav/TNavBankFilter.cpp:1264: Maxiumum  ==> Maximum
mbtrnav/terrain-nav/TNavBankFilter.cpp:1902: intial  ==> initial
mbtrnav/terrain-nav/TNavBankFilter.cpp:2120: overlaping  ==> overlapping
mbtrnav/terrain-nav/TNavBankFilter.cpp:2161: indicies  ==> indices
mbtrnav/terrain-nav/TNavBankFilter.cpp:2289: IFF  ==> IF  | disabled due to valid mathematical concept
mbtrnav/terrain-nav/TNavBankFilter.cpp:2496: guassian  ==> gaussian
mbtrnav/terrain-nav/matrixArrayCalcs.cpp:720: guassian  ==> gaussian
mbtrnav/terrain-nav/OctreeNode.tcc:71: assignes  ==> assigns
mbtrnav/terrain-nav/OctreeNode.tcc:209: actualy  ==> actually
mbtrnav/terrain-nav/OctreeNode.tcc:229: dynamicaly  ==> dynamically
mbtrnav/terrain-nav/OctreeNode.tcc:247: dynamicaly  ==> dynamically
mbtrnav/terrain-nav/OctreeNode.tcc:273: dynamicaly  ==> dynamically
mbtrnav/terrain-nav/Octree.tcc:452: ot  ==> to, of, or
mbtrnav/terrain-nav/Octree.tcc:478: recomended  ==> recommended
mbtrnav/terrain-nav/Octree.tcc:558: datas  ==> data
mbtrnav/terrain-nav/Octree.tcc:580: runns  ==> runs
mbtrnav/trnw/netif.c:255: thru  ==> through
mbtrnav/trnw/netif.c:286: initialze  ==> initialize
mbtrnav/trnw/netif.c:1208: relase  ==> release
mbtrnav/trnw/trn_msg.h:186: measurment  ==> measurement
mbtrnav/trnw/trnw.cpp:477: refernces  ==> references
WARNING: Binary file: mbtrnav/gctp/source/nad27sp 
mbtrnav/utils/main.cpp:352: measurment  ==> measurement
mbtrnav/utils/main.cpp:527: unsucessful  ==> unsuccessful
mbtrnav/utils/trn_replay.cpp:40: paramteres  ==> parameters
mbtrnav/utils/GlutWindow2d.h:63: occured  ==> occurred
mbtrnav/utils/GlutWindow2d.h:71: Overide  ==> Override
mbtrnav/utils/replay_app.cpp:38: paramteres  ==> parameters
mbtrnav/utils/csvOctreeMaker.cpp:15: cordinate  ==> coordinate
mbtrnav/utils/csvOctreeMaker.cpp:18: meaningfull  ==> meaningful
mbtrnav/utils/sysmon.sh:171: processsing  ==> processing
mbtrnav/utils/sysmon.sh:173: paramters  ==> parameters
mbtrnav/utils/grdOctreeMaker.cpp:15: cordinate  ==> coordinate
mbtrnav/utils/grdOctreeMaker.cpp:18: meaningfull  ==> meaningful
mbtrnav/utils/grdOctreeMaker.cpp:32: cordinates  ==> coordinates
mbtrnav/utils/grdOctreeMaker.cpp:74: thats  ==> that's
mbtrnav/utils/grdOctreeMaker.cpp:74: coppied  ==> copied
mbtrnav/utils/GlutWindow.h:109: occured  ==> occurred
mbtrnav/utils/GlutWindow.h:118: Overide  ==> Override
mbtrnav/utils/GlutWindow.h:184: filname  ==> filename
mbtrnav/utils/GlutWindow.cpp:122: occured  ==> occurred
mbtrnav/utils/GlutWindow.cpp:141: Overide  ==> Override
mbtrnav/utils/_Replay.cpp:38: paramteres  ==> parameters
mbtrnav/utils/ParticlePlot.h:78: Copys  ==> Copies
mbtrnav/utils/mainMbari.cpp:315: measurment  ==> measurement
mbtrnav/utils/mainMbari.cpp:475: unsucessful  ==> unsuccessful
mbtrnav/utils/GlutWindow2d.cpp:225: occured  ==> occurred
mbtrnav/utils/GlutWindow2d.cpp:275: Overide  ==> Override
mbtrnav/utils/ParticlePlot.cpp:92: overriden  ==> overridden
mbtrnav/utils/mainLinux.cpp:213: measurment  ==> measurement
mbtrnav/utils/mainLinux.cpp:378: unsucessful  ==> unsuccessful
mbtrnav/utils/LcmTrn.cpp:252: examing  ==> examining
mbtrnav/utils/trn_server.cpp:899: reqests  ==> requests
mbtrnav/qnx-utils/MathP.h:42: Recipies  ==> Recipes
mbtrnav/qnx-utils/MathP.h:180: Recipies  ==> Recipes
mbtrnav/qnx-utils/Math.cc:40: Recipies  ==> Recipes
mbtrnav/qnx-utils/Math.cc:221: Recipies  ==> Recipes
mbtrnav/newmat/newmatnl.h:124: preceeding  ==> preceding
mbtrnav/newmat/newmatnl.h:128: constuct  ==> construct
mbtrnav/newmat/tmt2.cpp:66: vlaues  ==> values
mbtrnav/newmat/newmatex.cpp:281: miscellanous  ==> miscellaneous
mbtrnav/newmat/tmtk.cpp:162: Ba  ==> By, be
mbtrnav/newmat/tmtk.cpp:164: Ba  ==> By, be
mbtrnav/newmat/tmtk.cpp:165: Ba  ==> By, be
mbtrnav/newmat/tmtk.cpp:168: Ba  ==> By, be
mbtrnav/newmat/tmtk.cpp:169: Ba  ==> By, be
mbtrnav/newmat/tmtk.cpp:172: Ba  ==> By, be
mbtrnav/newmat/newmat4.cpp:496: managment  ==> management
mbtrnav/newmat/fft.cpp:27: minimise  ==> minimise, minimize
mbtrnav/newmat/garch.cpp:147: dependant  ==> dependent
mbtrnav/newmat/example.cpp:44: explicity  ==> explicitly
mbtrnav/newmat/example.cpp:116: explicity  ==> explicitly
mbtrnutils/mbtrnpp.c:2858: intialize  ==> initialize
mbtrnutils/mbtrnpp.c:2861: intialization  ==> initialization

There is a log of training whitespace cruft:

find *trn* -name "*.[ch]" -o -name \*.cpp | xargs perl -pi -e 's/\s+\n/\n/g'
git s | grep trn | grep -v Makefile

gives

	modified:   mbtrn/mframe/src/mcbuf.c
	modified:   mbtrn/mframe/src/mcbuf.h
	modified:   mbtrn/mframe/src/medebug-test.c
	modified:   mbtrn/mframe/src/medebug.h
	modified:   mbtrn/mframe/src/merror.c
	modified:   mbtrn/mframe/src/merror.h
	modified:   mbtrn/mframe/src/mfile.c
	modified:   mbtrn/mframe/src/mfile.h
	modified:   mbtrn/mframe/src/mframe-test.c
	modified:   mbtrn/mframe/src/mframe.c
	modified:   mbtrn/mframe/src/mframe.h
	modified:   mbtrn/mframe/src/mlist.c
	modified:   mbtrn/mframe/src/mlist.h
	modified:   mbtrn/mframe/src/mlog.c
	modified:   mbtrn/mframe/src/mlog.h
	modified:   mbtrn/mframe/src/mmdebug-test.c
	modified:   mbtrn/mframe/src/mmdebug.c
	modified:   mbtrn/mframe/src/mmdebug.h
	modified:   mbtrn/mframe/src/msocket-test.c
	modified:   mbtrn/mframe/src/msocket.c
	modified:   mbtrn/mframe/src/msocket.h
	modified:   mbtrn/mframe/src/mstats-test.c
	modified:   mbtrn/mframe/src/mstats.c
	modified:   mbtrn/mframe/src/mstats.h
	modified:   mbtrn/mframe/src/mswap.c
	modified:   mbtrn/mframe/src/mswap.h
	modified:   mbtrn/mframe/src/mthread.c
	modified:   mbtrn/mframe/src/mthread.h
	modified:   mbtrn/mframe/src/mtime-test.c
	modified:   mbtrn/mframe/src/mtime.c
	modified:   mbtrn/mframe/src/mtime.h
	modified:   mbtrn/mframe/src/mutils.c
	modified:   mbtrn/mframe/src/mutils.h
	modified:   mbtrn/r7kr/r7kc.c
	modified:   mbtrn/r7kr/r7kr-test.c
	modified:   mbtrn/utils/emu7k.c
	modified:   mbtrn/utils/emu7k.h
	modified:   mbtrn/utils/frames7k.c
	modified:   mbtrn/utils/mb1_msg.c
	modified:   mbtrn/utils/mb1_msg.h
	modified:   mbtrn/utils/mb1conv.c
	modified:   mbtrn/utils/mb1conv.h
	modified:   mbtrn/utils/mb71_msg.c
	modified:   mbtrn/utils/mb71_msg.h
	modified:   mbtrn/utils/mbtnav_cli.c
	modified:   mbtrn/utils/mconfig.c
	modified:   mbtrn/utils/mconfig.h
	modified:   mbtrn/utils/stream7k.c
	modified:   mbtrn/utils/tbinx.c
	modified:   mbtrn/utils/trnc.c
	modified:   mbtrn/utils/udpc.c
	modified:   mbtrn/utils/udps.c
	modified:   mbtrnav/gctp/source/alberfor.c
	modified:   mbtrnav/gctp/source/alberinv.c
	modified:   mbtrnav/gctp/source/alconfor.c
	modified:   mbtrnav/gctp/source/alconinv.c
	modified:   mbtrnav/gctp/source/azimfor.c
	modified:   mbtrnav/gctp/source/aziminv.c
	modified:   mbtrnav/gctp/source/cproj.c
	modified:   mbtrnav/gctp/source/eqconfor.c
	modified:   mbtrnav/gctp/source/eqconinv.c
	modified:   mbtrnav/gctp/source/equifor.c
	modified:   mbtrnav/gctp/source/equiinv.c
	modified:   mbtrnav/gctp/source/for_init.c
	modified:   mbtrnav/gctp/source/gctp.c
	modified:   mbtrnav/gctp/source/gnomfor.c
	modified:   mbtrnav/gctp/source/gnominv.c
	modified:   mbtrnav/gctp/source/goodfor.c
	modified:   mbtrnav/gctp/source/goodinv.c
	modified:   mbtrnav/gctp/source/gvnspfor.c
	modified:   mbtrnav/gctp/source/gvnspinv.c
	modified:   mbtrnav/gctp/source/hamfor.c
	modified:   mbtrnav/gctp/source/haminv.c
	modified:   mbtrnav/gctp/source/imolwfor.c
	modified:   mbtrnav/gctp/source/imolwinv.c
	modified:   mbtrnav/gctp/source/inv_init.c
	modified:   mbtrnav/gctp/source/lamazfor.c
	modified:   mbtrnav/gctp/source/lamazinv.c
	modified:   mbtrnav/gctp/source/lamccfor.c
	modified:   mbtrnav/gctp/source/lamccinv.c
	modified:   mbtrnav/gctp/source/merfor.c
	modified:   mbtrnav/gctp/source/merinv.c
	modified:   mbtrnav/gctp/source/millfor.c
	modified:   mbtrnav/gctp/source/millinv.c
	modified:   mbtrnav/gctp/source/molwfor.c
	modified:   mbtrnav/gctp/source/molwinv.c
	modified:   mbtrnav/gctp/source/obleqfor.c
	modified:   mbtrnav/gctp/source/obleqinv.c
	modified:   mbtrnav/gctp/source/omerfor.c
	modified:   mbtrnav/gctp/source/omerinv.c
	modified:   mbtrnav/gctp/source/orthfor.c
	modified:   mbtrnav/gctp/source/orthinv.c
	modified:   mbtrnav/gctp/source/paksz.c
	modified:   mbtrnav/gctp/source/polyfor.c
	modified:   mbtrnav/gctp/source/polyinv.c
	modified:   mbtrnav/gctp/source/psfor.c
	modified:   mbtrnav/gctp/source/psinv.c
	modified:   mbtrnav/gctp/source/robfor.c
	modified:   mbtrnav/gctp/source/robinv.c
	modified:   mbtrnav/gctp/source/sinfor.c
	modified:   mbtrnav/gctp/source/sininv.c
	modified:   mbtrnav/gctp/source/somfor.c
	modified:   mbtrnav/gctp/source/sominv.c
	modified:   mbtrnav/gctp/source/sphdz.c
	modified:   mbtrnav/gctp/source/sterfor.c
	modified:   mbtrnav/gctp/source/sterinv.c
	modified:   mbtrnav/gctp/source/stplnfor.c
	modified:   mbtrnav/gctp/source/stplninv.c
	modified:   mbtrnav/gctp/source/tmfor.c
	modified:   mbtrnav/gctp/source/tminv.c
	modified:   mbtrnav/gctp/source/untfz.c
	modified:   mbtrnav/gctp/source/vandgfor.c
	modified:   mbtrnav/gctp/source/vandginv.c
	modified:   mbtrnav/gctp/source/wivfor.c
	modified:   mbtrnav/gctp/source/wivinv.c
	modified:   mbtrnav/gctp/source/wviifor.c
	modified:   mbtrnav/gctp/source/wviiinv.c
	modified:   mbtrnav/newmat/evalue.cpp
	modified:   mbtrnav/newmat/example.cpp
	modified:   mbtrnav/newmat/include.h
	modified:   mbtrnav/newmat/myexcept.cpp
	modified:   mbtrnav/newmat/newmat.h
	modified:   mbtrnav/newmat/newmat1.cpp
	modified:   mbtrnav/newmat/newmat6.cpp
	modified:   mbtrnav/newmat/newmatnl.cpp
	modified:   mbtrnav/newmat/newmatnl.h
	modified:   mbtrnav/newmat/newmatrm.cpp
	modified:   mbtrnav/newmat/nl_ex.cpp
	modified:   mbtrnav/newmat/precisio.h
	modified:   mbtrnav/newmat/sl_ex.cpp
	modified:   mbtrnav/newmat/tmt.cpp
	modified:   mbtrnav/newmat/tmt1.cpp
	modified:   mbtrnav/newmat/tmt6.cpp
	modified:   mbtrnav/newmat/tmt7.cpp
	modified:   mbtrnav/newmat/tmt9.cpp
	modified:   mbtrnav/newmat/tmtc.cpp
	modified:   mbtrnav/newmat/tmtj.cpp
	modified:   mbtrnav/newmat/tmtk.cpp
	modified:   mbtrnav/qnx-utils/AngleData.h
	modified:   mbtrnav/qnx-utils/AsciiFile.h
	modified:   mbtrnav/qnx-utils/BinaryFile.h
	modified:   mbtrnav/qnx-utils/CharData.h
	modified:   mbtrnav/qnx-utils/DataField.h
	modified:   mbtrnav/qnx-utils/DataFieldFactory.h
	modified:   mbtrnav/qnx-utils/DataLog.h
	modified:   mbtrnav/qnx-utils/DataLogReader.h
	modified:   mbtrnav/qnx-utils/DataLogWriter.h
	modified:   mbtrnav/qnx-utils/DoubleData.h
	modified:   mbtrnav/qnx-utils/DynamicArray.h
	modified:   mbtrnav/qnx-utils/Exception.h
	modified:   mbtrnav/qnx-utils/ExternalData.h
	modified:   mbtrnav/qnx-utils/FileData.h
	modified:   mbtrnav/qnx-utils/FloatData.h
	modified:   mbtrnav/qnx-utils/IntegerData.h
	modified:   mbtrnav/qnx-utils/MathP.h
	modified:   mbtrnav/qnx-utils/NavUtils.h
	modified:   mbtrnav/qnx-utils/ShortData.h
	modified:   mbtrnav/qnx-utils/StringConverter.h
	modified:   mbtrnav/qnx-utils/StringData.h
	modified:   mbtrnav/qnx-utils/TimeP.h
	modified:   mbtrnav/qnx-utils/TimeTag.h
	modified:   mbtrnav/terrain-nav/Octree.cpp
	modified:   mbtrnav/terrain-nav/OctreeNode.cpp
	modified:   mbtrnav/terrain-nav/OctreeSupport.cpp
	modified:   mbtrnav/terrain-nav/PositionLog.cpp
	modified:   mbtrnav/terrain-nav/PositionLog.h
	modified:   mbtrnav/terrain-nav/TNavBankFilter.cpp
	modified:   mbtrnav/terrain-nav/TNavBankFilter.h
	modified:   mbtrnav/terrain-nav/TNavConfig.cpp
	modified:   mbtrnav/terrain-nav/TNavConfig.h
	modified:   mbtrnav/terrain-nav/TNavExtendKalmanFilter.cpp
	modified:   mbtrnav/terrain-nav/TNavExtendKalmanFilter.h
	modified:   mbtrnav/terrain-nav/TNavFilter.cpp
	modified:   mbtrnav/terrain-nav/TNavFilter.h
	modified:   mbtrnav/terrain-nav/TNavPFLog.cpp
	modified:   mbtrnav/terrain-nav/TNavPFLog.h
	modified:   mbtrnav/terrain-nav/TNavParticleFilter.h
	modified:   mbtrnav/terrain-nav/TNavPointMassFilter.cpp
	modified:   mbtrnav/terrain-nav/TNavPointMassFilter.h
	modified:   mbtrnav/terrain-nav/TNavSigmaPointFilter.cpp
	modified:   mbtrnav/terrain-nav/TNavSigmaPointFilter.h
	modified:   mbtrnav/terrain-nav/TerrainMap.cpp
	modified:   mbtrnav/terrain-nav/TerrainMap.h
	modified:   mbtrnav/terrain-nav/TerrainMapDEM.cpp
	modified:   mbtrnav/terrain-nav/TerrainMapDEM.h
	modified:   mbtrnav/terrain-nav/TerrainMapOctree.cpp
	modified:   mbtrnav/terrain-nav/TerrainMapOctree.h
	modified:   mbtrnav/terrain-nav/TerrainNav.h
	modified:   mbtrnav/terrain-nav/TerrainNavLog.cpp
	modified:   mbtrnav/terrain-nav/TerrainNavLog.h
	modified:   mbtrnav/terrain-nav/genFilterDefs.h
	modified:   mbtrnav/terrain-nav/mapio.cpp
	modified:   mbtrnav/terrain-nav/mapio.h
	modified:   mbtrnav/terrain-nav/matrixArrayCalcs.cpp
	modified:   mbtrnav/terrain-nav/matrixArrayCalcs.h
	modified:   mbtrnav/terrain-nav/myOutput.cpp
	modified:   mbtrnav/terrain-nav/myOutput.h
	modified:   mbtrnav/terrain-nav/particleFilterDefs.h
	modified:   mbtrnav/terrain-nav/structDefs.h
	modified:   mbtrnav/terrain-nav/trn_log.cpp
	modified:   mbtrnav/trnw/mb1_dmsg.c
	modified:   mbtrnav/trnw/mb1_dmsg.h
	modified:   mbtrnav/trnw/mb1_msg.c
	modified:   mbtrnav/trnw/mb1_msg.h
	modified:   mbtrnav/trnw/trn_cli.c
	modified:   mbtrnav/trnw/trn_cli.h
	modified:   mbtrnav/trnw/trn_msg.h
	modified:   mbtrnav/trnw/trncli_test.c
	modified:   mbtrnav/trnw/trnif_msg.c
	modified:   mbtrnav/trnw/trnif_msg.h
	modified:   mbtrnav/trnw/trnif_proto.h
	modified:   mbtrnav/trnw/trnw.h
	modified:   mbtrnav/utils/ColorHelper.cpp
	modified:   mbtrnav/utils/GlutWindow.cpp
	modified:   mbtrnav/utils/GlutWindow.h
	modified:   mbtrnav/utils/GlutWindow2d.cpp
	modified:   mbtrnav/utils/GlutWindow2d.h
	modified:   mbtrnav/utils/LcmTrn.cpp
	modified:   mbtrnav/utils/LcmTrn.h
	modified:   mbtrnav/utils/ParticlePlot.cpp
	modified:   mbtrnav/utils/ParticlePlot.h
	modified:   mbtrnav/utils/Replay.cpp
	modified:   mbtrnav/utils/Replay.h
	modified:   mbtrnav/utils/TerrainNavClient.cpp
	modified:   mbtrnav/utils/TerrainNavClient.h
	modified:   mbtrnav/utils/TrnClient.cpp
	modified:   mbtrnav/utils/TrnClient.h
	modified:   mbtrnav/utils/_Replay.cpp
	modified:   mbtrnav/utils/bodump.cpp
	modified:   mbtrnav/utils/csvOctreeMaker.cpp
	modified:   mbtrnav/utils/grdOctreeMaker.cpp
	modified:   mbtrnav/utils/lrtrn_app.cpp
	modified:   mbtrnav/utils/main.cpp
	modified:   mbtrnav/utils/mainLinux.cpp
	modified:   mbtrnav/utils/mainMbari.cpp
	modified:   mbtrnav/utils/netif-test.c
	modified:   mbtrnav/utils/octree2Patches.cpp
	modified:   mbtrnav/utils/replay_app.cpp
	modified:   mbtrnav/utils/testSantaMonicaMound.cpp
	modified:   mbtrnav/utils/test_trn_log.cpp
	modified:   mbtrnav/utils/tile_test.cpp
	modified:   mbtrnav/utils/translateOctree.cpp
	modified:   mbtrnav/utils/trn_replay.cpp
	modified:   mbtrnutils/mbtrnpp.c

mbedit_prog.c: operation on ‘*(ping[i].beamflag + (sizetype)j)’ may be undefined [-Wsequence-point]

With

gcc (Debian 8.3.0-6) 8.3.0

I see:

gcc -DHAVE_CONFIG_H -I. -I../../src/mbio  -I../../src/mbio -I../../src/mbaux -I../../src/gsf  -I/usr/include    -g -O2 -Wno-format -Wno-stringop-truncation -Wno-stringop-overflow -Wall -Wextra -Wno-sign-compare -Wno-maybe-uninitialized -Wno-format-overflow -MT mbedit_prog.o -MD -MP -MF $depbase.Tpo -c -o mbedit_prog.o mbedit_prog.c &&\
mv -f $depbase.Tpo $depbase.Po
mbedit_prog.c: In function ‘mbedit_action_mouse_restore’:
mbedit_prog.c:1847:28: warning: operation on ‘*(ping[i].beamflag + (sizetype)j)’ may be undefined [-Wsequence-point]
        ping[i].beamflag[j] = ping[i].beamflag[j] = mb_beam_set_flag_none(ping[i].beamflag[j]);
mbedit_prog.c: In function ‘mbedit_filter_ping’:
mbedit_prog.c:3343:32: warning: operation on ‘*(ping[iping].beamflag + (sizetype)j)’ may be undefined [-Wsequence-point]
        ping[iping].beamflag[j] = ping[iping].beamflag[j] = mb_beam_set_flag_filter2(ping[iping].beamflag[j]);
mbedit_prog.c:3364:32: warning: operation on ‘*(ping[iping].beamflag + (sizetype)j)’ may be undefined [-Wsequence-point]
        ping[iping].beamflag[j] = ping[iping].beamflag[j] = mb_beam_set_flag_filter2(ping[iping].beamflag[j]);
mbedit_prog.c:3391:33: warning: operation on ‘*(ping[iping].beamflag + (sizetype)j)’ may be undefined [-Wsequence-point]
         ping[iping].beamflag[j] = ping[iping].beamflag[j] =
mbedit_prog.c:3415:33: warning: operation on ‘*(ping[iping].beamflag + (sizetype)j)’ may be undefined [-Wsequence-point]
         ping[iping].beamflag[j] = ping[iping].beamflag[j] =

e.g. What is this supposed to be? It looks like a = a = mb_beam_set_flag_none(a)

if (!mb_beam_ok(ping[i].beamflag[j]) && !mb_beam_check_flag_unusable(ping[i].beamflag[j]))
    ping[i].beamflag[j] = ping[i].beamflag[j] = mb_beam_set_flag_none(ping[i].beamflag[j]);

Support Proj 6 / 7

Moving discussion from #84 to here for PROJ.

Proj 6 introduces a new API by Even R. via the GDAL Barn Raising project. In Proj 6, the old way is allowed with a #define, but that will be going away in the next major version. This is a place to discuss handling the Proj 6 API.

I’m currently having fits with PROJ6 - autoconf is now failing to recognize proj_api.h even when the -DACCEPT_USE_OF_DEPRECATED_PROJ_API_H is explicitly in the CFLAGS used by the AC_CHECK_HEADER() test - this workaround was working up to this morning. I’ve no idea if it broke due to a homebrew update or an Apple update. Any ideas on forcing autoconf to behave?

The file is there:
Haxby:mbsystem caress$ ll /usr/local/opt/proj/include/proj_api.h
-rw-r--r--@ 1 caress staff 8346 Feb 26 13:09 /usr/local/opt/proj/include/proj_api.h

With the PROJ6 release header file now nastily requires that the environment variable ACCEPT_USE_OF_DEPRECATED_PROJ_API_H be defined. I do that in my code easily enouugh, but for the purposes of the autoconf AC_CHECK_HEADER() test I explicitly add this to what ought to be the operative CFLAGS:

dnl PROJ header location specified: $libproj_CPPFLAGS - check if proj_api.h is there...
AS_ECHO(["PROJ header location specified: $libproj_CPPFLAGS - check if proj_api.h is there..."])
save_CPPFLAGS=$CPPFLAGS
save_CFLAGS=$CFLAGS
CPPFLAGS="$CPPFLAGS $libproj_CPPFLAGS"
CFLAGS="$CFLAGS $libproj_CPPFLAGS -DACCEPT_USE_OF_DEPRECATED_PROJ_API_H"
AC_CHECK_HEADER(proj_api.h, [PROJ_SETTING=yes], [PROJ_SETTING=no],)
CPPFLAGS=$save_CPPFLAGS
CFLAGS=$save_CFLAGS
if test "$PROJ_SETTING" = "no"; then
   AC_MSG_ERROR([Did not find PROJ headers according to --with-proj-include - check the installation!])
fi

What I get when I run the configure script is:

PROJ header location specified: -I/usr/local/opt/proj/include - check if proj_api.h is there...
checking proj_api.h usability... no
checking proj_api.h presence... no
checking for proj_api.h... no
configure: error: Did not find PROJ headers according to --with-proj-include - check the installation!

mbedit || should maybe be &&

mbedit_prog.c:3351:35: style: Condition 'filter_cutbeam_begin>filter_cutbeam_end' is always true [knownConditionTrueFalse]
    else if (filter_cutbeam_begin > filter_cutbeam_end) {
                                  ^
mbedit_prog.c:3405:39: style: Condition 'filter_cutdistance_begin>filter_cutdistance_end' is always true [knownConditionTrueFalse]
    else if (filter_cutdistance_begin > filter_cutdistance_end) {
                                      ^
mbedit_prog.c:3462:36: style: Condition 'filter_cutangle_begin>filter_cutangle_end' is always true [knownConditionTrueFalse]
    else if (filter_cutangle_begin > filter_cutangle_end) {

A test for mb_rt.c - ray tracing

This is a place for me to take notes while looking at mb_rt.c. I don't totally understand the design of it and before I try to improve it, it needs to have good test coverage. It's a great candidate for fuzzing and microbenchmarks.

Lots of questions starting with:

  • Why the global static model variable when a ptr is already passed? Can we just fix a few functions and drop the model variable poluting all of mb_rt's scope?
  • What is MBBA?
  • Is the assumption of plotting baked into this?

So far, I have a start to mb_rt.h and an alloc test:

#ifndef MBIO_MB_RT_H_
#define MBIO_MB_RT_H_

struct velocity_model {
	/* velocity model */
	int number_node;
	double *depth;
	double *velocity;
	int number_layer;
	int *layer_mode;
	double *layer_gradient;
	double *layer_depth_center;
	double *layer_depth_top;
	double *layer_depth_bottom;
	double *layer_vel_top;
	double *layer_vel_bottom;

	/* raytracing bookkeeping variables */
	int ray_status;
	int done;
	int outofbounds;
	int layer;
	int turned;
	int plot_mode;
	int number_plot_max;
	int number_plot;
	int sign_x;
	double xx;
	double zz;
	double xf;
	double zf;
	double tt;
	double dt;
	double tt_left;
	double vv_source;
	double pp;
	double xc;
	double zc;
	double radius;
	double *xx_plot;
	double *zz_plot;
};

#ifdef __cplusplus
extern "C" {
#endif

int mb_rt_init(int verbose, int number_node, double *depth, double *velocity, void **modelptr, int *error);
int mb_rt_deall(int verbose, void **modelptr, int *error);
int mb_rt(int verbose, void *modelptr, double source_depth, double source_angle, double end_time, int ssv_mode,
          double surface_vel, double null_angle, int nplot_max, int *nplot, double *xplot, double *zplot, double *x, double *z,
          double *travel_time, int *ray_stat, int *error);
int mb_rt_circular(int verbose, int *error);  // TODO(schwehr): This is why the global is needed, yes?
int mb_rt_quad1(int verbose, int *error);
int mb_rt_quad2(int verbose, int *error);
int mb_rt_quad3(int verbose, int *error);
int mb_rt_quad4(int verbose, int *error);
int mb_rt_get_depth(int verbose, double beta, int dir_sign, int turn_sign, double *depth, int *error);
int mb_rt_plot_circular(int verbose, int *error);
int mb_rt_line(int verbose, int *error);
int mb_rt_vertical(int verbose, int *error);

#ifdef __cplusplus
}  /* extern "C" */
#endif

#endif  /* MBIO_MB_RT_H_ */

and

#include "mb_rt.h"

#include <vector>

#include "gmock.h"
#include "gtest.h"
#include "mb_define.h"
#include "mb_status.h"

namespace {

TEST(MbRtTest, Alloc) {
  int verbose = 2;
  std::vector<double> dep{10.1, 20.2, 30.3};
  std::vector<double> vel{1518.1, 1519.2, 1518.3};
  struct velocity_model *model = nullptr;
  int error = -999;
  EXPECT_EQ(MB_SUCCESS, mb_rt_init(verbose, dep.size(), dep.data(), vel.data(),
                                   (void **)&model, &error));
  EXPECT_NE(nullptr, model);
  EXPECT_EQ(error, MB_ERROR_NO_ERROR);
  EXPECT_EQ(MB_SUCCESS, mb_rt_deall(verbose, (void **)&model, &error));
}

}  // namespace

Causing crashes is super easy to do. Give a too long size or having the two arrays be different lengths. What should size of 0 do?

Request for mbio/mbinfo test data

The best test data will already be in a public archive. The more metadata to go with a data sample the better.

https://www3.mbari.org/data/mbsystem/html/mbio.html
http://www3.mbari.org/products/mbsystem/formatdoc/index.html
https://github.com/dwcaress/MB-System/blob/master/src/mbio/mb_format.h

This is a call for sample data files to help with testing of MB-System. By having coverage of as many formats with as many of the possible packet/message types will let MB-System grow over time without regressing it’s existing ability to read so many formats. Any file donated will assumed to be done so under the MB-System license so that the files or portions of those files can go along with MB-System. These will be a part of MB-System’s unittests and fuzzing infrastructure. Initially, I’ve just setup https://github.com/dwcaress/MB-System/blob/master/test/utilities/mbinfo_test.py with two initial formats covered: mb21/MBF_HSATLRAW and b173 MBF_MGD77TXT. I’ve used mbcopy to create test files for other formats, but those are definitely suboptimal. Eventually, I’d like to have C++ tests that test each packet type on it’s own, but that is for down the road.

Many of these formats are in public archives. I’m happy to use those and could use help from the community finding good examples.

What is most useful initially:

  • First off, anything logged from a real system is a step forward. So if we have nothing, anything is a win
  • Smaller is better. Bigger files will be hard to put into git and slow everything down. E.g. for fuzzing, the default is to limit the entire file content to 4K. I often increase that to 20K, but much bigger and things get really slow. Unittests need to finish quickly and more data is slower
  • To contrast with smaller, we want every type of packet/datagram possible. Especially things like SVP, vessel configs, etc. If a format supports backscatter, sidescan, etc, it would be great to have those.
  • Different versions of systems. E.g. GSF has had a lot of changes over the years so it would be great to have many versions on hand.

Not all of those files will be used in the unittest. For those that are used we might need to cut down files for size and time reasons before they can be good test inputs.

For later:

  • Files that cause MB-system to crash. These are great seeds for fuzzing. Eventually, MB-System should try to never crash even on the most corrupt file. But that comes after unittests
  • Files that can be used to test more complicated utilities in MB-System like gridding and preprocessing
  • Files that can be used for performance testing. These need to be big enough to be bigger than RAM caches and to minimize the influence of other systems and transients.
  • Formats that are not yet supported. It would be awesome to have work staged for anyone willing to contribute code for new formats to MB-System. Or packets/datagrams not yet supported

Known sources that people can look into:

https://www.ngdc.noaa.gov/multibeam-survey-search/

mb56 test data

Part of #319

I'm trying out my mbreadsimrad code to see if I can make a smaller file or files that produce usable results with as many diverse datagrams as possible. My first attempt failed. I likely need to save a couple pings between saved timestamp / position datagrams. And I'm using code I haven't looked at since 2010.

From man mbio:

           MBIO Data Format ID:  56
           Format name:          MBF_EM300RAW
           Informal Description: Simrad current multibeam
                                 vendor format
           Attributes:           Simrad EM120, EM300, EM1002,
                                 EM3000, bathymetry, amplitude,
                                 and sidescan, up to 254 beams,
                                 variable pixels, ascii + binary,
                                 Simrad.

mb_format.h:

#define MBF_EM300RAW 56

Cruises I'm looking at... I went on the NBP0209 cruise and I think it was the second cruise after the install of the em120. During that cruise, the multibeam crashed each time we went over the dateline. NBP1403 was the newest cruise from the palmer's em120 that I could find in https://www.ngdc.noaa.gov/multibeam-survey-search/ . I also grabbed a random cruise that listed an em300.

This code does not produce something useful:

#!/usr/bin/env python3

import glob
import mmap
import os
import struct
import sys
# import datetime

class SimradFile(object):

    def __init__(self,filename):
        self.filename = filename
        tmp_file = open(filename, 'r+')
        self.size = os.path.getsize(filename)
        self.data = mmap.mmap(tmp_file.fileno(), self.size, access=mmap.ACCESS_READ)
    def __iter__(self):
        iter = SimradIterator(self)
        return iter

class SimradIterator(object):
    def __init__(self,simrad):
        self.data = simrad.data
        self.offset = 0
        self.file_size = simrad.size
    def __iter__(self):
        return self
    def __next__(self):
        if self.offset >= self.file_size:
            raise StopIteration
        dg_length = struct.unpack('I',self.data[self.offset:self.offset+4])[0]
        dg_id = self.data[self.offset+5]
        data = self.data[self.offset:self.offset + dg_length]
        self.offset += 4 + dg_length
        # return dg
        return dg_id, data

dg_id_set = set()
# src = SimradFile('0009_20140321_005219_raw.all.mb56')
with open('out', 'wb') as out:
  for count, filename in enumerate(sorted(glob.glob('*.mb56'))):
    print(filename, count)
    src = SimradFile('0009_20140321_005219_raw.all.mb56')
    for dg_id, data in src:
      if dg_id in dg_id_set:
        continue
      print(dg_id, len(data))
      dg_id_set.add(dg_id)
      out.write(data)
./src/utilities/mbinfo -I$HOME/data/mb/nbp1403-em120/nbp1403-em120-minimal.mb56

Swath Data File:      nbp1403-em120-minimal.mb56
MBIO Data Format ID:  56
Format name:          MBF_EM300RAW
Informal Description: Simrad current multibeam vendor format
Attributes:           Simrad EM120, EM300, EM1002, EM3000, 
                      bathymetry, amplitude, and sidescan,
                      up to 254 beams, variable pixels, ascii + binary, Simrad.

Data Totals:
Number of Records:                           0
Bathymetry Data (0 beams):
  Number of Beams:                0
  Number of Good Beams:           0      0.00%
  Number of Zero Beams:           0      0.00%
  Number of Flagged Beams:        0      0.00%
Amplitude Data (0 beams):
  Number of Beams:                0
  Number of Good Beams:           0      0.00%
  Number of Zero Beams:           0      0.00%
  Number of Flagged Beams:        0      0.00%
Sidescan Data (0 pixels):
  Number of Pixels:               0
  Number of Good Pixels:          0      0.00%
  Number of Zero Pixels:          0      0.00%
  Number of Flagged Pixels:       0      0.00%

Navigation Totals:
Total Time:             0.0000 hours
Total Track Length:     0.0000 km
Average Speed:          0.0000 km/hr ( 0.0000 knots)

Start of Data:
Time:  00 00 0000 00:00:00.000000  JD0 (0000-00-00T00:00:00.000000)
Lon:     0.000000000     Lat:     0.000000000     Depth:     0.0000 meters
Speed:  0.0000 km/hr ( 0.0000 knots)  Heading:   0.0000 degrees
Sonar Depth:    0.0000 m  Sonar Altitude:    0.0000 m

End of Data:
Time:  00 00 0000 00:00:00.000000  JD0 (0000-00-00T00:00:00.000000)
Lon:     0.000000000     Lat:     0.000000000     Depth:     0.0000 meters
Speed:  0.0000 km/hr ( 0.0000 knots)  Heading:   0.0000 degrees
Sonar Depth:    0.0000 m  Sonar Altitude:    0.0000 m

Limits:
Minimum Longitude:       0.000000000   Maximum Longitude:       0.000000000
Minimum Latitude:        0.000000000   Maximum Latitude:        0.000000000
Minimum Sonar Depth:     0.0000   Maximum Sonar Depth:     0.0000
Minimum Altitude:        0.0000   Maximum Altitude:        0.0000

a run of the tool looks something like this right now with each new datagram type and size listed as it finds them:

./em120_dg.py 
0000_20140320_220551_raw.all.mb56
73 710
82 52
85 376
51 52
80 114
49 88
67 28
65 1222
87 1030
105 710

My datagram type table:

datagram_names = {
    0x30: 'PU Id outputs',              # char: '0'     dec:  48
    0x31: 'PU Status output',           # char: '1'     dec:  49
    0x33: 'Extra Parameters',           # char: '3'     dec:  51
    0x41: 'Attitude',                   # char: 'A'     dec:  65
    0x42: 'PU BIST result',             # char: 'B'     dec:  66
    0x43: 'Clock',                      # char: 'C'     dec:  67
    0x44: 'depth',                      # char: 'D'     dec:  68
    0x45: 'Single beam depth',          # char: 'E'     dec:  69
    0x46: 'Range and angles (old)',     # char: 'F'     dec:  70
    0x47: 'Surface sound speed',        # char: 'G'     dec:  71
    0x48: 'Headings',                   # char: 'H'     dec:  72
    0x49: 'Installation params',        # char: 'I'     dec:  73
    0x4a: 'Mech transducer tilts',      # char: 'J'     dec:  74
    0x4b: 'Central beams echogram',     # char: 'K'     dec:  75
    0x4e: 'Range and angle 78',         # char: 'N'     dec:  78
    0x50: 'Positions',                  # char: 'P'     dec:  80
    0x52: 'Runtime parameters',         # char: 'R'     dec:  82
    0x53: 'Seabed image',               # char: 'S'     dec:  83
    0x54: 'Tide',                       # char: 'T'     dec:  84
    0x55: 'Sound speed profile',        # char: 'U'     dec:  85
    0x57: 'SSP output',                 # char: 'W'     dec:  87
    0x58: 'XYZ',                        # char: 'X'     dec:  88
    0x59: 'Seabed image data 89',       # char: 'Y'     dec:  89
    0x66: 'Range and angles (new)',     # char: 'f'     dec:  102
    0x68: 'Depth or height',            # char: 'h'     dec:  104
    0x69: 'installation params',        # char: 'i'     dec:  105
    0x6b: 'Water column',               # char: 'k'     dec:  107
    0x6e: 'Network attitude velocity',  # char: 'n'     dec:  110
    0x72: 'remote information',         # char: 'r'     dec:  114
}

Access of arrays with incorrect length checks

Describe the bug

There are a number of places in the code where for loops cover a different number of entries than there actually are in an array. This can lead to things like under reporting print messages in the case of too few. The case of reading too many is more troublesome as it is Undefined Behavior (UB) that could lead to segfault or other uncontrolled program termination. The results can vary based on the compiler, optimization settings, and architecture.

There are 13 cases of access beyond the end of an array and all are in the reson code.

To Reproduce

See the warnings generated by recent gcc in travis runs using an ubuntu 19.04 disco image. e.g.

https://travis-ci.org/schwehr/MB-System/builds/522233215#L8942

mbsys_reson7k3.c: In function ‘mbsys_reson7k3_print_DetectionDataSetup’:
mbsys_reson7k3.c:2270:5: warning: iteration 13 invokes undefined behavior [-Waggressive-loop-optimizations]
     fprintf(stderr, "%s     reserved[%2d]:               %u\n", first, i, DetectionDataSetup->reserved[i]);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mbsys_reson7k3.c:2269:3: note: within this loop
   for (i = 0; i < 14; i++) {
   ^~~

Where reserved is shorter by 1 in mbsys_reson7k3.h:

  u32 reserved[13];                /* Reserved for future use */                                                          

Expected behavior

The for loop length check should be correct. Use either a const, #define, or arraysize macro.

e.g. here is one in c++: https://github.com/OSGeo/gdal/blob/master/gdal/port/cpl_port.h#L1037

#define CPL_ARRAYSIZE(array) \
  ((sizeof(array) / sizeof(*(array))) / \
  static_cast<size_t>(!(sizeof(array) % sizeof(*(array)))))

See https://stackoverflow.com/questions/4415524/common-array-length-macro-for-c for more

Computing context (please complete the following information):

This trouble is for all platforms and exists here. I'm not sure how far back this trouble exists.

Additional context

This is a very common class of bugs. The check being too large can be caught by static analysis or asan/msan, but the too short case is sneakier. Using bare constant literals (e.g. 13 and 14) in the code without defining a constant is a common cause of this kind of trouble.

defined but not used variables in headers

Describe the bug

Variables defined with static in headers get put into compilation units where they aren't used.

To Reproduce

On debian testing for example:

gcc --version
gcc (Debian 7.3.0-18) 7.3.0
CFLAGS="-O2 -Wall -Wextra -Wshadow" ./configure --enable-test

gcc -DHAVE_CONFIG_H -I. -I../../src/mbio  -I../../src/mbio -I../../src/mbaux -I../../src/gsf  -I/usr/include/gmt -I/usr/include     -O2 -Wall -Wextra -Wshadow -MT mbinfo.o -MD -MP -MF $depbase.Tpo -c -o mbinfo.o mbinfo.c &&\
mv -f $depbase.Tpo $depbase.Po

[SNIP]

In file included from mbinfo.c:37:0:
At top level:
../../src/mbio/mb_io.h:147:14: warning: ‘mb_sensor_type_string’ defined but not used [-Wunused-variable]
 static char *mb_sensor_type_string[] = {"Unknown sensor type",
              ^~~~~~~~~~~~~~~~~~~~~
../../src/mbio/mb_io.h:123:12: warning: ‘mb_sensor_type_id’ defined but not used [-Wunused-variable]
 static int mb_sensor_type_id[] = {
            ^~~~~~~~~~~~~~~~~
../../src/mbio/mb_io.h:52:14: warning: ‘mb_platform_type_string’ defined but not used [-Wunused-variable]
 static char *mb_platform_type_string[] = {
              ^~~~~~~~~~~~~~~~~~~~~~~

`char *function_name` → `__func__`

char *function_name = "mbsys_simrad3_extract_nnav"; and the like can be replaced by __func__. Extra bonus since I've found a couple places where the wrong function name is used and it's usually missing static and const

🎉😎

e.g.

help and man for mbformat missing options

Also the SYNOPSIS runs into the mbformat

The help is missing -K

./mbformat -H

Program MBFORMAT
MB-system Version 5.7.5beta9

MBFORMAT is an utility which identifies the swath data formats 
associated with MBIO format id's.  If no format id is specified, 
MBFORMAT lists all of the currently supported formats.

usage: mbformat [-Fformat -Ifile -L -W -V -H]

man mbformat does not cover the -w option for html output

man mbformat
mbformat(1)                                 MB-System 5.0                                 mbformat(1)

NAME
       mbformat -  List information about swath sonar data formats supported by the MBIO library.

VERSION
       Version 5.0

SYNOPSISmbformat [ -Fformat -Ifile -L -K -V -H]
DESCRIPTION
       mbformat  is a utility which identifies the swath sonar data formats associated with mbio for‐
       mat id's.  If no format id or input filename is specified, mbformat lists all of the currently
       supported  formats  along  with  short  descriptions. If a format id is specified using the -F
       option, then mbformat prints a short description of that format. If a  filename  is  specified
       using  the -I option, then mbformat attempts to identify a valid format id for that file using

Seen on debian-testing at 5ea7315

mb58 and mb59 processing bug

Describe the bug
The Mb58 and mb59 format still can not be processed when i use the mbprocess program.

To Reproduce
Provide information sufficient to reproduce the behavior:

  1. Test data can download from NGDC (https://www.ngdc.noaa.gov/ships/marcus_g_langseth/MGL1112_mb.html)

Expected behavior
Editing events is not written to the new file.

**Screenshots / shell **

Computing context (please complete the following information):

  • OS: [ubuntu 16.4]
  • MB-System version [7.5 beta 12]
  • GMT version (e.g. 5.4.4)

Additional context

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.