r2sonic2image

Description

r2sonic2image is a utility (possibly a debugging or work-in-progress tool) that reads R2Sonic multibeam sonar .r2s files, specifically focusing on Full Time Series (FTS) snippet data and bathymetry data. Its primary function appears to be to extract and analyze snippet intensity information relative to bathymetric bottom detections for a given ping. While named r2sonic2image, the provided code snippet mainly prints information to standard output and does not produce a graphical image file.

It can be used to investigate the raw snippet waveforms around the detected bottom to understand detection quality or characteristics.

Usage

r2sonic2image -r2s <input.r2s> [-ping <ping_number>] [-v]

Arguments

Option Description  
-r2s <input.r2s> Required. Path to the input R2Sonic .r2s file.  
-ping <ping_num> Specifies the ping number (0-indexed) to process. 0 (default)
-v Enable verbose output.  

How It Works

  1. Initialization: Parses command-line arguments to get the input .r2s filename and the ping number to process.
  2. File Opening: Opens the input .r2s file for reading. Creates image.8bit (for the 8-bit output image) and image.txt (for detailed text output).
  3. R2Sonic Indexing: Calls build_R2SONIC_INDEX() (an external function) to build an index of the .r2s file, locating all FTS (R2SONIC_ID_FTS0) and Bathy (R2SONIC_ID_BTH0) records.
  4. Bathy and Snippet Data Extraction:
    • Seeks to the file_offset of the specified ping’s Bathy record and reads the R2SONIC_BATHY data (bathy).
    • Finds the corresponding snippet ping (snippet_ping) using find_R2SONIC_PING_MATCH().
    • Iterates through potential sub-packets of the snippet data (as snippets can be fragmented across multiple records) and reads R2SONIC_FTS data (fts).
  5. Snippet-Bathy Correlation and Output:
    • For each beam in the bathy record:
      • If snippet data is available for the beam (fts.snippet[i].num_samples is not zero), it calculates:
        • sample: The sample index within the snippet corresponding to the beam’s twtt (two-way travel time).
        • intensity: The intensity value at that sample in the snippet.
        • sample_corr: A corrected sample index using a constant offset (0.045 - 0.119 * cos(angle)) to twtt.
        • intensity_corr: The intensity at the corrected sample.
        • sample_center: The center sample of the snippet.
        • intensity_center: The intensity at the center sample.
      • It prints these calculated values for the beam.
      • It then prints all snippet samples (fts.snippet[i].first_sample + j) and their intensities (fts.snippet[i].samples[j]) for the current beam.
  6. Cleanup: Frees the R2Sonic index and closes the input file.

Output Files

  • Prints detailed information about beam-snippet correlation and snippet time series to standard output.
  • image.8bit: (No explicit generation in snippet) Potentially an intended output for a graphical image.
  • image.txt: (No explicit generation in snippet) Potentially an intended output for a text file.

Dependencies

  • R2Sonic_parser.h: For R2Sonic data structures and parsing functions (build_R2SONIC_INDEX, read_R2SONIC_BATHY, read_R2SONIC_FTS).
  • support.h: For general utility functions and error handling.
  • math.h: For mathematical functions.

Notes

While named r2sonic2image, the primary output of this tool appears to be textual information printed to standard output for debugging and analysis, rather than a graphical image file. It’s useful for in-depth investigation of snippet data in relation to bottom detections, helping to understand the raw acoustic returns and potentially refine bottom tracking algorithms. The tool relies on internal R2Sonic data structures for interpretation.