FV3 Bundle
gsw_gibbs_ice.f90
Go to the documentation of this file.
1 ! =========================================================================
2 elemental function gsw_gibbs_ice (nt, np, t, p)
3 ! =========================================================================
4 !
5 ! Ice specific Gibbs energy and derivatives up to order 2.
6 !
7 ! nt = order of t derivative [ integers 0, 1 or 2 ]
8 ! np = order of p derivative [ integers 0, 1 or 2 ]
9 ! t = in-situ temperature (ITS-90) [ deg C ]
10 ! p = sea pressure [ dbar ]
11 !
12 ! gibbs_ice = Specific Gibbs energy of ice or its derivatives.
13 ! The Gibbs energy (when nt = np = 0) has units of: [ J/kg ]
14 ! The temperature derivatives are output in units of:
15 ! [ (J/kg) (K)^(-nt) ]
16 ! The pressure derivatives are output in units of:
17 ! [ (J/kg) (Pa)^(-np) ]
18 ! The mixed derivatives are output in units of:
19 ! [ (J/kg) (K)^(-nt) (Pa)^(-np) ]
20 ! Note. The derivatives are taken with respect to pressure in Pa, not
21 ! withstanding that the pressure input into this routine is in dbar.
22 !--------------------------------------------------------------------------
23 
25 
27 
29 
30 use gsw_mod_kinds
31 
32 implicit none
33 
34 integer, intent(in) :: nt, np
35 real (r8), intent(in) :: t, p
36 
37 real (r8) :: gsw_gibbs_ice
38 
39 real (r8) :: dzi, g0, g0p, g0pp, sqrec_pt
40 complex (r8) :: r2, r2p, r2pp, g, sqtau_t1, sqtau_t2, tau, tau_t1, tau_t2
41 
42 real (r8), parameter :: s0 = -3.32733756492168e3_r8
43 
44 character (*), parameter :: func_name = "gsw_gibbs_ice"
45 
46 tau = cmplx((t + gsw_t0)*rec_t3p,0.0_r8,r8)
47 
48 dzi = db2pa*p*rec_pt
49 
50 if (nt.eq.0 .and. np.eq.0) then
51 
52  tau_t1 = tau/t1
53  sqtau_t1 = tau_t1*tau_t1
54  tau_t2 = tau/t2
55  sqtau_t2 = tau_t2*tau_t2
56 
57  g0 = g00 + dzi*(g01 + dzi*(g02 + dzi*(g03 + g04*dzi)))
58 
59  r2 = r20 + dzi*(r21 + r22*dzi)
60 
61  g = r1*(tau*log((1.0_r8 + tau_t1)/(1.0_r8 - tau_t1)) &
62  + t1*(log(1.0_r8 - sqtau_t1) - sqtau_t1)) &
63  + r2*(tau*log((1.0_r8 + tau_t2)/(1.0_r8 - tau_t2)) &
64  + t2*(log(1.0_r8 - sqtau_t2) - sqtau_t2))
65 
66  gsw_gibbs_ice = real(g0 - t3p*(s0*tau - g),r8)
67 
68 elseif (nt.eq.1 .and. np.eq.0) then
69 
70  tau_t1 = tau/t1
71  tau_t2 = tau/t2
72 
73  r2 = r20 + dzi*(r21 + r22*dzi)
74 
75  g = r1*(log((1.0_r8 + tau_t1)/(1.0_r8 - tau_t1)) - 2.0_r8*tau_t1) &
76  + r2*(log((1.0_r8 + tau_t2)/(1.0_r8 - tau_t2)) - 2.0_r8*tau_t2)
77 
78  gsw_gibbs_ice = -s0 + real(g,r8)
79 
80 elseif (nt.eq.0 .and. np.eq.1) then
81 
82  tau_t2 = tau/t2
83  sqtau_t2 = tau_t2*tau_t2
84 
85  g0p = rec_pt*(g01 + dzi*(2.0_r8*g02 + dzi*(3.0_r8*g03 + 4.0_r8*g04*dzi)))
86 
87  r2p = rec_pt*(r21 + 2.0_r8*r22*dzi)
88 
89  g = r2p*(tau*log((1.0_r8 + tau_t2)/(1.0_r8 - tau_t2)) &
90  + t2*(log(1.0_r8 - sqtau_t2) - sqtau_t2))
91 
92  gsw_gibbs_ice = g0p + t3p*real(g,r8)
93 
94 elseif (nt.eq.1 .and. np.eq.1) then
95 
96  tau_t2 = tau/t2
97 
98  r2p = rec_pt*(r21 + 2.0_r8*r22*dzi)
99 
100  g = r2p*(log((1.0_r8 + tau_t2)/(1.0_r8 - tau_t2)) - 2.0_r8*tau_t2)
101 
102  gsw_gibbs_ice = real(g,r8)
103 
104 elseif (nt.eq.2 .and. np.eq.0) then
105 
106  r2 = r20 + dzi*(r21 + r22*dzi)
107 
108  g = r1*(1.0_r8/(t1 - tau) + 1.0_r8/(t1 + tau) - 2.0_r8/t1) &
109  + r2*(1.0_r8/(t2 - tau) + 1.0_r8/(t2 + tau) - 2.0_r8/t2)
110 
111  gsw_gibbs_ice = rec_t3p*real(g,r8)
112 
113 elseif (nt.eq.0 .and. np.eq.2) then
114 
115  sqrec_pt = rec_pt*rec_pt
116 
117  tau_t2 = tau/t2
118  sqtau_t2 = tau_t2*tau_t2
119 
120  g0pp = sqrec_pt*(2.0_r8*g02 + dzi*(6.0_r8*g03 + 12.0_r8*g04*dzi))
121 
122  r2pp = 2.0_r8*r22*sqrec_pt
123 
124  g = r2pp*(tau*log((1.0_r8 + tau_t2)/(1.0_r8 - tau_t2)) &
125  + t2*(log(1.0_r8 - sqtau_t2) - sqtau_t2))
126 
127  gsw_gibbs_ice = g0pp + t3p*real(g,r8)
128 
129 else
130 
131  gsw_gibbs_ice = gsw_error_code(1,func_name)
132 
133 end if
134 
135 return
136 end function
137 
138 !--------------------------------------------------------------------------
elemental real(r8) function gsw_gibbs_ice(nt, np, t, p)
integer, parameter r8
elemental real(r8) function, public gsw_error_code(err_num, func_name, error_code)