FV3 Bundle
gsw_ct_maxdensity.f90
Go to the documentation of this file.
1 !==========================================================================
2 elemental function gsw_ct_maxdensity (sa, p)
3 !==========================================================================
4 !
5 ! Calculates the Conservative Temperature of maximum density of seawater.
6 ! This function returns the Conservative temperature at which the density
7 ! of seawater is a maximum, at given Absolute Salinity, SA, and sea
8 ! pressure, p (in dbar).
9 !
10 ! SA = Absolute Salinity [ g/kg ]
11 ! p = sea pressure [ dbar ]
12 ! ( i.e. absolute pressure - 10.1325 dbar )
13 !
14 ! CT_maxdensity = Conservative Temperature at which [ deg C ]
15 ! the density of seawater is a maximum for
16 ! given Absolute Salinity and pressure.
17 !--------------------------------------------------------------------------
18 
19 use gsw_mod_toolbox, only : gsw_alpha
20 
21 use gsw_mod_kinds
22 
23 implicit none
24 
25 real (r8), intent(in) :: sa, p
26 
27 real (r8) :: gsw_ct_maxdensity
28 
29 integer :: number_of_iterations
30 real (r8) :: alpha, ct, ct_mean, ct_old, dalpha_dct
31 
32 real (r8), parameter :: dct = 0.001_r8
33 
34 ct = 3.978_r8 - 0.22072_r8*sa ! the initial guess of ct.
35 
36 dalpha_dct = 1.1e-5_r8 ! the initial guess for dalpha_dct.
37 
38 do number_of_iterations = 1, 3
39  ct_old = ct
40  alpha = gsw_alpha(sa,ct_old,p)
41  ct = ct_old - alpha/dalpha_dct
42  ct_mean = 0.5_r8*(ct + ct_old)
43  dalpha_dct = (gsw_alpha(sa,ct_mean+dct,p) &
44  - gsw_alpha(sa,ct_mean-dct,p))/(dct + dct)
45  ct = ct_old - alpha/dalpha_dct
46 end do
47 
48 ! After three iterations of this modified Newton-Raphson (McDougall and
49 ! Wotherspoon, 2012) iteration, the error in CT_maxdensity is typically no
50 ! larger than 1x10^-15 degress C.
51 
53 
54 return
55 end function
56 
57 !--------------------------------------------------------------------------
elemental real(r8) function gsw_ct_maxdensity(sa, p)