SABER
tools_atlas.F90
Go to the documentation of this file.
1 # 1 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
2 # 1 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/../generics.fypp" 1
3 !----------------------------------------------------------------------
4 ! Header: generics
5 !> Generic ranks, dimensions and types
6 ! Author: Benjamin Menetrier
7 ! Licensing: this code is distributed under the CeCILL-C license
8 ! Copyright 2015-... UCAR, CERFACS, METEO-FRANCE and IRIT
9 !----------------------------------------------------------------------
10 
11 # 56 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/../generics.fypp"
12 # 2 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp" 2
13 # 1 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/../instrumentation.fypp" 1
14 # 1 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/../subr_list.fypp" 1
15 !----------------------------------------------------------------------
16 ! Header: subr_list
17 !> Subroutines/functions list
18 ! Author: Benjamin Menetrier
19 ! Licensing: this code is distributed under the CeCILL-C license
20 ! Copyright 2015-... UCAR, CERFACS, METEO-FRANCE and IRIT
21 !----------------------------------------------------------------------
22 
23 # 726 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/../subr_list.fypp"
24 # 2 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/../instrumentation.fypp" 2
25 !----------------------------------------------------------------------
26 ! Header: instrumentation
27 !> Instrumentation functions
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 # 112 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/../instrumentation.fypp"
34 # 3 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp" 2
35 !----------------------------------------------------------------------
36 ! Module: tools_atlas
37 !> ATLAS tools
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 !----------------------------------------------------------------------
43 
44 use atlas_module, only: atlas_field,atlas_fieldset,atlas_integer,atlas_real,atlas_functionspace,atlas_functionspace_nodecolumns, &
45  & atlas_functionspace_pointcloud,atlas_functionspace_structuredcolumns
46 use tools_const, only: rad2deg
48 use type_mpl, only: mpl_type
49 
50 
51 implicit none
52 
53 interface field_to_array
54 # 23 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
55 # 24 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
56  module procedure atlas_field_to_array_int_r2
57 # 24 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
58  module procedure atlas_field_to_array_real_r2
59 # 24 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
60  module procedure atlas_field_to_array_logical_r2
61 # 26 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
62 # 23 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
63 # 24 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
64  module procedure atlas_field_to_array_int_r3
65 # 24 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
66  module procedure atlas_field_to_array_real_r3
67 # 24 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
68  module procedure atlas_field_to_array_logical_r3
69 # 26 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
70 # 27 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
71 end interface
73 # 30 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
74 # 31 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
75  module procedure atlas_field_from_array_int_r2
76 # 31 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
77  module procedure atlas_field_from_array_real_r2
78 # 31 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
79  module procedure atlas_field_from_array_logical_r2
80 # 33 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
81 # 30 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
82 # 31 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
83  module procedure atlas_field_from_array_int_r3
84 # 31 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
85  module procedure atlas_field_from_array_real_r3
86 # 31 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
87  module procedure atlas_field_from_array_logical_r3
88 # 33 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
89 # 34 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
90 end interface
92  module procedure atlas_create_atlas_function_space
93 end interface
94 
95 private
97 
98 contains
99 
100 # 45 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
101 # 46 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
102 !----------------------------------------------------------------------
103 ! Subroutine: atlas_field_to_array_int_r2
104 !> Convert ATLAS field to field
105 !----------------------------------------------------------------------
106 subroutine atlas_field_to_array_int_r2(afield,mpl,array,lev2d)
107 
108 implicit none
109 
110 ! Passed variables
111 type(atlas_field),intent(in) :: afield !< ATLAS field
112 type(mpl_type),intent(inout) :: mpl !< MPI data
113 integer(kind_int),intent(out) :: array(:,:) !< Array, the rightmost dimension being the vertical
114 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
115 
116 ! Local variables
117 integer :: nmga,nnodes,nl,nl0,nl2d,il0
118 integer :: shp(2)
119 integer(kind_int),pointer :: ptr_1(:),ptr_2(:,:)
120 character(len=1024) :: llev2d
121 type(atlas_functionspace) :: afunctionspace
122 type(atlas_functionspace_nodecolumns) :: afunctionspace_nc
123 type(atlas_functionspace_pointcloud) :: afunctionspace_pc
124 type(atlas_functionspace_structuredcolumns) :: afunctionspace_sc
125 
126 ! Set name
127 
128 
129 ! Probe in
130 
131 
132 ! Local lev2d
133 llev2d = 'first'
134 if (present(lev2d)) llev2d = lev2d
135 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_to_array_int_r2','wrong lev2d')
136 
137 ! Check kind
138 if (afield%kind()/=atlas_integer(kind_int)) call mpl%abort('atlas_field_to_array_int_r2','wrong kind for field '//afield%name())
139 
140 ! Get generic functionspace
141 afunctionspace = afield%functionspace()
142 
143 select case (afunctionspace%name())
144 case ('NodeColumns')
145  ! Get NodeColumns function space
146  afunctionspace_nc = afield%functionspace()
147 
148  ! Get number of nodes
149  nmga = afunctionspace_nc%nb_nodes()
150 case ('PointCloud')
151  ! Get PointCloud function space
152  afunctionspace_pc = afield%functionspace()
153 
154  ! Get number of points
155  nmga = afunctionspace_pc%size()
156 case ('StructuredColumns')
157  ! Get StructuredColumns function space
158  afunctionspace_sc = afield%functionspace()
159 
160  ! Get number of nodes
161  nmga = afunctionspace_sc%size_owned()
162 case default
163  call mpl%abort('atlas_field_to_array_int_r2','wrong function space for field '//afield%name()//': '//afunctionspace%name())
164 end select
165 
166 ! Get number of nodes and number of levels
167 ! - afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
168 ! - the size of the rightmost dimension of arr2d/arr3d is always positive
169 ! - to ensure that sizes are compatible for copying data, we use the minimum between the two
170 shp = shape(array)
171 nnodes = product(shp(1:2-1))
172 nl = shp(2)
173 nl0 = min(afield%levels(),nl)
174 
175 ! Check number of nodes
176 if (nmga/=nnodes) call mpl%abort('atlas_field_to_array_int_r2','wrong number of nodes for field '//afield%name())
177 
178 ! Initialization
179 array = 0
180 
181 ! Copy data
182 ! For the 2D case (afield%levels()==0), the field is copied:
183 ! - at the first level of array if (lev2d=='first')
184 ! - at the last level of array if (lev2d=='last')
185 ! NB: an ATLAS field with 1 level only (afield%levels()==1) is considered as a 3D field, so lev2d does not apply
186 if (nl0==0) then
187  if (nl>0) then
188  if (trim(llev2d)=='first') then
189  nl2d = 1
190  elseif (trim(llev2d)=='last') then
191  nl2d = nl
192  end if
193  call afield%data(ptr_1)
194  array(:,nl2d) = ptr_1
195 
196  end if
197 else
198  call afield%data(ptr_2)
199  do il0=1,nl0
200  array(:,il0) = ptr_2(il0,:)
201 
202  end do
203 end if
204 
205 ! Probe out
206 
207 
208 end subroutine atlas_field_to_array_int_r2
209 # 46 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
210 !----------------------------------------------------------------------
211 ! Subroutine: atlas_field_to_array_real_r2
212 !> Convert ATLAS field to field
213 !----------------------------------------------------------------------
214 subroutine atlas_field_to_array_real_r2(afield,mpl,array,lev2d)
215 
216 implicit none
217 
218 ! Passed variables
219 type(atlas_field),intent(in) :: afield !< ATLAS field
220 type(mpl_type),intent(inout) :: mpl !< MPI data
221 real(kind_real),intent(out) :: array(:,:) !< Array, the rightmost dimension being the vertical
222 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
223 
224 ! Local variables
225 integer :: nmga,nnodes,nl,nl0,nl2d,il0
226 integer :: shp(2)
227 real(kind_real),pointer :: ptr_1(:),ptr_2(:,:)
228 character(len=1024) :: llev2d
229 type(atlas_functionspace) :: afunctionspace
230 type(atlas_functionspace_nodecolumns) :: afunctionspace_nc
231 type(atlas_functionspace_pointcloud) :: afunctionspace_pc
232 type(atlas_functionspace_structuredcolumns) :: afunctionspace_sc
233 
234 ! Set name
235 
236 
237 ! Probe in
238 
239 
240 ! Local lev2d
241 llev2d = 'first'
242 if (present(lev2d)) llev2d = lev2d
243 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_to_array_real_r2','wrong lev2d')
244 
245 ! Check kind
246 if (afield%kind()/=atlas_real(kind_real)) call mpl%abort('atlas_field_to_array_real_r2','wrong kind for field '//afield%name())
247 
248 ! Get generic functionspace
249 afunctionspace = afield%functionspace()
250 
251 select case (afunctionspace%name())
252 case ('NodeColumns')
253  ! Get NodeColumns function space
254  afunctionspace_nc = afield%functionspace()
255 
256  ! Get number of nodes
257  nmga = afunctionspace_nc%nb_nodes()
258 case ('PointCloud')
259  ! Get PointCloud function space
260  afunctionspace_pc = afield%functionspace()
261 
262  ! Get number of points
263  nmga = afunctionspace_pc%size()
264 case ('StructuredColumns')
265  ! Get StructuredColumns function space
266  afunctionspace_sc = afield%functionspace()
267 
268  ! Get number of nodes
269  nmga = afunctionspace_sc%size_owned()
270 case default
271  call mpl%abort('atlas_field_to_array_real_r2','wrong function space for field '//afield%name()//': '//afunctionspace%name())
272 end select
273 
274 ! Get number of nodes and number of levels
275 ! - afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
276 ! - the size of the rightmost dimension of arr2d/arr3d is always positive
277 ! - to ensure that sizes are compatible for copying data, we use the minimum between the two
278 shp = shape(array)
279 nnodes = product(shp(1:2-1))
280 nl = shp(2)
281 nl0 = min(afield%levels(),nl)
282 
283 ! Check number of nodes
284 if (nmga/=nnodes) call mpl%abort('atlas_field_to_array_real_r2','wrong number of nodes for field '//afield%name())
285 
286 ! Initialization
287 array = 0.0_kind_real
288 
289 ! Copy data
290 ! For the 2D case (afield%levels()==0), the field is copied:
291 ! - at the first level of array if (lev2d=='first')
292 ! - at the last level of array if (lev2d=='last')
293 ! NB: an ATLAS field with 1 level only (afield%levels()==1) is considered as a 3D field, so lev2d does not apply
294 if (nl0==0) then
295  if (nl>0) then
296  if (trim(llev2d)=='first') then
297  nl2d = 1
298  elseif (trim(llev2d)=='last') then
299  nl2d = nl
300  end if
301  call afield%data(ptr_1)
302  array(:,nl2d) = ptr_1
303 
304  end if
305 else
306  call afield%data(ptr_2)
307  do il0=1,nl0
308  array(:,il0) = ptr_2(il0,:)
309 
310  end do
311 end if
312 
313 ! Probe out
314 
315 
316 end subroutine atlas_field_to_array_real_r2
317 # 154 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
318 # 45 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
319 # 46 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
320 !----------------------------------------------------------------------
321 ! Subroutine: atlas_field_to_array_int_r3
322 !> Convert ATLAS field to field
323 !----------------------------------------------------------------------
324 subroutine atlas_field_to_array_int_r3(afield,mpl,array,lev2d)
325 
326 implicit none
327 
328 ! Passed variables
329 type(atlas_field),intent(in) :: afield !< ATLAS field
330 type(mpl_type),intent(inout) :: mpl !< MPI data
331 integer(kind_int),intent(out) :: array(:,:,:) !< Array, the rightmost dimension being the vertical
332 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
333 
334 ! Local variables
335 integer :: nmga,nnodes,nl,nl0,nl2d,il0
336 integer :: shp(3)
337 integer(kind_int),pointer :: ptr_1(:),ptr_2(:,:)
338 character(len=1024) :: llev2d
339 type(atlas_functionspace) :: afunctionspace
340 type(atlas_functionspace_nodecolumns) :: afunctionspace_nc
341 type(atlas_functionspace_pointcloud) :: afunctionspace_pc
342 type(atlas_functionspace_structuredcolumns) :: afunctionspace_sc
343 
344 ! Set name
345 
346 
347 ! Probe in
348 
349 
350 ! Local lev2d
351 llev2d = 'first'
352 if (present(lev2d)) llev2d = lev2d
353 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_to_array_int_r3','wrong lev2d')
354 
355 ! Check kind
356 if (afield%kind()/=atlas_integer(kind_int)) call mpl%abort('atlas_field_to_array_int_r3','wrong kind for field '//afield%name())
357 
358 ! Get generic functionspace
359 afunctionspace = afield%functionspace()
360 
361 select case (afunctionspace%name())
362 case ('NodeColumns')
363  ! Get NodeColumns function space
364  afunctionspace_nc = afield%functionspace()
365 
366  ! Get number of nodes
367  nmga = afunctionspace_nc%nb_nodes()
368 case ('PointCloud')
369  ! Get PointCloud function space
370  afunctionspace_pc = afield%functionspace()
371 
372  ! Get number of points
373  nmga = afunctionspace_pc%size()
374 case ('StructuredColumns')
375  ! Get StructuredColumns function space
376  afunctionspace_sc = afield%functionspace()
377 
378  ! Get number of nodes
379  nmga = afunctionspace_sc%size_owned()
380 case default
381  call mpl%abort('atlas_field_to_array_int_r3','wrong function space for field '//afield%name()//': '//afunctionspace%name())
382 end select
383 
384 ! Get number of nodes and number of levels
385 ! - afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
386 ! - the size of the rightmost dimension of arr2d/arr3d is always positive
387 ! - to ensure that sizes are compatible for copying data, we use the minimum between the two
388 shp = shape(array)
389 nnodes = product(shp(1:3-1))
390 nl = shp(3)
391 nl0 = min(afield%levels(),nl)
392 
393 ! Check number of nodes
394 if (nmga/=nnodes) call mpl%abort('atlas_field_to_array_int_r3','wrong number of nodes for field '//afield%name())
395 
396 ! Initialization
397 array = 0
398 
399 ! Copy data
400 ! For the 2D case (afield%levels()==0), the field is copied:
401 ! - at the first level of array if (lev2d=='first')
402 ! - at the last level of array if (lev2d=='last')
403 ! NB: an ATLAS field with 1 level only (afield%levels()==1) is considered as a 3D field, so lev2d does not apply
404 if (nl0==0) then
405  if (nl>0) then
406  if (trim(llev2d)=='first') then
407  nl2d = 1
408  elseif (trim(llev2d)=='last') then
409  nl2d = nl
410  end if
411  call afield%data(ptr_1)
412 
413  array(:,:,nl2d) = reshape(ptr_1,shp(1:2))
414  end if
415 else
416  call afield%data(ptr_2)
417  do il0=1,nl0
418 
419  array(:,:,il0) = reshape(ptr_2(il0,:),shp(1:2))
420  end do
421 end if
422 
423 ! Probe out
424 
425 
426 end subroutine atlas_field_to_array_int_r3
427 # 46 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
428 !----------------------------------------------------------------------
429 ! Subroutine: atlas_field_to_array_real_r3
430 !> Convert ATLAS field to field
431 !----------------------------------------------------------------------
432 subroutine atlas_field_to_array_real_r3(afield,mpl,array,lev2d)
433 
434 implicit none
435 
436 ! Passed variables
437 type(atlas_field),intent(in) :: afield !< ATLAS field
438 type(mpl_type),intent(inout) :: mpl !< MPI data
439 real(kind_real),intent(out) :: array(:,:,:) !< Array, the rightmost dimension being the vertical
440 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
441 
442 ! Local variables
443 integer :: nmga,nnodes,nl,nl0,nl2d,il0
444 integer :: shp(3)
445 real(kind_real),pointer :: ptr_1(:),ptr_2(:,:)
446 character(len=1024) :: llev2d
447 type(atlas_functionspace) :: afunctionspace
448 type(atlas_functionspace_nodecolumns) :: afunctionspace_nc
449 type(atlas_functionspace_pointcloud) :: afunctionspace_pc
450 type(atlas_functionspace_structuredcolumns) :: afunctionspace_sc
451 
452 ! Set name
453 
454 
455 ! Probe in
456 
457 
458 ! Local lev2d
459 llev2d = 'first'
460 if (present(lev2d)) llev2d = lev2d
461 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_to_array_real_r3','wrong lev2d')
462 
463 ! Check kind
464 if (afield%kind()/=atlas_real(kind_real)) call mpl%abort('atlas_field_to_array_real_r3','wrong kind for field '//afield%name())
465 
466 ! Get generic functionspace
467 afunctionspace = afield%functionspace()
468 
469 select case (afunctionspace%name())
470 case ('NodeColumns')
471  ! Get NodeColumns function space
472  afunctionspace_nc = afield%functionspace()
473 
474  ! Get number of nodes
475  nmga = afunctionspace_nc%nb_nodes()
476 case ('PointCloud')
477  ! Get PointCloud function space
478  afunctionspace_pc = afield%functionspace()
479 
480  ! Get number of points
481  nmga = afunctionspace_pc%size()
482 case ('StructuredColumns')
483  ! Get StructuredColumns function space
484  afunctionspace_sc = afield%functionspace()
485 
486  ! Get number of nodes
487  nmga = afunctionspace_sc%size_owned()
488 case default
489  call mpl%abort('atlas_field_to_array_real_r3','wrong function space for field '//afield%name()//': '//afunctionspace%name())
490 end select
491 
492 ! Get number of nodes and number of levels
493 ! - afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
494 ! - the size of the rightmost dimension of arr2d/arr3d is always positive
495 ! - to ensure that sizes are compatible for copying data, we use the minimum between the two
496 shp = shape(array)
497 nnodes = product(shp(1:3-1))
498 nl = shp(3)
499 nl0 = min(afield%levels(),nl)
500 
501 ! Check number of nodes
502 if (nmga/=nnodes) call mpl%abort('atlas_field_to_array_real_r3','wrong number of nodes for field '//afield%name())
503 
504 ! Initialization
505 array = 0.0_kind_real
506 
507 ! Copy data
508 ! For the 2D case (afield%levels()==0), the field is copied:
509 ! - at the first level of array if (lev2d=='first')
510 ! - at the last level of array if (lev2d=='last')
511 ! NB: an ATLAS field with 1 level only (afield%levels()==1) is considered as a 3D field, so lev2d does not apply
512 if (nl0==0) then
513  if (nl>0) then
514  if (trim(llev2d)=='first') then
515  nl2d = 1
516  elseif (trim(llev2d)=='last') then
517  nl2d = nl
518  end if
519  call afield%data(ptr_1)
520 
521  array(:,:,nl2d) = reshape(ptr_1,shp(1:2))
522  end if
523 else
524  call afield%data(ptr_2)
525  do il0=1,nl0
526 
527  array(:,:,il0) = reshape(ptr_2(il0,:),shp(1:2))
528  end do
529 end if
530 
531 ! Probe out
532 
533 
534 end subroutine atlas_field_to_array_real_r3
535 # 154 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
536 # 155 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
537 
538 # 157 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
539 !----------------------------------------------------------------------
540 ! Subroutine: atlas_field_to_array_logical_r2
541 !> Convert ATLAS field to field
542 !----------------------------------------------------------------------
543 subroutine atlas_field_to_array_logical_r2(afield,mpl,array,lev2d)
544 
545 implicit none
546 
547 ! Passed variables
548 type(atlas_field),intent(in) :: afield !< ATLAS field
549 type(mpl_type),intent(inout) :: mpl !< MPI data
550 logical,intent(out) :: array(:,:) !< Array, the rightmost dimension being the vertical
551 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
552 
553 ! Local variables
554 integer :: il0
555  integer :: imga
556 
557 integer,allocatable :: array_int(:,:)
558 character(len=1024) :: llev2d
559 
560 ! Set name
561 
562 
563 ! Probe in
564 
565 
566 ! Local lev2d
567 llev2d = 'first'
568 if (present(lev2d)) llev2d = lev2d
569 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_to_array_logical_r2','wrong lev2d')
570 
571 ! Allocation
572  allocate(array_int(size(array,1),size(array,2)))
573 
574 
575 ! Get integer array
576 call field_to_array(afield,mpl,array_int,lev2d)
577 
578 ! Convert integer to logical
579 # 198 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
580  do il0=1,size(array,2)
581  do imga=1,size(array,1)
582  if (array_int(imga,il0)==0) then
583  array(imga,il0) = .false.
584  elseif (array_int(imga,il0)==1) then
585  array(imga,il0) = .true.
586  else
587  call mpl%abort('atlas_field_to_array_logical_r2','wrong value in 0-1 integer field for field '//afield%name())
588  end if
589  end do
590  end do
591 # 210 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
592 # 225 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
593 
594 ! Release memory
595 deallocate(array_int)
596 
597 ! Probe out
598 
599 
600 end subroutine atlas_field_to_array_logical_r2
601 # 157 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
602 !----------------------------------------------------------------------
603 ! Subroutine: atlas_field_to_array_logical_r3
604 !> Convert ATLAS field to field
605 !----------------------------------------------------------------------
606 subroutine atlas_field_to_array_logical_r3(afield,mpl,array,lev2d)
607 
608 implicit none
609 
610 ! Passed variables
611 type(atlas_field),intent(in) :: afield !< ATLAS field
612 type(mpl_type),intent(inout) :: mpl !< MPI data
613 logical,intent(out) :: array(:,:,:) !< Array, the rightmost dimension being the vertical
614 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
615 
616 ! Local variables
617 integer :: il0
618 
619  integer :: ixa,iya
620 integer,allocatable :: array_int(:,:,:)
621 character(len=1024) :: llev2d
622 
623 ! Set name
624 
625 
626 ! Probe in
627 
628 
629 ! Local lev2d
630 llev2d = 'first'
631 if (present(lev2d)) llev2d = lev2d
632 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_to_array_logical_r3','wrong lev2d')
633 
634 ! Allocation
635 
636  allocate(array_int(size(array,1),size(array,2),size(array,3)))
637 
638 ! Get integer array
639 call field_to_array(afield,mpl,array_int,lev2d)
640 
641 ! Convert integer to logical
642 # 210 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
643 # 211 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
644  do il0=1,size(array,3)
645  do iya=1,size(array,2)
646  do ixa=1,size(array,1)
647  if (array_int(ixa,iya,il0)==0) then
648  array(ixa,iya,il0) = .false.
649  elseif (array_int(ixa,iya,il0)==1) then
650  array(ixa,iya,il0) = .true.
651  else
652  call mpl%abort('atlas_field_to_array_logical_r3','wrong value in 0-1 integer field for field '//afield%name())
653  end if
654  end do
655  end do
656  end do
657 # 225 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
658 
659 ! Release memory
660 deallocate(array_int)
661 
662 ! Probe out
663 
664 
665 end subroutine atlas_field_to_array_logical_r3
666 # 234 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
667 
668 # 236 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
669 # 237 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
670 !----------------------------------------------------------------------
671 ! Subroutine: atlas_field_from_array_int_r2
672 !> Convert field to ATLAS field, real
673 !----------------------------------------------------------------------
674 subroutine atlas_field_from_array_int_r2(afield,mpl,array,lev2d)
675 
676 implicit none
677 
678 ! Passed variables
679 type(atlas_field),intent(inout) :: afield !< ATLAS field
680 type(mpl_type),intent(inout) :: mpl !< MPI data
681 integer(kind_int),intent(in) :: array(:,:) !< Array, the rightmost dimension being the vertical
682 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
683 
684 ! Local variables
685 integer :: nmga,nnodes,nl,nl0,nl2d,il0
686 integer :: shp(2)
687 integer(kind_int),pointer :: ptr_1(:),ptr_2(:,:)
688 character(len=1024) :: llev2d
689 type(atlas_functionspace) :: afunctionspace
690 type(atlas_functionspace_nodecolumns) :: afunctionspace_nc
691 type(atlas_functionspace_pointcloud) :: afunctionspace_pc
692 type(atlas_functionspace_structuredcolumns) :: afunctionspace_sc
693 
694 ! Set name
695 
696 
697 ! Probe in
698 
699 
700 ! Local lev2d
701 llev2d = 'first'
702 if (present(lev2d)) llev2d = lev2d
703 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_from_array_int_r2','wrong lev2d')
704 
705 ! Check kind
706 if (afield%kind()/=atlas_integer(kind_int)) call mpl%abort('atlas_field_from_array_int_r2','wrong kind for field '//afield%name())
707 
708 ! Get generic functionspace
709 afunctionspace = afield%functionspace()
710 
711 select case (afunctionspace%name())
712 case ('NodeColumns')
713  ! Get NodeColumns function space
714  afunctionspace_nc = afield%functionspace()
715 
716  ! Get number of nodes
717  nmga = afunctionspace_nc%nb_nodes()
718 case ('PointCloud')
719  ! Get PointCloud function space
720  afunctionspace_pc = afield%functionspace()
721 
722  ! Get number of points
723  nmga = afunctionspace_pc%size()
724 case ('StructuredColumns')
725  ! Get StructuredColumns function space
726  afunctionspace_sc = afield%functionspace()
727 
728  ! Get number of nodes
729  nmga = afunctionspace_sc%size_owned()
730 case default
731  call mpl%abort('atlas_field_from_array_int_r2','wrong function space for field '//afield%name()//': '//afunctionspace%name())
732 end select
733 
734 ! Get number of nodes and number of levels
735 ! - afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
736 ! - the size of the rightmost dimension of arr2d/arr3d is always positive
737 ! - to ensure that sizes are compatible for copying data, we use the minimum between the two
738 shp = shape(array)
739 nnodes = product(shp(1:2-1))
740 nl = shp(2)
741 nl0 = min(afield%levels(),nl)
742 
743 ! Check number of nodes
744 if (nmga/=nnodes) call mpl%abort('atlas_field_from_array_int_r2','wrong number of nodes for field '//afield%name())
745 
746 ! Copy data
747 ! For the 2D case (afield%levels()==0), the field is copied:
748 ! - at the first level of array if (lev2d=='first')
749 ! - at the last level of array if (lev2d=='last')
750 ! NB: an ATLAS field with 1 level only (afield%levels()==1) is considered as a 3D field, so lev2d does not apply
751 if (nl0==0) then
752  if (nl>0) then
753  if (trim(llev2d)=='first') then
754  nl2d = 1
755  elseif (trim(llev2d)=='last') then
756  nl2d = nl
757  end if
758  call afield%data(ptr_1)
759  ptr_1 = array(:,nl2d)
760 
761  end if
762 else
763  call afield%data(ptr_2)
764  do il0=1,nl0
765  ptr_2(il0,:) = array(:,il0)
766 
767  end do
768 end if
769 
770 ! Probe out
771 
772 
773 end subroutine atlas_field_from_array_int_r2
774 # 237 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
775 !----------------------------------------------------------------------
776 ! Subroutine: atlas_field_from_array_real_r2
777 !> Convert field to ATLAS field, real
778 !----------------------------------------------------------------------
779 subroutine atlas_field_from_array_real_r2(afield,mpl,array,lev2d)
780 
781 implicit none
782 
783 ! Passed variables
784 type(atlas_field),intent(inout) :: afield !< ATLAS field
785 type(mpl_type),intent(inout) :: mpl !< MPI data
786 real(kind_real),intent(in) :: array(:,:) !< Array, the rightmost dimension being the vertical
787 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
788 
789 ! Local variables
790 integer :: nmga,nnodes,nl,nl0,nl2d,il0
791 integer :: shp(2)
792 real(kind_real),pointer :: ptr_1(:),ptr_2(:,:)
793 character(len=1024) :: llev2d
794 type(atlas_functionspace) :: afunctionspace
795 type(atlas_functionspace_nodecolumns) :: afunctionspace_nc
796 type(atlas_functionspace_pointcloud) :: afunctionspace_pc
797 type(atlas_functionspace_structuredcolumns) :: afunctionspace_sc
798 
799 ! Set name
800 
801 
802 ! Probe in
803 
804 
805 ! Local lev2d
806 llev2d = 'first'
807 if (present(lev2d)) llev2d = lev2d
808 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_from_array_real_r2','wrong lev2d')
809 
810 ! Check kind
811 if (afield%kind()/=atlas_real(kind_real)) call mpl%abort('atlas_field_from_array_real_r2','wrong kind for field '//afield%name())
812 
813 ! Get generic functionspace
814 afunctionspace = afield%functionspace()
815 
816 select case (afunctionspace%name())
817 case ('NodeColumns')
818  ! Get NodeColumns function space
819  afunctionspace_nc = afield%functionspace()
820 
821  ! Get number of nodes
822  nmga = afunctionspace_nc%nb_nodes()
823 case ('PointCloud')
824  ! Get PointCloud function space
825  afunctionspace_pc = afield%functionspace()
826 
827  ! Get number of points
828  nmga = afunctionspace_pc%size()
829 case ('StructuredColumns')
830  ! Get StructuredColumns function space
831  afunctionspace_sc = afield%functionspace()
832 
833  ! Get number of nodes
834  nmga = afunctionspace_sc%size_owned()
835 case default
836  call mpl%abort('atlas_field_from_array_real_r2','wrong function space for field '//afield%name()//': '//afunctionspace%name())
837 end select
838 
839 ! Get number of nodes and number of levels
840 ! - afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
841 ! - the size of the rightmost dimension of arr2d/arr3d is always positive
842 ! - to ensure that sizes are compatible for copying data, we use the minimum between the two
843 shp = shape(array)
844 nnodes = product(shp(1:2-1))
845 nl = shp(2)
846 nl0 = min(afield%levels(),nl)
847 
848 ! Check number of nodes
849 if (nmga/=nnodes) call mpl%abort('atlas_field_from_array_real_r2','wrong number of nodes for field '//afield%name())
850 
851 ! Copy data
852 ! For the 2D case (afield%levels()==0), the field is copied:
853 ! - at the first level of array if (lev2d=='first')
854 ! - at the last level of array if (lev2d=='last')
855 ! NB: an ATLAS field with 1 level only (afield%levels()==1) is considered as a 3D field, so lev2d does not apply
856 if (nl0==0) then
857  if (nl>0) then
858  if (trim(llev2d)=='first') then
859  nl2d = 1
860  elseif (trim(llev2d)=='last') then
861  nl2d = nl
862  end if
863  call afield%data(ptr_1)
864  ptr_1 = array(:,nl2d)
865 
866  end if
867 else
868  call afield%data(ptr_2)
869  do il0=1,nl0
870  ptr_2(il0,:) = array(:,il0)
871 
872  end do
873 end if
874 
875 ! Probe out
876 
877 
878 end subroutine atlas_field_from_array_real_r2
879 # 342 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
880 # 236 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
881 # 237 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
882 !----------------------------------------------------------------------
883 ! Subroutine: atlas_field_from_array_int_r3
884 !> Convert field to ATLAS field, real
885 !----------------------------------------------------------------------
886 subroutine atlas_field_from_array_int_r3(afield,mpl,array,lev2d)
887 
888 implicit none
889 
890 ! Passed variables
891 type(atlas_field),intent(inout) :: afield !< ATLAS field
892 type(mpl_type),intent(inout) :: mpl !< MPI data
893 integer(kind_int),intent(in) :: array(:,:,:) !< Array, the rightmost dimension being the vertical
894 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
895 
896 ! Local variables
897 integer :: nmga,nnodes,nl,nl0,nl2d,il0
898 integer :: shp(3)
899 integer(kind_int),pointer :: ptr_1(:),ptr_2(:,:)
900 character(len=1024) :: llev2d
901 type(atlas_functionspace) :: afunctionspace
902 type(atlas_functionspace_nodecolumns) :: afunctionspace_nc
903 type(atlas_functionspace_pointcloud) :: afunctionspace_pc
904 type(atlas_functionspace_structuredcolumns) :: afunctionspace_sc
905 
906 ! Set name
907 
908 
909 ! Probe in
910 
911 
912 ! Local lev2d
913 llev2d = 'first'
914 if (present(lev2d)) llev2d = lev2d
915 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_from_array_int_r3','wrong lev2d')
916 
917 ! Check kind
918 if (afield%kind()/=atlas_integer(kind_int)) call mpl%abort('atlas_field_from_array_int_r3','wrong kind for field '//afield%name())
919 
920 ! Get generic functionspace
921 afunctionspace = afield%functionspace()
922 
923 select case (afunctionspace%name())
924 case ('NodeColumns')
925  ! Get NodeColumns function space
926  afunctionspace_nc = afield%functionspace()
927 
928  ! Get number of nodes
929  nmga = afunctionspace_nc%nb_nodes()
930 case ('PointCloud')
931  ! Get PointCloud function space
932  afunctionspace_pc = afield%functionspace()
933 
934  ! Get number of points
935  nmga = afunctionspace_pc%size()
936 case ('StructuredColumns')
937  ! Get StructuredColumns function space
938  afunctionspace_sc = afield%functionspace()
939 
940  ! Get number of nodes
941  nmga = afunctionspace_sc%size_owned()
942 case default
943  call mpl%abort('atlas_field_from_array_int_r3','wrong function space for field '//afield%name()//': '//afunctionspace%name())
944 end select
945 
946 ! Get number of nodes and number of levels
947 ! - afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
948 ! - the size of the rightmost dimension of arr2d/arr3d is always positive
949 ! - to ensure that sizes are compatible for copying data, we use the minimum between the two
950 shp = shape(array)
951 nnodes = product(shp(1:3-1))
952 nl = shp(3)
953 nl0 = min(afield%levels(),nl)
954 
955 ! Check number of nodes
956 if (nmga/=nnodes) call mpl%abort('atlas_field_from_array_int_r3','wrong number of nodes for field '//afield%name())
957 
958 ! Copy data
959 ! For the 2D case (afield%levels()==0), the field is copied:
960 ! - at the first level of array if (lev2d=='first')
961 ! - at the last level of array if (lev2d=='last')
962 ! NB: an ATLAS field with 1 level only (afield%levels()==1) is considered as a 3D field, so lev2d does not apply
963 if (nl0==0) then
964  if (nl>0) then
965  if (trim(llev2d)=='first') then
966  nl2d = 1
967  elseif (trim(llev2d)=='last') then
968  nl2d = nl
969  end if
970  call afield%data(ptr_1)
971 
972  ptr_1 = reshape(array(:,:,nl2d),(/product(shp(1:2))/))
973  end if
974 else
975  call afield%data(ptr_2)
976  do il0=1,nl0
977 
978  ptr_2(il0,:) = reshape(array(:,:,il0),(/product(shp(1:2))/))
979  end do
980 end if
981 
982 ! Probe out
983 
984 
985 end subroutine atlas_field_from_array_int_r3
986 # 237 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
987 !----------------------------------------------------------------------
988 ! Subroutine: atlas_field_from_array_real_r3
989 !> Convert field to ATLAS field, real
990 !----------------------------------------------------------------------
991 subroutine atlas_field_from_array_real_r3(afield,mpl,array,lev2d)
992 
993 implicit none
994 
995 ! Passed variables
996 type(atlas_field),intent(inout) :: afield !< ATLAS field
997 type(mpl_type),intent(inout) :: mpl !< MPI data
998 real(kind_real),intent(in) :: array(:,:,:) !< Array, the rightmost dimension being the vertical
999 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
1000 
1001 ! Local variables
1002 integer :: nmga,nnodes,nl,nl0,nl2d,il0
1003 integer :: shp(3)
1004 real(kind_real),pointer :: ptr_1(:),ptr_2(:,:)
1005 character(len=1024) :: llev2d
1006 type(atlas_functionspace) :: afunctionspace
1007 type(atlas_functionspace_nodecolumns) :: afunctionspace_nc
1008 type(atlas_functionspace_pointcloud) :: afunctionspace_pc
1009 type(atlas_functionspace_structuredcolumns) :: afunctionspace_sc
1010 
1011 ! Set name
1012 
1013 
1014 ! Probe in
1015 
1016 
1017 ! Local lev2d
1018 llev2d = 'first'
1019 if (present(lev2d)) llev2d = lev2d
1020 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_from_array_real_r3','wrong lev2d')
1021 
1022 ! Check kind
1023 if (afield%kind()/=atlas_real(kind_real)) call mpl%abort('atlas_field_from_array_real_r3','wrong kind for field '//afield%name())
1024 
1025 ! Get generic functionspace
1026 afunctionspace = afield%functionspace()
1027 
1028 select case (afunctionspace%name())
1029 case ('NodeColumns')
1030  ! Get NodeColumns function space
1031  afunctionspace_nc = afield%functionspace()
1032 
1033  ! Get number of nodes
1034  nmga = afunctionspace_nc%nb_nodes()
1035 case ('PointCloud')
1036  ! Get PointCloud function space
1037  afunctionspace_pc = afield%functionspace()
1038 
1039  ! Get number of points
1040  nmga = afunctionspace_pc%size()
1041 case ('StructuredColumns')
1042  ! Get StructuredColumns function space
1043  afunctionspace_sc = afield%functionspace()
1044 
1045  ! Get number of nodes
1046  nmga = afunctionspace_sc%size_owned()
1047 case default
1048  call mpl%abort('atlas_field_from_array_real_r3','wrong function space for field '//afield%name()//': '//afunctionspace%name())
1049 end select
1050 
1051 ! Get number of nodes and number of levels
1052 ! - afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
1053 ! - the size of the rightmost dimension of arr2d/arr3d is always positive
1054 ! - to ensure that sizes are compatible for copying data, we use the minimum between the two
1055 shp = shape(array)
1056 nnodes = product(shp(1:3-1))
1057 nl = shp(3)
1058 nl0 = min(afield%levels(),nl)
1059 
1060 ! Check number of nodes
1061 if (nmga/=nnodes) call mpl%abort('atlas_field_from_array_real_r3','wrong number of nodes for field '//afield%name())
1062 
1063 ! Copy data
1064 ! For the 2D case (afield%levels()==0), the field is copied:
1065 ! - at the first level of array if (lev2d=='first')
1066 ! - at the last level of array if (lev2d=='last')
1067 ! NB: an ATLAS field with 1 level only (afield%levels()==1) is considered as a 3D field, so lev2d does not apply
1068 if (nl0==0) then
1069  if (nl>0) then
1070  if (trim(llev2d)=='first') then
1071  nl2d = 1
1072  elseif (trim(llev2d)=='last') then
1073  nl2d = nl
1074  end if
1075  call afield%data(ptr_1)
1076 
1077  ptr_1 = reshape(array(:,:,nl2d),(/product(shp(1:2))/))
1078  end if
1079 else
1080  call afield%data(ptr_2)
1081  do il0=1,nl0
1082 
1083  ptr_2(il0,:) = reshape(array(:,:,il0),(/product(shp(1:2))/))
1084  end do
1085 end if
1086 
1087 ! Probe out
1088 
1089 
1090 end subroutine atlas_field_from_array_real_r3
1091 # 342 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
1092 # 343 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
1093 
1094 # 345 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
1095 !----------------------------------------------------------------------
1096 ! Subroutine: atlas_field_from_array_logical_r2
1097 !> Convert ATLAS field from field
1098 !----------------------------------------------------------------------
1099 subroutine atlas_field_from_array_logical_r2(afield,mpl,array,lev2d)
1100 
1101 implicit none
1102 
1103 ! Passed variables
1104 type(atlas_field),intent(inout) :: afield !< ATLAS field
1105 type(mpl_type),intent(inout) :: mpl !< MPI data
1106 logical,intent(in) :: array(:,:) !< Array, the rightmost dimension being the vertical
1107 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
1108 
1109 ! Local variables
1110 integer :: il0
1111  integer :: imga
1112 
1113 integer,allocatable :: array_int(:,:)
1114 character(len=1024) :: llev2d
1115 
1116 ! Set name
1117 
1118 
1119 ! Probe in
1120 
1121 
1122 ! Local lev2d
1123 llev2d = 'first'
1124 if (present(lev2d)) llev2d = lev2d
1125 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_from_array_logical_r2','wrong lev2d')
1126 
1127 ! Allocation
1128  allocate(array_int(size(array,1),size(array,2)))
1129 
1130 
1131 ! Convert logical to integer
1132 # 383 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
1133  do il0=1,size(array,2)
1134  do imga=1,size(array,1)
1135  if (array(imga,il0)) then
1136  array_int(imga,il0) = 1
1137  else
1138  array_int(imga,il0) = 0
1139  end if
1140  end do
1141  end do
1142 # 393 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
1143 # 406 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
1144 
1145 ! Set integer array
1146 call field_from_array(afield,mpl,array_int,lev2d)
1147 
1148 ! Release memory
1149 deallocate(array_int)
1150 
1151 ! Probe out
1152 
1153 
1154 end subroutine atlas_field_from_array_logical_r2
1155 # 345 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
1156 !----------------------------------------------------------------------
1157 ! Subroutine: atlas_field_from_array_logical_r3
1158 !> Convert ATLAS field from field
1159 !----------------------------------------------------------------------
1160 subroutine atlas_field_from_array_logical_r3(afield,mpl,array,lev2d)
1161 
1162 implicit none
1163 
1164 ! Passed variables
1165 type(atlas_field),intent(inout) :: afield !< ATLAS field
1166 type(mpl_type),intent(inout) :: mpl !< MPI data
1167 logical,intent(in) :: array(:,:,:) !< Array, the rightmost dimension being the vertical
1168 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
1169 
1170 ! Local variables
1171 integer :: il0
1172 
1173  integer :: ixa,iya
1174 integer,allocatable :: array_int(:,:,:)
1175 character(len=1024) :: llev2d
1176 
1177 ! Set name
1178 
1179 
1180 ! Probe in
1181 
1182 
1183 ! Local lev2d
1184 llev2d = 'first'
1185 if (present(lev2d)) llev2d = lev2d
1186 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_from_array_logical_r3','wrong lev2d')
1187 
1188 ! Allocation
1189 
1190  allocate(array_int(size(array,1),size(array,2),size(array,3)))
1191 
1192 ! Convert logical to integer
1193 # 393 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
1194 # 394 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
1195  do il0=1,size(array,3)
1196  do iya=1,size(array,2)
1197  do ixa=1,size(array,1)
1198  if (array(ixa,iya,il0)) then
1199  array_int(ixa,iya,il0) = 1
1200  else
1201  array_int(ixa,iya,il0) = 0
1202  end if
1203  end do
1204  end do
1205  end do
1206 # 406 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
1207 
1208 ! Set integer array
1209 call field_from_array(afield,mpl,array_int,lev2d)
1210 
1211 ! Release memory
1212 deallocate(array_int)
1213 
1214 ! Probe out
1215 
1216 
1217 end subroutine atlas_field_from_array_logical_r3
1218 # 418 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/util/tools_atlas.fypp"
1219 
1220 !----------------------------------------------------------------------
1221 ! Subroutine: atlas_create_atlas_function_space
1222 !> Create ATLAS function space from lon/lat
1223 !----------------------------------------------------------------------
1224 subroutine atlas_create_atlas_function_space(nmga,lon_mga,lat_mga,afunctionspace)
1225 
1226 implicit none
1227 
1228 ! Passed variables
1229 integer,intent(in) :: nmga !< Number of nodes
1230 real(kind_real),intent(in) :: lon_mga(nmga) !< Longitudes [in degrees]
1231 real(kind_real),intent(in) :: lat_mga(nmga) !< Latitudes [in degrees]
1232 type(atlas_functionspace),intent(out) :: afunctionspace !< ATLAS function space
1233 
1234 ! Local variables
1235 integer :: imga
1236 real(kind_real),pointer :: real_ptr(:,:)
1237 type(atlas_field) :: afield
1238 
1239 ! Set name
1240 
1241 
1242 ! Probe in
1243 
1244 
1245 ! Create lon/lat field
1246 afield = atlas_field(name='lonlat',kind=atlas_real(kind_real),shape=(/2,nmga/))
1247 call afield%data(real_ptr)
1248 do imga=1,nmga
1249  real_ptr(1,imga) = lon_mga(imga)
1250  real_ptr(2,imga) = lat_mga(imga)
1251 end do
1252 
1253 ! Create function space PointCloud
1254 afunctionspace = atlas_functionspace_pointcloud(afield)
1255 
1256 ! Probe out
1257 
1258 
1259 end subroutine atlas_create_atlas_function_space
1260 
1261 end module tools_atlas
Generic ranks, dimensions and types.
Definition: tools_atlas.F90:42
subroutine atlas_field_from_array_logical_r2(afield, mpl, array, lev2d)
Convert ATLAS field from field.
subroutine atlas_field_to_array_logical_r3(afield, mpl, array, lev2d)
Convert ATLAS field to field.
subroutine atlas_field_from_array_logical_r3(afield, mpl, array, lev2d)
Convert ATLAS field from field.
subroutine atlas_field_to_array_int_r2(afield, mpl, array, lev2d)
Convert ATLAS field to field.
subroutine atlas_field_from_array_int_r3(afield, mpl, array, lev2d)
Convert field to ATLAS field, real.
subroutine atlas_field_from_array_real_r3(afield, mpl, array, lev2d)
Convert field to ATLAS field, real.
subroutine atlas_field_from_array_int_r2(afield, mpl, array, lev2d)
Convert field to ATLAS field, real.
subroutine atlas_field_to_array_real_r2(afield, mpl, array, lev2d)
Convert ATLAS field to field.
subroutine atlas_field_from_array_real_r2(afield, mpl, array, lev2d)
Convert field to ATLAS field, real.
subroutine atlas_field_to_array_logical_r2(afield, mpl, array, lev2d)
Convert ATLAS field to field.
subroutine atlas_field_to_array_int_r3(afield, mpl, array, lev2d)
Convert ATLAS field to field.
subroutine atlas_create_atlas_function_space(nmga, lon_mga, lat_mga, afunctionspace)
Create ATLAS function space from lon/lat.
subroutine atlas_field_to_array_real_r3(afield, mpl, array, lev2d)
Convert ATLAS field to field.
Subroutines/functions list.
Definition: tools_const.F90:31
real(kind_real), parameter, public rad2deg
Radian to degree.
Definition: tools_const.F90:53
Kinds definition.
Definition: tools_kinds.F90:9
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:25
Generic ranks, dimensions and types.
Definition: type_mpl.F90:42