FV3 Bundle
gsw_sa_from_rho.f90
Go to the documentation of this file.
1 !==========================================================================
2 elemental function gsw_sa_from_rho (rho, ct, p)
3 !==========================================================================
4 !
5 ! Calculates the Absolute Salinity of a seawater sample, for given values
6 ! of its density, Conservative Temperature and sea pressure (in dbar).
7 
8 ! rho = density of a seawater sample (e.g. 1026 kg/m^3). [ kg/m^3 ]
9 ! Note. This input has not had 1000 kg/m^3 subtracted from it.
10 ! That is, it is 'density', not 'density anomaly'.
11 ! ct = Conservative Temperature (ITS-90) [ deg C ]
12 ! p = sea pressure [ dbar ]
13 !
14 ! sa = Absolute Salinity [g/kg]
15 !--------------------------------------------------------------------------
16 
18 
20 
21 use gsw_mod_kinds
22 
23 implicit none
24 
25 real (r8), intent(in) :: rho, ct, p
26 
27 real (r8) :: gsw_sa_from_rho
28 
29 integer no_iter
30 
31 real (r8) :: sa, v_lab, v_0, v_50, v_sa, sa_old, delta_v, sa_mean
32 
33 character (*), parameter :: func_name = "gsw_sa_from_rho"
34 
35 v_lab = 1.0_r8/rho
36 v_0 = gsw_specvol(0.0_r8,ct,p)
37 v_50 = gsw_specvol(50.0_r8,ct,p)
38 
39 sa = 50.0_r8*(v_lab - v_0)/(v_50 - v_0)
40 
41 if (sa.lt.0_r8.or.sa.gt.50_r8) then
42  gsw_sa_from_rho = gsw_error_code(1,func_name)
43  return
44 end if
45 
46 v_sa = (v_50 - v_0)/50.0_r8
47 
48 do no_iter = 1, 2
49  sa_old = sa
50  delta_v = gsw_specvol(sa_old,ct,p) - v_lab
51  sa = sa_old - delta_v/v_sa
52  sa_mean = 0.5_r8*(sa + sa_old)
53  call gsw_specvol_first_derivatives(sa_mean,ct,p,v_sa)
54  sa = sa_old - delta_v/v_sa
55  if (sa.lt.0_r8.or.sa.gt.50_r8) then
56  gsw_sa_from_rho = gsw_error_code(no_iter+1,func_name)
57  return
58  end if
59 end do
60 
61 gsw_sa_from_rho = sa
62 
63 return
64 end function
65 
66 !--------------------------------------------------------------------------
elemental real(r8) function gsw_sa_from_rho(rho, ct, p)
real(r8), parameter, public gsw_error_limit
elemental real(r8) function, public gsw_error_code(err_num, func_name, error_code)