rhoH2O <- function(T, p=0, S=0, method=c("Chen", "Fofonoff")) {
method <- match.arg(method)
if (method == "Chen") {
if (p !=0) warning("Chen formula only valid for limnological range, p ignored!")
if (S !=0) warning("Chen formula only valid for limnological range, S ignored!")
}
switch(method,
Chen = rhoH2O_Chen(T, p, S),
Fofonoff = 1e-3 / sv_Fofonoff(T, p, S)
)
}
rhoH2O_Chen <- function(T, p=0, S=0) {
# Chen, Ch.-T. and F.J. Millero (1986) - Precise thermodynamic
# properties of natural waters covering only the limnological range.
# Limnol. Oceanogr. 31 No. 3, 657 - 662
# rho in g/cm^3
# p in bar
# T in °C
rho0 <- 0.9998395 + 0.000067914 * T -
0.0000090894 * T * T + 0.00000010171 * T * T * T -
0.0000000012846 * T ^ 4 + 0.000000000011592 * T ^ 5 -
5.0125E-14 * T ^ 6 + (0.0008181 - 0.00000385 * T + 0.0000000496 * T * T) * S
K <- 19652.17 + 148.113 * T * -2.293 * T * T + 0.01256 * T ^ 3 - 0.0000418 * T ^ 4 +
(3.2726 - 0.0002147 * T + 0.0001128 * T ^ 2) * p + (53.238 - 0.313 * T + 0.005728 * p) * S
rho0 * (1 - p / K) ^ -1
}
sv_Fofonoff <- function(T, p=0, S=0) {
# see also http://www.satlab.hawaii.edu/ocn620/hydro/sv.m
# function y = sv(p,t,s)
# specific volume (m^3/kg) from
# pressure (dbar), temperature (C), salinity (PSS-78)
#
# Fofonoff N.P. and R.C. Millard (1983)
# Algorithms for Computation of Fundamental Properties of Seawater.
# UNESCO technical papers in marine science, 44, 53 pp.
#
# check vals: p(dbar) t(C) S(PSS) y (m^3/kg)
# --------------------------------------
# 0 5 0 1.000033251e-3
# 10000 5 0 0.957736964e-3
# 0 25 0 1.002960780e-3
# 10000 25 0 0.963482064e-3
# 0 5 35 0.973069835e-3
# 10000 5 35 0.935025857e-3
# 0 25 35 0.977189409e-3
# 10000 25 35 0.941142660e-3
#
# SCKennan(20apr95)
p <- p / 10
a0 <- 999.842594
a1 <- 0.06793952
a2 <- -0.00909529
a3 <- 0.0001001685
a4 <- -0.000001120083
a5 <- 0.000000006536332
b0 <- 0.824493
b1 <- -0.0040899
b2 <- 0.000076438
b3 <- -0.00000082467
b4 <- 0.0000000053875
c0 <- -0.00572466
c1 <- 0.00010227
c2 <- -0.0000016546
d0 <- 0.00048314
e0 <- 19652.21
e1 <- 148.4206
e2 <- -2.327105
e3 <- 0.01360477
e4 <- -0.00005155288
f0 <- 54.6746
f1 <- -0.603459
f2 <- 0.0109987
f3 <- -0.00006167
g0 <- 0.07944
g1 <- 0.016483
g2 <- -0.00053009
h0 <- 3.239908
h1 <- 0.00143713
h2 <- 0.000116092
h3 <- -0.000000577905
i0 <- 0.0022838
i1 <- -0.000010981
i2 <- -0.0000016078
j0 <- 0.000191075
k0 <- 0.0000850935
k1 <- -0.00000612293
k2 <- 0.000000052787
m0 <- -0.00000099348
m1 <- 0.000000020816
m2 <- 0.00000000091697
Rw <- a0 + a1 * T + a2 * T ^ 2 + a3 * T ^ 3 + a4 * T ^ 4 + a5 * T ^ 5
Kw <- e0 + e1 * T + e2 * T ^ 2 + e3 * T ^ 3 + e4 * T ^ 4
Aw <- h0 + h1 * T + h2 * T ^ 2 + h3 * T ^ 3
Bw <- k0 + k1 * T + k2 * T ^ 2
R <- Rw + (b0 + b1 * T + b2 * T ^ 2 + b3 * T ^ 3 + b4 * T ^ 4) * S +
(c0 + c1 * T + c2 * T ^ 2) * S ^ (3 / 2) + d0 * (S ^ 2)
K <- Kw + (f0 + f1 * T + f2 * T ^ 2 + f3 * T ^ 3) * S +
(g0 + g1 * T + g2 * T ^ 2) * S ^ (3 / 2)
a <- Aw + (i0 + i1 * T + i2 * T ^ 2) * S + j0 * S ^ (3 / 2)
B <- Bw + (m0 + m1 * T + m2 * T ^ 2) * S
K <- K + a * p + B * (p ^ 2)
(1 - p / K) / R
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.