thin_nav
Description
thin_nav filters a binary OMG navigation file (.nav, jcu_nav_rec) to remove redundant or non-monotonic records and writes the cleaned output to a new binary file named <filename>_thin.
It supports two filtering modes:
- Thin by Position (Default): Retains the first record and writes subsequent records only when either latitude or longitude changes (
nav_rec.lat != old_lat || nav_rec.lon != old_lon). - Thin by Time (
-by_time): Enforces strictly increasing timestamps (new_time > old_time), dropping any duplicate-timestamp fixes or backward time jumps.
Usage
thin_nav [-v] [-by_time] <filename>
Common Workflow Examples
1. Remove duplicate consecutive positions from a .nav file:
thin_nav merged/JD100/0001_line.nav
# Produces: merged/JD100/0001_line.nav_thin
2. Enforce strictly increasing timestamps (new_time > old_time) with verbose logging:
thin_nav -v -by_time merged/JD100/0001_line.nav
# Produces: merged/JD100/0001_line.nav_thin
mv merged/JD100/0001_line.nav_thin merged/JD100/0001_line.nav
Arguments
| Option | Description | Default |
|---|---|---|
<filename> | Required. Input binary .nav filename. The output file is automatically named <filename>_thin via mem_strappend(filename, "_thin"). | None |
-by_time | Switch from position deduplication (thin_by_position = 1) to strictly monotonic timestamp filtering (thin_by_time = 1). Keeps a record only if its timestamp time + centisecs / 100.0 is strictly greater than the last kept recordβs timestamp (new_time > old_time). | Disabled (thins by position) |
-v | Verbose mode: prints every retained record index and (in -by_time mode) warns whenever duplicate or backward timestamps are skipped ("Got same time on recs i i-1 ... skipping it"). | Disabled |
How It Works
- Initialization & First Record: Opens
<filename>for reading and<filename>_thinfor writing. Computes the total number of 48-byte records aslength = ftell(nav_file) / JCU_BINNAV_RECLEN. Reads record0, initializesold_lat,old_lon, andold_time = nav_rec.time + nav_rec.centisecs / 100.0, and writes record0directly to<filename>_thin(new_nav_counter = 1). - Sequential Filtering (
i = 1 .. length - 1):- Position Mode (Default): Checks
if (nav_rec.lat != old_lat || nav_rec.lon != old_lon). When true, writesnav_recto<filename>_thinat indexnew_nav_counter, incrementsnew_nav_counter, and updatesold_latandold_lon. - Time Mode (
-by_time): Computesnew_time = (double)nav_rec.time + (double)nav_rec.centisecs / 100.0. Checksif (new_time > old_time). When true, writesnav_recto<filename>_thin, incrementsnew_nav_counter, and updatesold_time = new_time. Becauseold_timeis only updated when a record is accepted, any backward time glitch is completely skipped until timestamps once again exceed the pre-glitchold_time.
- Position Mode (Default): Checks
- Completion Summary: Prints
Thinned <length - new_nav_counter> of <length> nav recs...and closes both files.