FV3 Bundle
gsw_poly_check.f90
Go to the documentation of this file.
2 
6 
7 implicit none
8 
9 integer :: gsw_error_flag = 0
10 
11 integer :: i
12 
13 real (r8) :: saturation_fraction
14 
15 real (r8), dimension(:,:), allocatable :: lat, long
16 
17 real (r8), dimension(:,:), allocatable :: val1, val2, val3, val4, val5, val6
18 
19 real (r8), dimension(:,:), allocatable :: c, sr, sstar, pt, entropy
20 real (r8), dimension(:,:), allocatable :: h, ctf, tf, diff
21 real (r8), dimension(:,:), allocatable :: ctf_poly, tf_poly, pt0
22 
23 allocate(lat(cast_m,cast_n))
24 allocate(long(cast_m,cast_n))
25 allocate(pt0(cast_ice_m,cast_ice_n))
26 
27 allocate(val1(cast_m,cast_n))
28 allocate(val2(cast_m,cast_n))
29 allocate(val3(cast_m,cast_n))
30 allocate(val4(cast_m,cast_n))
31 allocate(val5(cast_m,cast_n))
32 allocate(val6(cast_m,cast_n))
33 
34 allocate(c(cast_m,cast_n))
35 allocate(sr(cast_m,cast_n))
36 allocate(sstar(cast_m,cast_n))
37 allocate(pt(cast_m,cast_n))
38 allocate(entropy(cast_m,cast_n))
39 allocate(ctf(cast_m,cast_n))
40 allocate(tf(cast_m,cast_n))
41 allocate(ctf_poly(cast_m,cast_n))
42 allocate(tf_poly(cast_m,cast_n))
43 allocate(h(cast_m,cast_n))
44 allocate(diff(cast_m,cast_n))
45 
46 do i = 1, cast_n
47  lat(:,i) = lat_cast(i)
48  long(:,i) = long_cast(i)
49 end do
50 
51 !------------------------------------------------------------------------------
52 call section_title('Freezing temperatures')
53 
54 saturation_fraction = 0.5_r8
55 
56 ctf = gsw_ct_freezing_exact(sa,p,saturation_fraction)
57 ctf_poly = gsw_ct_freezing_poly(sa,p,saturation_fraction)
58 call check_accuracy('CT_freezing',ctf,ctf_poly)
59 
60 tf = gsw_t_freezing_exact(sa,p,saturation_fraction)
61 tf_poly = gsw_t_freezing_poly(sa,p,saturation_fraction)
62 call check_accuracy('t_freezing',tf,tf_poly)
63 
66 call check_accuracy('pot_enthalpy_ice_freezing',val1,val2)
67 
68 val1 = gsw_sa_freezing_from_ct(ctf,p,saturation_fraction)
69 val2 = gsw_sa_freezing_from_ct_poly(ctf,p,saturation_fraction)
70 call check_accuracy('SA_freezing_from_CT',val1,val2)
71 
72 val1 = gsw_sa_freezing_from_t(tf,p,saturation_fraction)
73 val2 = gsw_sa_freezing_from_t_poly(tf,p,saturation_fraction)
74 call check_accuracy('SA_freezing_from_t',val1,val2)
75 
76 call gsw_ct_freezing_first_derivatives(sa,p,saturation_fraction,val1,val2)
77 call gsw_ct_freezing_first_derivatives_poly(sa,p,saturation_fraction,val3,val4)
78 call check_accuracy('CT_freezing_first_derivatives (ctf_sa)',val1,val3)
79 call check_accuracy('CT_freezing_first_derivatives (ctf_p)',val2,val4)
80 
81 call gsw_t_freezing_first_derivatives(sa,p,saturation_fraction,val1,val2)
82 call gsw_t_freezing_first_derivatives_poly(sa,p,saturation_fraction,val3,val4)
83 call check_accuracy('t_freezing_first_derivatives (tf_sa)',val1,val3)
84 call check_accuracy('t_freezing_first_derivatives (tf_p)',val2,val4)
85 
88 call check_accuracy('pot_enthalpy_ice_freezing_first_derivatives (sa)',val1,val3)
89 call check_accuracy('pot_enthalpy_ice_freezing_first_derivatives (p)',val2,val4)
90 
91 !------------------------------------------------------------------------------
92 call section_title('Themodynamic properties of ice Ih')
93 
94 deallocate(h,val1,val2,val3,val4,val5,val6)
95 allocate(h(cast_ice_m,cast_ice_n))
96 allocate(val1(cast_ice_m,cast_ice_n))
97 allocate(val2(cast_ice_m,cast_ice_n))
98 allocate(val3(cast_ice_m,cast_ice_n))
99 allocate(val4(cast_ice_m,cast_ice_n))
100 allocate(val5(cast_ice_m,cast_ice_n))
101 allocate(val6(cast_ice_m,cast_ice_n))
102 
105 
108 call check_accuracy('pot_enthalpy_from_pt_ice',val1,val2)
109 
112 call check_accuracy('pt_from_pot_enthalpy_ice',val1,val2)
113 
114 !------------------------------------------------------------------------------
115 call section_title('Thermodynamic interaction between ice and seawater')
116 
117 saturation_fraction = 0.0_r8
118 
121 call check_accuracy('melting_ice_SA_CT_ratio',val1,val2)
122 
125 call check_accuracy('melting_ice_equilibrium_SA_CT_ratio',val1,val2)
126 
129 call check_accuracy('frazil_ratios_adiabatic (dsa_dct)',val1,val4)
130 call check_accuracy('frazil_ratios_adiabatic (dsa_dp)',val2,val5)
131 call check_accuracy('frazil_ratios_adiabatic (dct_dp)',val3,val6)
132 
135  val5,val6)
136 call check_accuracy('frazil_properties_potential (sa_final)',val1,val4)
137 call check_accuracy('frazil_properties_potential (ct_final)',val2,val5)
138 call check_accuracy('frazil_properties_potential (w_ih_final)',val3,val6)
139 
140 !------------------------------------------------------------------------------
141 call section_title('Thermodynamic interaction between seaice and seawater')
142 
147 call check_accuracy('melting_seaice_SA_CT_ratio',val1,val2)
148 
151 call check_accuracy('melting_seaice_equilibrium_SA_CT_ratio',val1,val2)
152 
154  w_seaice,sa_seaice,t_seaice,val1,val2)
155 !call check_accuracy('melting_seaice_into_seawater',val1, &
156 ! 'melting_seaice_into_seawater_SA_final')
157 !call check_accuracy('melting_seaice_into_seawater',val2, &
158 ! 'melting_seaice_into_seawater_CT_final')
159 
161  sa_seaice,t_seaice,val1,val2,val3)
162 !call check_accuracy('seaice_fraction_to_freeze_seawater',val1, &
163 ! 'seaice_fraction_to_freeze_seawater_SA_freeze')
164 !call check_accuracy('seaice_fraction_to_freeze_seawater',val2, &
165 ! 'seaice_fraction_to_freeze_seawater_CT_freeze')
166 !call check_accuracy('seaice_fraction_to_freeze_seawater',val3, &
167 ! 'seaice_fraction_to_freeze_seawater_w_Ih')
168 
169 !------------------------------------------------------------------------------
170 if (gsw_error_flag.eq.1) then
171  print*
172  print*; print*, 'Your installation of the Gibbs SeaWater (GSW) Oceanographic Toolbox has errors!'
173 else
174  print*
175  print*; print*, 'Well done! The gsw_check_fuctions confirms that the Gibbs'
176  print*; print*, 'SeaWater (GSW) Oceanographic Toolbox is installed correctly.'
177  print*
178 endif
179 
180 contains
181 
182  !--------------------------------------------------------------------------
183 
184  subroutine section_title (title)
186  character (*), intent(in) :: title
187 
188  print *
189  print *, "----------------------------------------------------------------------------"
190  print *, title
191  print *
192 
193  return
194  end subroutine section_title
195 
196  !--------------------------------------------------------------------------
197 
198  subroutine check_accuracy (func_name, fvalue1, fvalue2, vprint)
201 
202  implicit none
203 
204  character (*), intent(in) :: func_name
205  real (r8), intent(in) :: fvalue1(:,:), fvalue2(:,:)
206  logical, intent(in), optional :: vprint
207 
208  integer :: ndots, i, j
209  real (r8) :: diff(size(fvalue1,1),size(fvalue1,2))
210  character (len(func_name)+3) :: message
211  character (4) :: errflg
212 
213  character (*), parameter :: att_name = 'computation_accuracy'
214  character (*), parameter :: &
215  dots = ' .............................................................'
216 
217  message = func_name
218 
219  diff = fvalue1 - fvalue2
220 
221  if (present(vprint)) then
222  if (vprint) then
223  print '(i3,3ES24.15)', ((i,fvalue1(i,j),fvalue2(i,j),diff(i,j),&
224  i=1,size(fvalue1,1)), j=1,size(fvalue1,2))
225  print *
226  end if
227  end if
228 
229  if (any(fvalue1 .gt. gsw_error_limit)) then
230  where (fvalue1 .gt. gsw_error_limit) diff = 0.0_r8
231  errflg = ' (*)'
232  else
233  errflg = ' '
234  end if
235  ndots = 52 - len(trim(message))
236 
237  print '(1x,2a,2es12.3)', trim(message), dots(:ndots), minval(diff), &
238  maxval(diff)
239 
240  return
241  end subroutine check_accuracy
242 
243 end
244 
245 !--------------------------------------------------------------------------
real(r8), dimension(cast_n) lat_cast
integer, parameter cast_m
integer, parameter, public long
Definition: Type_Kinds.f90:76
subroutine section_title(title)
subroutine check_accuracy(func_name, fvalue, result, result_ice, result_mpres, result_cast, vprint)
program gsw_poly_check
real(r8), dimension(cast_n) long_cast
real(r8), dimension(cast_m, cast_n) p
real(r8), parameter, public gsw_error_limit
real(r8), dimension(cast_ice_m, cast_ice_n) sa_arctic
real(r8), dimension(cast_ice_m, cast_ice_n) w_seaice
integer, parameter cast_n
real(r8), dimension(cast_ice_m, cast_ice_n) p_arctic
real(r8), dimension(cast_ice_m, cast_ice_n) t_seaice
real(r8), dimension(cast_ice_m, cast_ice_n) h_pot_bulk
real(r8), dimension(cast_ice_m, cast_ice_n) w_ice
real(r8), dimension(cast_ice_m, cast_ice_n) sa_seaice
real(r8), dimension(cast_ice_m, cast_ice_n) sa_bulk
integer, parameter cast_ice_m
integer, parameter cast_ice_n
real(r8), dimension(cast_m, cast_n) sa
real(r8), dimension(cast_ice_m, cast_ice_n) ct_arctic
real(r8), dimension(cast_ice_m, cast_ice_n) t_ice