FV3 Bundle
gsw_rho_second_derivatives.f90
Go to the documentation of this file.
1 !==========================================================================
2 elemental subroutine gsw_rho_second_derivatives (sa, ct, p, rho_sa_sa, &
3  rho_sa_ct, rho_ct_ct, rho_sa_p, rho_ct_p)
4 !==========================================================================
5 !
6 ! Calculates five second-order derivatives of rho. Note that this function
7 ! uses the using the computationally-efficient expression for specific
8 ! 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 ! rho_SA_SA = The second-order derivative of rho with respect to
16 ! Absolute Salinity at constant CT & p. [ J/(kg (g/kg)^2) ]
17 ! rho_SA_CT = The second-order derivative of rho with respect to
18 ! SA and CT at constant p. [ J/(kg K(g/kg)) ]
19 ! rho_CT_CT = The second-order derivative of rho with respect to CT at
20 ! constant SA & p
21 ! rho_SA_P = The second-order derivative with respect to SA & P at
22 ! constant CT.
23 ! rho_CT_P = The second-order derivative with respect to CT & P at
24 ! constant SA.
25 !--------------------------------------------------------------------------
26 
29 
30 use gsw_mod_kinds
31 
32 implicit none
33 
34 real (r8), intent(in) :: sa, ct, p
35 real (r8), intent(out), optional :: rho_sa_sa, rho_sa_ct, rho_ct_ct
36 real (r8), intent(out), optional :: rho_sa_p, rho_ct_p
37 
38 integer :: iflag1, iflag2
39 real (r8) :: rec_v, rec_v2, rec_v3, v_ct, v_ct_ct, v_ct_p, v_p, v_sa, v_sa_ct
40 real (r8) :: v_sa_p, v_sa_sa
41 
42 iflag1 = 0
43 if (present(rho_sa_sa) .or. present(rho_sa_ct) &
44  .or. present(rho_sa_p)) iflag1 = ibset(iflag1,1)
45 if (present(rho_sa_ct) .or. present(rho_ct_ct) &
46  .or. present(rho_ct_p)) iflag1 = ibset(iflag1,2)
47 if (present(rho_sa_p) .or. present(rho_ct_p)) iflag1 = ibset(iflag1,3)
48 
49 call gsw_specvol_first_derivatives(sa,ct,p,v_sa,v_ct,v_p,iflag=iflag1)
50 
51 iflag2 = 0
52 if (present(rho_sa_sa)) iflag2 = ibset(iflag2,1)
53 if (present(rho_sa_ct)) iflag2 = ibset(iflag2,2)
54 if (present(rho_ct_ct)) iflag2 = ibset(iflag2,3)
55 if (present(rho_sa_p)) iflag2 = ibset(iflag2,4)
56 if (present(rho_ct_p)) iflag2 = ibset(iflag2,5)
57 
58 call gsw_specvol_second_derivatives(sa,ct,p,v_sa_sa,v_sa_ct,v_ct_ct, &
59  v_sa_p,v_ct_p,iflag=iflag2)
60 
61 rec_v = 1.0_r8/gsw_specvol(sa,ct,p)
62 rec_v2 = rec_v**2
63 rec_v3 = rec_v2*rec_v
64 
65 if (present(rho_sa_sa)) rho_sa_sa = -v_sa_sa*rec_v2 + 2.0_r8*v_sa*v_sa*rec_v3
66 
67 if (present(rho_sa_ct)) rho_sa_ct = -v_sa_ct*rec_v2 + 2.0_r8*v_sa*v_ct*rec_v3
68 
69 if (present(rho_ct_ct)) rho_ct_ct = -v_ct_ct*rec_v2 + 2.0_r8*v_ct*v_ct*rec_v3
70 
71 if (present(rho_sa_p)) rho_sa_p = -v_sa_p*rec_v2 + 2.0_r8*v_sa*v_p*rec_v3
72 
73 if (present(rho_ct_p)) rho_ct_p = -v_ct_p*rec_v2 + 2.0_r8*v_ct*v_p*rec_v3
74 
75 return
76 end subroutine
77 
78 !--------------------------------------------------------------------------
elemental subroutine gsw_rho_second_derivatives(sa, ct, p, rho_sa_sa, rho_sa_ct, rho_ct_ct, rho_sa_p, rho_ct_p)