FV3 Bundle
gsw_ct_from_enthalpy_exact.f90
Go to the documentation of this file.
1 !==========================================================================
2 elemental function gsw_ct_from_enthalpy_exact (sa, h, p)
3 !==========================================================================
4 !
5 ! Calculates the Conservative Temperature of seawater, given the Absolute
6 ! Salinity, specific enthalpy, h, and pressure p.
7 !
8 ! SA = Absolute Salinity [ g/kg ]
9 ! h = specific enthalpy [ J/kg ]
10 ! p = sea pressure [ dbar ]
11 ! ( i.e. absolute pressure - 10.1325d0 dbar )
12 !
13 ! CT = Conservative Temperature ( ITS-90) [ deg C ]
14 !--------------------------------------------------------------------------
15 
18 
20 
22 
23 use gsw_mod_kinds
24 
25 implicit none
26 
27 real (r8), intent(in) :: sa, h, p
28 
29 real (r8) :: gsw_ct_from_enthalpy_exact
30 
31 real (r8) :: ct, ct_freezing, ct_mean, ct_old, f, h_freezing
32 real (r8) :: h_ct, h_40
33 
34 real (r8), parameter :: ct_40 = 40.0_r8
35 
36 character (*), parameter :: func_name = "gsw_ct_from_enthalpy_exact"
37 
38 ct_freezing = gsw_ct_freezing_exact(sa,p,0.0_r8)
39 
40 h_freezing = gsw_enthalpy_ct_exact(sa,ct_freezing,p)
41 if (h .lt. h_freezing - gsw_cp0) then
42  ! The input, seawater enthalpy h, is less than the enthalpy at the
43  ! freezing temperature, i.e. the water is frozen.
45  return
46 endif
47 
48 h_40 = gsw_enthalpy_ct_exact(sa,ct_40,p)
49 if (h .gt. h_40) then
50  ! The input seawater enthalpy is greater than the enthalpy when CT is 40C
52  return
53 endif
54 
55 ! First guess of ct
56 ct = ct_freezing + (ct_40 - ct_freezing)*(h - h_freezing)/(h_40 - h_freezing)
57 call gsw_enthalpy_first_derivatives_ct_exact(sa,ct,p,h_ct=h_ct)
58 
59 !--------------------------------------------------------------------------
60 ! Begin the modified Newton-Raphson iterative procedure
61 !--------------------------------------------------------------------------
62 
63 ct_old = ct
64 f = gsw_enthalpy_ct_exact(sa,ct_old,p) - h
65 ct = ct_old - f/h_ct
66 ct_mean = 0.5_r8*(ct + ct_old)
67 call gsw_enthalpy_first_derivatives_ct_exact(sa,ct_mean,p,h_ct=h_ct)
68 ct = ct_old - f/h_ct
69 
70 ! After 1 iteration of this modified Newton-Raphson iteration,
71 ! the error in CT is no larger than 5x10^-14 degrees C, which
72 ! is machine precision for this calculation.
73 
75 
76 return
77 end function
78 
79 !--------------------------------------------------------------------------
elemental real(r8) function, public gsw_error_code(err_num, func_name, error_code)
elemental real(r8) function gsw_ct_from_enthalpy_exact(sa, h, p)