r2sonic2omg
Description
r2sonic2omg is a utility designed to convert R2Sonic multibeam sonar data (.r2s files) into the OMG-HDCS (Ocean Mapping Group - Hydrographic Data Conversion System) merged file format. This tool extracts bathymetry, snippet (full time series), and TruePix (beam-formed magnitude and angle time series) data from the .r2s files and maps them to the corresponding structures in the OMG-HDCS format.
It allows for optional roll stabilization and provides flags to skip certain data types, making it flexible for different processing workflows. The output merged file is a foundational format for further processing and visualization within the OMG toolkit.
Usage
r2sonic2omg -r2s <input.r2s> -omg <omg_file_prefix> [-skip_fts] [-skip_truepix] [-roll_stabilize] [-v]
Arguments
| Option | Description | |—|—| | -r2s <input.r2s> | Required. Path to the input R2Sonic .r2s file. | | -omg <omg_file_prefix> | Required. Prefix for the output OMG-HDCS files. The tool will generate: * <omg_file_prefix>.merged: The main OMG-HDCS merged file. * <omg_file_prefix>.merged.ss_data: Snippet side-scan data (if not skipped). * <omg_file_prefix>.sonar_settings: Binary file containing R2Sonic packet headers (BTH0, FTS0, TPX0). | | -skip_fts | Skips processing and writing of Full Time Series (FTS) snippet data. | | -skip_truepix | Skips processing and writing of TruePix data. | | -roll_stabilize | Adjusts beam angles by roll stabilization angles prior to calculating preliminary soundings. This does not affect receiver steering angles in the output file. | | -v | Enable verbose output. | |
How It Works
- Initialization: Parses command-line arguments, setting input/output filenames and various flags (e.g.,
skip_fts,skip_truepix,do_roll_stabilize). - File Opening: Opens the input
.r2sfile for reading. Creates the output OMG-HDCS merged file (.merged), snippet data file (.merged.ss_data), and a sonar settings file (.sonar_settings). - R2Sonic Indexing: Calls
build_R2SONIC_INDEX()(an external function) to create an index of all packet types within the.r2sfile. - OMG Summary Header Initialization:
- Reads the first bathy packet to determine
base_timeandsonar_type. - Initializes an
OMG_HDCS_summary_headerstructure, settingfileVersion,toolType,refTime,numDepths, etc. - Writes this summary header to the
.mergedfile. - Allocates memory for
OMG_HDCS_beamstructures.
- Reads the first bathy packet to determine
- Packet Traversal Loop: Iterates through each Bathy packet (
R2SONIC_ID_BTH0) found in the.r2sindex:- Seeks to the Bathy packet’s file offset and reads the
R2SONIC_BATHYdata (bathy). - Finds corresponding FTS (
R2SONIC_ID_SNI0) and TruePix (R2SONIC_ID_TPX0) packets by matching ping numbers. - Reads
R2SONIC_FTSandR2SONIC_TRUEPIXdata if not skipped. Handles fragmented FTS packets. - OMG Profile Header Population: Populates an
OMG_HDCS_profile_headerstructure:ping_timeis converted from R2Sonic time.numDepths,bathy_sample_rate,td_sound_speedare set frombathyheader.profile.vesselRollis set ifdo_roll_stabilize.- Offsets to raw R2Sonic headers (BTH0, FTS0, TPX0) are stored in
profile.sonar_settings_offset_*and written to.sonar_settings. - TruePix magnitude and angle data are written to
.merged.ss_data, and their offsets/scales are stored in the profile header.
- OMG Beam Structure Population: For each beam in the
bathydata:beams[i].twtt,beams[i].range,beams[i].Rc_steerare set.beams[i].statusandbeams[i].Q_factorare derived from R2Sonicqualityflags.- Preliminary
beams[i].observedDepthandbeams[i].acrossTrackare calculated usingrange,angle, and optionallyroll_stabilize_angle. beams[i].reflectivityis set frombathy.beam[i].intensityor TruePix data.- If FTS data is available and not skipped:
beams[i].no_samples,beams[i].snippet_first_sampleare set.beams[i].centre_nois calculated fromtwtt_corr.beams[i].offsetis set to the current file pointer in.merged.ss_data.- Snippet samples are written to
.merged.ss_data.
- Write to Merged File:
OMG_HDCS_write_profile()andOMG_HDCS_put_raw_beams()write the populated profile header and beam data to the.mergedfile.
- Seeks to the Bathy packet’s file offset and reads the
- Cleanup: Frees allocated memory and closes all open files.
Output Files
<omg_file_prefix>.merged: Standard OMG-HDCS merged file.<omg_file_prefix>.merged.ss_data: Snippet side-scan data (binary, raw short intensities).<omg_file_prefix>.sonar_settings: Binary file containing R2Sonic packet headers (for BTH0, FTS0, TPX0).
Dependencies
R2Sonic_parser.h: For R2Sonic data structures and parsing functions.OMG_HDCS_jversion.h: For OMG-HDCS data structures.support.h: For general utility functions and error handling.
Notes
r2sonic2omg is a crucial tool for integrating R2Sonic raw data into the standard OMG-HDCS processing workflow. It handles the complex translation from R2Sonic’s proprietary binary format to the structured OMG-HDCS format, including extracting and organizing bathymetry, snippet, and TruePix data. The optional roll stabilization and data skipping flags provide flexibility for different processing needs. The tool creates new files without modifying the original .r2s input.