FV3 Bundle
gsw_sp_from_c.f90
Go to the documentation of this file.
1 !==========================================================================
2 elemental function gsw_sp_from_c (c, t, p)
3 !==========================================================================
4 !
5 ! Calculates Practical Salinity, SP, from conductivity, C, primarily using
6 ! the PSS-78 algorithm. Note that the PSS-78 algorithm for Practical
7 ! Salinity is only valid in the range 2 < SP < 42. If the PSS-78
8 ! algorithm produces a Practical Salinity that is less than 2 then the
9 ! Practical Salinity is recalculated with a modified form of the Hill et
10 ! al. (1986) formula. The modification of the Hill et al. (1986)
11 ! expression is to ensure that it is exactly consistent with PSS-78
12 ! at SP = 2. Note that the input values of conductivity need to be in
13 ! units of mS/cm (not S/m).
14 !
15 ! c : conductivity [ mS/cm ]
16 ! t : in-situ temperature [ITS-90] [deg C]
17 ! p : sea pressure [dbar]
18 !
19 ! sp : Practical Salinity [unitless]
20 !--------------------------------------------------------------------------
21 
23 
25 
27 
29 
30 use gsw_mod_kinds
31 
32 implicit none
33 
34 real (r8), intent(in) :: c, t, p
35 
36 real (r8) :: gsw_sp_from_c
37 
38 real (r8) :: sp, t68, ft68, r, rt_lc, rp, rt, rtx
39 real (r8) :: hill_ratio, x, sqrty, part1, part2, sp_hill_raw
40 
41 character (*), parameter :: func_name = "gsw_sp_from_c"
42 
43 t68 = t*1.00024_r8
44 ft68 = (t68 - 15.0_r8)/(1.0_r8 + k*(t68 - 15.0_r8))
45 
46 ! The dimensionless conductivity ratio, R, is the conductivity input, C,
47 ! divided by the present estimate of C(SP=35, t_68=15, p=0) which is
48 ! 42.9140 mS/cm (=4.29140 S/m), (Culkin and Smith, 1980).
49 
50 r = c/gsw_c3515
51 
52 ! rt_lc corresponds to rt as defined in the UNESCO 44 (1983) routines.
53 rt_lc = c0 + (c1 + (c2 + (c3 + c4*t68)*t68)*t68)*t68
54 rp = 1.0_r8 + (p*(e1 + e2*p + e3*p*p))/(1.0_r8 + d1*t68 + d2*t68*t68 + (d3 + d4*t68)*r)
55 rt = r/(rp*rt_lc)
56 
57 if (rt .lt. 0.0_r8) then
58  gsw_sp_from_c = gsw_error_code(1,func_name)
59  return
60 endif
61 
62 rtx = sqrt(rt)
63 
64 sp = a0 + (a1 + (a2 + (a3 + (a4 + a5*rtx)*rtx)*rtx)*rtx)*rtx + &
65  ft68*(b0 + (b1 + (b2 + (b3 + (b4 + b5*rtx)*rtx)*rtx)*rtx)*rtx)
66 
67 ! The following section of the code is designed for SP < 2 based on the
68 ! Hill et al. (1986) algorithm. This algorithm is adjusted so that it is
69 ! exactly equal to the PSS-78 algorithm at SP = 2.
70 
71 if (sp .lt. 2.0_r8) then
72  hill_ratio = gsw_hill_ratio_at_sp2(t)
73  x = 400.0_r8*rt
74  sqrty = 10.0_r8*rtx
75  part1 = 1.0_r8 + x*(1.5_r8 + x)
76  part2 = 1.0_r8 + sqrty*(1.0_r8 + sqrty*(1.0_r8 + sqrty))
77  sp_hill_raw = sp - a0/part1 - b0*ft68/part2
78  sp = hill_ratio*sp_hill_raw
79 endif
80 
81 if (sp .lt. 0.0_r8) then
82  gsw_sp_from_c = gsw_error_code(2,func_name)
83 else
84  gsw_sp_from_c = sp
85 end if
86 
87 return
88 end function
89 
90 !--------------------------------------------------------------------------
real(r8), parameter, public gsw_error_limit
elemental real(r8) function gsw_sp_from_c(c, t, p)
elemental real(r8) function, public gsw_error_code(err_num, func_name, error_code)