FV3 Bundle
gsw_pt_from_entropy.f90
Go to the documentation of this file.
1 ! =========================================================================
2 elemental function gsw_pt_from_entropy (sa, entropy)
3 ! =========================================================================
4 !
5 ! Calculates potential temperature with reference pressure p_ref = 0 dbar
6 ! and with entropy as an input variable.
7 !
8 ! SA = Absolute Salinity [ g/kg ]
9 ! entropy = specific entropy [ deg C ]
10 !
11 ! pt = potential temperature [ deg C ]
12 ! with reference sea pressure (p_ref) = 0 dbar.
13 ! Note. The reference sea pressure of the output, pt, is zero dbar.
14 !--------------------------------------------------------------------------
15 
17 
19 
20 use gsw_mod_kinds
21 
22 implicit none
23 
24 real (r8), intent(in) :: sa, entropy
25 
26 real (r8) :: gsw_pt_from_entropy
27 
28 integer :: number_of_iterations
29 real (r8) :: c, dentropy, dentropy_dt, ent_sa, part1, part2, pt, ptm
30 real (r8) :: pt_old
31 
32 ! Find the initial value of pt
33 part1 = 1.0_r8 - sa/gsw_sso
34 part2 = 1.0_r8 - 0.05_r8*part1
35 ent_sa = (gsw_cp0/gsw_t0)*part1*(1.0_r8 - 1.01_r8*part1)
36 c = (entropy - ent_sa)*(part2/gsw_cp0)
37 pt = gsw_t0*(exp(c) - 1.0_r8)
38 dentropy_dt = gsw_cp0/((gsw_t0 + pt)*part2)
39 
40 do number_of_iterations = 1, 2
41  pt_old = pt
42  dentropy = gsw_entropy_from_pt(sa,pt_old) - entropy
43  pt = pt_old - dentropy/dentropy_dt
44  ptm = 0.5_r8*(pt + pt_old)
45  dentropy_dt = -gsw_gibbs_pt0_pt0(sa,ptm)
46  pt = pt_old - dentropy/dentropy_dt
47 end do
48 
49 ! Maximum error of 2.2x10^-6 degrees C for one iteration.
50 ! Maximum error is 1.4x10^-14 degrees C for two iterations
51 ! (two iterations is the default, "for Number_of_iterations = 1:2").
52 
54 
55 return
56 end function
57 
58 !--------------------------------------------------------------------------
elemental real(r8) function gsw_pt_from_entropy(sa, entropy)