FV3 Bundle
gsw_mlp.f90
Go to the documentation of this file.
1 !==========================================================================
2 pure function gsw_mlp (sa, ct, p)
3 !==========================================================================
4 !
5 ! Calculates the mixed-layer pressure as described in de Boyer Montégut
6 ! et al. (2004). The mlp is always deeper than 20 dbar, if the initial
7 ! estimate of the mlp is less than 20 dbar, the temperature and salinity
8 ! of the bottles in the top 5 dbar are set to that of the bottle closest
9 ! to 5 dbar. This removes the effect if a thin layer of fresh water,
10 ! such as that from a river outflow or from rain.
11 !
12 ! SA = Absolute Salinity [ g/kg ]
13 ! CT = Conservative Temperature (ITS-90) [ deg C ]
14 ! p = sea pressure [ dbar ]
15 ! ( i.e. absolute pressure - 10.1325 dbar )
16 !
17 ! mlp = mixed-layer pressure [ dbar ]
18 !
19 !==========================================================================
20 
21 use gsw_mod_toolbox, only : gsw_rho
22 
24 
25 use gsw_mod_kinds
26 
27 implicit none
28 
29 real (r8), intent(in) :: sa(:), ct(:), p(:)
30 
31 real (r8) :: gsw_mlp
32 
33 integer :: k(1), np
34 
35 real (r8) :: min_p
36 
37 real (r8), allocatable :: diff_rho0(:), dp(:), rho0(:)
38 
39 character (*), parameter :: func_name = "gsw_mlp"
40 
41 np = size(p)
42 allocate(dp(np-1))
43 dp = p(2:np) - p(1:np-1)
44 if (any(dp .le. 0.0_r8)) then ! pressure must be monotonic and unique
45  gsw_mlp = gsw_error_code(1,func_name)
46  return
47 end if
48 
49 min_p = minval(p)
50 if (min_p .gt. 20.0_r8) then ! the profile starts at p greater than 20 dbar
51  gsw_mlp = gsw_error_code(2,func_name)
52  return
53 end if
54 
55 allocate(rho0(np),diff_rho0(np))
56 
57 rho0 = gsw_rho(sa,ct,0.0_r8)
58 
59 diff_rho0 = (minval(rho0) + 0.3_r8) - rho0
60 k = minloc(diff_rho0, diff_rho0 .gt. 0.0_r8)
61 gsw_mlp = p(k(1))
62 
63 if ((gsw_mlp-min_p) .lt. 20.0_r8) then
64 
65  ! If the mlp is less than 20 dbar it is possible that this density
66  ! difference is being effected by a thin fresh water layer at the surface,
67  ! set the salinities and temperatures of the bottles in the top section of
68  ! the cast to be equal to that of the bottle closest to 5 dbar.
69 
70  k = minloc(abs(p - 5.0_r8))
71  rho0(1:k(1)-1) = rho0(k(1))
72 
73  diff_rho0 = (minval(rho0) + 0.3_r8) - rho0
74  k = minloc(diff_rho0, diff_rho0 .gt. 0.0_r8)
75  gsw_mlp = p(k(1))
76 
77  if ((gsw_mlp-min_p) .lt. 20.0_r8) then
78  gsw_mlp = gsw_error_code(3,func_name)
79  return
80  end if
81 
82 end if
83 
84 return
85 end function
86 
87 !--------------------------------------------------------------------------
pure real(r8) function gsw_mlp(sa, ct, p)
Definition: gsw_mlp.f90:3
elemental real(r8) function, public gsw_error_code(err_num, func_name, error_code)