57 #include "version_variable.h" 60 integer :: isc, iec, jsc, jec
61 integer :: isd, ied, jsd, jed
119 t_in, s_in, dic_in, pt_in, sit_in, ta_in, htotallo, &
120 htotalhi, htotal, co2star, alpha, pCO2surf, co3_ion)
128 real,
parameter :: permeg = 1.e-6
129 real,
parameter :: xacc = 1.0e-10
135 real,
dimension(dope_vec%isd:dope_vec%ied,dope_vec%jsd:dope_vec%jed), &
145 real,
dimension(dope_vec%isd:dope_vec%ied,dope_vec%jsd:dope_vec%jed), &
146 intent(inout) :: htotal
147 real,
dimension(dope_vec%isd:dope_vec%ied,dope_vec%jsd:dope_vec%jed), &
148 intent(out),
optional :: alpha, &
155 integer :: isc, iec, jsc, jec
157 real :: alpha_internal
159 real :: co2star_internal
189 isc = dope_vec%isc ; iec = dope_vec%iec
190 jsc = dope_vec%jsc ; jec = dope_vec%jec
210 tk = 273.15 + t_in(i,j)
215 is = 19.924 * s_in(i,j) /(1000.0 -1.005 * s_in(i,j))
218 s2 = s_in(i,j) * s_in(i,j)
219 sqrts = sqrt(s_in(i,j))
220 scl = s_in(i,j) / 1.80655
221 logf_of_s = log(1.0 - 0.001005 * s_in(i,j))
226 k0 = exp(93.4517/tk100 - 60.2409 + 23.3585 * log(tk100) + &
227 s_in(i,j) * (0.023517 - 0.023656 * tk100 + &
236 k1 = 10.0**(-(3670.7 * invtk - 62.008 + 9.7944 * dlogtk - &
237 0.0118 * s_in(i,j) + 0.000116 * s2))
238 k2 = 10.0**(-(1394.7 * invtk + 4.777 - &
239 0.0184 * s_in(i,j) + 0.000118 * s2))
246 kb = exp((-8966.90 - 2890.53 * sqrts - 77.942 * s_in(i,j) + &
247 1.728 * sqrts**3 - 0.0996 * s2) * invtk + (148.0248 + &
248 137.1942 * sqrts + 1.62142 * s_in(i,j)) + (-24.4344 - &
249 25.085 * sqrts - 0.2474 * s_in(i,j)) * dlogtk + &
250 0.053105 * sqrts * tk)
257 k1p = exp(-4576.752 * invtk + 115.525 - 18.453 * dlogtk + &
258 (-106.736 * invtk + 0.69171) * sqrts + (-0.65643 * &
259 invtk - 0.01844) * s_in(i,j))
266 k2p = exp(-8814.715 * invtk + 172.0883 - 27.927 * (-160.340 * &
267 invtk + 1.3566) * sqrts + (0.37335 * invtk - &
268 0.05778) * s_in(i,j))
276 k3p = exp(-3070.75 * invtk - 18.141 +(17.27039 * invtk + &
277 2.81197) * sqrts + (-44.99486 * invtk - 0.09984) * &
285 ksi = exp(-8904.2 * invtk + 117.385 - 19.334 * dlogtk + &
286 (-458.79 * invtk + 3.5913) * sqrtis + (188.74 * &
287 invtk - 1.5998) * is + (-12.1652 * invtk + 0.07871) * &
296 kw = exp(-13847.26 * invtk + 148.9652 - 23.6521 * dlogtk + &
297 (118.67 * invtk - 5.977 + 1.0495 * dlogtk) * sqrts - &
305 ks = exp(-4276.1 * invtk + 141.328 - 23.093 * dlogtk + &
306 (-13856.0 * invtk + 324.57 - 47.986 * dlogtk) * &
307 sqrtis + (35474.0 * invtk - 771.54 + 114.723 * &
308 dlogtk) * is - 2698.0 * invtk * sqrtis**3 + &
309 1776.0 * invtk * is2 + logf_of_s)
316 kf = exp(1590.2 * invtk - 12.641 + 1.525 * sqrtis + logf_of_s + &
317 log(1.0 + (0.1400 / 96.062) * scl / ks))
324 bt = 0.000232 / 10.811 * scl
328 st = 0.14 / 96.062 * scl
332 ft = 0.000067 / 18.9984 * scl
357 if (mask(i,j) .ne. 0.0)
then 358 htotal(i,j) =
drtsafe(k0, k1, k2, kb, k1p, k2p, k3p, ksi, kw, &
359 ks, kf, bt, dic_in(i,j), ft, pt_in(i,j),&
360 sit_in(i,j), st, ta_in(i,j), &
361 htotalhi(i,j), htotallo(i,j), xacc)
367 htotal2 = htotal(i,j) * htotal(i,j)
368 co2star_internal = dic_in(i,j) * htotal2 / (htotal2 + &
369 k1 * htotal(i,j) + k1 * k2)
370 if (
present(co2star)) co2star(i,j) = co2star_internal
371 if (
present(co3_ion)) co3_ion(i,j) = co2star_internal * k1 * k2 / htotal2
376 if (
present(alpha) .or.
present(pco2surf))
then 377 alpha_internal = exp(-162.8301 + 218.2968 / tk100 + 90.9241 * &
378 (dlogtk -log100) - 1.47696 * tk1002 + &
379 s_in(i,j) * (0.025695 - 0.025225 * tk100 + &
382 if (
present(alpha)) alpha(i,j) = alpha_internal
383 if (
present(pco2surf))
then 384 pco2surf(i,j) = co2star_internal / (alpha_internal * permeg)
402 function drtsafe(k0, k1, k2, kb, k1p, k2p, k3p, ksi, kw, ks, kf, &
403 bt, dic, ft, pt, sit, st, ta, x1, x2, xacc)
411 real :: k0, k1, k2, kb, k1p, k2p, k3p, ksi, kw, ks, kf
412 real :: bt, dic, ft, pt, sit, st, ta
420 integer,
parameter :: maxit = 100
427 real :: fl, df, fh, swap, xl, xh, dxold, dx, f, temp
429 call ta_iter_1(k0, k1, k2, kb, k1p, k2p, k3p, ksi, kw, ks, kf, &
430 bt, dic, ft, pt, sit, st, ta, x1, fl, df)
431 call ta_iter_1(k0, k1, k2, kb, k1p, k2p, k3p, ksi, kw, ks, kf, &
432 bt, dic, ft, pt, sit, st, ta, x2, fh, df)
446 call ta_iter_1(k0, k1, k2, kb, k1p, k2p, k3p, ksi, kw, ks, kf, &
447 bt, dic, ft, pt, sit, st, ta, drtsafe, f, df)
449 if (((drtsafe-xh)*df-f)*((drtsafe-xl)*df-f) .ge. 0.0 .or. &
450 abs(2.0*f) .gt. abs(dxold*df))
then 454 if (xl .eq. drtsafe)
then 463 if (temp .eq. drtsafe)
then 468 if (abs(dx) .lt. xacc)
then 472 call ta_iter_1(k0, k1, k2, kb, k1p, k2p, k3p, ksi, kw, ks, kf, &
473 bt, dic, ft, pt, sit, st, ta, drtsafe, f, df)
500 subroutine ta_iter_1(k0, k1, k2, kb, k1p, k2p, k3p, ksi, kw, ks, kf, &
501 bt, dic, ft, pt, sit, st, ta, x, fn, df)
509 real :: k0, k1, k2, kb, k1p, k2p, k3p, ksi, kw, ks, kf
510 real :: bt, dic, ft, pt, sit, st, ta, x, fn, df
516 real :: x2, x3, k12, k12p, k123p, c, a, a2, da, b, b2, db
524 a = x3 + k1p*x2 + k12p*x + k123p
526 da = 3.0*x2 + 2.0*k1p*x + k12p
533 fn = k1*x*dic/b + 2.0*dic*k12/b + bt/ (1.0 + x/kb) + kw/x + &
534 pt*k12p*x/a + 2.0*pt*k123p/a + sit/(1.0 + x/ksi) - &
535 x/c - st/(1.0 + ks/x/c) - ft/(1.0 + kf/x) - pt*x3/a - ta
539 df = ((k1*dic*b) - k1*x*dic*db)/b2 - 2.0*dic*k12*db/b2 - &
540 bt/kb/(1.0+x/kb)**2 - kw/x2 + (pt*k12p*(a - x*da))/a2 - &
541 2.0*pt*k123p*da/a2 - sit/ksi/ (1.0+x/ksi)**2 - 1.0/c + &
542 st*(1.0 + ks/x/c)**(-2)*(ks/c/x2) + &
543 ft*(1.0 + kf/x)**(-2)*kf/x2 - pt*x2*(3.0*a-x*da)/a2
subroutine ta_iter_1(k0, k1, k2, kb, k1p, k2p, k3p, ksi, kw, ks, kf, bt, dic, ft, pt, sit, st, ta, x, fn, df)
subroutine, public mom_ocmip2_co2calc(dope_vec, mask, t_in, s_in, dic_in, pt_in, sit_in, ta_in, htotallo, htotalhi, htotal, co2star, alpha, pCO2surf, co3_ion)
real function drtsafe(k0, k1, k2, kb, k1p, k2p, k3p, ksi, kw, ks, kf, bt, dic, ft, pt, sit, st, ta, x1, x2, xacc)