Gibbs Energy of Seawater, and its Derivatives
Arguments
- ns
An integer, the order of the
SA
derivative. Must be 0, 1, or 2.- nt
An integer, the order of the
t
derivative. Must be 0, 1, or 2.- np
An integer, the order of the
p
derivative. Must be 0, 1, or 2.- SA
Absolute Salinity [ g/kg ]. The valid range for most `gsw` functions is 0 to 42 g/kg.
- t
in-situ temperature (ITS-90) [ degC ]
- p
sea pressure [dbar], i.e. absolute pressure [dbar] minus 10.1325 dbar
Value
Gibbs energy [ J/kg ] if ns
=nt
=np
=0. Derivative of energy
with respect to SA
[ J/kg/(g/kg)^ns ] if ns
is nonzero and nt
=np
=0,
etc. Note that derivatives with respect to pressure are in units with Pa, not dbar.
Implementation Note
This R function uses a wrapper to a C function contained within the GSW-C system as updated 2022-10-11 at https://github.com/TEOS-10/GSW-C with git commit `657216dd4f5ea079b5f0e021a4163e2d26893371`.
The C function uses data from the library/gsw_data_v3_0.mat
file provided in the GSW-Matlab source code, version 3.06-11.
Unfortunately, this version of the mat file is no longer displayed on the
TEOS-10.org website. Therefore, in the interests of making GSW-R be
self-contained, a copy was downloaded from
http://www.teos-10.org/software/gsw_matlab_v3_06_11.zip on 2022-05-25,
the .mat file was stored in the developer/create_data directory of
https://github.com/TEOS-10/GSW-R, and then the dataset used in GSW-R
was created based on that .mat file.
Please consult http://www.teos-10.org to learn more about the various TEOS-10 software systems.
Caution
The TEOS-10 webpage for gsw_gibbs
does not provide test values, so
the present R version should be considered untested.
Examples
library(gsw)
p <- seq(0, 100, 1)
SA <- rep(35, length(p))
t <- rep(-5, length(p))
## Check the derivative wrt pressure. Note the unit change
E <- gsw_gibbs(0, 0, 0, SA, t, p)
# Estimate derivative from linear fit (try plotting: it is very linear)
m <- lm(E ~ p)
print(summary(m))
#>
#> Call:
#> lm(formula = E ~ p)
#>
#> Residuals:
#> Min 1Q Median 3Q Max
#> -0.038423 -0.013827 0.005232 0.015858 0.019788
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) -1.939e+02 3.531e-03 -54906 <2e-16 ***
#> p 9.725e+00 6.100e-05 159414 <2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Residual standard error: 0.01787 on 99 degrees of freedom
#> Multiple R-squared: 1, Adjusted R-squared: 1
#> F-statistic: 2.541e+10 on 1 and 99 DF, p-value: < 2.2e-16
#>
plot(p, E)
abline(m)
dEdp1 <- coef(m)[2]
# Calculate derivative ... note we multiply by 1e4 to get from 1/Pa to 1/dbar
dEdp2 <- 1e4 * gsw_gibbs(0, 0, 1, SA[1], t[1], p[1])
## Ratio
dEdp1 / dEdp2
#> p
#> 0.9997605