[Seacarb-commits] r3 - in pkg: . seacarb3 seacarb3/R seacarb3/data seacarb3/man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Dec 24 17:02:21 CET 2008
Author: phgrosjean
Date: 2008-12-24 17:02:21 +0100 (Wed, 24 Dec 2008)
New Revision: 3
Added:
pkg/seacarb3/
pkg/seacarb3/ChangeLog
pkg/seacarb3/DESCRIPTION
pkg/seacarb3/NAMESPACE
pkg/seacarb3/R/
pkg/seacarb3/R/K1.R
pkg/seacarb3/R/K1p.R
pkg/seacarb3/R/K2.R
pkg/seacarb3/R/K2p.R
pkg/seacarb3/R/K3p.R
pkg/seacarb3/R/Kb.R
pkg/seacarb3/R/Kconv.R
pkg/seacarb3/R/Kf.R
pkg/seacarb3/R/Kh.R
pkg/seacarb3/R/Khs.R
pkg/seacarb3/R/Kn.R
pkg/seacarb3/R/Ks.R
pkg/seacarb3/R/Ksi.R
pkg/seacarb3/R/Kspa.R
pkg/seacarb3/R/Kspc.R
pkg/seacarb3/R/Kw.R
pkg/seacarb3/R/bjerrum.R
pkg/seacarb3/R/bor.R
pkg/seacarb3/R/buffer.R
pkg/seacarb3/R/carb.R
pkg/seacarb3/R/convert.R
pkg/seacarb3/R/internals.R
pkg/seacarb3/R/pCa.R
pkg/seacarb3/R/pHconv.R
pkg/seacarb3/R/pHinsitu.R
pkg/seacarb3/R/pTA.R
pkg/seacarb3/R/pgas.R
pkg/seacarb3/R/pmix.R
pkg/seacarb3/R/ppH.R
pkg/seacarb3/R/rho.R
pkg/seacarb3/R/speciation.R
pkg/seacarb3/R/stp.R
pkg/seacarb3/R/swK.R
pkg/seacarb3/R/swconc.R
pkg/seacarb3/R/swobj.R
pkg/seacarb3/R/swpH.R
pkg/seacarb3/TODO
pkg/seacarb3/data/
pkg/seacarb3/data/seacarb_test.txt
pkg/seacarb3/man/
pkg/seacarb3/man/K1.Rd
pkg/seacarb3/man/K1p.Rd
pkg/seacarb3/man/K2.Rd
pkg/seacarb3/man/K2p.Rd
pkg/seacarb3/man/K3p.Rd
pkg/seacarb3/man/Kb.Rd
pkg/seacarb3/man/Kconv.Rd
pkg/seacarb3/man/Kf.Rd
pkg/seacarb3/man/Kh.Rd
pkg/seacarb3/man/Khs.Rd
pkg/seacarb3/man/Kn.Rd
pkg/seacarb3/man/Ks.Rd
pkg/seacarb3/man/Ksi.Rd
pkg/seacarb3/man/Kspa.Rd
pkg/seacarb3/man/Kspc.Rd
pkg/seacarb3/man/Kw.Rd
pkg/seacarb3/man/bjerrum.Rd
pkg/seacarb3/man/bor.Rd
pkg/seacarb3/man/buffer.Rd
pkg/seacarb3/man/carb.Rd
pkg/seacarb3/man/convert.Rd
pkg/seacarb3/man/pCa.Rd
pkg/seacarb3/man/pHconv.Rd
pkg/seacarb3/man/pHinsitu.Rd
pkg/seacarb3/man/pTA.Rd
pkg/seacarb3/man/pgas.Rd
pkg/seacarb3/man/pmix.Rd
pkg/seacarb3/man/ppH.Rd
pkg/seacarb3/man/rho.Rd
pkg/seacarb3/man/seacarb_test.Rd
pkg/seacarb3/man/speciation.Rd
pkg/seacarb3/man/stp.Rd
pkg/seacarb3/man/swconc.Rd
pkg/seacarb3/man/swpH.Rd
Log:
seacarb3 original version 3.0.0
Added: pkg/seacarb3/ChangeLog
===================================================================
--- pkg/seacarb3/ChangeLog (rev 0)
+++ pkg/seacarb3/ChangeLog 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,137 @@
+--------------------------
+version 3.0.0, 2008-12-22
+
+- All code is refactored (Ph. Grosjean). Duplicated code is placed inside
+ internal functions. Code now respects the standard formatting in R
+- S3 objects are defined, taking into account concentration unit, pH scale and
+ salinity - temperature - hydrostatic pressure ('stp' object) (PhG)
+ + 'swobj' is a general object for calculation, using stp and unit
+ + 'swconc' represents chemical concentration
+ + 'swpH' represents seawter pH
+ + 'swK' represents seawater chemical equilibrium constant
+ + 'speciation' is a special object for speciation according to total and K
+- There are print() and plot() methods for most objects (PhG)
+- The convert() method properly, and automatically, converts from one unit to
+ the other (molarity <-> molality <-> molinity), and from one pH scale to the
+ other (free scale <-> total scale <-> seawater scale) (PhG)
+- All constants have now a first argument 'x' that can be a 'stp' object, a
+ data.frame or list with 'S', 'T', 'P' components, or any other object having
+ a 'stp' attribute defined. If x = NULL (default), the original behaviour of
+ working with 'S', 'T' and 'P' arguments is used
+- bjerrum() and speciation() are reworked to provide nicely formatted text in
+ title and axes labels, and a legend is added indicating chemical species
+- kconv() renamed Kconv() to homogenize capitalisation + total2SWS -> total2sws
+ and free2SWS -> free2sws (PhG)
+- Man pages have now test functions that check correctness of code during
+ compilation of the package (PhG)
+- A NAMESPACE file, isolating visible from internal functions is added (PhG)
+
+
+--------------------------
+version 2.0.5, 2008-12-08
+
+Changes made thanks to comments kindly provided by Andreas Hofman (A.Hofmann at nioo.knaw.nl):
+- K2 modified to fix a bug which provided warnings when several pressures were used.
+- Khs modified to fix a bug (in coefficient a2).
+- The value of the R constant was updated according to Dickson et al. (2007). The new value is 8.314475 J/(K*mol).
+- kconv was modified in order to include pressure correction.
+
+--------------------------
+version 2.0.4, 2008-11-06
+
+- pH, pTA, pmix, pCa, and pgas now accept Sit (concentration of silicate) and Pt (concentration of total phosphate) as input arguments.
+- Various style changes in the help files.
+
+--------------------------
+version 2.0.3, 2008-11-04
+
+- The code of all functions which calculate constants was modified in order to be able to use vectors as input arguments.
+- The man files were changed accordingly by adding a "details" section.
+
+--------------------------
+version 2.0.1, 2008-10-28
+
+- added the data set seacarb_test
+- added and example to use carb with a data frame
+- various cosmetic changes in the help files
+
+--------------------------
+version 2.0, 2008-10-27
+
+- added function "pCa" which calculates the changes in the saturation states of aragonite and calcite resulting from the manipulation of the calcium concentration
+- added function "pgas" which calculates the carbonate chemistry after changes in pCO2 generated by gas bubbling
+- added function "pmix" which calculates the carbonate chemistry after mixing of two water samples with different pCO2
+- added function "ppH" which calculates the carbonate chemistry after pH manipulations through addition of acid or base
+- added function "pTA" which calculates the carbonate chemistry following addition of CO3 or HCO3
+- carb function modified to return only S, T, P, pH, pCO2, fCO2, HCO3, CO3, DIC, ALK, OmegaAragonite and OmegaCalcite.
+- added function "buffer" which calculates the buffer parameters of the seawater carbonate system.
+- carb function modified in order to closely follow the recommendations of the "Guide to Best Practices for Ocean CO2 Measurements" (Dickson et al., 2007). Phosphate ans ilicate concentrations are now taken into account.
+- K1 function uses the equation of Lueker et al. (2000) by default
+- K2 function uses the equation the method of Lueker et al. (2000) by default
+- Kf function uses, by default, the equation of Perez and Fraga (1987). The equation of Dickson and Roy can be used with the argument kf = 'dg'.
+
+--------------------------
+version 1.2.3, 2007-11-27
+
+- carb function modified to allow NA values in the input data. A warning is returned if this happens but all other data rows are processed. Change made by Bernard Gentili.
+
+--------------------------
+version 1.2.2, 2007-09-09
+
+- correction of the definition of PiH and PhiH in the "carb" documentation file
+- BetaD is the Revelle factor (the "carb" documentation has been updated
+- cosmetic changes to some documentation files
+
+--------------------------
+version 1.2.1, 2007-08-21
+
+- cosmetic changes to some documentation files
+
+--------------------------
+version 1.2, 2007-08-21
+
+- added function "speciation" which estimates the concentration of the various ionic forms of a molecule as a function of pH (contributed by Karline Soetaert)
+- added function "kconv" which provides conversion factors to change the pH scale of dissociation constants (contributed by Karline Soetaert)
+- added function "pHconv" which provides conversion factors for changing the pH scale (contributed by Karline Soetaert)
+- added function "Kn" which provides the ammonium dissociation constant (contributed by Karline Soetaert)
+- added function "Khs" which provides the dissociation constant of hydrogen sulfide (contributed by Karline Soetaert)
+- added function "Ksi" which provides the Si(OH)4 dissociation constant (contributed by Karline Soetaert)
+- added function "bjerrum" which makes a bjerrum plot (contributed by Karline Soetaert)
+
+--------------------------
+version 1.1.1, 2007-08-14
+
+- bor(), K1(), K1p() and K2() now return the values
+- return values are now set for all variables
+
+--------------------------
+version 1.1, 2007-07-24
+
+- carb() has now 5 more flags (code contributed by Jim Orr):
+ # flag = 21 pH-pCO2 given
+ # flag = 22 pCO2-HCO3 given
+ # flag = 23 pCO2-CO3 given
+ # flag = 24 pCO2-ALK given
+ # flag = 25 pCO2-DIC given
+
+--------------------------
+version 1.0.5, 2007-07-23
+
+- minor changes to the documentation (tried to have the superscripts right)
+
+--------------------------
+version 1.0, 2007-01-08
+
+- added function phinsi which calculates the pH at in situ temperature from pH values measured in the laboratory and other ancillay data
+
+--------------------------
+version 1.0, 2007-01-08
+
+- a test data file is now provided
+- various cosmetic changes
+
+--------------------------
+version 0.98, 2006-05-07
+
+- data entry via a file is NO LONGER possible
+- results of the carb command are no longer automatically saved in a file
Added: pkg/seacarb3/DESCRIPTION
===================================================================
--- pkg/seacarb3/DESCRIPTION (rev 0)
+++ pkg/seacarb3/DESCRIPTION 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,10 @@
+Package: seacarb3
+Title: Calculates parameters of the seawater carbonate system (additions and changes proposed to the original seacarb)
+Version: 3.0.0
+Date: 2008-12-22
+Author: Heloise Lavigne, Aurelien Proye, Philippe Grosjean and Jean-Pierre Gattuso. Portions of code and/or corrections were contributed by Jean-Marie Epitalon, Bernard Gentili, Jim Orr and Karline Soetaert
+Description: Calculates parameters of the seawater carbonate system
+Maintainer: Jean-Pierre Gattuso <gattuso at obs-vlfr.fr>
+URL: http://www.obs-vlfr.fr/~gattuso/seacarb.php
+License: GPL version 2 or newer
+Packaged: Mon Dec 22 23:43:55 2008; phgrosjean
Added: pkg/seacarb3/NAMESPACE
===================================================================
--- pkg/seacarb3/NAMESPACE (rev 0)
+++ pkg/seacarb3/NAMESPACE 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,44 @@
+export(bjerrum,
+ bor,
+ buffer,
+ carb,
+ convert,
+ K1,
+ K1p,
+ K2,
+ K2p,
+ K3p,
+ Kb,
+ Kconv,
+ Kf,
+ Kh,
+ Khs,
+ Kn,
+ Ks,
+ Ksi,
+ Kspa,
+ Kspc,
+ Kw,
+ pCa,
+ pgas,
+ pHconv,
+ pHinsitu,
+ pmix,
+ ppH,
+ pTA,
+ rho,
+ speciation,
+ stp,
+ "stp<-",
+ swconc,
+ swpH)
+
+S3method(print, stp)
+S3method("[", swobj)
+S3method(as.data.frame, swobj)
+S3method(print, swconc)
+S3method(convert, swconc)
+S3method(print, swpH)
+S3method(convert, swpH)
+S3method(print, swK)
+S3method(plot, speciation)
Added: pkg/seacarb3/R/K1.R
===================================================================
--- pkg/seacarb3/R/K1.R (rev 0)
+++ pkg/seacarb3/R/K1.R 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,69 @@
+# Copyright (C) 2008 Jean-Pierre Gattuso and Hlose Lavigne and Aurelien Proye
+# Refactored by Ph. Grosjean, 2008
+#
+# This file is part of seacarb.
+#
+# Seacarb is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# Seacarb is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# seacarb; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+#
+
+"K1" <- function (x = NULL, S = 35, T = 25, P = 0, k1k2 = "l")
+{
+ # --------------------- K1 with k1k2 = "l" ------------------------------
+ # first acidity constant: K1 = [H+] . [HCO3-] / [CO2*]
+ #
+ # Mehrbach et al (1973) refit by Lueker et al. (2000).
+ #
+ # (Lueker et al., 2000 in Guide to the Best Practices for Ocean CO2 Measurements
+ # Dickson, Sabin and Christian , 2007, Chapter 5, p. 13)
+ #
+ # pH-scale: 'total'. mol/kg-soln
+
+ # --------------------- K1 with k1k2 = "r" ------------------------------
+ #
+ # (Roy et al., 1993 in Dickson and Goyet, 1994, Chapter 5, p. 14)
+ # pH-scale: 'total'. mol/kg-soln
+
+ # Check and rework arguments
+ stp <- stp(x, S, T, P)
+ if (!identical(k1k2, "l") && !identical(k1k2, "r"))
+ stop("'k1k2' must be 'l' for Lueker et al., 2000 or 'r' for Roy et al., 1993")
+
+ TK <- .TK(stp$T)
+
+ if (k1k2 == "l") {
+ logK1lue <- -3633.86 / TK + 61.2172 - 9.67770 * log(TK) +
+ 0.011555 * stp$S - 0.0001152* stp$S^2
+ res <- 10^logK1lue * .KPcorr(stp, "K1")
+ version <- "Lueker et al., 2000"
+ } else {
+ lnK1roy <- 2.83655 - 2307.1266 / TK - 1.5529413 * log(TK) -
+ (0.20760841 + 4.0484 / TK) * sqrt(stp$S) + 0.08468345 * stp$S -
+ 0.00654208 * stp$S^(3/2) + log(1 - 0.001005 * stp$S)
+ res <- exp(lnK1roy) * .KPcorr(stp, "K1")
+ version <- "Roy et al., 1993"
+ }
+
+ # Construct the 'swK' object together with its metadata
+ attr(res, "K") <- "K1" # Name of the constant
+ attr(res, "k1k2") <- k1k2
+ attr(res, "version") <- version
+ attr(res, "unit") <- "mol/kg-soln"
+ attr(res, "pH scale") <- "total scale"
+
+ attr(res, "definition") <- "[H+] . [HCO3-] / [CO2*]"
+ attr(res, "stp") <- stp
+ attr(res, "class") <- c("swK", "swobj")
+ return(res)
+}
+
+# log(K1(k1k2 = "r")) # = -13.4847
\ No newline at end of file
Added: pkg/seacarb3/R/K1p.R
===================================================================
--- pkg/seacarb3/R/K1p.R (rev 0)
+++ pkg/seacarb3/R/K1p.R 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,46 @@
+# Copyright (C) 2003 Jean-Pierre Gattuso and Aurelien Proye
+# Refactored by Ph. Grosjean, 2008
+#
+# This file is part of seacarb.
+#
+# Seacarb is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# Seacarb is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# seacarb; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+#
+
+"K1p" <- function (x = NULL, S = 35, T = 25, P = 0)
+{
+ # --------------------- Phosphoric acid ---------------------
+ #
+ # (DOE, 1994) (Dickson and Goyet): pH_T, mol/(kg-soln)
+ # Ch.5 p. 16
+ #
+
+ # Check and rework arguments
+ stp <- stp(x, S, T, P)
+
+ TK <- .TK(stp$T)
+
+ lnK1p <- -4576.752 / TK + 115.525 - 18.453 * log(TK) +
+ (-106.736 / TK + 0.69171) * sqrt(stp$S) + (-0.65643 / TK - 0.01844) * stp$S
+ res <- exp(lnK1p) * .KPcorr(stp, "K1p")
+
+ # Construct the 'swK' object together with its metadata
+ attr(res, "K") <- "K1p" # Name of the constant
+ attr(res, "unit") <- "mol/kg-soln"
+ attr(res, "pH scale") <- "total scale"
+ attr(res, "definition") <- "[H+] . [H2PO4-] / [H3PO4]"
+ attr(res, "stp") <- stp
+ attr(res, "class") <- c("swK", "swobj")
+ return(res)
+}
+
+#log(K1p()) # = -3.71
\ No newline at end of file
Added: pkg/seacarb3/R/K2.R
===================================================================
--- pkg/seacarb3/R/K2.R (rev 0)
+++ pkg/seacarb3/R/K2.R 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,70 @@
+# Copyright (C) 2008 Jean-Pierre Gattuso and Hlose Lavigne and Aurelien Proye
+# Refactored by Ph. Grosjean, 2008
+#
+# This file is part of seacarb.
+#
+# Seacarb is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# Seacarb is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# seacarb; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+#
+
+"K2" <- function (x = NULL, S = 35, T = 25, P = 0, k1k2 = "l")
+{
+ # --------------------- K2 with k1k2 = "l" ------------------------------
+ # second acidity constant: K2 = [H+] . [CO3--] / [HCO3-]
+ #
+ # Mehrbach et al (1973) refit by Lueker et al. (2000).
+ #
+ # (Lueker et al., 2000 in Guide to the Best Practices for Ocean CO2 Measurements
+ # Dickson, Sabin and Christian , 2007, Chapter 5, p. 14)
+ #
+ # pH-scale: 'total'. mol/kg-soln
+
+ # --------------------- K2 with k1k2 = "r" ------------------------------
+ #
+ # (Roy et al., 1993 in Dickson and Goyet, 1994, Chapter 5, p. 15)
+ # pH-scale: 'total'. mol/kg-soln
+
+ # Check and rework arguments
+ stp <- stp(x, S, T, P)
+ if (!identical(k1k2, "l") && !identical(k1k2, "r"))
+ stop("'k1k2' must be 'l' for Lueker et al., 2000 or 'r' for Roy et al., 1993")
+
+ TK <- .TK(stp$T)
+
+ if (k1k2 == "l") {
+ logK2lue <- -471.78 / TK - 25.9290 + 3.16967 * log(TK) +
+ 0.01781 * stp$S - 0.0001122 * stp$S^2
+ res <- 10^logK2lue * .KPcorr(stp, "K2")
+ version <- "Lueker et al., 2000"
+ } else {
+ lnK2roy <- -9.226508 - 3351.6106 / TK - 0.2005743 * log(TK) +
+ (-0.106901773 - 23.9722 / TK) * sqrt(stp$S) +
+ 0.1130822 * stp$S - 0.00846934 * stp$S^(3/2) +
+ log(1 - 0.001005 * stp$S)
+ res <- exp(lnK2roy) * .KPcorr(stp, "K2")
+ version <- "Roy et al., 1993"
+ }
+
+ # Construct the 'swK' object together with its metadata
+ attr(res, "K") <- "K2" # Name of the constant
+ attr(res, "k1k2") <- k1k2
+ attr(res, "version") <- version
+ attr(res, "unit") <- "mol/kg-soln"
+ attr(res, "pH scale") <- "total scale"
+
+ attr(res, "definition") <- "[H+] . [CO3--] / [HCO3-]"
+ attr(res, "stp") <- stp
+ attr(res, "class") <- c("swK", "swobj")
+ return(res)
+}
+
+# log(K1(k1k2 = "r")) # = -20.5504
\ No newline at end of file
Added: pkg/seacarb3/R/K2p.R
===================================================================
--- pkg/seacarb3/R/K2p.R (rev 0)
+++ pkg/seacarb3/R/K2p.R 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,46 @@
+# Copyright (C) 2008 Jean-Pierre Gattuso and Hlose Lavigne and Aurelien Proye
+# Refactored by Ph. Grosjean, 2008
+#
+# This file is part of seacarb.
+#
+# Seacarb is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# Seacarb is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# seacarb; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+#
+
+"K2p" <- function (x = NULL, S = 35, T = 25, P = 0)
+{
+ # --------------------- Phosphoric acid ---------------------
+ #
+ # Guide to Best Practices in Ocean CO2 Measurements 2007 Chap 5 p 15
+ # (Dickson and Goyet): pH_T, mol/(kg-soln)
+ #
+
+ # Check and rework arguments
+ stp <- stp(x, S, T, P)
+
+ TK <- .TK(stp$T)
+
+ lnK2p <- -8814.715 / TK + 172.0883 - 27.927 * log(TK) +
+ (-160.34 / TK + 1.3566) * sqrt(stp$S) + (0.37335 / TK - 0.05778) * stp$S
+ res <- exp(lnK2p) * .KPcorr(stp, "K2p")
+
+ # Construct the 'swK' object together with its metadata
+ attr(res, "K") <- "K2p" # Name of the constant
+ attr(res, "unit") <- "mol/kg-soln"
+ attr(res, "pH scale") <- "total scale"
+ attr(res, "definition") <- "[H+] . [HPO4--] / [H2PO4-]"
+ attr(res, "stp") <- stp
+ attr(res, "class") <- c("swK", "swobj")
+ return(res)
+}
+
+# log(K2p()) # = -13.727
\ No newline at end of file
Added: pkg/seacarb3/R/K3p.R
===================================================================
--- pkg/seacarb3/R/K3p.R (rev 0)
+++ pkg/seacarb3/R/K3p.R 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,47 @@
+# Copyright (C) 2008 Jean-Pierre Gattuso and Hlose Lavigne and Aurelien Proye
+# Refactored by Ph. Grosjean, 2008
+#
+# This file is part of seacarb.
+#
+# Seacarb is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# Seacarb is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# seacarb; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+#
+
+"K3p" <- function (x = NULL, S = 35, T = 25, P = 0)
+{
+ # --------------------- Phosphoric acid ---------------------
+ #
+ # Guide to Best Practices in Ocean CO2 Measurements 2007 Chap 5 p 15
+ #
+ # Ch.5 p. 15
+ #
+
+ # Check and rework arguments
+ stp <- stp(x, S, T, P)
+
+ TK <- .TK(stp$T)
+
+ lnK3p <- -3070.75 / TK - 18.141 + (17.27039 / TK + 2.81197) * sqrt(stp$S) +
+ (-44.99486 / TK - 0.09984) * stp$S
+ res <- exp(lnK3p) * .KPcorr(stp, "K3p")
+
+ # Construct the 'swK' object together with its metadata
+ attr(res, "K") <- "K3p" # Name of the constant
+ attr(res, "unit") <- "mol/kg-soln"
+ attr(res, "pH scale") <- "total scale"
+ attr(res, "definition") <- "[H+] . [PO4---] / [HPO4--]"
+ attr(res, "stp") <- stp
+ attr(res, "class") <- c("swK", "swobj")
+ return(res)
+}
+
+# log(K3p()) # = -20.24
\ No newline at end of file
Added: pkg/seacarb3/R/Kb.R
===================================================================
--- pkg/seacarb3/R/Kb.R (rev 0)
+++ pkg/seacarb3/R/Kb.R 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,48 @@
+# Copyright (C) 2008 Jean-Pierre Gattuso and Hlose Lavigne and Aurelien Proye
+# Refactored by Ph. Grosjean, 2008
+#
+# This file is part of seacarb.
+#
+# Seacarb is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# Seacarb is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# seacarb; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+#
+
+"Kb" <- function (x = NULL, S = 35, T = 25, P = 0)
+{
+ # Kb = [H+] . [B(OH)4-] / [B(OH)3]
+ #
+ # (Dickson, 1990 in Guide to Best Practices in Ocean CO2 Measurements 2007)
+ # pH-scale: 'total'. mol/kg-soln
+
+ # Check and rework arguments
+ stp <- stp(x, S, T, P)
+
+ TK <- .TK(stp$T)
+
+ lnKb <- (-8966.90 - 2890.53 * sqrt(stp$S) - 77.942 * stp$S +
+ 1.728 * stp$S^(3/2) - 0.0996 * stp$S^2) / TK + 148.0248 +
+ 137.1942 * sqrt(stp$S) + 1.62142 * stp$S +
+ (-24.4344 - 25.085 * sqrt(stp$S) - 0.2474 * stp$S) * log(TK) +
+ 0.053105 * sqrt(stp$S) * TK
+ res <- exp(lnKb) * .KPcorr(stp, "Kb")
+
+ # Construct the 'swK' object together with its metadata
+ attr(res, "K") <- "Kb" # Name of the constant
+ attr(res, "unit") <- "mol/kg-soln"
+ attr(res, "pH scale") <- "total scale"
+ attr(res, "definition") <- "[H+] . [B(OH)4-] / [B(OH)3]"
+ attr(res, "stp") <- stp
+ attr(res, "class") <- c("swK", "swobj")
+ return(res)
+}
+
+# log(Kb()) # = -19.7964
\ No newline at end of file
Added: pkg/seacarb3/R/Kconv.R
===================================================================
--- pkg/seacarb3/R/Kconv.R (rev 0)
+++ pkg/seacarb3/R/Kconv.R 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,55 @@
+# Copyright (C) 2007 Karline Soetaert (K.Soetaert at nioo.knaw.nl)
+# Slightly reworked by Ph. Grosjean, 2008, and renamed 'Kconv' for coherence
+#
+# This file is part of seacarb.
+#
+# Seacarb is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# Seacarb is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# seacarb; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+#
+
+#--------------------------------------------------------------
+# Conversion factors for converting dissociation constants
+# from total pH scale to free pH scale (Ktotal2free)
+# from total pH scale to seawater pH scale (Ktotal2sws)
+# and from free pH scale to seawater scale (Kfree2sws)
+# Kfree = Ktotal * Ktotal2free
+# Ksws = Ktotal * Ktotal2sws
+# Ksws = Kfree * Kfree2sws
+#--------------------------------------------------------------
+
+### TODO: not same result as kconv() initial, but don't see the problem
+# for Kconv(Kf.version = "dg")
+"Kconv" <- function (x = NULL, S = 35, T = 25, P = 0, kf = "pf")
+{
+ stp <- stp(x, S, T, P)
+
+ ST <- 0.14 / 96.062 / 1.80655 * stp$S # total sulfate
+ Ks <- Ks(stp)
+ FT <- 7e-5 * (stp$S / 35) # total fluoride
+ Kf <- Kf(stp, kf = kf)
+
+ total2free <- 1 / (1 + ST / Ks) # Kfree = Ktotal * total2free
+
+ Kf = Kf*total2free # convert Kf from total to free pH scale
+
+ free2sws <- 1 + ST / Ks + FT / Kf # Ksws = Kfree * free2sws
+ total2sws <- total2free * free2sws # Ksws = Ktotal * total2sws
+
+ res <- list(
+ Ktotal2sws = as.numeric(total2sws),
+ Ktotal2free = as.numeric(total2free),
+ Kfree2sws = as.numeric(free2sws))
+ attr(res, "stp") <- stp
+ attr(res, "Kf.version") <- attr(Kf, "version")
+
+ return(res)
+}
Added: pkg/seacarb3/R/Kf.R
===================================================================
--- pkg/seacarb3/R/Kf.R (rev 0)
+++ pkg/seacarb3/R/Kf.R 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,65 @@
+# Copyright (C) 2008 Jean-Pierre Gattuso and Hlose Lavigne and Aurelien Proye
+# Refactored by Ph. Grosjean, 2008
+#
+# This file is part of seacarb.
+#
+# Seacarb is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# Seacarb is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# seacarb; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+#
+
+"Kf" <- function (x = NULL, S = 35, T = 25, P = 0, kf = "pf")
+{
+ #---------------------- Kf Perez and Fraga ---------------------------
+ # Kf = [H+] . [F-] / [HF]
+ #
+ # Perez and Fraga, 1987 in Guide to the Best Practices for Ocean CO2 Measurements
+ # Dickson, Sabin and Christian , 2007, Chapter 5, p. 14)
+ #
+ # --------------------- Kf Dickson and Goyet -------------------------
+ # (Dickson and Riley, 1979 in Dickson and Goyet,
+ # 1994, Chapter 5, p. 14)
+ #
+ # pH scale: 'total', mol/kg-soln
+ #
+
+ # Check and rework arguments
+ stp <- stp(x, S, T, P)
+ if (!identical(kf, "pf") && !identical(kf, "dg"))
+ stop("'kf' must be 'pf' for Perez and Fraga, 1987 or 'dg' for Dickson and Goyet, 1979")
+
+ TK <- .TK(stp$T)
+
+ if (kf == "pf") {
+ lnKf <- 874 / TK - 9.68 + 0.111 * sqrt(stp$S)
+ version <- "Perez and Fraga, 1987"
+ } else {
+ iom0 <- .iom0(stp$S)
+ ST <- 0.14 / 96.062 / 1.80655 * stp$S # total sulfate
+ lnKf <- 1590.2 / TK - 12.641 + 1.525 * sqrt(iom0) +
+ log(1 - 0.001005 * stp$S) + log(1 + ST / Ks(stp))
+ version <- "Dickson and Goyet, 1979"
+ }
+ res <- exp(lnKf) * .KPcorr(stp, "Kf")
+
+ # Construct the 'swK' object together with its metadata
+ attr(res, "K") <- "Kf" # Name of the constant
+ attr(res, "kf") <- kf
+ attr(res, "version") <- version
+ attr(res, "unit") <- "mol/kg-soln"
+ attr(res, "pH scale") <- "total scale"
+ attr(res, "definition") <- "[H+] . [F-] / [HF]"
+ attr(res, "stp") <- stp
+ attr(res, "class") <- c("swK", "swobj")
+ return(res)
+}
+
+# log(Kf(kf = "dg")) # = -5.80
\ No newline at end of file
Added: pkg/seacarb3/R/Kh.R
===================================================================
--- pkg/seacarb3/R/Kh.R (rev 0)
+++ pkg/seacarb3/R/Kh.R 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,48 @@
+# Copyright (C) 2008 Jean-Pierre Gattuso and Hlose Lavigne and Aurelien Proye
+# Refactored by Ph. Grosjean, 2008
+#
+# This file is part of seacarb.
+#
+# Seacarb is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# Seacarb is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# seacarb; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+#
+
+"Kh" <- function (x = NULL, S = 35, T = 25, P = 0)
+{
+ # --------------------- Kh (K Henry) ---------------------------------
+ # Kh = [CO2*] / f(CO2) = [CO2] / p CO2 for CO2(g) <-> CO2(aq.)
+ #
+ # Weiss (1974) [mol/kg/atm]
+ # (Dickson, 1994 DOE chap 5 p 13)
+ # f(CO2) is fugacity in atm. [ ] in mol/kg-soln
+
+ # Check and rework arguments
+ stp <- stp(x, S, T, P)
+ if (any(stp$P > 0)) warning("'Kh' calculated only for P = 0")
+
+ TK <- .TK(stp$T)
+
+ lnK0 <- 9345.17 / TK - 60.2409 + 23.3585 * log(TK / 100) +
+ (0.023517 - 0.00023656 * TK + 0.0047036e-4 * TK^2) * stp$S
+ res <- exp(lnK0) # Correction for P > 0 ???
+
+ # Construct the 'swK' object together with its metadata
+ attr(res, "K") <- "Kh" # Name of the constant
+ attr(res, "unit") <- "mol/kg-soln"
+ attr(res, "pH scale") <- "total scale"
+ attr(res, "definition") <- "[CO2*] / f(CO2)"
+ attr(res, "stp") <- stp
+ attr(res, "class") <- c("swK", "swobj")
+ return(res)
+}
+
+# log(Kh()) # = -3.5617
\ No newline at end of file
Added: pkg/seacarb3/R/Khs.R
===================================================================
--- pkg/seacarb3/R/Khs.R (rev 0)
+++ pkg/seacarb3/R/Khs.R 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,45 @@
+# Copyright (C) 2007 Karline Soetaert (K.Soetaert at nioo.knaw.nl)
+# Refactored by Ph. Grosjean, 2008
+#
+# This file is part of seacarb.
+#
+# Seacarb is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# Seacarb is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# seacarb; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+#
+
+"Khs" <- function (x = NULL, S = 35, T = 25, P = 0)
+{
+ # First dissociation constant of H2S on total scale - Millero 1995
+ #
+ # Khs = [H+] . [HS-] / [H2S]
+ #
+
+ # Check and rework arguments
+ stp <- stp(x, S, T, P)
+
+ TK <- .TK(stp$T)
+
+ lnKhs <- 225.838 + 0.3449 * sqrt(stp$S) - 0.0274 * stp$S -
+ 13275.3 / TK - 34.6435 * log(TK)
+ res <- exp(lnKhs) * .KPcorr(stp, "Khs")
+
+ # Construct the 'swK' object together with its metadata
+ attr(res, "K") <- "Khs" # Name of the constant
+ attr(res, "unit") <- "mol/kg-soln"
+ attr(res, "pH scale") <- "total scale"
+ attr(res, "definition") <- "[H+] . [HS-] / [H2S]"
+ attr(res, "stp") <- stp
+ attr(res, "class") <- c("swK", "swobj")
+ return(res)
+}
+
+# log(Khs()) # = -14.9908
\ No newline at end of file
Added: pkg/seacarb3/R/Kn.R
===================================================================
--- pkg/seacarb3/R/Kn.R (rev 0)
+++ pkg/seacarb3/R/Kn.R 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,47 @@
+# Copyright (C) 2007 Karline Soetaert (K.Soetaert at nioo.knaw.nl)
+# Refactored by Ph. Grosjean, 2008
+#
+# This file is part of seacarb.
+#
+# Seacarb is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# Seacarb is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# seacarb; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+#
+
+"Kn" <- function (x = NULL, S = 35, T = 25, P = 0, ...)
+{
+ # Dissociation constant of ammonium on seawater scale - Millero 1995
+ #
+ # Kn = [H+] . [NH3] / [NH4+]
+ # pH scale: originaly, seawater scale, but converted to total scale
+ #
+
+ # Check and rework arguments
+ stp <- stp(x, S, T, P)
+
+ TK <- .TK(stp$T)
+
+ lnKn <- -6285.33 / TK + 0.0001635 * TK -0.25444 +
+ (0.46532 - 123.7184 / TK) * sqrt(stp$S) +
+ (-0.01992 + 3.17556 / TK) * stp$S
+ res <- exp(lnKn) * .KPcorr(stp, "Kn") / Kconv(stp, ...)$Ktotal2sws
+
+ # Construct the 'swK' object together with its metadata
+ attr(res, "K") <- "Kn" # Name of the constant
+ attr(res, "unit") <- "mol/kg-soln"
+ attr(res, "pH scale") <- "total scale"
+ attr(res, "definition") <- "[H+] . [NH3] / [NH4+]"
+ attr(res, "stp") <- stp
+ attr(res, "class") <- c("swK", "swobj")
+ return(res)
+}
+
+# log(Kn()) # = -21.3361???
\ No newline at end of file
Added: pkg/seacarb3/R/Ks.R
===================================================================
--- pkg/seacarb3/R/Ks.R (rev 0)
+++ pkg/seacarb3/R/Ks.R 2008-12-24 16:02:21 UTC (rev 3)
@@ -0,0 +1,51 @@
+# Copyright (C) 2008 Jean-Pierre Gattuso and Hlose Lavigne and Aurelien Proye
+# Refactored by Ph. Grosjean, 2008
+#
+# This file is part of seacarb.
+#
+# Seacarb is free software; you can redistribute it and/or modify it under the
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/seacarb -r 3
More information about the Seacarb-commits
mailing list