new_speedtosalinity
Description
new_speedtosalinity is a utility that calculates salinity from sound velocity, temperature, and depth (converted to pressure) using empirical equations. It reads a file containing depth, sound velocity, and temperature data, then iterates through possible salinity values to find the best fit for the observed sound velocity using either the Wilson (1962) or Chen-Millero-Li (1977) equations.
This tool is essential for oceanographic applications where direct salinity measurements are unavailable, but sound velocity, temperature, and depth are known. It allows for the reconstruction of salinity profiles for use in various oceanographic models.
Usage
new_speedtosalinity -in <infile> -out <outfile> (-wilson | -cml) [-v] [-test]
Arguments
| Option | Description |
|---|---|
-in <infile> | Required. Path to the input ASCII file containing depth, sound_velocity, temperature data. |
-out <outfile> | Required. Path for the output ASCII file containing depth, sound_velocity, temperature, salinity data. |
-wilson | Required (choose one). Uses the Wilson (1962) empirical equation to calculate sound velocity. |
-cml | Required (choose one). Uses the Chen-Millero-Li (1977) empirical equation to calculate sound velocity. |
-v | Enable verbose output. |
-test | Runs a hardcoded test case for vchemilli and exits. |
Input File Format (ASCII)
The input file (-in) is expected to be a comma-separated ASCII file with three columns: depth, sound_velocity, temperature
How It Works
- Initialization: Parses command-line arguments to get input/output filenames, select the empirical equation (
-wilsonor-cml), and set verbose/test modes. - File Opening: Opens the input ASCII file (
-in) for reading and the output ASCII file (-out) for writing. - Data Processing Loop: Reads
depth,sound_velocity, andtemperaturefrom each line of the input file:- Pressure Calculation: Converts
depthtopressure(in kg/cm²) by adding atmospheric pressure and accounting for density. - Salinity Iteration:
- Initializes
salinityto 0 andminDiffto a large value. - Iterates
salinityfrom 0 up tomax_salinity(400, representing 0 to 40.0 ppt in 0.1 ppt increments). - For each
salinityvalue, it calculatestemp_velocityusing eithervsw()(Wilson) orvchemilli()(Chen-Millero-Li) function. - Compares
temp_velocitywith the observedsound_velocityto find thebest_guess_salinitythat minimizes the absolute difference.
- Initializes
- Output: Writes
depth,sound_velocity,temperature, andbest_guess_salinityto the output file.
- Pressure Calculation: Converts
vsw(double t, double p, double s)(Wilson 1962 Equation):- Calculates sound velocity based on temperature (
t), pressure (p), and salinity (s) using Wilson’s empirical formula.
- Calculates sound velocity based on temperature (
vchemilli(double t, double p, double s)(Chen-Millero-Li 1977 Equation):- Calculates sound velocity based on temperature (
t), pressure (p), and salinity (s) using the Chen-Millero-Li empirical formula, which is generally more accurate.
- Calculates sound velocity based on temperature (
- Cleanup: Closes input and output files.
Output Files
<outfile>: An ASCII file containingdepth,sound_velocity,temperature,best_guess_salinitydata.
Dependencies
support.h: For general utility functions.math.h: For mathematical functions.
Notes
This tool is a valuable component in oceanographic data analysis, particularly when direct salinity measurements are missing or unreliable. By leveraging the empirical relationships between sound velocity, temperature, salinity, and pressure, it enables the reconstruction of crucial oceanographic parameters. The two available equations (Wilson and Chen-Millero-Li) provide options for different accuracy requirements. The tool creates a new file, preserving the original input.