SABER
tools_func.F90
Go to the documentation of this file.
1 # 1 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2 # 1 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/../instrumentation.fypp" 1
3 # 1 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/../subr_list.fypp" 1
4 !----------------------------------------------------------------------
5 ! Header: subr_list
6 !> Subroutines/functions list
7 ! Author: Benjamin Menetrier
8 ! Licensing: this code is distributed under the CeCILL-C license
9 ! Copyright 2015-... UCAR, CERFACS, METEO-FRANCE and IRIT
10 !----------------------------------------------------------------------
11 
12 # 926 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/../subr_list.fypp"
13 # 2 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/../instrumentation.fypp" 2
14 !----------------------------------------------------------------------
15 ! Header: instrumentation
16 !> Instrumentation functions
17 ! Author: Benjamin Menetrier
18 ! Licensing: this code is distributed under the CeCILL-C license
19 ! Copyright 2015-... UCAR, CERFACS, METEO-FRANCE and IRIT
20 !----------------------------------------------------------------------
21 
22 # 112 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/../instrumentation.fypp"
23 # 2 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp" 2
24 # 1 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/../generics.fypp" 1
25 !----------------------------------------------------------------------
26 ! Header: generics
27 !> Generic ranks, dimensions and types
28 ! Author: Benjamin Menetrier
29 ! Licensing: this code is distributed under the CeCILL-C license
30 ! Copyright 2015-... UCAR, CERFACS, METEO-FRANCE and IRIT
31 !----------------------------------------------------------------------
32 
33 # 57 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/../generics.fypp"
34 # 3 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp" 2
35 !----------------------------------------------------------------------
36 ! Module: tools_func
37 !> Usual functions
38 ! Author: Benjamin Menetrier
39 ! Licensing: this code is distributed under the CeCILL-C license
40 ! Copyright 2015-... UCAR, CERFACS, METEO-FRANCE and IRIT
41 !----------------------------------------------------------------------
42 module tools_func
43 
44 use atlas_module, only: atlas_geometry
45 use iso_c_binding, only: c_int16_t,c_int32_t
46 use tools_asa007, only: cholesky,syminv
49 use tools_qsort, only: qsort
50 use tools_repro, only: rth,inf,sup,infeq,small
51 use type_mpl, only: mpl_type
52 
53 
54 implicit none
55 
56 real(kind_real),parameter :: gc2gau = 0.28_kind_real !< GC99 support radius to Gaussian Daley length-scale (empirical)
57 real(kind_real),parameter :: gau2gc = one/gc2gau !< Gaussian Daley length-scale to GC99 support radius (empirical)
58 real(kind_real),parameter :: dmin = 1.0e-12_kind_real !< Minimum tensor diagonal value
59 real(kind_real),parameter :: condmax = thousand !< Maximum tensor conditioning number
60 integer,parameter :: m = 0 !< Number of implicit iteration for the Matern function (-1: GC99, 0: Gaussian, >0: Matern)
61 
62 interface
63  function c_fletcher32(n,var) bind(c,name='fletcher32') result(hash)
64  use iso_c_binding, only: c_int16_t,c_int32_t
65  integer(c_int32_t) :: n
66  integer(c_int16_t) :: var(*)
67  integer(c_int32_t) :: hash
68  end function c_fletcher32
69 end interface
70 interface fletcher32
71  module procedure func_fletcher32
72 end interface
73 interface lonlatmod
74  module procedure func_lonlatmod
75 end interface
76 interface gridhash
77  module procedure func_gridhash
78 end interface
80  module procedure func_independent_levels
81 end interface
82 interface sphere_dist
83  module procedure func_sphere_dist
84 end interface
85 interface cart_dist
86  module procedure func_cart_dist
87 end interface
88 interface lonlat2xyz
89  module procedure func_lonlat2xyz
90 end interface
91 interface xyz2lonlat
92  module procedure func_xyz2lonlat
93 end interface
94 interface vector_product
95  module procedure func_vector_product
96 end interface
97 interface det
98  module procedure func_det
99 end interface
100 interface inside
101  module procedure func_inside
102 end interface
103 interface order_cc
104  module procedure func_order_cc
105 end interface
106 interface add
107  module procedure func_add
108 end interface
109 interface divide
110  module procedure func_divide
111 end interface
113  module procedure func_vert_interp_size
114 end interface
116  module procedure func_vert_interp_setup
117 end interface
118 interface vert_interp
119  module procedure func_vert_interp
120 end interface
121 interface fit_diag
122  module procedure func_fit_diag
123 end interface
124 interface gc99
125  module procedure func_gc99
126 end interface
127 interface fit_func
128  module procedure func_fit_func
129 end interface
130 interface fit_lct
131  module procedure func_fit_lct
132 end interface
133 interface lct_d2h
134  module procedure func_lct_d2h
135 end interface
136 interface lct_h2r
137  module procedure func_lct_h2r
138 end interface
139 interface lct_r2d
140  module procedure func_lct_r2d
141 end interface
142 interface check_cond
143  module procedure func_check_cond
144 end interface
145 interface matern
146  module procedure func_matern
147 end interface
148 interface cholesky
149  module procedure func_cholesky
150 end interface
151 interface syminv
152  module procedure func_syminv
153 end interface
154 interface histogram
155  module procedure func_histogram
156 end interface
157 interface cx_to_cxa
158  module procedure func_cx_to_cxa
159 end interface
160 interface cx_to_proc
161  module procedure func_cx_to_proc
162 end interface
163 interface cx_to_cxu
164  module procedure func_cx_to_cxu
165 end interface
166 interface convert_i2l
167  module procedure func_convert_i2l_r0
168 # 137 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
169  module procedure func_convert_i2l_r1
170 # 137 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
171  module procedure func_convert_i2l_r2
172 # 137 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
173  module procedure func_convert_i2l_r3
174 # 137 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
175  module procedure func_convert_i2l_r4
176 # 139 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
177 end interface
178 interface convert_l2i
179  module procedure func_convert_l2i_r0
180 # 143 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
181  module procedure func_convert_l2i_r1
182 # 143 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
183  module procedure func_convert_l2i_r2
184 # 143 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
185  module procedure func_convert_l2i_r3
186 # 143 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
187  module procedure func_convert_l2i_r4
188 # 145 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
189 end interface
190 interface zss_maxval
191 # 148 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
192 # 149 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
193  module procedure func_zss_maxval_int_r1
194 # 149 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
195  module procedure func_zss_maxval_int_r2
196 # 149 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
197  module procedure func_zss_maxval_int_r3
198 # 149 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
199  module procedure func_zss_maxval_int_r4
200 # 149 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
201  module procedure func_zss_maxval_int_r5
202 # 149 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
203  module procedure func_zss_maxval_int_r6
204 # 151 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
205 # 148 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
206 # 149 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
207  module procedure func_zss_maxval_real_r1
208 # 149 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
209  module procedure func_zss_maxval_real_r2
210 # 149 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
211  module procedure func_zss_maxval_real_r3
212 # 149 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
213  module procedure func_zss_maxval_real_r4
214 # 149 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
215  module procedure func_zss_maxval_real_r5
216 # 149 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
217  module procedure func_zss_maxval_real_r6
218 # 151 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
219 # 152 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
220 end interface
221 interface zss_minval
222 # 155 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
223 # 156 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
224  module procedure func_zss_minval_int_r1
225 # 156 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
226  module procedure func_zss_minval_int_r2
227 # 156 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
228  module procedure func_zss_minval_int_r3
229 # 156 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
230  module procedure func_zss_minval_int_r4
231 # 156 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
232  module procedure func_zss_minval_int_r5
233 # 156 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
234  module procedure func_zss_minval_int_r6
235 # 158 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
236 # 155 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
237 # 156 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
238  module procedure func_zss_minval_real_r1
239 # 156 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
240  module procedure func_zss_minval_real_r2
241 # 156 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
242  module procedure func_zss_minval_real_r3
243 # 156 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
244  module procedure func_zss_minval_real_r4
245 # 156 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
246  module procedure func_zss_minval_real_r5
247 # 156 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
248  module procedure func_zss_minval_real_r6
249 # 158 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
250 # 159 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
251 end interface
252 interface zss_sum
253 # 162 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
254 # 163 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
255  module procedure func_zss_sum_int_r1
256 # 163 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
257  module procedure func_zss_sum_int_r2
258 # 163 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
259  module procedure func_zss_sum_int_r3
260 # 163 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
261  module procedure func_zss_sum_int_r4
262 # 163 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
263  module procedure func_zss_sum_int_r5
264 # 163 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
265  module procedure func_zss_sum_int_r6
266 # 165 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
267 # 162 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
268 # 163 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
269  module procedure func_zss_sum_real_r1
270 # 163 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
271  module procedure func_zss_sum_real_r2
272 # 163 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
273  module procedure func_zss_sum_real_r3
274 # 163 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
275  module procedure func_zss_sum_real_r4
276 # 163 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
277  module procedure func_zss_sum_real_r5
278 # 163 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
279  module procedure func_zss_sum_real_r6
280 # 165 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
281 # 166 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
282 end interface
283 interface zss_count
284 # 169 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
285  module procedure func_zss_count_r1
286 # 169 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
287  module procedure func_zss_count_r2
288 # 169 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
289  module procedure func_zss_count_r3
290 # 169 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
291  module procedure func_zss_count_r4
292 # 169 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
293  module procedure func_zss_count_r5
294 # 169 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
295  module procedure func_zss_count_r6
296 # 171 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
297 end interface
298 
299 private
300 public :: gc2gau,gau2gc,dmin,m
305 
306 contains
307 
308 !----------------------------------------------------------------------
309 ! Function: func_fletcher32
310 !> Fletcher-32 checksum algorithm
311 !----------------------------------------------------------------------
312 function func_fletcher32(var) result(value)
313 
314 implicit none
315 
316 ! Passed variables
317 real(kind_real),intent(in) :: var(:) !< Variable
318 
319 ! Returned variable
320 integer :: value
321 
322 ! Local values
323 integer(c_int32_t) :: array_size
324 integer(c_int16_t),allocatable :: array(:)
325 
326 ! Set name
327 
328 
329 ! Probe in
330 
331 
332 ! Allocation
333 allocate(array(size(var)))
334 
335 ! Initialization
336 array = transfer(var,(/0_kind_short/))
337 array_size = size(array)
338 
339 ! Call C function
340 value = c_fletcher32(array_size,array)
341 
342 ! Release memory
343 deallocate(array)
344 
345 ! Probe out
346 
347 
348 end function func_fletcher32
349 
350 !----------------------------------------------------------------------
351 ! Subroutine: func_lonlatmod
352 !> Set latitude between -pi/2 and pi/2 and longitude between -pi and pi
353 !----------------------------------------------------------------------
354 subroutine func_lonlatmod(lon,lat)
355 
356 implicit none
357 
358 ! Passed variables
359 real(kind_real),intent(inout) :: lon !< Longitude [radians]
360 real(kind_real),intent(inout) :: lat !< Latitude [radians]
361 
362 ! Set name
363 
364 
365 ! Probe in
366 
367 
368 ! Check latitude bounds
369 if (lat>half*pi) then
370  lat = pi-lat
371  lon = lon+pi
372 elseif (lat<-half*pi) then
373  lat = -pi-lat
374  lon = lon+pi
375 end if
376 
377 ! Check longitude bounds
378 if (lon>pi) then
379  lon = lon-two*pi
380 elseif (lon<-pi) then
381  lon = lon+two*pi
382 end if
383 
384 ! Same zero longitude for poles
385 if (abs(lat)>(half-1.0e-6_kind_real)*pi) lon = zero
386 
387 ! Probe out
388 
389 
390 end subroutine func_lonlatmod
391 
392 !----------------------------------------------------------------------
393 ! Subroutine: func_gridhash
394 !> Compute grid hash profile
395 !----------------------------------------------------------------------
396 subroutine func_gridhash(ncx,nlx,lon_cx,lat_cx,mask_cx,grid_hash)
397 
398 implicit none
399 
400 ! Passed variables
401 integer,intent(in) :: ncx !< Number of points
402 integer,intent(in) :: nlx !< Number of levels
403 real(kind_real),intent(in) :: lon_cx(ncx) !< Longitude [radians]
404 real(kind_real),intent(in) :: lat_cx(ncx) !< Latitude [radians]
405 logical,intent(in) :: mask_cx(ncx,nlx) !< Mask
406 integer,intent(out) :: grid_hash(0:nlx) !< Grid hash profile
407 
408 ! Local variables
409 integer :: ilx,ncx_eff,icx_eff,icx
410 real(kind_real),allocatable :: lonlat(:)
411 
412 ! Set name
413 
414 
415 ! Probe in
416 
417 
418 do ilx=1,nlx
419  ! Count points in the mask
420  ncx_eff = count(mask_cx(:,ilx))
421 
422  if (ncx_eff>0) then
423  ! Allocation
424  allocate(lonlat(2*ncx_eff))
425 
426  ! Copy lonlat
427  icx_eff = 0
428  do icx=1,ncx
429  if (mask_cx(icx,ilx)) then
430  icx_eff = icx_eff+1
431  lonlat(icx_eff) = lon_cx(icx)
432  icx_eff = icx_eff+1
433  lonlat(icx_eff) = lat_cx(icx)
434  end if
435  end do
436 
437  ! Compute hash
438  grid_hash(ilx) = fletcher32(lonlat)
439 
440  ! Release memory
441  deallocate(lonlat)
442  else
443  grid_hash(ilx) = 0
444  end if
445 end do
446 
447 ! Final grid hash
448 grid_hash(0) = fletcher32(real(grid_hash(1:nlx),kind_real))
449 
450 ! Probe out
451 
452 
453 end subroutine func_gridhash
454 
455 !----------------------------------------------------------------------
456 ! Subroutine: func_independent_levels
457 !> Compute independent levels
458 !----------------------------------------------------------------------
459 subroutine func_independent_levels(mpl,nlx,grid_hash,nlxi,lx_to_lxi,lxi_to_lx,ifmt)
460 
461 implicit none
462 
463 ! Passed variables
464 type(mpl_type),intent(inout) :: mpl !< MPI data
465 integer,intent(in) :: nlx !< Number of levels
466 integer,intent(in) :: grid_hash(nlx) !< Grid hash profile
467 integer,intent(out) :: nlxi !< Number of independent levels
468 integer,intent(out) :: lx_to_lxi(nlx) !< Levels to independent levels
469 integer,intent(out) :: lxi_to_lx(nlx) !< Independent levels to levels
470 integer,intent(in) :: ifmt !< Indentation
471 
472 ! Local variables
473 integer :: ilx,ilxi,jlx,jlxi,n
474 integer :: proc_to_grid_hash(mpl%nproc),grid_hash_glb(nlx)
475 character(len=1024) :: cfmt
476 
477 ! Set name
478 
479 
480 ! Probe in
481 
482 
483 ! Compute global hash value
484 do ilx=1,nlx
485  call mpl%f_comm%allgather(grid_hash(ilx),proc_to_grid_hash)
486  grid_hash_glb(ilx) = fletcher32(real(proc_to_grid_hash,kind_real))
487 end do
488 
489 ! Count independent levels
490 nlxi = 1
491 do ilx=2,nlx
492  if (all(grid_hash_glb(1:ilx-1)/=grid_hash_glb(ilx))) nlxi = nlxi+1
493 end do
494 
495 ! Initialization
496 lxi_to_lx = mpl%msv%vali
497 
498 ! Get independent level
499 ilx = 1
500 ilxi = 1
501 lx_to_lxi(ilx) = ilxi
502 lxi_to_lx(ilxi) = ilx
503 do ilx=2,nlx
504  if (all(grid_hash_glb(1:ilx-1)/=grid_hash_glb(ilx))) then
505  ! New independent level
506  ilxi = ilxi+1
507  lx_to_lxi(ilx) = ilxi
508  lxi_to_lx(ilxi) = ilx
509  else
510  ! Similar level
511  do jlx=1,ilx-1
512  if (grid_hash_glb(jlx)==grid_hash_glb(ilx)) then
513  jlxi = lx_to_lxi(jlx)
514  lx_to_lxi(ilx) = jlxi
515  exit
516  end if
517  end do
518  end if
519 end do
520 
521 ! Print levels
522 write(cfmt,'(a,i2.2,a)') '(a',ifmt,',a)'
523 write(mpl%info,trim(cfmt)) '','Compute independent levels: '
524 call mpl%flush(.false.)
525 do ilxi=1,nlxi
526  ilx = lxi_to_lx(ilxi)
527  n = count(lx_to_lxi==ilxi)
528  if (n<10) then
529  cfmt = '(i3,a,i1,a)'
530  elseif (n<100) then
531  cfmt = '(i3,a,i2,a)'
532  else
533  cfmt = '(i3,a,i3,a)'
534  end if
535  write(mpl%info,trim(cfmt)) ilx,'[',n,'] '
536  call mpl%flush(.false.)
537 end do
538 write(mpl%info,'(a)') ''
539 call mpl%flush
540 
541 ! Probe out
542 
543 
544 end subroutine func_independent_levels
545 
546 !----------------------------------------------------------------------
547 ! Subroutine: func_cart_dist
548 !> Compute the cartesian distance between two points
549 !----------------------------------------------------------------------
550 subroutine func_cart_dist(x_i,y_i,z_i,x_f,y_f,z_f,dist)
551 
552 implicit none
553 
554 ! Passed variable
555 real(kind_real),intent(in) :: x_i !< Initial point X coordinate
556 real(kind_real),intent(in) :: y_i !< Initial point Y coordinate
557 real(kind_real),intent(in) :: z_i !< Initial point Z coordinate
558 real(kind_real),intent(in) :: x_f !< Final point X coordinate
559 real(kind_real),intent(in) :: y_f !< Final point Y coordinate
560 real(kind_real),intent(in) :: z_f !< Final point Z coordinate
561 real(kind_real),intent(out) :: dist !< Great-circle distance
562 
563 ! Set name
564 
565 
566 ! Probe in
567 
568 
569 ! Compute distance
570 dist = sqrt((x_f-x_i)**2+(y_f-y_i)**2+(z_f-z_i)**2)
571 
572 ! Probe out
573 
574 
575 end subroutine func_cart_dist
576 
577 !----------------------------------------------------------------------
578 ! Subroutine: func_sphere_dist
579 !> Compute the great-circle distance between two points
580 !----------------------------------------------------------------------
581 subroutine func_sphere_dist(lon_i,lat_i,lon_f,lat_f,dist)
582 
583 implicit none
584 
585 ! Passed variable
586 real(kind_real),intent(in) :: lon_i !< Initial point longitude [radians]
587 real(kind_real),intent(in) :: lat_i !< Initial point latitude [radians]
588 real(kind_real),intent(in) :: lon_f !< Final point longitude [radians]
589 real(kind_real),intent(in) :: lat_f !< Final point latitude [radians]
590 real(kind_real),intent(out) :: dist !< Great-circle distance
591 
592 ! Local variables
593 type(atlas_geometry) :: ageometry
594 
595 ! Set name
596 
597 
598 ! Probe in
599 
600 
601 ! Create ATLAS geometry
602 ageometry = atlas_geometry('UnitSphere')
603 
604 ! Compute distance
605 dist = ageometry%distance(lon_i*rad2deg,lat_i*rad2deg,lon_f*rad2deg,lat_f*rad2deg)
606 
607 ! Probe out
608 
609 
610 end subroutine func_sphere_dist
611 
612 !----------------------------------------------------------------------
613 ! Subroutine: func_lonlat2xyz
614 !> Convert longitude/latitude to cartesian coordinates
615 !----------------------------------------------------------------------
616 subroutine func_lonlat2xyz(mpl,lon,lat,x,y,z)
617 
618 implicit none
619 
620 ! Passed variables
621 type(mpl_type),intent(inout) :: mpl !< MPI data
622 real(kind_real),intent(in) :: lon !< Longitude [radians]
623 real(kind_real),intent(in) :: lat !< Latitude [radians]
624 real(kind_real),intent(out) :: x !< X coordinate
625 real(kind_real),intent(out) :: y !< Y coordinate
626 real(kind_real),intent(out) :: z !< Z coordinate
627 
628 ! Local variables
629 type(atlas_geometry) :: ageometry
630 
631 ! Set name
632 
633 
634 ! Probe in
635 
636 
637 if (mpl%msv%isnot(lat).and.mpl%msv%isnot(lon)) then
638  ! Check longitude/latitude
639  if (inf(lon,-pi).and.sup(lon,pi)) call mpl%abort('func_lonlat2xyz','wrong longitude')
640  if (inf(lat,-half*pi).and.sup(lat,-half*pi)) call mpl%abort('func_lonlat2xyz','wrong latitude')
641 
642  ! Create ATLAS geometry
643  ageometry = atlas_geometry('UnitSphere')
644 
645  ! Convert to x/y/z
646  call ageometry%lonlat2xyz(lon*rad2deg,lat*rad2deg,x,y,z)
647 else
648  ! Missing values
649  x = mpl%msv%valr
650  y = mpl%msv%valr
651  z = mpl%msv%valr
652 end if
653 
654 ! Probe out
655 
656 
657 end subroutine func_lonlat2xyz
658 
659 !----------------------------------------------------------------------
660 ! Subroutine: func_xyz2lonlat
661 !> Convert longitude/latitude to cartesian coordinates
662 !----------------------------------------------------------------------
663 subroutine func_xyz2lonlat(mpl,x,y,z,lon,lat)
664 
665 implicit none
666 
667 ! Passed variables
668 type(mpl_type),intent(in) :: mpl !< MPI data
669 real(kind_real),intent(in) :: x !< X coordinate
670 real(kind_real),intent(in) :: y !< Y coordinate
671 real(kind_real),intent(in) :: z !< Z coordinate
672 real(kind_real),intent(out) :: lon !< Longitude [radians]
673 real(kind_real),intent(out) :: lat !< Latitude [radians]
674 
675 ! Local variables
676 type(atlas_geometry) :: ageometry
677 
678 ! Set name
679 
680 
681 ! Probe in
682 
683 
684 if (mpl%msv%isnot(x).and.mpl%msv%isnot(y).and.mpl%msv%isnot(z)) then
685  ! Create ATLAS geometry
686  ageometry = atlas_geometry('UnitSphere')
687 
688  ! Convert to lon/lat
689  call ageometry%xyz2lonlat(x,y,z,lon,lat)
690 
691  ! Copy coordinates
692  lon = lon*deg2rad
693  lat = lat*deg2rad
694 else
695  ! Missing values
696  lon = mpl%msv%valr
697  lat = mpl%msv%valr
698 end if
699 
700 ! Probe out
701 
702 
703 end subroutine func_xyz2lonlat
704 
705 !----------------------------------------------------------------------
706 ! Subroutine: func_vector_product
707 !> Compute normalized vector product
708 !----------------------------------------------------------------------
709 subroutine func_vector_product(v1,v2,vp)
710 
711 implicit none
712 
713 ! Passed variables
714 real(kind_real),intent(in) :: v1(3) !< First vector
715 real(kind_real),intent(in) :: v2(3) !< Second vector
716 real(kind_real),intent(out) :: vp(3) !< Vector product
717 
718 ! Local variable
719 real(kind_real) :: r
720 
721 ! Set name
722 
723 
724 ! Probe in
725 
726 
727 ! Vector product
728 vp(1) = v1(2)*v2(3)-v1(3)*v2(2)
729 vp(2) = v1(3)*v2(1)-v1(1)*v2(3)
730 vp(3) = v1(1)*v2(2)-v1(2)*v2(1)
731 
732 ! Normalization
733 r = sqrt(sum(vp**2))
734 if (r>zero) vp = vp/r
735 
736 ! Probe out
737 
738 
739 end subroutine func_vector_product
740 
741 !----------------------------------------------------------------------
742 ! Subroutine: func_det
743 !> Compute determinant (vector triple product)
744 !----------------------------------------------------------------------
745 subroutine func_det(v1,v2,v3,p,cflag)
746 
747 implicit none
748 
749 ! Passed variables
750 real(kind_real),intent(in) :: v1(3) !< First vector
751 real(kind_real),intent(in) :: v2(3) !< Second vector
752 real(kind_real),intent(in) :: v3(3) !< Third vector
753 real(kind_real),intent(out) :: p !< Determinant
754 logical,intent(out) :: cflag !< Confidence flag
755 
756 ! Local variable
757 integer :: i
758 real(kind_real) :: terms(6)
759 
760 ! Set name
761 
762 
763 ! Probe in
764 
765 
766 ! Terms
767 terms(1) = v1(2)*v2(3)*v3(1)
768 terms(2) = -v1(3)*v2(2)*v3(1)
769 terms(3) = v1(3)*v2(1)*v3(2)
770 terms(4) = -v1(1)*v2(3)*v3(2)
771 terms(5) = v1(1)*v2(2)*v3(3)
772 terms(6) = -v1(2)*v2(1)*v3(3)
773 
774 ! Sum
775 p = sum(terms)
776 
777 ! Confidence flag
778 cflag = .true.
779 do i=1,6
780  if ((abs(terms(i))>zero).and.small(p,terms(i))) cflag = .false.
781 end do
782 
783 ! Probe out
784 
785 
786 end subroutine func_det
787 
788 !----------------------------------------------------------------------
789 ! Subroutine: func_inside
790 !> Find whether a point is inside the hull boundaries or not
791 !----------------------------------------------------------------------
792 subroutine func_inside(mpl,vbnd,lon,lat,inside_hull)
793 
794 implicit none
795 
796 ! Passed variables
797 type(mpl_type),intent(inout) :: mpl !< MPI data
798 real(kind_real),intent(in) :: vbnd(:,:) !< Boundary coordinates
799 real(kind_real),intent(in) :: lon !< Longitude
800 real(kind_real),intent(in) :: lat !< Latitude
801 logical,intent(out) :: inside_hull !< True if the point is inside the hull
802 
803 ! Local variables
804 integer :: i,inext
805 real(kind_real) :: vp(3),v1(3),v2(3),cp(3),cd(3)
806 
807 ! Set name
808 
809 
810 ! Probe in
811 
812 
813 ! Transform to cartesian coordinates
814 call lonlat2xyz(mpl,lon,lat,vp(1),vp(2),vp(3))
815 
816 ! Initialization
817 inside_hull = .true.
818 
819 do i=1,size(vbnd,2)
820  ! Index
821  if (i<size(vbnd,2)) then
822  inext = i+1
823  else
824  inext = 1
825  end if
826 
827  ! Cross-product
828  v1 = vbnd(:,inext)-vbnd(:,i)
829  v2 = vp-vbnd(:,i)
830  call vector_product(v1,v2,cp)
831 
832  ! Centroid
833  cd = (vp+vbnd(:,i)+vbnd(:,inext))/three
834 
835  ! Compare the directions
836  if (inf(sum(cp*cd),zero)) then
837  inside_hull = .false.
838  exit
839  end if
840 end do
841 
842 ! Probe out
843 
844 
845 end subroutine func_inside
846 
847 !----------------------------------------------------------------------
848 ! Subroutine: func_order_cc
849 !> Order points in counter-clockwise order with respect to a central point
850 !----------------------------------------------------------------------
851 subroutine func_order_cc(mpl,lon,lat,n,x,y,z,order,diff)
852 
853 implicit none
854 
855 ! Passed variables
856 type(mpl_type),intent(inout) :: mpl !< MPI data
857 real(kind_real),intent(in) :: lon !< Longitude of the central point
858 real(kind_real),intent(in) :: lat !< Latitude of the central point
859 integer :: n !< Number of points
860 real(kind_real),intent(in) :: x(n) !< List of X-coordinates
861 real(kind_real),intent(in) :: y(n) !< List of Y-coordinates
862 real(kind_real),intent(in) :: z(n) !< List of Z-coordinates
863 integer,intent(out) :: order(n) !< Counter-clockwise order
864 real(kind_real),intent(out),optional :: diff(n) !< Angles differences
865 
866 ! Local variable
867 integer :: i
868 real(kind_real) :: rvec(3),costheta,sintheta,p(3),rvecxv(3),v(3),list(n)
869 real(kind_real),allocatable :: list_save(:)
870 
871 ! Set name
872 
873 
874 ! Probe in
875 
876 
877 ! Rotation vector in cartesian coordinates
878 call lonlat2xyz(mpl,lon-half*pi,zero,rvec(1),rvec(2),rvec(3))
879 
880 ! Rotation angle
881 costheta = cos(half*pi-lat)
882 sintheta = sin(half*pi-lat)
883 
884 ! Compute angle
885 do i=1,n
886  ! Rodrigues' rotation
887  p = (/x(i),y(i),z(i)/)
888  call vector_product(rvec,p,rvecxv)
889  v = p*costheta+rvecxv*sintheta+rvec*sum(rvec*p)*(one-costheta)
890 
891  ! Angle
892  list(i) = atan2(v(2),v(1))
893 end do
894 
895 if (present(diff)) then
896  ! Allocation
897  allocate(list_save(n))
898 
899  ! Copy
900  list_save = list
901 end if
902 
903 ! Sort angles in counter-clockwise order
904 call qsort(n,list,order)
905 
906 if (present(diff)) then
907  ! Get angles differences
908  diff(order(1)) = list_save(order(1))-list_save(order(n))+two*pi
909  do i=2,n
910  diff(order(i)) = list_save(order(i))-list_save(order(i-1))
911  end do
912 
913  ! Release memory
914  deallocate(list_save)
915 end if
916 
917 ! Probe out
918 
919 
920 end subroutine func_order_cc
921 
922 !----------------------------------------------------------------------
923 ! Subroutine: func_add
924 !> Check if value missing and add if not missing
925 !----------------------------------------------------------------------
926 subroutine func_add(mpl,val,cumul,num,wgt)
927 
928 implicit none
929 
930 ! Passed variables
931 type(mpl_type),intent(in) :: mpl !< MPI data
932 real(kind_real),intent(in) :: val !< Value to add
933 real(kind_real),intent(inout) :: cumul !< Cumul
934 real(kind_real),intent(inout) :: num !< Number of values
935 real(kind_real),intent(in),optional :: wgt !< Weight
936 
937 ! Local variables
938 real(kind_real) :: lwgt
939 
940 ! Set name
941 
942 
943 ! Probe in
944 
945 
946 ! Initialize weight
947 lwgt = one
948 if (present(wgt)) lwgt = wgt
949 
950 ! Add value to cumul
951 if (mpl%msv%isnot(val)) then
952  cumul = cumul+lwgt*val
953  num = num+lwgt
954 end if
955 
956 ! Probe out
957 
958 
959 end subroutine func_add
960 
961 !----------------------------------------------------------------------
962 ! Subroutine: func_divide
963 !> Check if value missing and divide if not missing
964 !----------------------------------------------------------------------
965 subroutine func_divide(mpl,val,num)
966 
967 implicit none
968 
969 ! Passed variables
970 type(mpl_type),intent(in) :: mpl !< MPI data
971 real(kind_real),intent(inout) :: val !< Value to divide
972 real(kind_real),intent(in) :: num !< Divider
973 
974 ! Set name
975 
976 
977 ! Probe in
978 
979 
980 ! Divide cumul by num
981 if (abs(num)>zero) then
982  val = val/num
983 else
984  val = mpl%msv%valr
985 end if
986 
987 ! Probe out
988 
989 
990 end subroutine func_divide
991 
992 !----------------------------------------------------------------------
993 ! Subroutine: func_vert_interp_size
994 !> Count vertical interpolation levels
995 !----------------------------------------------------------------------
996 subroutine func_vert_interp_size(nl0,dl0,nl1)
997 
998 implicit none
999 
1000 ! Passed variables
1001 integer,intent(in) :: nl0 !< Number of levels
1002 integer,intent(in) :: dl0 !< Level delta
1003 integer,intent(out) :: nl1 !< Number of interpolation levels
1004 
1005 ! Local variables
1006 integer :: il0_prev,il0,dl0_tmp
1007 
1008 ! Set name
1009 
1010 
1011 ! Probe in
1012 
1013 
1014 ! Initialization
1015 nl1 = 1
1016 il0_prev = 1
1017 
1018 ! Loop over levels
1019 do il0=2,nl0
1020  dl0_tmp = il0-il0_prev
1021  if (dl0_tmp==dl0) then
1022  il0_prev = il0
1023  nl1 = nl1+1
1024  end if
1025 end do
1026 
1027 ! Probe out
1028 
1029 
1030 end subroutine func_vert_interp_size
1031 
1032 !----------------------------------------------------------------------
1033 ! Subroutine: func_vert_interp_setup
1034 !> Setup vertical interpolation levels and weights
1035 !----------------------------------------------------------------------
1036 subroutine func_vert_interp_setup(nl0,dl0,nl1,il0_interp,il1inf,il1sup,rinf,rsup)
1037 
1038 implicit none
1039 
1040 ! Passed variables
1041 integer,intent(in) :: nl0 !< Number of levels
1042 integer,intent(in) :: dl0 !< Level delta
1043 integer,intent(in) :: nl1 !< Number of interpolation levels
1044 integer,intent(out) :: il0_interp(nl1) !< Interpolation levels
1045 integer,intent(out) :: il1inf(nl0) !< Inferior interpolation levels
1046 integer,intent(out) :: il1sup(nl0) !< Superior interpolation levels
1047 real(kind_real),intent(out) :: rinf(nl0) !< Inferior interpolation weights
1048 real(kind_real),intent(out) :: rsup(nl0) !< Superior interpolation weights
1049 
1050 ! Local variables
1051 integer :: il0,il0_prev,jl0,dl0_tmp,il0_inf,il0_sup
1052 integer :: il1,il1_inf,il1_sup
1053 
1054 ! Set name
1055 
1056 
1057 ! Probe in
1058 
1059 
1060 ! Initialization
1061 il1 = 1
1062 il0_interp(il1) = 1
1063 il0_prev = 1
1064 il0_sup = 1
1065 
1066 ! Loop over levels
1067 do il0=2,nl0
1068  dl0_tmp = il0-il0_prev
1069  if (dl0_tmp==dl0) then
1070  il0_prev = il0
1071  il1 = il1+1
1072  il0_interp(il1) = il0
1073  end if
1074 end do
1075 
1076 ! Loop over interpolation levels
1077 do il1_inf=1,nl1
1078  il1_sup = min(il1_inf+1,nl1)
1079  il0_inf = il0_sup
1080  il0_sup = min(il0_inf+dl0,nl0)
1081  do jl0=il0_inf,il0_sup
1082  if (il0_inf==il0_sup) then
1083  il1inf(jl0) = il1_inf
1084  rinf(jl0) = one
1085  il1sup(jl0) = il1_sup
1086  rsup(jl0) = zero
1087  else
1088  il1inf(jl0) = il1_inf
1089  rinf(jl0) = real(il0_sup-jl0,kind_real)/real(il0_sup-il0_inf,kind_real)
1090  il1sup(jl0) = il1_sup
1091  rsup(jl0) = real(jl0-il0_inf,kind_real)/real(il0_sup-il0_inf,kind_real)
1092  end if
1093  end do
1094 end do
1095 
1096 ! Probe out
1097 
1098 
1099 end subroutine func_vert_interp_setup
1100 
1101 !----------------------------------------------------------------------
1102 ! Subroutine: func_vert_interp
1103 !> Apply vertical interpolation
1104 !----------------------------------------------------------------------
1105 subroutine func_vert_interp(mpl,nl1,var_l1,nl0,il1inf,il1sup,rinf,rsup,var_l0)
1106 
1107 implicit none
1108 
1109 ! Passed variables
1110 type(mpl_type),intent(inout) :: mpl !< MPI data
1111 integer,intent(in) :: nl1 !< Number of interpolation levels
1112 real(kind_real),intent(in) :: var_l1(nl1) !< Input variable
1113 integer,intent(in) :: nl0 !< Number of levels
1114 integer,intent(in) :: il1inf(nl0) !< Inferior interpolation levels
1115 integer,intent(in) :: il1sup(nl0) !< Superior interpolation levels
1116 real(kind_real),intent(in) :: rinf(nl0) !< Inferior interpolation weights
1117 real(kind_real),intent(in) :: rsup(nl0) !< Superior interpolation weights
1118 real(kind_real),intent(out) :: var_l0(nl0) !< Output variable
1119 
1120 ! Local variables
1121 integer :: il0
1122 
1123 ! Set name
1124 
1125 
1126 ! Probe in
1127 
1128 
1129 ! Interpolate
1130 do il0=1,nl0
1131  if (mpl%msv%isnot(var_l1(il1inf(il0))).and.mpl%msv%isnot(var_l1(il1sup(il0)))) then
1132  var_l0(il0) = rinf(il0)*var_l1(il1inf(il0))+rsup(il0)*var_l1(il1sup(il0))
1133  else
1134  var_l0(il0) = mpl%msv%valr
1135  end if
1136 end do
1137 
1138 ! Probe out
1139 
1140 
1141 end subroutine func_vert_interp
1142 
1143 !----------------------------------------------------------------------
1144 ! Subroutine: func_fit_diag
1145 !> Compute diagnostic fit function
1146 !----------------------------------------------------------------------
1147 subroutine func_fit_diag(mpl,nc3,nl0r,disth,distv,coef,rh,rv,fit)
1148 
1149 implicit none
1150 
1151 ! Passed variables
1152 type(mpl_type),intent(inout) :: mpl !< MPI data
1153 integer,intent(in) :: nc3 !< Number of classes
1154 integer,intent(in) :: nl0r !< Effective number of levels
1155 real(kind_real),intent(in) :: disth(nc3) !< Horizontal distance
1156 real(kind_real),intent(in) :: distv(nl0r) !< Vertical distance
1157 real(kind_real),intent(in) :: coef !< Diagonal coefficient
1158 real(kind_real),intent(in) :: rh !< Horizontal support radius
1159 real(kind_real),intent(in) :: rv !< Vertical support radius
1160 real(kind_real),intent(out) :: fit(nc3,nl0r) !< Fit
1161 
1162 ! Local variables
1163 integer :: jl0r,jc3,nc3max
1164 real(kind_real) :: disthsq(nc3),distvsq(nl0r),distnorm
1165 
1166 ! Set name
1167 
1168 
1169 ! Probe in
1170 
1171 
1172 if (mpl%msv%is(coef).or.mpl%msv%is(rh).or.mpl%msv%is(rv)) then
1173  ! Set to missing values if no value available
1174  fit = mpl%msv%valr
1175 else
1176  ! Initialization
1177  fit = zero
1178 
1179  ! Find maximum class
1180  nc3max = 0
1181  do jc3=1,nc3
1182  if (disth(jc3)>rh) exit
1183  nc3max = jc3
1184  end do
1185 
1186  ! Squared normalized horizontal distance
1187  do jc3=1,nc3max
1188  if (rh>zero) then
1189  disthsq(jc3) = (disth(jc3)/rh)**2
1190  elseif (disth(jc3)>zero) then
1191  disthsq(jc3) = zero
1192  else
1193  disthsq(jc3) = one
1194  end if
1195  end do
1196 
1197  ! Squared normalized vertical distance
1198  do jl0r=1,nl0r
1199  if (rv>zero) then
1200  distvsq(jl0r) = (distv(jl0r)/rv)**2
1201  elseif (distv(jl0r)>zero) then
1202  distvsq(jl0r) = zero
1203  else
1204  distvsq(jl0r) = one
1205  end if
1206  end do
1207 
1208  ! Unitary fit function
1209  do jl0r=1,nl0r
1210  do jc3=1,nc3max
1211  distnorm = sqrt(disthsq(jc3)+distvsq(jl0r))
1212  fit(jc3,jl0r) = fit_func(mpl,distnorm)
1213  end do
1214  end do
1215 
1216  ! Diagonal coefficient
1217  fit = fit*coef
1218 end if
1219 
1220 ! Probe out
1221 
1222 
1223 end subroutine func_fit_diag
1224 
1225 !----------------------------------------------------------------------
1226 ! Function: func_gc99
1227 !> Gaspari and Cohn (1999) function, with the support radius as a parameter
1228 !----------------------------------------------------------------------
1229 function func_gc99(distnorm) result(value)
1230 
1231 ! Passed variables
1232 real(kind_real),intent(in) :: distnorm !< Normalized distance
1233 
1234 ! Returned variable
1235 real(kind_real) :: value
1236 
1237 ! Set name
1238 
1239 
1240 ! Probe in
1241 
1242 
1243 ! Gaspari and Cohn (1999) function
1244 if (distnorm<half) then
1245  value = one-distnorm
1246  value = one+eight/five*distnorm*value
1247  value = one-three/four*distnorm*value
1248  value = one-20.0_kind_real/three*distnorm**2*value
1249 elseif (distnorm<one) then
1250  value = one-distnorm/three
1251  value = one-eight/five*distnorm*value
1252  value = one+three/four*distnorm*value
1253  value = one-two/three*distnorm*value
1254  value = one-five/two*distnorm*value
1255  value = one-12.0_kind_real*distnorm*value
1256  value = -value/(three*distnorm)
1257 else
1258  value = zero
1259 end if
1260 
1261 ! Set small values to zero (bad conditioning)
1262 if (inf(value,sqrt(rth))) value = zero
1263 
1264 ! Probe out
1265 
1266 
1267 end function func_gc99
1268 
1269 !----------------------------------------------------------------------
1270 ! Function: func_fit_func
1271 !> Fit_function
1272 !----------------------------------------------------------------------
1273 function func_fit_func(mpl,distnorm) result(value)
1274 
1275 ! Passed variables
1276 type(mpl_type),intent(inout) :: mpl !< MPI data
1277 real(kind_real),intent(in) :: distnorm !< Normalized distance
1278 
1279 ! Returned variable
1280 real(kind_real) :: value
1281 
1282 ! Set name
1283 
1284 
1285 ! Probe in
1286 
1287 
1288 ! Distance check bound
1289 if (distnorm<zero) call mpl%abort('func_fit_func','negative normalized distance')
1290 
1291 ! Gaspari and Cohn (1999) function
1292 value = gc99(distnorm)
1293 
1294 ! Enforce positivity
1295 value = max(value,zero)
1296 
1297 ! Probe out
1298 
1299 
1300 end function func_fit_func
1301 
1302 !----------------------------------------------------------------------
1303 ! Subroutine: func_fit_lct
1304 !> LCT fit
1305 !----------------------------------------------------------------------
1306 subroutine func_fit_lct(mpl,nc3,nl0r,dxsq,dysq,dxdy,dzsq,dmask,nscales,D,coef,fit)
1307 
1308 implicit none
1309 
1310 ! Passed variables
1311 type(mpl_type),intent(inout) :: mpl !< MPI data
1312 integer,intent(in) :: nc3 !< Number of classes
1313 integer,intent(in) :: nl0r !< Number of levels
1314 real(kind_real),intent(in) :: dxsq(nc3,nl0r) !< Zonal separation squared
1315 real(kind_real),intent(in) :: dysq(nc3,nl0r) !< Meridian separation squared
1316 real(kind_real),intent(in) :: dxdy(nc3,nl0r) !< Zonal x meridian separations product
1317 real(kind_real),intent(in) :: dzsq(nc3,nl0r) !< Vertical separation squared
1318 logical,intent(in) :: dmask(nc3,nl0r) !< Mask
1319 integer,intent(in) :: nscales !< Number of LCT scales
1320 real(kind_real),intent(in) :: D(4,nscales) !< LCT components
1321 real(kind_real),intent(in) :: coef(nscales) !< LCT coefficients
1322 real(kind_real),intent(out) :: fit(nc3,nl0r) !< Fit
1323 
1324 ! Local variables
1325 integer :: jl0r,jc3,iscales
1326 real(kind_real) :: Dcoef(nscales),D11,D22,D33,D12,H11,H22,H33,H12,rsq,distnorm
1327 
1328 ! Set name
1329 
1330 
1331 ! Probe in
1332 
1333 
1334 ! Initialization
1335 fit = mpl%msv%valr
1336 
1337 ! Coefficients
1338 dcoef = max(dmin,min(coef,one))
1339 dcoef = dcoef/sum(dcoef)
1340 do iscales=1,nscales
1341  ! Ensure positive-definiteness of D
1342  d11 = max(dmin,d(1,iscales))
1343  d22 = max(dmin,d(2,iscales))
1344  if (nl0r>1) then
1345  d33 = d(3,iscales)
1346  else
1347  d33 = zero
1348  end if
1349  d12 = sqrt(d11*d22)*max(-one+dmin,min(d(4,iscales),one-dmin))
1350 
1351  ! Inverse D to get H
1352  call lct_d2h(mpl,d11,d22,d33,d12,h11,h22,h33,h12)
1353 
1354  ! Homogeneous anisotropic approximation
1355  do jl0r=1,nl0r
1356  do jc3=1,nc3
1357  if (dmask(jc3,jl0r)) then
1358  ! Initialization
1359  if (iscales==1) fit(jc3,jl0r) = zero
1360 
1361  ! Squared distance
1362  rsq = h11*dxsq(jc3,jl0r)+h22*dysq(jc3,jl0r)+h33*dzsq(jc3,jl0r)+two*h12*dxdy(jc3,jl0r)
1363 
1364  if (m==-1) then
1365  ! Gaspari-Cohn 1999 function
1366  distnorm = sqrt(rsq)*gc2gau
1367  fit(jc3,jl0r) = fit(jc3,jl0r)+dcoef(iscales)*gc99(distnorm)
1368  elseif (m==0) then
1369  ! Gaussian function
1370  if (rsq<40.0_kind_real) fit(jc3,jl0r) = fit(jc3,jl0r)+dcoef(iscales)*exp(-half*rsq)
1371  else
1372  ! Matern function
1373  fit(jc3,jl0r) = fit(jc3,jl0r)+dcoef(iscales)*matern(mpl,m,sqrt(rsq))
1374  end if
1375  end if
1376  end do
1377  end do
1378 end do
1379 
1380 ! Probe out
1381 
1382 
1383 end subroutine func_fit_lct
1384 
1385 !----------------------------------------------------------------------
1386 ! Subroutine: func_lct_d2h
1387 !> From D (Daley tensor) to H (local correlation tensor)
1388 !----------------------------------------------------------------------
1389 subroutine func_lct_d2h(mpl,D11,D22,D33,D12,H11,H22,H33,H12)
1390 
1391 implicit none
1392 
1393 ! Passed variables
1394 type(mpl_type),intent(inout) :: mpl!< MPI data
1395 real(kind_real),intent(in) :: D11 !< Daley tensor component 11
1396 real(kind_real),intent(in) :: D22 !< Daley tensor component 22
1397 real(kind_real),intent(in) :: D33 !< Daley tensor component 33
1398 real(kind_real),intent(in) :: D12 !< Daley tensor component 12
1399 real(kind_real),intent(out) :: H11 !< Local correlation tensor component 11
1400 real(kind_real),intent(out) :: H22 !< Local correlation tensor component 22
1401 real(kind_real),intent(out) :: H33 !< Local correlation tensor component 33
1402 real(kind_real),intent(out) :: H12 !< Local correlation tensor component 12
1403 
1404 ! Local variables
1405 real(kind_real) :: det
1406 
1407 ! Set name
1408 
1409 
1410 ! Probe in
1411 
1412 
1413 if (mpl%msv%isnot(d11).and.mpl%msv%isnot(d22).and.mpl%msv%isnot(d33).and.mpl%msv%isnot(d12)) then
1414  ! Compute horizontal determinant
1415  det = d11*d22-d12**2
1416 
1417  ! Inverse D to get H
1418  if (det>zero) then
1419  h11 = d22/det
1420  h22 = d11/det
1421  h12 = -d12/det
1422  else
1423  call mpl%abort('func_lct_d2h','non-invertible tensor')
1424  end if
1425  if (d33>zero) then
1426  h33 = one/d33
1427  else
1428  h33 = zero
1429  end if
1430 else
1431  ! Missing values
1432  h11 = mpl%msv%valr
1433  h22 = mpl%msv%valr
1434  h33 = mpl%msv%valr
1435  h12 = mpl%msv%valr
1436 end if
1437 
1438 ! Probe out
1439 
1440 
1441 end subroutine func_lct_d2h
1442 
1443 !----------------------------------------------------------------------
1444 ! Subroutine: func_lct_h2r
1445 !> From H (local correlation tensor) to support radii
1446 !----------------------------------------------------------------------
1447 subroutine func_lct_h2r(mpl,H11,H22,H33,H12,rh,rv)
1448 
1449 implicit none
1450 
1451 ! Passed variables
1452 type(mpl_type),intent(inout) :: mpl !< MPI data
1453 real(kind_real),intent(in) :: H11 !< Local correlation tensor component 11
1454 real(kind_real),intent(in) :: H22 !< Local correlation tensor component 22
1455 real(kind_real),intent(in) :: H33 !< Local correlation tensor component 33
1456 real(kind_real),intent(in) :: H12 !< Local correlation tensor component 12
1457 real(kind_real),intent(out) :: rh !< Horizontal support radius
1458 real(kind_real),intent(out) :: rv !< Vertical support radius
1459 
1460 ! Local variables
1461 real(kind_real) :: tr,det,diff
1462 
1463 ! Set name
1464 
1465 
1466 ! Probe in
1467 
1468 
1469 if (mpl%msv%isnot(h11).and.mpl%msv%isnot(h22).and.mpl%msv%isnot(h33).and.mpl%msv%isnot(h12)) then
1470  ! Check diagonal positivity
1471  if ((h11<zero).or.(h22<zero)) call mpl%abort('func_lct_h2r','negative diagonal LCT coefficients')
1472 
1473  ! Compute horizontal trace
1474  tr = h11+h22
1475 
1476  ! Compute horizontal determinant
1477  det = h11*h22-h12**2
1478 
1479  ! Compute horizontal support radius
1480  diff = quarter*(h11-h22)**2+h12**2
1481  if ((det>zero).and..not.(diff<zero)) then
1482  if (sup(half*tr,sqrt(diff))) then
1483  rh = gau2gc/sqrt(half*tr-sqrt(diff))
1484  else
1485  call mpl%abort('func_lct_h2r','non positive-definite LCT (eigenvalue)')
1486  end if
1487  else
1488  call mpl%abort('func_lct_h2r','non positive-definite LCT (determinant)')
1489  end if
1490 
1491  ! Compute vertical support radius
1492  if (h33>zero) then
1493  rv = gau2gc/sqrt(h33)
1494  else
1495  rv = zero
1496  end if
1497 else
1498  ! Missing values
1499  rh = mpl%msv%valr
1500  rv = mpl%msv%valr
1501 end if
1502 
1503 ! Probe out
1504 
1505 
1506 end subroutine func_lct_h2r
1507 
1508 !----------------------------------------------------------------------
1509 ! Subroutine: func_lct_r2d
1510 !> From support radius to Daley tensor diagonal element
1511 !----------------------------------------------------------------------
1512 subroutine func_lct_r2d(r,D)
1513 
1514 implicit none
1515 
1516 ! Passed variables
1517 real(kind_real),intent(in) :: r !< Support radius
1518 real(kind_real),intent(out) :: D !< Daley tensor diagonal element
1519 
1520 ! Set name
1521 
1522 
1523 ! Probe in
1524 
1525 
1526 ! Convert from support radius to Daley length-scale and square
1527 d = (gc2gau*r)**2
1528 
1529 ! Probe out
1530 
1531 
1532 end subroutine func_lct_r2d
1533 
1534 !----------------------------------------------------------------------
1535 ! Subroutine: func_check_cond
1536 !> Check tensor conditioning
1537 !----------------------------------------------------------------------
1538 subroutine func_check_cond(d1,d2,nod,valid)
1539 
1540 implicit none
1541 
1542 ! Passed variables
1543 real(kind_real),intent(in) :: d1 !< First diagonal coefficient
1544 real(kind_real),intent(in) :: d2 !< Second diagonal coefficient
1545 real(kind_real),intent(in) :: nod !< Normalized off-diagonal coefficient
1546 logical,intent(out) :: valid !< Conditioning validity
1547 
1548 ! Local variables
1549 real(kind_real) :: det,tr,diff,ev1,ev2
1550 
1551 ! Set name
1552 
1553 
1554 ! Probe in
1555 
1556 
1557 ! Compute trace and determinant
1558 tr = d1+d2
1559 det = d1*d2*(one-nod**2)
1560 diff = quarter*(d1-d2)**2+d1*d2*nod**2
1561 
1562 if ((det>zero).and..not.(diff<zero)) then
1563  ! Compute eigenvalues
1564  ev1 = half*tr+sqrt(diff)
1565  ev2 = half*tr-sqrt(diff)
1566 
1567  if (ev2>zero) then
1568  ! Check conditioning
1569  valid = inf(ev1,condmax*ev2)
1570  else
1571  ! Lowest negative eigenvalue is negative
1572  valid = .false.
1573  end if
1574 else
1575  ! Non-positive definite tensor
1576  valid = .false.
1577 end if
1578 
1579 ! Probe out
1580 
1581 
1582 end subroutine func_check_cond
1583 
1584 !----------------------------------------------------------------------
1585 ! Function: func_matern
1586 !> Compute the normalized diffusion function from eq. (55) of Mirouze and Weaver (2013), for the 3d case (d = 3)
1587 !----------------------------------------------------------------------
1588 function func_matern(mpl,M,x) result(value)
1589 
1590 implicit none
1591 
1592 ! Passed variables
1593 type(mpl_type),intent(inout) :: mpl !< MPI data
1594 integer,intent(in) :: m !< Matern function order
1595 real(kind_real),intent(in) :: x !< Argument
1596 
1597 ! Returned variable
1598 real(kind_real) :: value
1599 
1600 ! Local variables
1601 integer :: j
1602 real(kind_real) :: xtmp,beta
1603 
1604 ! Set name
1605 
1606 
1607 ! Probe in
1608 
1609 
1610 ! Check
1611 if (m<2) call mpl%abort('func_matern','M should be larger than 2')
1612 if (mod(m,2)>0) call mpl%abort('func_matern','M should be even')
1613 
1614 ! Initialization
1615 value = zero
1616 beta = one
1617 xtmp = x*sqrt(real(2*m-5,kind_real))
1618 
1619 do j=0,m-3
1620  ! Update sum
1621  value = value+beta*(xtmp)**(m-2-j)
1622 
1623  ! Update beta
1624  beta = beta*real((j+1+m-2)*(-j+m-2),kind_real)/real(2*(j+1),kind_real)
1625 end do
1626 
1627 ! Last term and normalization
1628 value = value/beta+one
1629 
1630 ! Exponential factor
1631 value = value*exp(-xtmp)
1632 
1633 ! Probe out
1634 
1635 
1636 end function func_matern
1637 
1638 !----------------------------------------------------------------------
1639 ! Subroutine: func_cholesky
1640 !> Compute cholesky decomposition
1641 ! Author: Original FORTRAN77 version by Michael Healy, modifications by AJ Miller, FORTRAN90 version by John Burkardt.
1642 !----------------------------------------------------------------------
1643 subroutine func_cholesky(mpl,n,a,u)
1644 
1645 implicit none
1646 
1647 ! Passed variables
1648 type(mpl_type),intent(inout) :: mpl !< MPI data
1649 integer,intent(in) :: n !< Matrix rank
1650 real(kind_real),intent(in) :: a(n,n) !< Matrix
1651 real(kind_real),intent(out) :: u(n,n) !< Matrix square-root
1652 
1653 ! Local variables
1654 integer :: nn,i,j,ij
1655 real(kind_real),allocatable :: apack(:),upack(:)
1656 
1657 ! Set name
1658 
1659 
1660 ! Probe in
1661 
1662 
1663 ! Allocation
1664 nn = (n*(n+1))/2
1665 allocate(apack(nn))
1666 allocate(upack(nn))
1667 
1668 ! Pack matrix
1669 ij = 0
1670 do i=1,n
1671  do j=1,i
1672  ij = ij+1
1673  apack(ij) = a(i,j)
1674  end do
1675 end do
1676 
1677 ! Cholesky decomposition
1678 call cholesky(mpl,n,nn,apack,upack)
1679 
1680 ! Unpack matrix
1681 ij = 0
1682 u = zero
1683 do i=1,n
1684  do j=1,i
1685  ij = ij+1
1686  u(i,j) = upack(ij)
1687  end do
1688 end do
1689 
1690 ! Release memory
1691 deallocate(apack)
1692 deallocate(upack)
1693 
1694 ! Probe out
1695 
1696 
1697 end subroutine func_cholesky
1698 
1699 !----------------------------------------------------------------------
1700 ! Subroutine: func_syminv
1701 !> Compute inverse of a symmetric matrix
1702 ! Author: Original FORTRAN77 version by Michael Healy, modifications by AJ Miller, FORTRAN90 version by John Burkardt.
1703 !----------------------------------------------------------------------
1704 subroutine func_syminv(mpl,n,a,c)
1705 
1706 implicit none
1707 
1708 ! Passed variables
1709 type(mpl_type),intent(inout) :: mpl !< MPI data
1710 integer,intent(in) :: n !< Matrix rank
1711 real(kind_real),intent(in) :: a(n,n) !< Matrix
1712 real(kind_real),intent(out) :: c(n,n) !< Matrix inverse
1713 
1714 ! Local variables
1715 integer :: nn,i,j,ij
1716 real(kind_real),allocatable :: apack(:),cpack(:)
1717 
1718 ! Set name
1719 
1720 
1721 ! Probe in
1722 
1723 
1724 ! Allocation
1725 nn = (n*(n+1))/2
1726 allocate(apack(nn))
1727 allocate(cpack(nn))
1728 
1729 ! Pack matrix
1730 ij = 0
1731 do i=1,n
1732  do j=1,i
1733  ij = ij+1
1734  apack(ij) = a(i,j)
1735  end do
1736 end do
1737 
1738 ! Matrix inversion
1739 call syminv(mpl,n,nn,apack,cpack)
1740 
1741 ! Unpack matrix
1742 ij = 0
1743 do i=1,n
1744  do j=1,i
1745  ij = ij+1
1746  c(i,j) = cpack(ij)
1747  c(j,i) = c(i,j)
1748  end do
1749 end do
1750 
1751 ! Release memory
1752 deallocate(apack)
1753 deallocate(cpack)
1754 
1755 ! Probe out
1756 
1757 
1758 end subroutine func_syminv
1759 
1760 !----------------------------------------------------------------------
1761 ! Subroutine: func_histogram
1762 !> Compute bins and histogram from a list of values
1763 !----------------------------------------------------------------------
1764 subroutine func_histogram(mpl,nlist,list,nbins,histmin,histmax,bins,hist)
1765 
1766 implicit none
1767 
1768 ! Passed variables
1769 type(mpl_type),intent(inout) :: mpl !< MPI data
1770 integer,intent(in) :: nlist !< List size
1771 real(kind_real),intent(in) :: list(nlist) !< List
1772 integer,intent(in) :: nbins !< Number of bins
1773 real(kind_real),intent(in) :: histmin !< Histogram minimum
1774 real(kind_real),intent(in) :: histmax !< Histogram maximum
1775 real(kind_real),intent(out) :: bins(nbins+1) !< Bins
1776 real(kind_real),intent(out) :: hist(nbins) !< Histogram
1777 
1778 ! Local variables
1779 integer :: ibins,ilist
1780 real(kind_real) :: delta
1781 logical :: found
1782 
1783 ! Set name
1784 
1785 
1786 ! Probe in
1787 
1788 
1789 ! Check data
1790 if (nbins<=0) call mpl%abort('func_histogram','the number of bins should be positive')
1791 if (histmax>histmin) then
1792  if (zss_minval(list,mask=mpl%msv%isnot(list))<histmin) call mpl%abort('func_histogram','values below histogram minimum')
1793  if (zss_maxval(list,mask=mpl%msv%isnot(list))>histmax) call mpl%abort('func_histogram','values over histogram maximum')
1794 
1795  ! Compute bins
1796  delta = (histmax-histmin)/real(nbins,kind_real)
1797  bins(1) = histmin
1798  do ibins=2,nbins
1799  bins(ibins) = histmin+real(ibins-1,kind_real)*delta
1800  end do
1801  bins(nbins+1) = histmax
1802 
1803  ! Extend first and last bins
1804  bins(1) = bins(1)-1.0e-6_kind_real*delta
1805  bins(nbins+1) = bins(nbins+1)+1.0e-6_kind_real*delta
1806 
1807  ! Compute histogram
1808  hist = zero
1809  do ilist=1,nlist
1810  if (mpl%msv%isnot(list(ilist))) then
1811  ibins = 0
1812  found = .false.
1813  do while (.not.found)
1814  ibins = ibins+1
1815  if (ibins>nbins) call mpl%abort('func_histogram','bin not found')
1816  if (infeq(bins(ibins),list(ilist)).and.inf(list(ilist),bins(ibins+1))) then
1817  hist(ibins) = hist(ibins)+one
1818  found = .true.
1819  end if
1820  end do
1821  end if
1822  end do
1823  if (abs(sum(hist)-real(count(mpl%msv%isnot(list)),kind_real))>half) &
1824  & call mpl%abort('func_histogram','histogram sum is not equal to the number of valid elements')
1825 else
1826  bins = mpl%msv%valr
1827  hist = zero
1828 end if
1829 
1830 ! Probe out
1831 
1832 
1833 end subroutine func_histogram
1834 
1835 !----------------------------------------------------------------------
1836 ! Function: func_cx_to_cxa
1837 !> Conversion from global to halo A on subset Scx
1838 !----------------------------------------------------------------------
1839 function func_cx_to_cxa(nproc,proc_to_cx_offset,icx) result(icxa)
1840 
1841 implicit none
1842 
1843 ! Passed variables
1844 integer,intent(in) :: nproc !< Number of processors
1845 integer,intent(in) :: proc_to_cx_offset(nproc) !< Processor to offset on subset Scx
1846 integer,intent(in) :: icx !< Global index
1847 
1848 ! Returned variable
1849 integer :: icxa
1850 
1851 ! Local variable
1852 integer :: iproc
1853 
1854 ! Set name
1855 
1856 
1857 ! Probe in
1858 
1859 
1860 ! Find processor
1861 iproc = cx_to_proc(nproc,proc_to_cx_offset,icx)
1862 
1863 ! Get halo A index
1864 icxa = icx-proc_to_cx_offset(iproc)
1865 
1866 ! Probe out
1867 
1868 
1869 end function func_cx_to_cxa
1870 
1871 !----------------------------------------------------------------------
1872 ! Function: func_cx_to_proc
1873 !> Conversion from global to processor on subset Scx
1874 !----------------------------------------------------------------------
1875 function func_cx_to_proc(nproc,proc_to_cx_offset,icx) result(iproc)
1876 
1877 implicit none
1878 
1879 ! Passed variables
1880 integer,intent(in) :: nproc !< Number of processors
1881 integer,intent(in) :: proc_to_cx_offset(nproc) !< Processor to offset on subset Scx
1882 integer,intent(in) :: icx !< Global index
1883 
1884 ! Returned variable
1885 integer :: iproc
1886 
1887 ! Set name
1888 
1889 
1890 ! Probe in
1891 
1892 
1893 ! Find processor
1894 do iproc=1,nproc-1
1895  if ((proc_to_cx_offset(iproc)<icx).and.(icx<=proc_to_cx_offset(iproc+1))) then
1896 
1897  return
1898  end if
1899 end do
1900 
1901 ! Probe out
1902 
1903 
1904 end function func_cx_to_proc
1905 
1906 !----------------------------------------------------------------------
1907 ! Function: func_cx_to_cxu
1908 !> Conversion from global to universe on subset Scx
1909 !----------------------------------------------------------------------
1910 function func_cx_to_cxu(nproc,proc_to_cx_offset,proc_to_ncxa,myuniverse,icx) result(icxu)
1911 
1912 implicit none
1913 
1914 ! Passed variables
1915 integer,intent(in) :: nproc !< Number of processors
1916 integer,intent(in) :: proc_to_cx_offset(nproc) !< Processor to offset on subset Scx
1917 integer,intent(in) :: proc_to_ncxa(nproc) !< Processor to halo A size for subset Scx
1918 logical,intent(in) :: myuniverse(nproc) !< Task universe
1919 integer,intent(in) :: icx !< Global index
1920 
1921 ! Returned variable
1922 integer :: icxu
1923 
1924 ! Local variable
1925 integer :: iproc,icxa,offset,jproc
1926 
1927 ! Set name
1928 
1929 
1930 ! Probe in
1931 
1932 
1933 ! Find processor
1934 iproc = cx_to_proc(nproc,proc_to_cx_offset,icx)
1935 
1936 if (myuniverse(iproc)) then
1937  ! Get halo A index
1938  icxa = icx-proc_to_cx_offset(iproc)
1939 
1940  ! Compute universe offset
1941  offset = 0
1942  do jproc=1,iproc-1
1943  if (myuniverse(jproc)) offset = offset+proc_to_ncxa(jproc)
1944  end do
1945 
1946  ! Get universe index
1947  icxu = offset+icxa
1948 else
1949  ! Not in my universe
1950  icxu = 0
1951 end if
1952 
1953 ! Probe out
1954 
1955 
1956 end function func_cx_to_cxu
1957 
1958 !----------------------------------------------------------------------
1959 ! Subroutine: func_convert_i2l_r0
1960 !> Convert integer to logical
1961 !----------------------------------------------------------------------
1962 subroutine func_convert_i2l_r0(mpl,fldi,fldl)
1963 
1964 implicit none
1965 
1966 ! Passed variables
1967 type(mpl_type),intent(inout) :: mpl !< MPI data
1968 integer,intent(in) :: fldi !< Integer field
1969 logical,intent(out) :: fldl !< Logical field
1970 
1971 ! Set name
1972 
1973 
1974 ! Probe in
1975 
1976 
1977 if (fldi==0) then
1978  fldl = .false.
1979 elseif (fldi==1) then
1980  fldl = .true.
1981 else
1982  call mpl%abort('func_convert_i2l_r0','wrong integer value')
1983 end if
1984 
1985 ! Probe out
1986 
1987 
1988 end subroutine func_convert_i2l_r0
1989 
1990 # 1865 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
1991 !----------------------------------------------------------------------
1992 ! Subroutine: func_convert_i2l_r1
1993 !> Convert integer to logical
1994 !----------------------------------------------------------------------
1995 subroutine func_convert_i2l_r1(mpl,fldi,fldl)
1996 
1997 implicit none
1998 
1999 ! Passed variables
2000 type(mpl_type),intent(inout) :: mpl !< MPI data
2001 integer,intent(in) :: fldi(:) !< Integer field
2002 logical,intent(out) :: fldl(:) !< Logical field
2003 
2004 ! Local variable
2005 # 1880 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2006 integer :: i1
2007 # 1882 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2008 
2009 ! Set name
2010 
2011 
2012 ! Probe in
2013 
2014 
2015 # 1890 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2016 do i1=1,size(fldl,1)
2017 # 1892 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2018  call convert_i2l(mpl,fldi( &
2019 # 1896 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2020  & i1),fldl( &
2021 # 1900 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2022  & i1))
2023 # 1902 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2024 end do
2025 # 1904 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2026 
2027 ! Probe out
2028 
2029 
2030 end subroutine func_convert_i2l_r1
2031 # 1865 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2032 !----------------------------------------------------------------------
2033 ! Subroutine: func_convert_i2l_r2
2034 !> Convert integer to logical
2035 !----------------------------------------------------------------------
2036 subroutine func_convert_i2l_r2(mpl,fldi,fldl)
2037 
2038 implicit none
2039 
2040 ! Passed variables
2041 type(mpl_type),intent(inout) :: mpl !< MPI data
2042 integer,intent(in) :: fldi(:,:) !< Integer field
2043 logical,intent(out) :: fldl(:,:) !< Logical field
2044 
2045 ! Local variable
2046 # 1880 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2047 integer :: i1
2048 # 1880 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2049 integer :: i2
2050 # 1882 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2051 
2052 ! Set name
2053 
2054 
2055 ! Probe in
2056 
2057 
2058 # 1890 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2059 do i2=1,size(fldl,2)
2060 # 1890 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2061 do i1=1,size(fldl,1)
2062 # 1892 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2063  call convert_i2l(mpl,fldi( &
2064 # 1894 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2065  & i1, &
2066 # 1896 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2067  & i2),fldl( &
2068 # 1898 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2069  & i1, &
2070 # 1900 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2071  & i2))
2072 # 1902 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2073 end do
2074 # 1902 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2075 end do
2076 # 1904 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2077 
2078 ! Probe out
2079 
2080 
2081 end subroutine func_convert_i2l_r2
2082 # 1865 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2083 !----------------------------------------------------------------------
2084 ! Subroutine: func_convert_i2l_r3
2085 !> Convert integer to logical
2086 !----------------------------------------------------------------------
2087 subroutine func_convert_i2l_r3(mpl,fldi,fldl)
2088 
2089 implicit none
2090 
2091 ! Passed variables
2092 type(mpl_type),intent(inout) :: mpl !< MPI data
2093 integer,intent(in) :: fldi(:,:,:) !< Integer field
2094 logical,intent(out) :: fldl(:,:,:) !< Logical field
2095 
2096 ! Local variable
2097 # 1880 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2098 integer :: i1
2099 # 1880 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2100 integer :: i2
2101 # 1880 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2102 integer :: i3
2103 # 1882 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2104 
2105 ! Set name
2106 
2107 
2108 ! Probe in
2109 
2110 
2111 # 1890 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2112 do i3=1,size(fldl,3)
2113 # 1890 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2114 do i2=1,size(fldl,2)
2115 # 1890 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2116 do i1=1,size(fldl,1)
2117 # 1892 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2118  call convert_i2l(mpl,fldi( &
2119 # 1894 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2120  & i1, &
2121 # 1894 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2122  & i2, &
2123 # 1896 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2124  & i3),fldl( &
2125 # 1898 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2126  & i1, &
2127 # 1898 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2128  & i2, &
2129 # 1900 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2130  & i3))
2131 # 1902 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2132 end do
2133 # 1902 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2134 end do
2135 # 1902 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2136 end do
2137 # 1904 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2138 
2139 ! Probe out
2140 
2141 
2142 end subroutine func_convert_i2l_r3
2143 # 1865 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2144 !----------------------------------------------------------------------
2145 ! Subroutine: func_convert_i2l_r4
2146 !> Convert integer to logical
2147 !----------------------------------------------------------------------
2148 subroutine func_convert_i2l_r4(mpl,fldi,fldl)
2149 
2150 implicit none
2151 
2152 ! Passed variables
2153 type(mpl_type),intent(inout) :: mpl !< MPI data
2154 integer,intent(in) :: fldi(:,:,:,:) !< Integer field
2155 logical,intent(out) :: fldl(:,:,:,:) !< Logical field
2156 
2157 ! Local variable
2158 # 1880 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2159 integer :: i1
2160 # 1880 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2161 integer :: i2
2162 # 1880 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2163 integer :: i3
2164 # 1880 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2165 integer :: i4
2166 # 1882 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2167 
2168 ! Set name
2169 
2170 
2171 ! Probe in
2172 
2173 
2174 # 1890 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2175 do i4=1,size(fldl,4)
2176 # 1890 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2177 do i3=1,size(fldl,3)
2178 # 1890 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2179 do i2=1,size(fldl,2)
2180 # 1890 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2181 do i1=1,size(fldl,1)
2182 # 1892 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2183  call convert_i2l(mpl,fldi( &
2184 # 1894 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2185  & i1, &
2186 # 1894 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2187  & i2, &
2188 # 1894 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2189  & i3, &
2190 # 1896 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2191  & i4),fldl( &
2192 # 1898 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2193  & i1, &
2194 # 1898 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2195  & i2, &
2196 # 1898 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2197  & i3, &
2198 # 1900 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2199  & i4))
2200 # 1902 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2201 end do
2202 # 1902 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2203 end do
2204 # 1902 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2205 end do
2206 # 1902 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2207 end do
2208 # 1904 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2209 
2210 ! Probe out
2211 
2212 
2213 end subroutine func_convert_i2l_r4
2214 # 1910 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2215 
2216 !----------------------------------------------------------------------
2217 ! Subroutine: func_convert_l2i_r0
2218 !> Convert logical to integer
2219 !----------------------------------------------------------------------
2220 subroutine func_convert_l2i_r0(fldl,fldi)
2221 
2222 implicit none
2223 
2224 ! Passed variables
2225 logical,intent(in) :: fldl !< Logical field
2226 integer,intent(out) :: fldi !< Integer field
2227 
2228 ! Set name
2229 
2230 
2231 ! Probe in
2232 
2233 
2234 if (fldl) then
2235  fldi = 1
2236 else
2237  fldi = 0
2238 end if
2239 
2240 ! Probe out
2241 
2242 
2243 end subroutine func_convert_l2i_r0
2244 
2245 # 1941 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2246 !----------------------------------------------------------------------
2247 ! Subroutine: func_convert_l2i_r1
2248 !> Convert logical to integer
2249 !----------------------------------------------------------------------
2250 subroutine func_convert_l2i_r1(fldl,fldi)
2251 
2252 implicit none
2253 
2254 ! Passed variables
2255 logical,intent(in) :: fldl(:) !< Logical field
2256 integer,intent(out) :: fldi(:) !< Integer field
2257 
2258 ! Local variable
2259 # 1955 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2260 integer :: i1
2261 # 1957 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2262 
2263 ! Set name
2264 
2265 
2266 ! Probe in
2267 
2268 
2269 # 1965 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2270 do i1=1,size(fldl,1)
2271 # 1967 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2272  call convert_l2i(fldl( &
2273 # 1971 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2274  & i1),fldi( &
2275 # 1975 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2276  & i1))
2277 # 1977 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2278 end do
2279 # 1979 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2280 
2281 ! Probe out
2282 
2283 
2284 end subroutine func_convert_l2i_r1
2285 # 1941 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2286 !----------------------------------------------------------------------
2287 ! Subroutine: func_convert_l2i_r2
2288 !> Convert logical to integer
2289 !----------------------------------------------------------------------
2290 subroutine func_convert_l2i_r2(fldl,fldi)
2291 
2292 implicit none
2293 
2294 ! Passed variables
2295 logical,intent(in) :: fldl(:,:) !< Logical field
2296 integer,intent(out) :: fldi(:,:) !< Integer field
2297 
2298 ! Local variable
2299 # 1955 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2300 integer :: i1
2301 # 1955 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2302 integer :: i2
2303 # 1957 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2304 
2305 ! Set name
2306 
2307 
2308 ! Probe in
2309 
2310 
2311 # 1965 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2312 do i2=1,size(fldl,2)
2313 # 1965 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2314 do i1=1,size(fldl,1)
2315 # 1967 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2316  call convert_l2i(fldl( &
2317 # 1969 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2318  & i1, &
2319 # 1971 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2320  & i2),fldi( &
2321 # 1973 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2322  & i1, &
2323 # 1975 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2324  & i2))
2325 # 1977 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2326 end do
2327 # 1977 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2328 end do
2329 # 1979 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2330 
2331 ! Probe out
2332 
2333 
2334 end subroutine func_convert_l2i_r2
2335 # 1941 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2336 !----------------------------------------------------------------------
2337 ! Subroutine: func_convert_l2i_r3
2338 !> Convert logical to integer
2339 !----------------------------------------------------------------------
2340 subroutine func_convert_l2i_r3(fldl,fldi)
2341 
2342 implicit none
2343 
2344 ! Passed variables
2345 logical,intent(in) :: fldl(:,:,:) !< Logical field
2346 integer,intent(out) :: fldi(:,:,:) !< Integer field
2347 
2348 ! Local variable
2349 # 1955 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2350 integer :: i1
2351 # 1955 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2352 integer :: i2
2353 # 1955 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2354 integer :: i3
2355 # 1957 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2356 
2357 ! Set name
2358 
2359 
2360 ! Probe in
2361 
2362 
2363 # 1965 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2364 do i3=1,size(fldl,3)
2365 # 1965 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2366 do i2=1,size(fldl,2)
2367 # 1965 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2368 do i1=1,size(fldl,1)
2369 # 1967 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2370  call convert_l2i(fldl( &
2371 # 1969 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2372  & i1, &
2373 # 1969 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2374  & i2, &
2375 # 1971 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2376  & i3),fldi( &
2377 # 1973 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2378  & i1, &
2379 # 1973 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2380  & i2, &
2381 # 1975 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2382  & i3))
2383 # 1977 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2384 end do
2385 # 1977 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2386 end do
2387 # 1977 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2388 end do
2389 # 1979 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2390 
2391 ! Probe out
2392 
2393 
2394 end subroutine func_convert_l2i_r3
2395 # 1941 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2396 !----------------------------------------------------------------------
2397 ! Subroutine: func_convert_l2i_r4
2398 !> Convert logical to integer
2399 !----------------------------------------------------------------------
2400 subroutine func_convert_l2i_r4(fldl,fldi)
2401 
2402 implicit none
2403 
2404 ! Passed variables
2405 logical,intent(in) :: fldl(:,:,:,:) !< Logical field
2406 integer,intent(out) :: fldi(:,:,:,:) !< Integer field
2407 
2408 ! Local variable
2409 # 1955 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2410 integer :: i1
2411 # 1955 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2412 integer :: i2
2413 # 1955 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2414 integer :: i3
2415 # 1955 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2416 integer :: i4
2417 # 1957 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2418 
2419 ! Set name
2420 
2421 
2422 ! Probe in
2423 
2424 
2425 # 1965 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2426 do i4=1,size(fldl,4)
2427 # 1965 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2428 do i3=1,size(fldl,3)
2429 # 1965 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2430 do i2=1,size(fldl,2)
2431 # 1965 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2432 do i1=1,size(fldl,1)
2433 # 1967 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2434  call convert_l2i(fldl( &
2435 # 1969 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2436  & i1, &
2437 # 1969 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2438  & i2, &
2439 # 1969 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2440  & i3, &
2441 # 1971 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2442  & i4),fldi( &
2443 # 1973 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2444  & i1, &
2445 # 1973 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2446  & i2, &
2447 # 1973 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2448  & i3, &
2449 # 1975 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2450  & i4))
2451 # 1977 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2452 end do
2453 # 1977 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2454 end do
2455 # 1977 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2456 end do
2457 # 1977 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2458 end do
2459 # 1979 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2460 
2461 ! Probe out
2462 
2463 
2464 end subroutine func_convert_l2i_r4
2465 # 1985 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2466 
2467 # 1987 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2468 # 1988 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2469 !----------------------------------------------------------------------
2470 ! Function: func_zss_maxval_int_r1
2471 !> Zero-size-safe maxval function
2472 !----------------------------------------------------------------------
2473 function func_zss_maxval_int_r1(array,mask) result(value)
2474 
2475 implicit none
2476 
2477 ! Passed variables
2478 integer(kind_int),intent(in) :: array(:) !< Array
2479 logical,intent(in),optional :: mask(:) !< Mask
2480 
2481 ! Returned variable
2482 integer(kind_int) :: value
2483 
2484 ! Set name
2485 
2486 
2487 ! Probe in
2488 
2489 
2490 if (size(array)>0) then
2491  if (present(mask)) then
2492  if (any(mask)) then
2493  value = maxval(array,mask=mask)
2494  else
2495  value = -huge_int
2496  end if
2497  else
2498  value = maxval(array)
2499  end if
2500 else
2501  value = -huge_int
2502 endif
2503 
2504 ! Probe out
2505 
2506 
2507 end function func_zss_maxval_int_r1
2508 # 1988 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2509 !----------------------------------------------------------------------
2510 ! Function: func_zss_maxval_int_r2
2511 !> Zero-size-safe maxval function
2512 !----------------------------------------------------------------------
2513 function func_zss_maxval_int_r2(array,mask) result(value)
2514 
2515 implicit none
2516 
2517 ! Passed variables
2518 integer(kind_int),intent(in) :: array(:,:) !< Array
2519 logical,intent(in),optional :: mask(:,:) !< Mask
2520 
2521 ! Returned variable
2522 integer(kind_int) :: value
2523 
2524 ! Set name
2525 
2526 
2527 ! Probe in
2528 
2529 
2530 if (size(array)>0) then
2531  if (present(mask)) then
2532  if (any(mask)) then
2533  value = maxval(array,mask=mask)
2534  else
2535  value = -huge_int
2536  end if
2537  else
2538  value = maxval(array)
2539  end if
2540 else
2541  value = -huge_int
2542 endif
2543 
2544 ! Probe out
2545 
2546 
2547 end function func_zss_maxval_int_r2
2548 # 1988 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2549 !----------------------------------------------------------------------
2550 ! Function: func_zss_maxval_int_r3
2551 !> Zero-size-safe maxval function
2552 !----------------------------------------------------------------------
2553 function func_zss_maxval_int_r3(array,mask) result(value)
2554 
2555 implicit none
2556 
2557 ! Passed variables
2558 integer(kind_int),intent(in) :: array(:,:,:) !< Array
2559 logical,intent(in),optional :: mask(:,:,:) !< Mask
2560 
2561 ! Returned variable
2562 integer(kind_int) :: value
2563 
2564 ! Set name
2565 
2566 
2567 ! Probe in
2568 
2569 
2570 if (size(array)>0) then
2571  if (present(mask)) then
2572  if (any(mask)) then
2573  value = maxval(array,mask=mask)
2574  else
2575  value = -huge_int
2576  end if
2577  else
2578  value = maxval(array)
2579  end if
2580 else
2581  value = -huge_int
2582 endif
2583 
2584 ! Probe out
2585 
2586 
2587 end function func_zss_maxval_int_r3
2588 # 1988 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2589 !----------------------------------------------------------------------
2590 ! Function: func_zss_maxval_int_r4
2591 !> Zero-size-safe maxval function
2592 !----------------------------------------------------------------------
2593 function func_zss_maxval_int_r4(array,mask) result(value)
2594 
2595 implicit none
2596 
2597 ! Passed variables
2598 integer(kind_int),intent(in) :: array(:,:,:,:) !< Array
2599 logical,intent(in),optional :: mask(:,:,:,:) !< Mask
2600 
2601 ! Returned variable
2602 integer(kind_int) :: value
2603 
2604 ! Set name
2605 
2606 
2607 ! Probe in
2608 
2609 
2610 if (size(array)>0) then
2611  if (present(mask)) then
2612  if (any(mask)) then
2613  value = maxval(array,mask=mask)
2614  else
2615  value = -huge_int
2616  end if
2617  else
2618  value = maxval(array)
2619  end if
2620 else
2621  value = -huge_int
2622 endif
2623 
2624 ! Probe out
2625 
2626 
2627 end function func_zss_maxval_int_r4
2628 # 1988 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2629 !----------------------------------------------------------------------
2630 ! Function: func_zss_maxval_int_r5
2631 !> Zero-size-safe maxval function
2632 !----------------------------------------------------------------------
2633 function func_zss_maxval_int_r5(array,mask) result(value)
2634 
2635 implicit none
2636 
2637 ! Passed variables
2638 integer(kind_int),intent(in) :: array(:,:,:,:,:) !< Array
2639 logical,intent(in),optional :: mask(:,:,:,:,:) !< Mask
2640 
2641 ! Returned variable
2642 integer(kind_int) :: value
2643 
2644 ! Set name
2645 
2646 
2647 ! Probe in
2648 
2649 
2650 if (size(array)>0) then
2651  if (present(mask)) then
2652  if (any(mask)) then
2653  value = maxval(array,mask=mask)
2654  else
2655  value = -huge_int
2656  end if
2657  else
2658  value = maxval(array)
2659  end if
2660 else
2661  value = -huge_int
2662 endif
2663 
2664 ! Probe out
2665 
2666 
2667 end function func_zss_maxval_int_r5
2668 # 1988 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2669 !----------------------------------------------------------------------
2670 ! Function: func_zss_maxval_int_r6
2671 !> Zero-size-safe maxval function
2672 !----------------------------------------------------------------------
2673 function func_zss_maxval_int_r6(array,mask) result(value)
2674 
2675 implicit none
2676 
2677 ! Passed variables
2678 integer(kind_int),intent(in) :: array(:,:,:,:,:,:) !< Array
2679 logical,intent(in),optional :: mask(:,:,:,:,:,:) !< Mask
2680 
2681 ! Returned variable
2682 integer(kind_int) :: value
2683 
2684 ! Set name
2685 
2686 
2687 ! Probe in
2688 
2689 
2690 if (size(array)>0) then
2691  if (present(mask)) then
2692  if (any(mask)) then
2693  value = maxval(array,mask=mask)
2694  else
2695  value = -huge_int
2696  end if
2697  else
2698  value = maxval(array)
2699  end if
2700 else
2701  value = -huge_int
2702 endif
2703 
2704 ! Probe out
2705 
2706 
2707 end function func_zss_maxval_int_r6
2708 # 2028 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2709 # 1987 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2710 # 1988 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2711 !----------------------------------------------------------------------
2712 ! Function: func_zss_maxval_real_r1
2713 !> Zero-size-safe maxval function
2714 !----------------------------------------------------------------------
2715 function func_zss_maxval_real_r1(array,mask) result(value)
2716 
2717 implicit none
2718 
2719 ! Passed variables
2720 real(kind_real),intent(in) :: array(:) !< Array
2721 logical,intent(in),optional :: mask(:) !< Mask
2722 
2723 ! Returned variable
2724 real(kind_real) :: value
2725 
2726 ! Set name
2727 
2728 
2729 ! Probe in
2730 
2731 
2732 if (size(array)>0) then
2733  if (present(mask)) then
2734  if (any(mask)) then
2735  value = maxval(array,mask=mask)
2736  else
2737  value = -huge_real
2738  end if
2739  else
2740  value = maxval(array)
2741  end if
2742 else
2743  value = -huge_real
2744 endif
2745 
2746 ! Probe out
2747 
2748 
2749 end function func_zss_maxval_real_r1
2750 # 1988 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2751 !----------------------------------------------------------------------
2752 ! Function: func_zss_maxval_real_r2
2753 !> Zero-size-safe maxval function
2754 !----------------------------------------------------------------------
2755 function func_zss_maxval_real_r2(array,mask) result(value)
2756 
2757 implicit none
2758 
2759 ! Passed variables
2760 real(kind_real),intent(in) :: array(:,:) !< Array
2761 logical,intent(in),optional :: mask(:,:) !< Mask
2762 
2763 ! Returned variable
2764 real(kind_real) :: value
2765 
2766 ! Set name
2767 
2768 
2769 ! Probe in
2770 
2771 
2772 if (size(array)>0) then
2773  if (present(mask)) then
2774  if (any(mask)) then
2775  value = maxval(array,mask=mask)
2776  else
2777  value = -huge_real
2778  end if
2779  else
2780  value = maxval(array)
2781  end if
2782 else
2783  value = -huge_real
2784 endif
2785 
2786 ! Probe out
2787 
2788 
2789 end function func_zss_maxval_real_r2
2790 # 1988 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2791 !----------------------------------------------------------------------
2792 ! Function: func_zss_maxval_real_r3
2793 !> Zero-size-safe maxval function
2794 !----------------------------------------------------------------------
2795 function func_zss_maxval_real_r3(array,mask) result(value)
2796 
2797 implicit none
2798 
2799 ! Passed variables
2800 real(kind_real),intent(in) :: array(:,:,:) !< Array
2801 logical,intent(in),optional :: mask(:,:,:) !< Mask
2802 
2803 ! Returned variable
2804 real(kind_real) :: value
2805 
2806 ! Set name
2807 
2808 
2809 ! Probe in
2810 
2811 
2812 if (size(array)>0) then
2813  if (present(mask)) then
2814  if (any(mask)) then
2815  value = maxval(array,mask=mask)
2816  else
2817  value = -huge_real
2818  end if
2819  else
2820  value = maxval(array)
2821  end if
2822 else
2823  value = -huge_real
2824 endif
2825 
2826 ! Probe out
2827 
2828 
2829 end function func_zss_maxval_real_r3
2830 # 1988 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2831 !----------------------------------------------------------------------
2832 ! Function: func_zss_maxval_real_r4
2833 !> Zero-size-safe maxval function
2834 !----------------------------------------------------------------------
2835 function func_zss_maxval_real_r4(array,mask) result(value)
2836 
2837 implicit none
2838 
2839 ! Passed variables
2840 real(kind_real),intent(in) :: array(:,:,:,:) !< Array
2841 logical,intent(in),optional :: mask(:,:,:,:) !< Mask
2842 
2843 ! Returned variable
2844 real(kind_real) :: value
2845 
2846 ! Set name
2847 
2848 
2849 ! Probe in
2850 
2851 
2852 if (size(array)>0) then
2853  if (present(mask)) then
2854  if (any(mask)) then
2855  value = maxval(array,mask=mask)
2856  else
2857  value = -huge_real
2858  end if
2859  else
2860  value = maxval(array)
2861  end if
2862 else
2863  value = -huge_real
2864 endif
2865 
2866 ! Probe out
2867 
2868 
2869 end function func_zss_maxval_real_r4
2870 # 1988 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2871 !----------------------------------------------------------------------
2872 ! Function: func_zss_maxval_real_r5
2873 !> Zero-size-safe maxval function
2874 !----------------------------------------------------------------------
2875 function func_zss_maxval_real_r5(array,mask) result(value)
2876 
2877 implicit none
2878 
2879 ! Passed variables
2880 real(kind_real),intent(in) :: array(:,:,:,:,:) !< Array
2881 logical,intent(in),optional :: mask(:,:,:,:,:) !< Mask
2882 
2883 ! Returned variable
2884 real(kind_real) :: value
2885 
2886 ! Set name
2887 
2888 
2889 ! Probe in
2890 
2891 
2892 if (size(array)>0) then
2893  if (present(mask)) then
2894  if (any(mask)) then
2895  value = maxval(array,mask=mask)
2896  else
2897  value = -huge_real
2898  end if
2899  else
2900  value = maxval(array)
2901  end if
2902 else
2903  value = -huge_real
2904 endif
2905 
2906 ! Probe out
2907 
2908 
2909 end function func_zss_maxval_real_r5
2910 # 1988 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2911 !----------------------------------------------------------------------
2912 ! Function: func_zss_maxval_real_r6
2913 !> Zero-size-safe maxval function
2914 !----------------------------------------------------------------------
2915 function func_zss_maxval_real_r6(array,mask) result(value)
2916 
2917 implicit none
2918 
2919 ! Passed variables
2920 real(kind_real),intent(in) :: array(:,:,:,:,:,:) !< Array
2921 logical,intent(in),optional :: mask(:,:,:,:,:,:) !< Mask
2922 
2923 ! Returned variable
2924 real(kind_real) :: value
2925 
2926 ! Set name
2927 
2928 
2929 ! Probe in
2930 
2931 
2932 if (size(array)>0) then
2933  if (present(mask)) then
2934  if (any(mask)) then
2935  value = maxval(array,mask=mask)
2936  else
2937  value = -huge_real
2938  end if
2939  else
2940  value = maxval(array)
2941  end if
2942 else
2943  value = -huge_real
2944 endif
2945 
2946 ! Probe out
2947 
2948 
2949 end function func_zss_maxval_real_r6
2950 # 2028 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2951 # 2029 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2952 
2953 # 2031 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2954 # 2032 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2955 !----------------------------------------------------------------------
2956 ! Function: func_zss_minval_int_r1
2957 !> Zero-size-safe minval function
2958 !----------------------------------------------------------------------
2959 function func_zss_minval_int_r1(array,mask) result(value)
2960 
2961 implicit none
2962 
2963 ! Passed variables
2964 integer(kind_int),intent(in) :: array(:) !< Array
2965 logical,intent(in),optional :: mask(:) !< Mask
2966 
2967 ! Returned variable
2968 integer(kind_int) :: value
2969 
2970 ! Set name
2971 
2972 
2973 ! Probe in
2974 
2975 
2976 if (size(array)>0) then
2977  if (present(mask)) then
2978  if (any(mask)) then
2979  value = minval(array,mask=mask)
2980  else
2981  value = huge_int
2982  end if
2983  else
2984  value = minval(array)
2985  end if
2986 else
2987  value = huge_int
2988 endif
2989 
2990 ! Probe out
2991 
2992 
2993 end function func_zss_minval_int_r1
2994 # 2032 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
2995 !----------------------------------------------------------------------
2996 ! Function: func_zss_minval_int_r2
2997 !> Zero-size-safe minval function
2998 !----------------------------------------------------------------------
2999 function func_zss_minval_int_r2(array,mask) result(value)
3000 
3001 implicit none
3002 
3003 ! Passed variables
3004 integer(kind_int),intent(in) :: array(:,:) !< Array
3005 logical,intent(in),optional :: mask(:,:) !< Mask
3006 
3007 ! Returned variable
3008 integer(kind_int) :: value
3009 
3010 ! Set name
3011 
3012 
3013 ! Probe in
3014 
3015 
3016 if (size(array)>0) then
3017  if (present(mask)) then
3018  if (any(mask)) then
3019  value = minval(array,mask=mask)
3020  else
3021  value = huge_int
3022  end if
3023  else
3024  value = minval(array)
3025  end if
3026 else
3027  value = huge_int
3028 endif
3029 
3030 ! Probe out
3031 
3032 
3033 end function func_zss_minval_int_r2
3034 # 2032 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3035 !----------------------------------------------------------------------
3036 ! Function: func_zss_minval_int_r3
3037 !> Zero-size-safe minval function
3038 !----------------------------------------------------------------------
3039 function func_zss_minval_int_r3(array,mask) result(value)
3040 
3041 implicit none
3042 
3043 ! Passed variables
3044 integer(kind_int),intent(in) :: array(:,:,:) !< Array
3045 logical,intent(in),optional :: mask(:,:,:) !< Mask
3046 
3047 ! Returned variable
3048 integer(kind_int) :: value
3049 
3050 ! Set name
3051 
3052 
3053 ! Probe in
3054 
3055 
3056 if (size(array)>0) then
3057  if (present(mask)) then
3058  if (any(mask)) then
3059  value = minval(array,mask=mask)
3060  else
3061  value = huge_int
3062  end if
3063  else
3064  value = minval(array)
3065  end if
3066 else
3067  value = huge_int
3068 endif
3069 
3070 ! Probe out
3071 
3072 
3073 end function func_zss_minval_int_r3
3074 # 2032 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3075 !----------------------------------------------------------------------
3076 ! Function: func_zss_minval_int_r4
3077 !> Zero-size-safe minval function
3078 !----------------------------------------------------------------------
3079 function func_zss_minval_int_r4(array,mask) result(value)
3080 
3081 implicit none
3082 
3083 ! Passed variables
3084 integer(kind_int),intent(in) :: array(:,:,:,:) !< Array
3085 logical,intent(in),optional :: mask(:,:,:,:) !< Mask
3086 
3087 ! Returned variable
3088 integer(kind_int) :: value
3089 
3090 ! Set name
3091 
3092 
3093 ! Probe in
3094 
3095 
3096 if (size(array)>0) then
3097  if (present(mask)) then
3098  if (any(mask)) then
3099  value = minval(array,mask=mask)
3100  else
3101  value = huge_int
3102  end if
3103  else
3104  value = minval(array)
3105  end if
3106 else
3107  value = huge_int
3108 endif
3109 
3110 ! Probe out
3111 
3112 
3113 end function func_zss_minval_int_r4
3114 # 2032 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3115 !----------------------------------------------------------------------
3116 ! Function: func_zss_minval_int_r5
3117 !> Zero-size-safe minval function
3118 !----------------------------------------------------------------------
3119 function func_zss_minval_int_r5(array,mask) result(value)
3120 
3121 implicit none
3122 
3123 ! Passed variables
3124 integer(kind_int),intent(in) :: array(:,:,:,:,:) !< Array
3125 logical,intent(in),optional :: mask(:,:,:,:,:) !< Mask
3126 
3127 ! Returned variable
3128 integer(kind_int) :: value
3129 
3130 ! Set name
3131 
3132 
3133 ! Probe in
3134 
3135 
3136 if (size(array)>0) then
3137  if (present(mask)) then
3138  if (any(mask)) then
3139  value = minval(array,mask=mask)
3140  else
3141  value = huge_int
3142  end if
3143  else
3144  value = minval(array)
3145  end if
3146 else
3147  value = huge_int
3148 endif
3149 
3150 ! Probe out
3151 
3152 
3153 end function func_zss_minval_int_r5
3154 # 2032 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3155 !----------------------------------------------------------------------
3156 ! Function: func_zss_minval_int_r6
3157 !> Zero-size-safe minval function
3158 !----------------------------------------------------------------------
3159 function func_zss_minval_int_r6(array,mask) result(value)
3160 
3161 implicit none
3162 
3163 ! Passed variables
3164 integer(kind_int),intent(in) :: array(:,:,:,:,:,:) !< Array
3165 logical,intent(in),optional :: mask(:,:,:,:,:,:) !< Mask
3166 
3167 ! Returned variable
3168 integer(kind_int) :: value
3169 
3170 ! Set name
3171 
3172 
3173 ! Probe in
3174 
3175 
3176 if (size(array)>0) then
3177  if (present(mask)) then
3178  if (any(mask)) then
3179  value = minval(array,mask=mask)
3180  else
3181  value = huge_int
3182  end if
3183  else
3184  value = minval(array)
3185  end if
3186 else
3187  value = huge_int
3188 endif
3189 
3190 ! Probe out
3191 
3192 
3193 end function func_zss_minval_int_r6
3194 # 2072 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3195 # 2031 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3196 # 2032 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3197 !----------------------------------------------------------------------
3198 ! Function: func_zss_minval_real_r1
3199 !> Zero-size-safe minval function
3200 !----------------------------------------------------------------------
3201 function func_zss_minval_real_r1(array,mask) result(value)
3202 
3203 implicit none
3204 
3205 ! Passed variables
3206 real(kind_real),intent(in) :: array(:) !< Array
3207 logical,intent(in),optional :: mask(:) !< Mask
3208 
3209 ! Returned variable
3210 real(kind_real) :: value
3211 
3212 ! Set name
3213 
3214 
3215 ! Probe in
3216 
3217 
3218 if (size(array)>0) then
3219  if (present(mask)) then
3220  if (any(mask)) then
3221  value = minval(array,mask=mask)
3222  else
3223  value = huge_real
3224  end if
3225  else
3226  value = minval(array)
3227  end if
3228 else
3229  value = huge_real
3230 endif
3231 
3232 ! Probe out
3233 
3234 
3235 end function func_zss_minval_real_r1
3236 # 2032 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3237 !----------------------------------------------------------------------
3238 ! Function: func_zss_minval_real_r2
3239 !> Zero-size-safe minval function
3240 !----------------------------------------------------------------------
3241 function func_zss_minval_real_r2(array,mask) result(value)
3242 
3243 implicit none
3244 
3245 ! Passed variables
3246 real(kind_real),intent(in) :: array(:,:) !< Array
3247 logical,intent(in),optional :: mask(:,:) !< Mask
3248 
3249 ! Returned variable
3250 real(kind_real) :: value
3251 
3252 ! Set name
3253 
3254 
3255 ! Probe in
3256 
3257 
3258 if (size(array)>0) then
3259  if (present(mask)) then
3260  if (any(mask)) then
3261  value = minval(array,mask=mask)
3262  else
3263  value = huge_real
3264  end if
3265  else
3266  value = minval(array)
3267  end if
3268 else
3269  value = huge_real
3270 endif
3271 
3272 ! Probe out
3273 
3274 
3275 end function func_zss_minval_real_r2
3276 # 2032 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3277 !----------------------------------------------------------------------
3278 ! Function: func_zss_minval_real_r3
3279 !> Zero-size-safe minval function
3280 !----------------------------------------------------------------------
3281 function func_zss_minval_real_r3(array,mask) result(value)
3282 
3283 implicit none
3284 
3285 ! Passed variables
3286 real(kind_real),intent(in) :: array(:,:,:) !< Array
3287 logical,intent(in),optional :: mask(:,:,:) !< Mask
3288 
3289 ! Returned variable
3290 real(kind_real) :: value
3291 
3292 ! Set name
3293 
3294 
3295 ! Probe in
3296 
3297 
3298 if (size(array)>0) then
3299  if (present(mask)) then
3300  if (any(mask)) then
3301  value = minval(array,mask=mask)
3302  else
3303  value = huge_real
3304  end if
3305  else
3306  value = minval(array)
3307  end if
3308 else
3309  value = huge_real
3310 endif
3311 
3312 ! Probe out
3313 
3314 
3315 end function func_zss_minval_real_r3
3316 # 2032 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3317 !----------------------------------------------------------------------
3318 ! Function: func_zss_minval_real_r4
3319 !> Zero-size-safe minval function
3320 !----------------------------------------------------------------------
3321 function func_zss_minval_real_r4(array,mask) result(value)
3322 
3323 implicit none
3324 
3325 ! Passed variables
3326 real(kind_real),intent(in) :: array(:,:,:,:) !< Array
3327 logical,intent(in),optional :: mask(:,:,:,:) !< Mask
3328 
3329 ! Returned variable
3330 real(kind_real) :: value
3331 
3332 ! Set name
3333 
3334 
3335 ! Probe in
3336 
3337 
3338 if (size(array)>0) then
3339  if (present(mask)) then
3340  if (any(mask)) then
3341  value = minval(array,mask=mask)
3342  else
3343  value = huge_real
3344  end if
3345  else
3346  value = minval(array)
3347  end if
3348 else
3349  value = huge_real
3350 endif
3351 
3352 ! Probe out
3353 
3354 
3355 end function func_zss_minval_real_r4
3356 # 2032 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3357 !----------------------------------------------------------------------
3358 ! Function: func_zss_minval_real_r5
3359 !> Zero-size-safe minval function
3360 !----------------------------------------------------------------------
3361 function func_zss_minval_real_r5(array,mask) result(value)
3362 
3363 implicit none
3364 
3365 ! Passed variables
3366 real(kind_real),intent(in) :: array(:,:,:,:,:) !< Array
3367 logical,intent(in),optional :: mask(:,:,:,:,:) !< Mask
3368 
3369 ! Returned variable
3370 real(kind_real) :: value
3371 
3372 ! Set name
3373 
3374 
3375 ! Probe in
3376 
3377 
3378 if (size(array)>0) then
3379  if (present(mask)) then
3380  if (any(mask)) then
3381  value = minval(array,mask=mask)
3382  else
3383  value = huge_real
3384  end if
3385  else
3386  value = minval(array)
3387  end if
3388 else
3389  value = huge_real
3390 endif
3391 
3392 ! Probe out
3393 
3394 
3395 end function func_zss_minval_real_r5
3396 # 2032 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3397 !----------------------------------------------------------------------
3398 ! Function: func_zss_minval_real_r6
3399 !> Zero-size-safe minval function
3400 !----------------------------------------------------------------------
3401 function func_zss_minval_real_r6(array,mask) result(value)
3402 
3403 implicit none
3404 
3405 ! Passed variables
3406 real(kind_real),intent(in) :: array(:,:,:,:,:,:) !< Array
3407 logical,intent(in),optional :: mask(:,:,:,:,:,:) !< Mask
3408 
3409 ! Returned variable
3410 real(kind_real) :: value
3411 
3412 ! Set name
3413 
3414 
3415 ! Probe in
3416 
3417 
3418 if (size(array)>0) then
3419  if (present(mask)) then
3420  if (any(mask)) then
3421  value = minval(array,mask=mask)
3422  else
3423  value = huge_real
3424  end if
3425  else
3426  value = minval(array)
3427  end if
3428 else
3429  value = huge_real
3430 endif
3431 
3432 ! Probe out
3433 
3434 
3435 end function func_zss_minval_real_r6
3436 # 2072 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3437 # 2073 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3438 
3439 # 2075 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3440 # 2076 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3441 !----------------------------------------------------------------------
3442 ! Function: func_zss_sum_int_r1
3443 !> Zero-size-safe sum function
3444 !----------------------------------------------------------------------
3445 function func_zss_sum_int_r1(array,mask) result(value)
3446 
3447 implicit none
3448 
3449 ! Passed variables
3450 integer(kind_int),intent(in) :: array(:) !< Array
3451 logical,intent(in),optional :: mask(:) !< Mask
3452 
3453 ! Returned variable
3454 integer(kind_int) :: value
3455 
3456 ! Set name
3457 
3458 
3459 ! Probe in
3460 
3461 
3462 if (size(array)>0) then
3463  if (present(mask)) then
3464  if (any(mask)) then
3465  value = sum(array,mask=mask)
3466  else
3467  value = 0
3468  end if
3469  else
3470  value = sum(array)
3471  end if
3472 else
3473  value = 0
3474 endif
3475 
3476 ! Probe out
3477 
3478 
3479 end function func_zss_sum_int_r1
3480 # 2076 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3481 !----------------------------------------------------------------------
3482 ! Function: func_zss_sum_int_r2
3483 !> Zero-size-safe sum function
3484 !----------------------------------------------------------------------
3485 function func_zss_sum_int_r2(array,mask) result(value)
3486 
3487 implicit none
3488 
3489 ! Passed variables
3490 integer(kind_int),intent(in) :: array(:,:) !< Array
3491 logical,intent(in),optional :: mask(:,:) !< Mask
3492 
3493 ! Returned variable
3494 integer(kind_int) :: value
3495 
3496 ! Set name
3497 
3498 
3499 ! Probe in
3500 
3501 
3502 if (size(array)>0) then
3503  if (present(mask)) then
3504  if (any(mask)) then
3505  value = sum(array,mask=mask)
3506  else
3507  value = 0
3508  end if
3509  else
3510  value = sum(array)
3511  end if
3512 else
3513  value = 0
3514 endif
3515 
3516 ! Probe out
3517 
3518 
3519 end function func_zss_sum_int_r2
3520 # 2076 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3521 !----------------------------------------------------------------------
3522 ! Function: func_zss_sum_int_r3
3523 !> Zero-size-safe sum function
3524 !----------------------------------------------------------------------
3525 function func_zss_sum_int_r3(array,mask) result(value)
3526 
3527 implicit none
3528 
3529 ! Passed variables
3530 integer(kind_int),intent(in) :: array(:,:,:) !< Array
3531 logical,intent(in),optional :: mask(:,:,:) !< Mask
3532 
3533 ! Returned variable
3534 integer(kind_int) :: value
3535 
3536 ! Set name
3537 
3538 
3539 ! Probe in
3540 
3541 
3542 if (size(array)>0) then
3543  if (present(mask)) then
3544  if (any(mask)) then
3545  value = sum(array,mask=mask)
3546  else
3547  value = 0
3548  end if
3549  else
3550  value = sum(array)
3551  end if
3552 else
3553  value = 0
3554 endif
3555 
3556 ! Probe out
3557 
3558 
3559 end function func_zss_sum_int_r3
3560 # 2076 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3561 !----------------------------------------------------------------------
3562 ! Function: func_zss_sum_int_r4
3563 !> Zero-size-safe sum function
3564 !----------------------------------------------------------------------
3565 function func_zss_sum_int_r4(array,mask) result(value)
3566 
3567 implicit none
3568 
3569 ! Passed variables
3570 integer(kind_int),intent(in) :: array(:,:,:,:) !< Array
3571 logical,intent(in),optional :: mask(:,:,:,:) !< Mask
3572 
3573 ! Returned variable
3574 integer(kind_int) :: value
3575 
3576 ! Set name
3577 
3578 
3579 ! Probe in
3580 
3581 
3582 if (size(array)>0) then
3583  if (present(mask)) then
3584  if (any(mask)) then
3585  value = sum(array,mask=mask)
3586  else
3587  value = 0
3588  end if
3589  else
3590  value = sum(array)
3591  end if
3592 else
3593  value = 0
3594 endif
3595 
3596 ! Probe out
3597 
3598 
3599 end function func_zss_sum_int_r4
3600 # 2076 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3601 !----------------------------------------------------------------------
3602 ! Function: func_zss_sum_int_r5
3603 !> Zero-size-safe sum function
3604 !----------------------------------------------------------------------
3605 function func_zss_sum_int_r5(array,mask) result(value)
3606 
3607 implicit none
3608 
3609 ! Passed variables
3610 integer(kind_int),intent(in) :: array(:,:,:,:,:) !< Array
3611 logical,intent(in),optional :: mask(:,:,:,:,:) !< Mask
3612 
3613 ! Returned variable
3614 integer(kind_int) :: value
3615 
3616 ! Set name
3617 
3618 
3619 ! Probe in
3620 
3621 
3622 if (size(array)>0) then
3623  if (present(mask)) then
3624  if (any(mask)) then
3625  value = sum(array,mask=mask)
3626  else
3627  value = 0
3628  end if
3629  else
3630  value = sum(array)
3631  end if
3632 else
3633  value = 0
3634 endif
3635 
3636 ! Probe out
3637 
3638 
3639 end function func_zss_sum_int_r5
3640 # 2076 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3641 !----------------------------------------------------------------------
3642 ! Function: func_zss_sum_int_r6
3643 !> Zero-size-safe sum function
3644 !----------------------------------------------------------------------
3645 function func_zss_sum_int_r6(array,mask) result(value)
3646 
3647 implicit none
3648 
3649 ! Passed variables
3650 integer(kind_int),intent(in) :: array(:,:,:,:,:,:) !< Array
3651 logical,intent(in),optional :: mask(:,:,:,:,:,:) !< Mask
3652 
3653 ! Returned variable
3654 integer(kind_int) :: value
3655 
3656 ! Set name
3657 
3658 
3659 ! Probe in
3660 
3661 
3662 if (size(array)>0) then
3663  if (present(mask)) then
3664  if (any(mask)) then
3665  value = sum(array,mask=mask)
3666  else
3667  value = 0
3668  end if
3669  else
3670  value = sum(array)
3671  end if
3672 else
3673  value = 0
3674 endif
3675 
3676 ! Probe out
3677 
3678 
3679 end function func_zss_sum_int_r6
3680 # 2116 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3681 # 2075 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3682 # 2076 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3683 !----------------------------------------------------------------------
3684 ! Function: func_zss_sum_real_r1
3685 !> Zero-size-safe sum function
3686 !----------------------------------------------------------------------
3687 function func_zss_sum_real_r1(array,mask) result(value)
3688 
3689 implicit none
3690 
3691 ! Passed variables
3692 real(kind_real),intent(in) :: array(:) !< Array
3693 logical,intent(in),optional :: mask(:) !< Mask
3694 
3695 ! Returned variable
3696 real(kind_real) :: value
3697 
3698 ! Set name
3699 
3700 
3701 ! Probe in
3702 
3703 
3704 if (size(array)>0) then
3705  if (present(mask)) then
3706  if (any(mask)) then
3707  value = sum(array,mask=mask)
3708  else
3709  value = 0.0_kind_real
3710  end if
3711  else
3712  value = sum(array)
3713  end if
3714 else
3715  value = 0.0_kind_real
3716 endif
3717 
3718 ! Probe out
3719 
3720 
3721 end function func_zss_sum_real_r1
3722 # 2076 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3723 !----------------------------------------------------------------------
3724 ! Function: func_zss_sum_real_r2
3725 !> Zero-size-safe sum function
3726 !----------------------------------------------------------------------
3727 function func_zss_sum_real_r2(array,mask) result(value)
3728 
3729 implicit none
3730 
3731 ! Passed variables
3732 real(kind_real),intent(in) :: array(:,:) !< Array
3733 logical,intent(in),optional :: mask(:,:) !< Mask
3734 
3735 ! Returned variable
3736 real(kind_real) :: value
3737 
3738 ! Set name
3739 
3740 
3741 ! Probe in
3742 
3743 
3744 if (size(array)>0) then
3745  if (present(mask)) then
3746  if (any(mask)) then
3747  value = sum(array,mask=mask)
3748  else
3749  value = 0.0_kind_real
3750  end if
3751  else
3752  value = sum(array)
3753  end if
3754 else
3755  value = 0.0_kind_real
3756 endif
3757 
3758 ! Probe out
3759 
3760 
3761 end function func_zss_sum_real_r2
3762 # 2076 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3763 !----------------------------------------------------------------------
3764 ! Function: func_zss_sum_real_r3
3765 !> Zero-size-safe sum function
3766 !----------------------------------------------------------------------
3767 function func_zss_sum_real_r3(array,mask) result(value)
3768 
3769 implicit none
3770 
3771 ! Passed variables
3772 real(kind_real),intent(in) :: array(:,:,:) !< Array
3773 logical,intent(in),optional :: mask(:,:,:) !< Mask
3774 
3775 ! Returned variable
3776 real(kind_real) :: value
3777 
3778 ! Set name
3779 
3780 
3781 ! Probe in
3782 
3783 
3784 if (size(array)>0) then
3785  if (present(mask)) then
3786  if (any(mask)) then
3787  value = sum(array,mask=mask)
3788  else
3789  value = 0.0_kind_real
3790  end if
3791  else
3792  value = sum(array)
3793  end if
3794 else
3795  value = 0.0_kind_real
3796 endif
3797 
3798 ! Probe out
3799 
3800 
3801 end function func_zss_sum_real_r3
3802 # 2076 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3803 !----------------------------------------------------------------------
3804 ! Function: func_zss_sum_real_r4
3805 !> Zero-size-safe sum function
3806 !----------------------------------------------------------------------
3807 function func_zss_sum_real_r4(array,mask) result(value)
3808 
3809 implicit none
3810 
3811 ! Passed variables
3812 real(kind_real),intent(in) :: array(:,:,:,:) !< Array
3813 logical,intent(in),optional :: mask(:,:,:,:) !< Mask
3814 
3815 ! Returned variable
3816 real(kind_real) :: value
3817 
3818 ! Set name
3819 
3820 
3821 ! Probe in
3822 
3823 
3824 if (size(array)>0) then
3825  if (present(mask)) then
3826  if (any(mask)) then
3827  value = sum(array,mask=mask)
3828  else
3829  value = 0.0_kind_real
3830  end if
3831  else
3832  value = sum(array)
3833  end if
3834 else
3835  value = 0.0_kind_real
3836 endif
3837 
3838 ! Probe out
3839 
3840 
3841 end function func_zss_sum_real_r4
3842 # 2076 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3843 !----------------------------------------------------------------------
3844 ! Function: func_zss_sum_real_r5
3845 !> Zero-size-safe sum function
3846 !----------------------------------------------------------------------
3847 function func_zss_sum_real_r5(array,mask) result(value)
3848 
3849 implicit none
3850 
3851 ! Passed variables
3852 real(kind_real),intent(in) :: array(:,:,:,:,:) !< Array
3853 logical,intent(in),optional :: mask(:,:,:,:,:) !< Mask
3854 
3855 ! Returned variable
3856 real(kind_real) :: value
3857 
3858 ! Set name
3859 
3860 
3861 ! Probe in
3862 
3863 
3864 if (size(array)>0) then
3865  if (present(mask)) then
3866  if (any(mask)) then
3867  value = sum(array,mask=mask)
3868  else
3869  value = 0.0_kind_real
3870  end if
3871  else
3872  value = sum(array)
3873  end if
3874 else
3875  value = 0.0_kind_real
3876 endif
3877 
3878 ! Probe out
3879 
3880 
3881 end function func_zss_sum_real_r5
3882 # 2076 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3883 !----------------------------------------------------------------------
3884 ! Function: func_zss_sum_real_r6
3885 !> Zero-size-safe sum function
3886 !----------------------------------------------------------------------
3887 function func_zss_sum_real_r6(array,mask) result(value)
3888 
3889 implicit none
3890 
3891 ! Passed variables
3892 real(kind_real),intent(in) :: array(:,:,:,:,:,:) !< Array
3893 logical,intent(in),optional :: mask(:,:,:,:,:,:) !< Mask
3894 
3895 ! Returned variable
3896 real(kind_real) :: value
3897 
3898 ! Set name
3899 
3900 
3901 ! Probe in
3902 
3903 
3904 if (size(array)>0) then
3905  if (present(mask)) then
3906  if (any(mask)) then
3907  value = sum(array,mask=mask)
3908  else
3909  value = 0.0_kind_real
3910  end if
3911  else
3912  value = sum(array)
3913  end if
3914 else
3915  value = 0.0_kind_real
3916 endif
3917 
3918 ! Probe out
3919 
3920 
3921 end function func_zss_sum_real_r6
3922 # 2116 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3923 # 2117 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3924 
3925 # 2119 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3926 !----------------------------------------------------------------------
3927 ! Function: func_zss_count_r1
3928 !> Zero-size-safe count function
3929 !----------------------------------------------------------------------
3930 function func_zss_count_r1(array) result(value)
3931 
3932 implicit none
3933 
3934 ! Passed variables
3935 logical,intent(in) :: array(:) !< Array
3936 
3937 ! Returned variable
3938 integer :: value
3939 
3940 ! Set name
3941 
3942 
3943 ! Probe in
3944 
3945 
3946 if (size(array)>0) then
3947  value = count(array)
3948 else
3949  value = 0
3950 endif
3951 
3952 ! Probe out
3953 
3954 
3955 end function func_zss_count_r1
3956 # 2119 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3957 !----------------------------------------------------------------------
3958 ! Function: func_zss_count_r2
3959 !> Zero-size-safe count function
3960 !----------------------------------------------------------------------
3961 function func_zss_count_r2(array) result(value)
3962 
3963 implicit none
3964 
3965 ! Passed variables
3966 logical,intent(in) :: array(:,:) !< Array
3967 
3968 ! Returned variable
3969 integer :: value
3970 
3971 ! Set name
3972 
3973 
3974 ! Probe in
3975 
3976 
3977 if (size(array)>0) then
3978  value = count(array)
3979 else
3980  value = 0
3981 endif
3982 
3983 ! Probe out
3984 
3985 
3986 end function func_zss_count_r2
3987 # 2119 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
3988 !----------------------------------------------------------------------
3989 ! Function: func_zss_count_r3
3990 !> Zero-size-safe count function
3991 !----------------------------------------------------------------------
3992 function func_zss_count_r3(array) result(value)
3993 
3994 implicit none
3995 
3996 ! Passed variables
3997 logical,intent(in) :: array(:,:,:) !< Array
3998 
3999 ! Returned variable
4000 integer :: value
4001 
4002 ! Set name
4003 
4004 
4005 ! Probe in
4006 
4007 
4008 if (size(array)>0) then
4009  value = count(array)
4010 else
4011  value = 0
4012 endif
4013 
4014 ! Probe out
4015 
4016 
4017 end function func_zss_count_r3
4018 # 2119 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
4019 !----------------------------------------------------------------------
4020 ! Function: func_zss_count_r4
4021 !> Zero-size-safe count function
4022 !----------------------------------------------------------------------
4023 function func_zss_count_r4(array) result(value)
4024 
4025 implicit none
4026 
4027 ! Passed variables
4028 logical,intent(in) :: array(:,:,:,:) !< Array
4029 
4030 ! Returned variable
4031 integer :: value
4032 
4033 ! Set name
4034 
4035 
4036 ! Probe in
4037 
4038 
4039 if (size(array)>0) then
4040  value = count(array)
4041 else
4042  value = 0
4043 endif
4044 
4045 ! Probe out
4046 
4047 
4048 end function func_zss_count_r4
4049 # 2119 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
4050 !----------------------------------------------------------------------
4051 ! Function: func_zss_count_r5
4052 !> Zero-size-safe count function
4053 !----------------------------------------------------------------------
4054 function func_zss_count_r5(array) result(value)
4055 
4056 implicit none
4057 
4058 ! Passed variables
4059 logical,intent(in) :: array(:,:,:,:,:) !< Array
4060 
4061 ! Returned variable
4062 integer :: value
4063 
4064 ! Set name
4065 
4066 
4067 ! Probe in
4068 
4069 
4070 if (size(array)>0) then
4071  value = count(array)
4072 else
4073  value = 0
4074 endif
4075 
4076 ! Probe out
4077 
4078 
4079 end function func_zss_count_r5
4080 # 2119 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
4081 !----------------------------------------------------------------------
4082 ! Function: func_zss_count_r6
4083 !> Zero-size-safe count function
4084 !----------------------------------------------------------------------
4085 function func_zss_count_r6(array) result(value)
4086 
4087 implicit none
4088 
4089 ! Passed variables
4090 logical,intent(in) :: array(:,:,:,:,:,:) !< Array
4091 
4092 ! Returned variable
4093 integer :: value
4094 
4095 ! Set name
4096 
4097 
4098 ! Probe in
4099 
4100 
4101 if (size(array)>0) then
4102  value = count(array)
4103 else
4104  value = 0
4105 endif
4106 
4107 ! Probe out
4108 
4109 
4110 end function func_zss_count_r6
4111 # 2150 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/bump/tools_func.fypp"
4112 
4113 end module tools_func
Subroutines/functions list.
Subroutines/functions list.
Definition: tools_const.F90:31
real(kind_real), parameter, public ten
Ten.
Definition: tools_const.F90:49
real(kind_real), parameter, public one
One.
Definition: tools_const.F90:42
real(kind_real), parameter, public three
Three.
Definition: tools_const.F90:44
real(kind_real), parameter, public half
Half.
Definition: tools_const.F90:41
real(kind_real), parameter, public five
Five.
Definition: tools_const.F90:46
real(kind_real), parameter, public pi
Pi.
Definition: tools_const.F90:53
real(kind_real), parameter, public deg2rad
Degree to radian.
Definition: tools_const.F90:54
real(kind_real), parameter, public zero
Zero.
Definition: tools_const.F90:37
real(kind_real), parameter, public rad2deg
Radian to degree.
Definition: tools_const.F90:55
real(kind_real), parameter, public eight
Eight.
Definition: tools_const.F90:48
real(kind_real), parameter, public thousand
Thousand.
Definition: tools_const.F90:52
real(kind_real), parameter, public hundredth
Hundredth.
Definition: tools_const.F90:38
real(kind_real), parameter, public four
Four.
Definition: tools_const.F90:45
real(kind_real), parameter, public tenth
Tenth.
Definition: tools_const.F90:39
real(kind_real), parameter, public two
Two.
Definition: tools_const.F90:43
real(kind_real), parameter, public quarter
Quarter.
Definition: tools_const.F90:40
Subroutines/functions list.
Definition: tools_func.F90:42
subroutine func_convert_l2i_r4(fldl, fldi)
Convert logical to integer.
integer function func_fletcher32(var)
Fletcher-32 checksum algorithm.
Definition: tools_func.F90:313
integer(kind_int) function func_zss_sum_int_r3(array, mask)
Zero-size-safe sum function.
subroutine func_syminv(mpl, n, a, c)
Compute inverse of a symmetric matrix.
subroutine func_order_cc(mpl, lon, lat, n, x, y, z, order, diff)
Order points in counter-clockwise order with respect to a central point.
Definition: tools_func.F90:852
subroutine func_lct_r2d(r, D)
From support radius to Daley tensor diagonal element.
real(kind_real) function func_zss_sum_real_r3(array, mask)
Zero-size-safe sum function.
integer function func_cx_to_cxa(nproc, proc_to_cx_offset, icx)
Conversion from global to halo A on subset Scx.
integer(kind_int) function func_zss_minval_int_r2(array, mask)
Zero-size-safe minval function.
integer function func_zss_count_r1(array)
Zero-size-safe count function.
integer function func_cx_to_cxu(nproc, proc_to_cx_offset, proc_to_ncxa, myuniverse, icx)
Conversion from global to universe on subset Scx.
subroutine func_fit_diag(mpl, nc3, nl0r, disth, distv, coef, rh, rv, fit)
Compute diagnostic fit function.
real(kind_real) function func_gc99(distnorm)
Gaspari and Cohn (1999) function, with the support radius as a parameter.
subroutine func_convert_i2l_r3(mpl, fldi, fldl)
Convert integer to logical.
integer(kind_int) function func_zss_minval_int_r3(array, mask)
Zero-size-safe minval function.
subroutine func_convert_l2i_r0(fldl, fldi)
Convert logical to integer.
real(kind_real) function func_zss_maxval_real_r5(array, mask)
Zero-size-safe maxval function.
integer(kind_int) function func_zss_maxval_int_r5(array, mask)
Zero-size-safe maxval function.
real(kind_real) function func_zss_minval_real_r2(array, mask)
Zero-size-safe minval function.
real(kind_real) function func_zss_maxval_real_r6(array, mask)
Zero-size-safe maxval function.
subroutine func_vert_interp_size(nl0, dl0, nl1)
Count vertical interpolation levels.
Definition: tools_func.F90:997
real(kind_real), parameter, public dmin
Minimum tensor diagonal value.
Definition: tools_func.F90:58
real(kind_real) function func_zss_maxval_real_r1(array, mask)
Zero-size-safe maxval function.
real(kind_real) function func_zss_maxval_real_r3(array, mask)
Zero-size-safe maxval function.
integer(kind_int) function func_zss_maxval_int_r4(array, mask)
Zero-size-safe maxval function.
subroutine func_lct_d2h(mpl, D11, D22, D33, D12, H11, H22, H33, H12)
From D (Daley tensor) to H (local correlation tensor)
real(kind_real) function func_matern(mpl, M, x)
Compute the normalized diffusion function from eq. (55) of Mirouze and Weaver (2013),...
subroutine func_check_cond(d1, d2, nod, valid)
Check tensor conditioning.
integer(kind_int) function func_zss_minval_int_r6(array, mask)
Zero-size-safe minval function.
real(kind_real) function func_zss_minval_real_r1(array, mask)
Zero-size-safe minval function.
subroutine func_sphere_dist(lon_i, lat_i, lon_f, lat_f, dist)
Compute the great-circle distance between two points.
Definition: tools_func.F90:582
integer(kind_int) function func_zss_maxval_int_r3(array, mask)
Zero-size-safe maxval function.
integer(kind_int) function func_zss_minval_int_r4(array, mask)
Zero-size-safe minval function.
subroutine func_xyz2lonlat(mpl, x, y, z, lon, lat)
Convert longitude/latitude to cartesian coordinates.
Definition: tools_func.F90:664
subroutine func_convert_l2i_r3(fldl, fldi)
Convert logical to integer.
real(kind_real) function func_zss_sum_real_r4(array, mask)
Zero-size-safe sum function.
subroutine func_lonlatmod(lon, lat)
Set latitude between -pi/2 and pi/2 and longitude between -pi and pi.
Definition: tools_func.F90:355
real(kind_real) function func_zss_maxval_real_r4(array, mask)
Zero-size-safe maxval function.
subroutine func_cholesky(mpl, n, a, u)
Compute cholesky decomposition.
subroutine func_convert_i2l_r0(mpl, fldi, fldl)
Convert integer to logical.
subroutine func_convert_i2l_r4(mpl, fldi, fldl)
Convert integer to logical.
subroutine func_lct_h2r(mpl, H11, H22, H33, H12, rh, rv)
From H (local correlation tensor) to support radii.
integer(kind_int) function func_zss_sum_int_r5(array, mask)
Zero-size-safe sum function.
real(kind_real) function func_zss_minval_real_r5(array, mask)
Zero-size-safe minval function.
integer function func_zss_count_r3(array)
Zero-size-safe count function.
integer(kind_int) function func_zss_sum_int_r2(array, mask)
Zero-size-safe sum function.
subroutine func_add(mpl, val, cumul, num, wgt)
Check if value missing and add if not missing.
Definition: tools_func.F90:927
integer function func_zss_count_r5(array)
Zero-size-safe count function.
integer, parameter, public m
Number of implicit iteration for the Matern function (-1: GC99, 0: Gaussian, >0: Matern)
Definition: tools_func.F90:60
real(kind_real) function func_zss_minval_real_r6(array, mask)
Zero-size-safe minval function.
integer(kind_int) function func_zss_sum_int_r4(array, mask)
Zero-size-safe sum function.
real(kind_real) function func_zss_sum_real_r6(array, mask)
Zero-size-safe sum function.
real(kind_real) function func_zss_minval_real_r4(array, mask)
Zero-size-safe minval function.
subroutine func_inside(mpl, vbnd, lon, lat, inside_hull)
Find whether a point is inside the hull boundaries or not.
Definition: tools_func.F90:793
subroutine func_gridhash(ncx, nlx, lon_cx, lat_cx, mask_cx, grid_hash)
Compute grid hash profile.
Definition: tools_func.F90:397
subroutine func_divide(mpl, val, num)
Check if value missing and divide if not missing.
Definition: tools_func.F90:966
integer(kind_int) function func_zss_maxval_int_r1(array, mask)
Zero-size-safe maxval function.
integer function func_zss_count_r2(array)
Zero-size-safe count function.
subroutine func_histogram(mpl, nlist, list, nbins, histmin, histmax, bins, hist)
Compute bins and histogram from a list of values.
real(kind_real), parameter condmax
Maximum tensor conditioning number.
Definition: tools_func.F90:59
real(kind_real) function func_zss_minval_real_r3(array, mask)
Zero-size-safe minval function.
subroutine func_convert_l2i_r2(fldl, fldi)
Convert logical to integer.
subroutine func_cart_dist(x_i, y_i, z_i, x_f, y_f, z_f, dist)
Compute the cartesian distance between two points.
Definition: tools_func.F90:551
real(kind_real) function func_zss_maxval_real_r2(array, mask)
Zero-size-safe maxval function.
integer function func_zss_count_r4(array)
Zero-size-safe count function.
subroutine func_fit_lct(mpl, nc3, nl0r, dxsq, dysq, dxdy, dzsq, dmask, nscales, D, coef, fit)
LCT fit.
integer function func_cx_to_proc(nproc, proc_to_cx_offset, icx)
Conversion from global to processor on subset Scx.
real(kind_real) function func_fit_func(mpl, distnorm)
Fit_function.
integer function func_zss_count_r6(array)
Zero-size-safe count function.
subroutine func_convert_l2i_r1(fldl, fldi)
Convert logical to integer.
subroutine func_det(v1, v2, v3, p, cflag)
Compute determinant (vector triple product)
Definition: tools_func.F90:746
subroutine func_vector_product(v1, v2, vp)
Compute normalized vector product.
Definition: tools_func.F90:710
real(kind_real) function func_zss_sum_real_r2(array, mask)
Zero-size-safe sum function.
subroutine func_independent_levels(mpl, nlx, grid_hash, nlxi, lx_to_lxi, lxi_to_lx, ifmt)
Compute independent levels.
Definition: tools_func.F90:460
real(kind_real), parameter, public gc2gau
GC99 support radius to Gaussian Daley length-scale (empirical)
Definition: tools_func.F90:56
integer(kind_int) function func_zss_sum_int_r6(array, mask)
Zero-size-safe sum function.
integer(kind_int) function func_zss_sum_int_r1(array, mask)
Zero-size-safe sum function.
subroutine func_convert_i2l_r2(mpl, fldi, fldl)
Convert integer to logical.
real(kind_real) function func_zss_sum_real_r5(array, mask)
Zero-size-safe sum function.
integer(kind_int) function func_zss_minval_int_r5(array, mask)
Zero-size-safe minval function.
subroutine func_lonlat2xyz(mpl, lon, lat, x, y, z)
Convert longitude/latitude to cartesian coordinates.
Definition: tools_func.F90:617
real(kind_real) function func_zss_sum_real_r1(array, mask)
Zero-size-safe sum function.
real(kind_real), parameter, public gau2gc
Gaussian Daley length-scale to GC99 support radius (empirical)
Definition: tools_func.F90:57
subroutine func_convert_i2l_r1(mpl, fldi, fldl)
Convert integer to logical.
integer(kind_int) function func_zss_minval_int_r1(array, mask)
Zero-size-safe minval function.
integer(kind_int) function func_zss_maxval_int_r2(array, mask)
Zero-size-safe maxval function.
integer(kind_int) function func_zss_maxval_int_r6(array, mask)
Zero-size-safe maxval function.
subroutine func_vert_interp_setup(nl0, dl0, nl1, il0_interp, il1inf, il1sup, rinf, rsup)
Setup vertical interpolation levels and weights.
subroutine func_vert_interp(mpl, nl1, var_l1, nl0, il1inf, il1sup, rinf, rsup, var_l0)
Apply vertical interpolation.
Kinds definition.
Definition: tools_kinds.F90:9
integer, parameter, public kind_short
Short integer kind.
Definition: tools_kinds.F90:18
integer, parameter, public kind_int
Integer kind.
Definition: tools_kinds.F90:17
integer, parameter, public kind_real
Real kind alias for the whole code.
Definition: tools_kinds.F90:31
integer, parameter, public huge_int
Integer huge.
Definition: tools_kinds.F90:35
real(kind_real), parameter, public huge_real
Real huge.
Definition: tools_kinds.F90:36
Generic ranks, dimensions and types.
Definition: tools_qsort.F90:46
Generic ranks, dimensions and types.
Definition: tools_repro.F90:42
real(kind_real), public rth
Reproducibility threshold.
Definition: tools_repro.F90:51
Generic ranks, dimensions and types.
Definition: type_mpl.F90:42