gsw/
lib.rs

1//! # Gibbs Sea Water
2//!
3//! Unofficial Gibbs Sea Water Oceanographic Toolbox of TEOS-10,
4//! based on version 3.06.12, implemented in Rust.
5//!
6//! Note that we do follow TEOS-10 manual and references, but this library is
7//! not endorsed by TEOS-10 committee. For the official TEOS-10 documentation
8//! and other software implementations, check: <http://www.teos-10.org>
9//!
10//! GSW-rs was initially implemented to provide support for embedded
11//! applications, but there is no restrictions on using it in regular
12//! computers or even HPC. It is an alternative for GSW-C, and we demonstrate
13//! how to link Python and R implementations of GSW with our Rust version
14//! instead.
15//!
16//! ## Features
17//!
18//! A few customizations can be chosen at compiling time by activating the
19//! following features:
20//!
21//! - **capi**: Include the C-API so that GSW-rs can be accessed as if it was
22//!   a C-library. For instance, the other GSW implementations based on GSW-C
23//!   could be linked with GSW-rs instead by using this feature.
24//! - **compat**: Reproduces the GSW-Matlab implementation for compatibility.
25//!   This option can result in negligible rounding differences. The most
26//!   notable differences are on handling special cases such as negative
27//!   salinity.
28//! - **invalidasnan**: Returns NaN values on failure. The default behavior is
29//!   to return an error. This is the closest option to reproduce GSW-C
30//!   implementation, when that one deviates from GSW-Matlab. The default
31//!   behavior returns NaN if the input is a NaN, or returns an *Error* on
32//!   failure.
33//! - **nodgdz**: Ignores vertical variations of gravity, i.e. no dependency
34//!   on *z*. This might be useful on some numerical models.
35//! - **std**: Activate the Rust standard library. The default implementation
36//!   does not rely on standard library so it can run in embedded systems.
37//!
38//! For instance, to compile it compatible with the Matlab library:
39//! ```text
40//! cargo build --features compat
41//! ```
42//!
43//! While compat results in precisely reproducing GSW-Matlab results, there is
44//! no equivalent for GSW-C, which is currently the base for Julia, Python,
45//! and R. The closest option to that is using **invalidasnan**, i.e.
46//! `--features invalidasnan`.
47//!
48//! Since these checks are defined at compiling time, those do not necessarily
49//! imply extra computing cost at running time. For instance, the cost of the
50//! **compat** checks do not affect at all when compiled with the default
51//! behavior.
52//!
53//! ## Design considerations
54//!
55//! - Functions that can result in failure return type `Result<T>`, as usual
56//!   in Rust. We prefer to return errors instead of NaN for two main reasons:
57//!   We can shortcut unnecessary long calculations, and we can provide more
58//!   information context for the next layer to support automatic decisions.
59//!   For instance, an application using GSW-rs might respond differently
60//!   if gets back an error due to an invalid salinity such as a negative
61//!   value versus a feasible salinity but out of the valid range.
62//! - The validation dataset from GSW-Matlab is converted to small binaries
63//!   so that we can run tests directly in embedded systems.
64//! - We reinforce the theoretical validity range. If the original publication
65//!   of an approximation defines that it was valid in the salinity range from
66//!   0 to 42, we reinforce that in the implemented function. We believe that
67//!   it is our job to avoid conceptual errors.
68//!
69//! ## References
70//!
71//! There is a long list of references which should be all listed at:
72//!
73//! IOC, SCOR and IAPSO, 2010: The international thermodynamic equation of
74//! seawater – 2010: Calculation and use of thermodynamic properties.
75//! Intergovernmental Oceanographic Commission, Manuals and Guides No. 56,
76//! UNESCO (English), 196 pp.
77//!
78//! Note that in GSW-rs, the functions missing references means that we have
79//! not have the chance to review it yet, but we are working on that.
80//!
81//! To cite this library, please check guidance in the README.
82
83////////////////////////////////////////////////////////////////////////////////
84
85// Do not depend on the standard library
86#![no_std]
87
88/// cbindgen:ignore
89#[allow(unused)]
90mod gsw_internal_const;
91
92/// cbindgen:ignore
93#[allow(unused)]
94mod gsw_sp_coefficients;
95
96/// cbindgen:ignore
97#[allow(unused)]
98mod gsw_specvol_coefficients;
99
100#[cfg(feature = "capi")]
101mod ffi;
102
103pub mod conversions;
104pub mod earth;
105mod gsw_internal_funcs;
106pub mod practical_salinity;
107pub mod volume;
108
109mod error;
110pub use crate::error::{Error, Result};