calcSpeedHead
Description
calcSpeedHead computes fix-to-fix Speed Over Ground (velocity, in m/s) and Course Over Ground (azi, in degrees $0^\circ..360^\circ$) from consecutive latitude/longitude positions and timestamps in one or more binary OMG navigation files (jcu_nav_rec, .nav), updating the input .nav files in-place.
[!WARNING] In-Place Modification & Field Placement:
calcSpeedHeadopens every input.navfile in read-write mode ("r+") and overwrites its records directly. Back up your.navfiles first if you need to preserve the original values.- To avoid overwriting data already stored in
tide_rec.azi(which often holds RTK height, tide, or gyro heading),calcSpeedHeadwrites the computed speed (m/s) intotide_rec.velocityand writes the computed course/azimuth (scaled by 100) into the integertide_rec.depthfield (tide_rec.depth = azi * 100.0). Record0inherits the speed and course computed for Record1.
Usage
calcSpeedHead [OPTIONS] <navfile(s)>
Common Workflow Examples
1. Compute speed and course in-place for one or more .nav files:
calcSpeedHead merged/JD100/0001_line.nav
2. Run with quality-control warnings for time steps outside $[0.05, 0.25]\text{ s}$ and speeds outside $[1.0, 5.0]\text{ m/s}$:
calcSpeedHead -check -allowed_mpers 1.0 5.0 -allowed_dtime 0.05 0.25 merged/JD100/*.nav
Arguments
| Option | Description | Default |
|---|---|---|
<nav(s)> | Required. One or more binary .nav files (up to 300 files). Modified in-place. | None |
-check | Enable diagnostic warnings when inter-fix time step dtime or speed velocity falls outside the allowed bounds (or equals 0.0). | Disabled |
-allowed_mpers <min> <max> | Used with -check. Minimum and maximum acceptable vessel speed in m/s. Requires two floating-point values. | 0.5 to 7.0 m/s (~1 to 14 knots) |
-allowed_dtime <min> <max> | Used with -check. Minimum and maximum acceptable inter-fix time step (dtime) in seconds. Requires two floating-point values. | 0.02 to 1.0 s (50 Hz to 1 Hz) |
-accept <N> | Integer parameter parsed on the command line (accept = strtoint(*argv)). | 9 |
-comp <filename> | Parsed on the command line (tidename = *argv), though fopen(tidename, "w") is commented out in the source and all writes go in-place to <nav(s)>. | Unused |
-ascii | Increments internal ascii_flag counter (unused in output loop). | Disabled |
-v | Enable verbose output (prints lat, lon, original azi, dtime, computed azi, and velocity for every fix). | Disabled |
How It Works
- Opens each input
.navfile in"r+"mode and determines the total number of 48-byte records (numrec = ftell(file[j]) / JCU_BINNAV_RECLEN). - Reads Record
0intolast_rec, then iterates through $k = 1 \dots \text{numrec}-1$:- Distance Calculation: Computes geodesic distance (meters) between
(tide_rec.lat, tide_rec.lon)and(last_rec.lat, last_rec.lon)usingcompute_distance_2(). - Course Over Ground (
azi): Computes the local north/east step (dlat = (lat2 - lat1) * 60 * 1852,dlon = (lon2 - lon1) * 60 * 1852 * cos(lat2)) and azimuth in degrees $[0, 360)$: \(\text{azi} = (\text{atan2}(-\text{dlon}, -\text{dlat}) + \pi) \times \frac{180}{\pi}\) - Time Step & Speed: Computes exact timestamp difference including hundredths of a second (
dtime = time1 - time2). Ifdtime != 0, setsvelocity = distance / dtime; otherwise setsvelocity = 0.0to prevent division by zero. - Quality Checks (
-check): Emitswarning()messages ifdtime < mindtime,dtime > maxdtime,dtime == 0.0,velocity > maxvel,velocity < minvel, orvelocity == 0.0. - In-Place Record Update: Stores
tide_rec.depth = azi * 100.0andtide_rec.velocity = velocity, writestide_recback to indexk(and on the first iterationtide_rec_no == 0, also copiesvelocityanddepthback into Record0).
- Distance Calculation: Computes geodesic distance (meters) between
-
At the end of each file, prints summary averages across the line:
Averages -- dtime <av_Dtime> Azi <av_Azi> Speed <av_Speed> Velocity <av_Velocity>where
av_Speedis the scalar mean speed andav_Velocity/av_Aziare the vector-averaged velocity magnitude and direction.