mergeOpWave
Description
mergeOpWave is a utility designed to merge Optech LASER Bathymetry waveform data (stored in a custom binary format) with corresponding Optech bottom detections (stored in OMG-HDCS merged files). It synchronizes waveform traces to individual beam records in the merged file based on timestamps and then stores pointers to the waveform data within the beam structure.
This tool is essential for linking the detailed waveform information to the final detected depths, allowing for more advanced analysis of bottom detection confidence, water column properties, and seafloor characteristics.
Usage
mergeOpWave -bathy <bathyfilename(s)> -waves <wavefilename(s)>
Arguments
| Option | Description | |
|---|---|---|
-bathy <bathyfilename(s)> | Required. One or more paths to input OMG-HDCS merged files (containing Optech bottom detections). These files are modified in place. | |
-waves <wavefilename(s)> | Required. One or more paths to input binary waveform files (generated by readOpWave). These files contain the waveform trace data. | |
-v | Enable verbose output. |
How It Works
- Initialization: Defines global variables, file handles, and structures for Optech waveform data (
optech_waveform) and waveform file bounds (wave_file_bounds). - Waveform File Processing: Loops through each specified binary waveform file (
-waves):- Opens the
.wavefile and its corresponding.16_datafile (which contains the actual 16-bit waveform traces). - Reads the first
optech_waveformrecord to getmin_timestamp. - Seeks to the end of the
.wavefile to determineno_recsandmax_timestamp. - Allocates memory for
wave_details[i](an array ofoptech_waveformstructures) and loads all waveform details from the.wavefile into memory.
- Opens the
- Bathy File Processing: Loops through each specified bathy (OMG-HDCS merged) file (
-bathy):- Opens the merged file for reading and writing (
r+). - Reads the summary header.
- Timestamp Range Check: Approximates the timestamp range of the merged file’s first and last beams.
- Waveform File Intersection: For each waveform file, it checks if its time bounds (
wavebound[k]) intersect with the current merged file’s time bounds usingwave_intersects_bathy. - Profile and Beam Iteration: If intersection is found, it iterates through each profile (ping) in the merged file, and then through each beam within that profile:
- Reads the profile header and raw beams.
- Timestamp Synchronization: Calculates a precise timestamp (
dtimestamp) for the current beam’s bottom strike usingprofile.laser_timestampRefandbeams[j].timestampOffset. - Waveform Record Search: If
dtimestampfalls within the time bounds of an intersecting waveform file, it callssearch_for_closer_timestampto find thewave_record(index) inwave_details[k]that best matchesdtimestamp. - Waveform Data Merging: If a matching
wave_recordis found:- Sets
beams[j].offsetto thePMT_byte_offsetfrom thewave_detailsrecord, which points to the waveform trace in the.16_datafile. - Sets
beams[j].no_PMT,no_GAPD,no_IR,no_RAMANfrom thewave_detailsrecord. - Note: The actual 16-bit waveform data (
data16) is read from the.16_datafile and written to an auxiliary.waveformfile associated with the merged file.beams[j].offsetthen points to this new location. This suggests a two-step process:readOpWavecreates the.waveand.16_datafiles, andmergeOpWavere-organizes the actual waveform data into a new.waveformfile that’s linked from the merged file.
- Sets
- Write Back: The modified
beams(with updated waveform pointers) are written back to the merged file.
- Opens the merged file for reading and writing (
- Cleanup: Closes all open files and frees allocated memory.
Output Files
The input merged files (-bathy) are modified in-place, updating beam structures with pointers to waveform data. An auxiliary .waveform file is created.
Helper Functions
wave_intersects_bathy(): Checks if the time range of a waveform file overlaps with the time range of a bathy file.search_for_closer_timestamp(): Searches for the closest matchingoptech_waveformrecord based ondtimestamp.
Dependencies
OMG_HDCS_jversion.h: For OMG-HDCS data structures.support.h: For general utility functions and error handling.Optech_waveform.h: Foroptech_waveformdata structure and related functions.
Notes
This tool is crucial for integrating raw waveform data with processed bottom detections, enabling more detailed analysis of the Optech SHOALS data. The two-step process (waveform extraction by readOpWave and merging by mergeOpWave) is necessary due to the structure of the data. As the tool modifies merged files in-place, backups are highly recommended.