FV3 Bundle
gsw_nsquared.f90
Go to the documentation of this file.
1 !==========================================================================
2 pure subroutine gsw_nsquared (sa, ct, p, lat, n2, p_mid)
3 !==========================================================================
4 !
5 ! Calculates the buoyancy frequency squared (N^2)(i.e. the Brunt-Vaisala
6 ! frequency squared) at the mid pressure from the equation,
7 !
8 !
9 ! 2 2 beta.d(SA) - alpha.d(CT)
10 ! N = g .rho_local. -------------------------
11 ! dP
12 !
13 ! The pressure increment, dP, in the above formula is in Pa, so that it is
14 ! 10^4 times the pressure increment dp in dbar.
15 !
16 ! sa : Absolute Salinity (a profile (length nz)) [g/kg]
17 ! ct : Conservative Temperature (a profile (length nz)) [deg C]
18 ! p : sea pressure (a profile (length nz)) [dbar]
19 ! lat : latitude (a profile (length nz)) [deg N]
20 ! n2 : Brunt-Vaisala Frequency squared (length nz-1) [s^-2]
21 ! p_mid : Mid pressure between p grid (length nz-1) [dbar]
22 !--------------------------------------------------------------------------
23 
25 
27 
29 
30 use gsw_mod_kinds
31 
32 implicit none
33 
34 real (r8), intent(in) :: sa(:), ct(:), p(:), lat(:)
35 real (r8), intent(out) :: n2(:), p_mid(:)
36 
37 integer :: nz, k
38 real (r8), dimension(:), allocatable :: dsa, sa_mid, dct, ct_mid, dp, rho_mid
39 real (r8), dimension(:), allocatable :: alpha_mid, beta_mid, grav_local, grav
40 
41 character (*), parameter :: func_name = "gsw_nsquared"
42 
43 nz = size(sa)
44 if (size(n2).lt.nz-1 .or. size(p_mid).lt.nz-1) then
45  n2 = gsw_error_code(1,func_name)
46  p_mid = n2(1)
47  return
48 end if
49 
50 allocate (grav(nz), dsa(nz-1), sa_mid(nz-1), dct(nz-1), ct_mid(nz-1), dp(nz-1))
51 allocate (rho_mid(nz-1), alpha_mid(nz-1), beta_mid(nz-1), grav_local(nz-1))
52 
53 grav = gsw_grav(lat(1:nz),p(1:nz))
54 
55 forall (k = 1: nz-1)
56  grav_local(k) = 0.5_r8*(grav(k) + grav(k+1))
57  dsa(k) = (sa(k+1) - sa(k))
58  sa_mid(k) = 0.5_r8*(sa(k) + sa(k+1))
59  dct(k) = (ct(k+1) - ct(k))
60  ct_mid(k) = 0.5_r8*(ct(k) + ct(k+1))
61  dp(k) = (p(k+1) - p(k))
62  p_mid(k) = 0.5_r8*(p(k) + p(k+1))
63 end forall
64 
65 call gsw_rho_alpha_beta(sa_mid,ct_mid,p_mid(1:nz-1),rho_mid,alpha_mid,beta_mid)
66 
67 n2(1:nz-1) = (grav_local**2) * (rho_mid/(db2pa*dp)) * &
68  (beta_mid*dsa - alpha_mid*dct)
69 
70 deallocate (grav, dsa, sa_mid, dct, ct_mid, dp)
71 deallocate (rho_mid, alpha_mid, beta_mid, grav_local)
72 
73 return
74 end subroutine
75 
76 !--------------------------------------------------------------------------
pure subroutine gsw_nsquared(sa, ct, p, lat, n2, p_mid)
Definition: gsw_nsquared.f90:3
real, parameter, public grav
Acceleration due to gravity [m/s^2].
Definition: constants.F90:76
elemental real(r8) function, public gsw_error_code(err_num, func_name, error_code)