speedtosalinity
Overview
speedtosalinity (code/tests/speedtosalinity.c) is an enhanced version of speed2salinity that inverts comma-separated (depth, velocity, temperature) sound velocity profiler casts to estimate practical salinity (best_guess_salinity) at $0.1\text{ ppt}$ resolution (400 integer steps of tenths of a part per thousand over $[0.0, 39.9]\text{ ppt}$) and allows the user to select between two classic empirical seawater sound speed equations:
-wilson: W. D. Wilson’s (1962) equation (vsw).-cml: Chen & Millero’s (1977) equation (vchemilli).
Syntax & CLI Options
speedtosalinity [-v] (-wilson | -cml) <infile.csv> <outfile.csv>
| Option | Description | Default |
|---|---|---|
-wilson | Use Wilson’s (1962) seawater sound speed equation (vsw). Mutually exclusive with -cml (one of -wilson or -cml is required). | 0 |
-cml | Use Chen & Millero’s (1977) seawater sound speed equation (vchemilli). Mutually exclusive with -wilson. | 0 |
<infile.csv> | Required. Input comma-separated ASCII file containing depth, velocity, temperature on each line. | None |
<outfile.csv> | Required. Output comma-separated ASCII file containing depth, velocity, temperature, best_guess_salinity. | None |
-v | Enable verbose output (verbose++), printing each step of the $0.1\text{ ppt}$ salinity search. | 0 |
Inversion Algorithm & Implementation Notes
1. Fine-Stepped $0.1\text{ ppt}$ Search Loop
To avoid floating-point accumulation rounding errors during the search loop, speedtosalinity uses an integer loop counter int salinity ranging from 0 to max_salinity - 1 (400, representing tenths of $\text{ppt}$) and passes (double)salinity / 10.0 to the chosen sound speed function:
where hydrostatic pressure $P$ in $\text{kg/cm}^2$ is evaluated from depth $z$ (m) as:
\[P = 1.0332 + (z \times 100.0) \times \frac{1.027}{1000.0}\] 2. Sound Speed Model Comparison (-wilson vs. -cml)
vsw(t, p, s)(-wilson): Evaluates Wilson (1962). Note that line 188–193 shares the same* +pcontinuation typo in the small cross-termvstpasspeed2salinity.c(accurate at shallow depths where $p \approx 1\text{ kg/cm}^2$).vchemilli(t, p, s)(-cml): Evaluates Chen & Millero (1977). Note that line 227 contains the historical typo1.0405e-12 + pow(t, 4)in terma3(documented inone.mdandtestSV.md), which biasesvchemilliat non-zero temperatures and pressures. Therefore,-wilsonis recommended when running the unmodifiedspeedtosalinitybinary, ora3on line 227 should be patched to1.0405e-12 * pow(t, 4)(as done intwo.c).
Example Usage
# Invert a sound velocity and temperature cast for salinity at 0.1 ppt resolution using Wilson (1962)
speedtosalinity -wilson cast_in.csv cast_salinity_out.csv