FV3 Bundle
gsw_specvol_second_derivatives.f90
Go to the documentation of this file.
1 !==========================================================================
2 elemental subroutine gsw_specvol_second_derivatives (sa, ct, p, v_sa_sa, &
3  v_sa_ct, v_ct_ct, v_sa_p, v_ct_p, iflag)
4 ! =========================================================================
5 !
6 ! Calculates five second-order derivatives of specific volume (v).
7 ! Note that this function uses the computationally-efficient
8 ! expression for specific volume (Roquet et al., 2014).
9 !
10 ! SA = Absolute Salinity [ g/kg ]
11 ! CT = Conservative Temperature (ITS-90) [ deg C ]
12 ! p = sea pressure [ dbar ]
13 ! ( i.e. absolute pressure - 10.1325 dbar )
14 !
15 ! v_SA_SA = The second derivative of specific volume with respect to
16 ! Absolute Salinity at constant CT & p. [ J/(kg (g/kg)^2) ]
17 ! v_SA_CT = The second derivative of specific volume with respect to
18 ! SA and CT at constant p. [ J/(kg K(g/kg)) ]
19 ! v_CT_CT = The second derivative of specific volume with respect to
20 ! CT at constant SA and p. [ J/(kg K^2) ]
21 ! v_SA_P = The second derivative of specific volume with respect to
22 ! SA and P at constant CT. [ J/(kg K(g/kg)) ]
23 ! v_CT_P = The second derivative of specific volume with respect to
24 ! CT and P at constant SA. [ J/(kg K(g/kg)) ]
25 !--------------------------------------------------------------------------
26 
28 
30 
31 use gsw_mod_kinds
32 
33 implicit none
34 
35 real (r8), intent(in) :: sa, ct, p
36 integer, intent(in), optional :: iflag
37 real (r8), intent(out), optional :: v_sa_sa, v_sa_ct, v_ct_ct, v_sa_p, v_ct_p
38 
39 integer :: i
40 logical :: flags(5)
41 real (r8) :: v_ct_ct_part, v_ct_p_part, v_sa_ct_part, v_sa_p_part
42 real (r8) :: v_sa_sa_part, xs, xs2, ys, z
43 
44 xs2 = gsw_sfac*sa + offset
45 xs = sqrt(xs2)
46 ys = ct*0.025_r8
47 z = p*1e-4_r8
48 
49 if (present(iflag)) then
50  do i = 1, 5
51  flags(i) = btest(iflag,i)
52  end do
53 else
54  flags = .true.
55 end if
56 
57 if (present(v_sa_sa) .and. flags(1)) then
58 
59  v_sa_sa_part = (-b000 + xs2*(b200 + xs*(2.0_r8*b300 + xs*(3.0_r8*b400 &
60  + 4.0_r8*b500*xs))) + ys*(-b010 + xs2*(b210 + xs*(2.0_r8*b310 &
61  + 3.0_r8*b410*xs)) + ys*(-b020 + xs2*(b220 + 2.0_r8*b320*xs) &
62  + ys*(-b030 + b230*xs2 + ys*(-b040 - b050*ys)))) + z*(-b001 &
63  + xs2*(b201 + xs*(2.0_r8*b301 + 3.0_r8*b401*xs)) + ys*(-b011 &
64  + xs2*(b211 + 2.0_r8*b311*xs) + ys*(-b021 + b221*xs2 &
65  + ys*(-b031 - b041*ys))) + z*(-b002 + xs2*(b202 + 2.0_r8*b302*xs) &
66  + ys*(-b012 + b212*xs2 + ys*(-b022 - b032*ys)) + z*(-b003 &
67  - b013*ys - b004*z))))/xs2
68 
69  v_sa_sa = 0.25_r8*gsw_sfac*gsw_sfac*v_sa_sa_part/xs
70 
71 end if
72 
73 if (present(v_sa_ct) .and. flags(2)) then
74 
75  v_sa_ct_part = (b010 + xs*(b110 + xs*(b210 + xs*(b310 + b410*xs))) &
76  + ys*(2.0_r8*(b020 + xs*(b120 + xs*(b220 + b320*xs))) &
77  + ys*(3.0_r8*(b030 + xs*(b130 + b230*xs)) + ys*(4.0_r8*(b040 + b140*xs) &
78  + 5.0_r8*b050*ys))) + z*(b011 + xs*(b111 + xs*(b211 + b311*xs)) &
79  + ys*(2.0_r8*(b021 + xs*(b121 + b221*xs)) + ys*(3.0_r8*(b031 + b131*xs) &
80  + 4.0_r8*b041*ys)) + z*(b012 + xs*(b112 + b212*xs) + ys*(2.0_r8*(b022 &
81  + b122*xs) + 3.0_r8*b032*ys) + b013*z)))/xs
82 
83  v_sa_ct = 0.025_r8*0.5_r8*gsw_sfac*v_sa_ct_part
84 
85 end if
86 
87 if (present(v_ct_ct) .and. flags(3)) then
88 
89  v_ct_ct_part = a010 + xs*(a110 + xs*(a210 + xs*(a310 + a410*xs))) &
90  + ys*(2.0_r8*(a020 + xs*(a120 + xs*(a220 + a320*xs))) &
91  + ys*(3.0_r8*(a030 + xs*(a130 + a230*xs)) + ys*(4.0_r8*(a040 &
92  + a140*xs) + 5.0_r8*a050*ys))) + z*( a011 + xs*(a111 + xs*(a211 &
93  + a311*xs)) + ys*(2.0_r8*(a021 + xs*(a121 + a221*xs)) &
94  + ys*(3.0_r8*(a031 + a131*xs) + 4.0_r8*a041*ys)) + z*(a012 &
95  + xs*(a112 + a212*xs) + ys*(2.0_r8*(a022 + a122*xs) &
96  + 3.0_r8*a032*ys) + a013*z))
97 
98  v_ct_ct = 0.025_r8*0.025_r8*v_ct_ct_part
99 
100 end if
101 
102 if (present(v_sa_p) .and. flags(4)) then
103 
104  v_sa_p_part = b001 + xs*(b101 + xs*(b201 + xs*(b301 + b401*xs))) + ys*(b011 &
105  + xs*(b111 + xs*(b211 + b311*xs)) + ys*(b021 + xs*(b121 + b221*xs) &
106  + ys*(b031 + b131*xs + b041*ys))) + z*(2.0_r8*(b002 + xs*(b102 &
107  + xs*(b202 + b302*xs)) + ys*(b012 + xs*(b112 + b212*xs) + ys*(b022 &
108  + b122*xs + b032*ys))) + z*(3.0_r8*(b003 + b103*xs + b013*ys) &
109  + 4.0_r8*b004*z))
110 
111  v_sa_p = 1e-8_r8*0.5_r8*gsw_sfac*v_sa_p_part
112 
113 end if
114 
115 if (present(v_ct_p) .and. flags(5)) then
116 
117  v_ct_p_part = a001 + xs*(a101 + xs*(a201 + xs*(a301 + a401*xs))) + ys*(a011 &
118  + xs*(a111 + xs*(a211 + a311*xs)) + ys*(a021 + xs*(a121 + a221*xs) &
119  + ys*(a031 + a131*xs + a041*ys))) + z*(2.0_r8*(a002 + xs*(a102 &
120  + xs*(a202 + a302*xs)) + ys*(a012 + xs*(a112 + a212*xs) + ys*(a022 &
121  + a122*xs + a032*ys))) + z*(3.0_r8*(a003 + a103*xs + a013*ys) &
122  + 4.0_r8*a004*z))
123 
124  v_ct_p = 1e-8_r8*0.025_r8*v_ct_p_part
125 
126 end if
127 
128 return
129 end subroutine
130 
131 !--------------------------------------------------------------------------
elemental subroutine gsw_specvol_second_derivatives(sa, ct, p, v_sa_sa, v_sa_ct, v_ct_ct, v_sa_p, v_ct_p, iflag)