SABER
tools_atlas.F90
Go to the documentation of this file.
1 # 1 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
2 # 1 "/Users/miesch/JEDI/code/working_copy/internal/mpas-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 # 57 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/../generics.fypp"
12 # 2 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp" 2
13 # 1 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/../instrumentation.fypp" 1
14 # 1 "/Users/miesch/JEDI/code/working_copy/internal/mpas-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 # 926 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/../subr_list.fypp"
24 # 2 "/Users/miesch/JEDI/code/working_copy/internal/mpas-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/internal/mpas-bundle/saber/src/saber/util/../instrumentation.fypp"
34 # 3 "/Users/miesch/JEDI/code/working_copy/internal/mpas-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_integer,atlas_real,atlas_functionspace,atlas_functionspace_nodecolumns, &
45  & atlas_functionspace_pointcloud,atlas_functionspace_structuredcolumns
46 use tools_const, only: rad2deg
49 use tools_netcdf, only: create_file
50 use type_mpl, only: mpl_type
51 
52 
53 implicit none
54 
55 interface field_to_array
56 # 25 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
57 # 26 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
58  module procedure atlas_field_to_array_int_r2
59 # 26 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
60  module procedure atlas_field_to_array_real_r2
61 # 26 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
62  module procedure atlas_field_to_array_logical_r2
63 # 28 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
64 # 25 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
65 # 26 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
66  module procedure atlas_field_to_array_int_r3
67 # 26 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
68  module procedure atlas_field_to_array_real_r3
69 # 26 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
70  module procedure atlas_field_to_array_logical_r3
71 # 28 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
72 # 29 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
73 end interface
75 # 32 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
76 # 33 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
77  module procedure atlas_field_from_array_int_r2
78 # 33 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
79  module procedure atlas_field_from_array_real_r2
80 # 33 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
81  module procedure atlas_field_from_array_logical_r2
82 # 35 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
83 # 32 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
84 # 33 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
85  module procedure atlas_field_from_array_int_r3
86 # 33 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
87  module procedure atlas_field_from_array_real_r3
88 # 33 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
89  module procedure atlas_field_from_array_logical_r3
90 # 35 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
91 # 36 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
92 end interface
94  module procedure atlas_create_atlas_function_space
95 end interface
97  module procedure atlas_get_atlas_field_size
98 end interface
99 
100 private
102 
103 contains
104 
105 # 50 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
106 # 51 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
107 !----------------------------------------------------------------------
108 ! Subroutine: atlas_field_to_array_int_r2
109 !> Convert ATLAS field to field
110 !----------------------------------------------------------------------
111 subroutine atlas_field_to_array_int_r2(afield,mpl,array,lev2d)
112 
113 implicit none
114 
115 ! Passed variables
116 type(atlas_field),intent(in) :: afield !< ATLAS field
117 type(mpl_type),intent(inout) :: mpl !< MPI data
118 integer(kind_int),intent(out) :: array(:,:) !< Array, the rightmost dimension being the vertical
119 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
120 
121 ! Local variables
122 integer :: nmga,nnodes,nl0,nl2d,il0
123 integer :: shp(2)
124 integer(kind_int),pointer :: ptr_1(:),ptr_2(:,:)
125 character(len=1024) :: llev2d
126 
127 ! Set name
128 
129 
130 ! Probe in
131 
132 
133 ! Local lev2d
134 llev2d = 'first'
135 if (present(lev2d)) llev2d = lev2d
136 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_to_array_int_r2','wrong lev2d')
137 
138 ! Check kind
139 if (afield%kind()/=atlas_integer(kind_int)) call mpl%abort('atlas_field_to_array_int_r2','wrong kind for field '//afield%name())
140 
141 ! Get ATLAS field size
142 nmga = get_atlas_field_size(mpl,afield)
143 
144 ! Get number of nodes and number of levels
145 ! - the size of the rightmost dimension of arr2d/arr3d is the number of levels (nl0)
146 ! - the product of the other dimenstions give the number of nodes (nnodes)
147 shp = shape(array)
148 nl0 = shp(2)
149 nnodes = product(shp(1:2-1))
150 
151 ! Check number of nodes
152 if (nmga/=nnodes) call mpl%abort('atlas_field_to_array_int_r2','wrong number of nodes for field '//afield%name())
153 
154 ! Initialization
155 array = 0
156 
157 ! Copy data
158 ! afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
159 ! For the 2D case (afield%levels()==0), the field is copied:
160 ! - at the first level of array if (lev2d=='first')
161 ! - at the last level of array if (lev2d=='last')
162 if (afield%levels()==0) then
163  if (trim(llev2d)=='first') then
164  nl2d = 1
165  elseif (trim(llev2d)=='last') then
166  nl2d = nl0
167  end if
168  call afield%data(ptr_1)
169  array(:,nl2d) = ptr_1
170 
171 else
172  if (nl0>afield%levels()) call mpl%abort('atlas_field_to_array_int_r2','not enough levels in ATLAS field')
173  call afield%data(ptr_2)
174  do il0=1,nl0
175  array(:,il0) = ptr_2(il0,:)
176 
177  end do
178 end if
179 
180 ! Probe out
181 
182 
183 end subroutine atlas_field_to_array_int_r2
184 # 51 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
185 !----------------------------------------------------------------------
186 ! Subroutine: atlas_field_to_array_real_r2
187 !> Convert ATLAS field to field
188 !----------------------------------------------------------------------
189 subroutine atlas_field_to_array_real_r2(afield,mpl,array,lev2d)
190 
191 implicit none
192 
193 ! Passed variables
194 type(atlas_field),intent(in) :: afield !< ATLAS field
195 type(mpl_type),intent(inout) :: mpl !< MPI data
196 real(kind_real),intent(out) :: array(:,:) !< Array, the rightmost dimension being the vertical
197 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
198 
199 ! Local variables
200 integer :: nmga,nnodes,nl0,nl2d,il0
201 integer :: shp(2)
202 real(kind_real),pointer :: ptr_1(:),ptr_2(:,:)
203 character(len=1024) :: llev2d
204 
205 ! Set name
206 
207 
208 ! Probe in
209 
210 
211 ! Local lev2d
212 llev2d = 'first'
213 if (present(lev2d)) llev2d = lev2d
214 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_to_array_real_r2','wrong lev2d')
215 
216 ! Check kind
217 if (afield%kind()/=atlas_real(kind_real)) call mpl%abort('atlas_field_to_array_real_r2','wrong kind for field '//afield%name())
218 
219 ! Get ATLAS field size
220 nmga = get_atlas_field_size(mpl,afield)
221 
222 ! Get number of nodes and number of levels
223 ! - the size of the rightmost dimension of arr2d/arr3d is the number of levels (nl0)
224 ! - the product of the other dimenstions give the number of nodes (nnodes)
225 shp = shape(array)
226 nl0 = shp(2)
227 nnodes = product(shp(1:2-1))
228 
229 ! Check number of nodes
230 if (nmga/=nnodes) call mpl%abort('atlas_field_to_array_real_r2','wrong number of nodes for field '//afield%name())
231 
232 ! Initialization
233 array = 0.0_kind_real
234 
235 ! Copy data
236 ! afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
237 ! For the 2D case (afield%levels()==0), the field is copied:
238 ! - at the first level of array if (lev2d=='first')
239 ! - at the last level of array if (lev2d=='last')
240 if (afield%levels()==0) then
241  if (trim(llev2d)=='first') then
242  nl2d = 1
243  elseif (trim(llev2d)=='last') then
244  nl2d = nl0
245  end if
246  call afield%data(ptr_1)
247  array(:,nl2d) = ptr_1
248 
249 else
250  if (nl0>afield%levels()) call mpl%abort('atlas_field_to_array_real_r2','not enough levels in ATLAS field')
251  call afield%data(ptr_2)
252  do il0=1,nl0
253  array(:,il0) = ptr_2(il0,:)
254 
255  end do
256 end if
257 
258 ! Probe out
259 
260 
261 end subroutine atlas_field_to_array_real_r2
262 # 129 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
263 # 50 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
264 # 51 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
265 !----------------------------------------------------------------------
266 ! Subroutine: atlas_field_to_array_int_r3
267 !> Convert ATLAS field to field
268 !----------------------------------------------------------------------
269 subroutine atlas_field_to_array_int_r3(afield,mpl,array,lev2d)
270 
271 implicit none
272 
273 ! Passed variables
274 type(atlas_field),intent(in) :: afield !< ATLAS field
275 type(mpl_type),intent(inout) :: mpl !< MPI data
276 integer(kind_int),intent(out) :: array(:,:,:) !< Array, the rightmost dimension being the vertical
277 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
278 
279 ! Local variables
280 integer :: nmga,nnodes,nl0,nl2d,il0
281 integer :: shp(3)
282 integer(kind_int),pointer :: ptr_1(:),ptr_2(:,:)
283 character(len=1024) :: llev2d
284 
285 ! Set name
286 
287 
288 ! Probe in
289 
290 
291 ! Local lev2d
292 llev2d = 'first'
293 if (present(lev2d)) llev2d = lev2d
294 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_to_array_int_r3','wrong lev2d')
295 
296 ! Check kind
297 if (afield%kind()/=atlas_integer(kind_int)) call mpl%abort('atlas_field_to_array_int_r3','wrong kind for field '//afield%name())
298 
299 ! Get ATLAS field size
300 nmga = get_atlas_field_size(mpl,afield)
301 
302 ! Get number of nodes and number of levels
303 ! - the size of the rightmost dimension of arr2d/arr3d is the number of levels (nl0)
304 ! - the product of the other dimenstions give the number of nodes (nnodes)
305 shp = shape(array)
306 nl0 = shp(3)
307 nnodes = product(shp(1:3-1))
308 
309 ! Check number of nodes
310 if (nmga/=nnodes) call mpl%abort('atlas_field_to_array_int_r3','wrong number of nodes for field '//afield%name())
311 
312 ! Initialization
313 array = 0
314 
315 ! Copy data
316 ! afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
317 ! For the 2D case (afield%levels()==0), the field is copied:
318 ! - at the first level of array if (lev2d=='first')
319 ! - at the last level of array if (lev2d=='last')
320 if (afield%levels()==0) then
321  if (trim(llev2d)=='first') then
322  nl2d = 1
323  elseif (trim(llev2d)=='last') then
324  nl2d = nl0
325  end if
326  call afield%data(ptr_1)
327 
328  array(:,:,nl2d) = reshape(ptr_1,shp(1:2))
329 else
330  if (nl0>afield%levels()) call mpl%abort('atlas_field_to_array_int_r3','not enough levels in ATLAS field')
331  call afield%data(ptr_2)
332  do il0=1,nl0
333 
334  array(:,:,il0) = reshape(ptr_2(il0,:),shp(1:2))
335  end do
336 end if
337 
338 ! Probe out
339 
340 
341 end subroutine atlas_field_to_array_int_r3
342 # 51 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
343 !----------------------------------------------------------------------
344 ! Subroutine: atlas_field_to_array_real_r3
345 !> Convert ATLAS field to field
346 !----------------------------------------------------------------------
347 subroutine atlas_field_to_array_real_r3(afield,mpl,array,lev2d)
348 
349 implicit none
350 
351 ! Passed variables
352 type(atlas_field),intent(in) :: afield !< ATLAS field
353 type(mpl_type),intent(inout) :: mpl !< MPI data
354 real(kind_real),intent(out) :: array(:,:,:) !< Array, the rightmost dimension being the vertical
355 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
356 
357 ! Local variables
358 integer :: nmga,nnodes,nl0,nl2d,il0
359 integer :: shp(3)
360 real(kind_real),pointer :: ptr_1(:),ptr_2(:,:)
361 character(len=1024) :: llev2d
362 
363 ! Set name
364 
365 
366 ! Probe in
367 
368 
369 ! Local lev2d
370 llev2d = 'first'
371 if (present(lev2d)) llev2d = lev2d
372 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_to_array_real_r3','wrong lev2d')
373 
374 ! Check kind
375 if (afield%kind()/=atlas_real(kind_real)) call mpl%abort('atlas_field_to_array_real_r3','wrong kind for field '//afield%name())
376 
377 ! Get ATLAS field size
378 nmga = get_atlas_field_size(mpl,afield)
379 
380 ! Get number of nodes and number of levels
381 ! - the size of the rightmost dimension of arr2d/arr3d is the number of levels (nl0)
382 ! - the product of the other dimenstions give the number of nodes (nnodes)
383 shp = shape(array)
384 nl0 = shp(3)
385 nnodes = product(shp(1:3-1))
386 
387 ! Check number of nodes
388 if (nmga/=nnodes) call mpl%abort('atlas_field_to_array_real_r3','wrong number of nodes for field '//afield%name())
389 
390 ! Initialization
391 array = 0.0_kind_real
392 
393 ! Copy data
394 ! afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
395 ! For the 2D case (afield%levels()==0), the field is copied:
396 ! - at the first level of array if (lev2d=='first')
397 ! - at the last level of array if (lev2d=='last')
398 if (afield%levels()==0) then
399  if (trim(llev2d)=='first') then
400  nl2d = 1
401  elseif (trim(llev2d)=='last') then
402  nl2d = nl0
403  end if
404  call afield%data(ptr_1)
405 
406  array(:,:,nl2d) = reshape(ptr_1,shp(1:2))
407 else
408  if (nl0>afield%levels()) call mpl%abort('atlas_field_to_array_real_r3','not enough levels in ATLAS field')
409  call afield%data(ptr_2)
410  do il0=1,nl0
411 
412  array(:,:,il0) = reshape(ptr_2(il0,:),shp(1:2))
413  end do
414 end if
415 
416 ! Probe out
417 
418 
419 end subroutine atlas_field_to_array_real_r3
420 # 129 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
421 # 130 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
422 
423 # 132 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
424 !----------------------------------------------------------------------
425 ! Subroutine: atlas_field_to_array_logical_r2
426 !> Convert ATLAS field to field
427 !----------------------------------------------------------------------
428 subroutine atlas_field_to_array_logical_r2(afield,mpl,array,lev2d)
429 
430 implicit none
431 
432 ! Passed variables
433 type(atlas_field),intent(in) :: afield !< ATLAS field
434 type(mpl_type),intent(inout) :: mpl !< MPI data
435 logical,intent(out) :: array(:,:) !< Array, the rightmost dimension being the vertical
436 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
437 
438 ! Local variables
439 integer :: shp(2)
440 integer,allocatable :: array_int(:,:)
441 character(len=1024) :: llev2d
442 
443 ! Set name
444 
445 
446 ! Probe in
447 
448 
449 ! Local lev2d
450 llev2d = 'first'
451 if (present(lev2d)) llev2d = lev2d
452 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_to_array_logical_r2','wrong lev2d')
453 
454 ! Allocation
455 shp = shape(array)
456  allocate(array_int(shp(1),shp(2)))
457 
458 
459 ! Get integer array
460 call field_to_array(afield,mpl,array_int,lev2d)
461 
462 ! Convert integer to logical
463 call convert_i2l(mpl,array_int,array)
464 
465 ! Release memory
466 deallocate(array_int)
467 
468 ! Probe out
469 
470 
471 end subroutine atlas_field_to_array_logical_r2
472 # 132 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
473 !----------------------------------------------------------------------
474 ! Subroutine: atlas_field_to_array_logical_r3
475 !> Convert ATLAS field to field
476 !----------------------------------------------------------------------
477 subroutine atlas_field_to_array_logical_r3(afield,mpl,array,lev2d)
478 
479 implicit none
480 
481 ! Passed variables
482 type(atlas_field),intent(in) :: afield !< ATLAS field
483 type(mpl_type),intent(inout) :: mpl !< MPI data
484 logical,intent(out) :: array(:,:,:) !< Array, the rightmost dimension being the vertical
485 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
486 
487 ! Local variables
488 integer :: shp(3)
489 integer,allocatable :: array_int(:,:,:)
490 character(len=1024) :: llev2d
491 
492 ! Set name
493 
494 
495 ! Probe in
496 
497 
498 ! Local lev2d
499 llev2d = 'first'
500 if (present(lev2d)) llev2d = lev2d
501 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_to_array_logical_r3','wrong lev2d')
502 
503 ! Allocation
504 shp = shape(array)
505 
506  allocate(array_int(shp(1),shp(2),shp(3)))
507 
508 ! Get integer array
509 call field_to_array(afield,mpl,array_int,lev2d)
510 
511 ! Convert integer to logical
512 call convert_i2l(mpl,array_int,array)
513 
514 ! Release memory
515 deallocate(array_int)
516 
517 ! Probe out
518 
519 
520 end subroutine atlas_field_to_array_logical_r3
521 # 181 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
522 
523 # 183 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
524 # 184 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
525 !----------------------------------------------------------------------
526 ! Subroutine: atlas_field_from_array_int_r2
527 !> Convert field to ATLAS field, real
528 !----------------------------------------------------------------------
529 subroutine atlas_field_from_array_int_r2(afield,mpl,array,lev2d)
530 
531 implicit none
532 
533 ! Passed variables
534 type(atlas_field),intent(inout) :: afield !< ATLAS field
535 type(mpl_type),intent(inout) :: mpl !< MPI data
536 integer(kind_int),intent(in) :: array(:,:) !< Array, the rightmost dimension being the vertical
537 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
538 
539 ! Local variables
540 integer :: nmga,nnodes,nl0,nl2d,il0
541 integer :: shp(2)
542 integer(kind_int),pointer :: ptr_1(:),ptr_2(:,:)
543 character(len=1024) :: llev2d
544 
545 ! Set name
546 
547 
548 ! Probe in
549 
550 
551 ! Local lev2d
552 llev2d = 'first'
553 if (present(lev2d)) llev2d = lev2d
554 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_from_array_int_r2','wrong lev2d')
555 
556 ! Check kind
557 if (afield%kind()/=atlas_integer(kind_int)) call mpl%abort('atlas_field_from_array_int_r2','wrong kind for field '//afield%name())
558 
559 ! Get ATLAS field size
560 nmga = get_atlas_field_size(mpl,afield)
561 
562 ! Get number of nodes and number of levels
563 ! - the size of the rightmost dimension of arr2d/arr3d is the number of levels (nl0)
564 ! - the product of the other dimenstions give the number of nodes (nnodes)
565 shp = shape(array)
566 nl0 = shp(2)
567 nnodes = product(shp(1:2-1))
568 
569 ! Check number of nodes
570 if (nmga/=nnodes) call mpl%abort('atlas_field_from_array_int_r2','wrong number of nodes for field '//afield%name())
571 
572 ! Copy data
573 ! afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
574 ! For the 2D case (afield%levels()==0), the field is copied:
575 ! - at the first level of array if (lev2d=='first')
576 ! - at the last level of array if (lev2d=='last')
577 if (afield%levels()==0) then
578  if (trim(llev2d)=='first') then
579  nl2d = 1
580  elseif (trim(llev2d)=='last') then
581  nl2d = nl0
582  end if
583  call afield%data(ptr_1)
584  ptr_1 = array(:,nl2d)
585 
586 else
587  if (nl0>afield%levels()) call mpl%abort('atlas_field_from_array_int_r2','not enough levels in ATLAS field')
588  call afield%data(ptr_2)
589  do il0=1,nl0
590  ptr_2(il0,:) = array(:,il0)
591 
592  end do
593 end if
594 
595 ! Probe out
596 
597 
598 end subroutine atlas_field_from_array_int_r2
599 # 184 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
600 !----------------------------------------------------------------------
601 ! Subroutine: atlas_field_from_array_real_r2
602 !> Convert field to ATLAS field, real
603 !----------------------------------------------------------------------
604 subroutine atlas_field_from_array_real_r2(afield,mpl,array,lev2d)
605 
606 implicit none
607 
608 ! Passed variables
609 type(atlas_field),intent(inout) :: afield !< ATLAS field
610 type(mpl_type),intent(inout) :: mpl !< MPI data
611 real(kind_real),intent(in) :: array(:,:) !< Array, the rightmost dimension being the vertical
612 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
613 
614 ! Local variables
615 integer :: nmga,nnodes,nl0,nl2d,il0
616 integer :: shp(2)
617 real(kind_real),pointer :: ptr_1(:),ptr_2(:,:)
618 character(len=1024) :: llev2d
619 
620 ! Set name
621 
622 
623 ! Probe in
624 
625 
626 ! Local lev2d
627 llev2d = 'first'
628 if (present(lev2d)) llev2d = lev2d
629 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_from_array_real_r2','wrong lev2d')
630 
631 ! Check kind
632 if (afield%kind()/=atlas_real(kind_real)) call mpl%abort('atlas_field_from_array_real_r2','wrong kind for field '//afield%name())
633 
634 ! Get ATLAS field size
635 nmga = get_atlas_field_size(mpl,afield)
636 
637 ! Get number of nodes and number of levels
638 ! - the size of the rightmost dimension of arr2d/arr3d is the number of levels (nl0)
639 ! - the product of the other dimenstions give the number of nodes (nnodes)
640 shp = shape(array)
641 nl0 = shp(2)
642 nnodes = product(shp(1:2-1))
643 
644 ! Check number of nodes
645 if (nmga/=nnodes) call mpl%abort('atlas_field_from_array_real_r2','wrong number of nodes for field '//afield%name())
646 
647 ! Copy data
648 ! afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
649 ! For the 2D case (afield%levels()==0), the field is copied:
650 ! - at the first level of array if (lev2d=='first')
651 ! - at the last level of array if (lev2d=='last')
652 if (afield%levels()==0) then
653  if (trim(llev2d)=='first') then
654  nl2d = 1
655  elseif (trim(llev2d)=='last') then
656  nl2d = nl0
657  end if
658  call afield%data(ptr_1)
659  ptr_1 = array(:,nl2d)
660 
661 else
662  if (nl0>afield%levels()) call mpl%abort('atlas_field_from_array_real_r2','not enough levels in ATLAS field')
663  call afield%data(ptr_2)
664  do il0=1,nl0
665  ptr_2(il0,:) = array(:,il0)
666 
667  end do
668 end if
669 
670 ! Probe out
671 
672 
673 end subroutine atlas_field_from_array_real_r2
674 # 259 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
675 # 183 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
676 # 184 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
677 !----------------------------------------------------------------------
678 ! Subroutine: atlas_field_from_array_int_r3
679 !> Convert field to ATLAS field, real
680 !----------------------------------------------------------------------
681 subroutine atlas_field_from_array_int_r3(afield,mpl,array,lev2d)
682 
683 implicit none
684 
685 ! Passed variables
686 type(atlas_field),intent(inout) :: afield !< ATLAS field
687 type(mpl_type),intent(inout) :: mpl !< MPI data
688 integer(kind_int),intent(in) :: array(:,:,:) !< Array, the rightmost dimension being the vertical
689 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
690 
691 ! Local variables
692 integer :: nmga,nnodes,nl0,nl2d,il0
693 integer :: shp(3)
694 integer(kind_int),pointer :: ptr_1(:),ptr_2(:,:)
695 character(len=1024) :: llev2d
696 
697 ! Set name
698 
699 
700 ! Probe in
701 
702 
703 ! Local lev2d
704 llev2d = 'first'
705 if (present(lev2d)) llev2d = lev2d
706 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_from_array_int_r3','wrong lev2d')
707 
708 ! Check kind
709 if (afield%kind()/=atlas_integer(kind_int)) call mpl%abort('atlas_field_from_array_int_r3','wrong kind for field '//afield%name())
710 
711 ! Get ATLAS field size
712 nmga = get_atlas_field_size(mpl,afield)
713 
714 ! Get number of nodes and number of levels
715 ! - the size of the rightmost dimension of arr2d/arr3d is the number of levels (nl0)
716 ! - the product of the other dimenstions give the number of nodes (nnodes)
717 shp = shape(array)
718 nl0 = shp(3)
719 nnodes = product(shp(1:3-1))
720 
721 ! Check number of nodes
722 if (nmga/=nnodes) call mpl%abort('atlas_field_from_array_int_r3','wrong number of nodes for field '//afield%name())
723 
724 ! Copy data
725 ! afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
726 ! For the 2D case (afield%levels()==0), the field is copied:
727 ! - at the first level of array if (lev2d=='first')
728 ! - at the last level of array if (lev2d=='last')
729 if (afield%levels()==0) then
730  if (trim(llev2d)=='first') then
731  nl2d = 1
732  elseif (trim(llev2d)=='last') then
733  nl2d = nl0
734  end if
735  call afield%data(ptr_1)
736 
737  ptr_1 = reshape(array(:,:,nl2d),(/product(shp(1:2))/))
738 else
739  if (nl0>afield%levels()) call mpl%abort('atlas_field_from_array_int_r3','not enough levels in ATLAS field')
740  call afield%data(ptr_2)
741  do il0=1,nl0
742 
743  ptr_2(il0,:) = reshape(array(:,:,il0),(/product(shp(1:2))/))
744  end do
745 end if
746 
747 ! Probe out
748 
749 
750 end subroutine atlas_field_from_array_int_r3
751 # 184 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
752 !----------------------------------------------------------------------
753 ! Subroutine: atlas_field_from_array_real_r3
754 !> Convert field to ATLAS field, real
755 !----------------------------------------------------------------------
756 subroutine atlas_field_from_array_real_r3(afield,mpl,array,lev2d)
757 
758 implicit none
759 
760 ! Passed variables
761 type(atlas_field),intent(inout) :: afield !< ATLAS field
762 type(mpl_type),intent(inout) :: mpl !< MPI data
763 real(kind_real),intent(in) :: array(:,:,:) !< Array, the rightmost dimension being the vertical
764 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
765 
766 ! Local variables
767 integer :: nmga,nnodes,nl0,nl2d,il0
768 integer :: shp(3)
769 real(kind_real),pointer :: ptr_1(:),ptr_2(:,:)
770 character(len=1024) :: llev2d
771 
772 ! Set name
773 
774 
775 ! Probe in
776 
777 
778 ! Local lev2d
779 llev2d = 'first'
780 if (present(lev2d)) llev2d = lev2d
781 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_from_array_real_r3','wrong lev2d')
782 
783 ! Check kind
784 if (afield%kind()/=atlas_real(kind_real)) call mpl%abort('atlas_field_from_array_real_r3','wrong kind for field '//afield%name())
785 
786 ! Get ATLAS field size
787 nmga = get_atlas_field_size(mpl,afield)
788 
789 ! Get number of nodes and number of levels
790 ! - the size of the rightmost dimension of arr2d/arr3d is the number of levels (nl0)
791 ! - the product of the other dimenstions give the number of nodes (nnodes)
792 shp = shape(array)
793 nl0 = shp(3)
794 nnodes = product(shp(1:3-1))
795 
796 ! Check number of nodes
797 if (nmga/=nnodes) call mpl%abort('atlas_field_from_array_real_r3','wrong number of nodes for field '//afield%name())
798 
799 ! Copy data
800 ! afield%levels() is 0 for 2D ATLAS fields, positive for 3D fields
801 ! For the 2D case (afield%levels()==0), the field is copied:
802 ! - at the first level of array if (lev2d=='first')
803 ! - at the last level of array if (lev2d=='last')
804 if (afield%levels()==0) then
805  if (trim(llev2d)=='first') then
806  nl2d = 1
807  elseif (trim(llev2d)=='last') then
808  nl2d = nl0
809  end if
810  call afield%data(ptr_1)
811 
812  ptr_1 = reshape(array(:,:,nl2d),(/product(shp(1:2))/))
813 else
814  if (nl0>afield%levels()) call mpl%abort('atlas_field_from_array_real_r3','not enough levels in ATLAS field')
815  call afield%data(ptr_2)
816  do il0=1,nl0
817 
818  ptr_2(il0,:) = reshape(array(:,:,il0),(/product(shp(1:2))/))
819  end do
820 end if
821 
822 ! Probe out
823 
824 
825 end subroutine atlas_field_from_array_real_r3
826 # 259 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
827 # 260 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
828 
829 # 262 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
830 !----------------------------------------------------------------------
831 ! Subroutine: atlas_field_from_array_logical_r2
832 !> Convert ATLAS field from field
833 !----------------------------------------------------------------------
834 subroutine atlas_field_from_array_logical_r2(afield,mpl,array,lev2d)
835 
836 implicit none
837 
838 ! Passed variables
839 type(atlas_field),intent(inout) :: afield !< ATLAS field
840 type(mpl_type),intent(inout) :: mpl !< MPI data
841 logical,intent(in) :: array(:,:) !< Array, the rightmost dimension being the vertical
842 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
843 
844 ! Local variables
845 integer :: shp(2)
846 integer,allocatable :: array_int(:,:)
847 character(len=1024) :: llev2d
848 
849 ! Set name
850 
851 
852 ! Probe in
853 
854 
855 ! Local lev2d
856 llev2d = 'first'
857 if (present(lev2d)) llev2d = lev2d
858 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_from_array_logical_r2','wrong lev2d')
859 
860 ! Allocation
861 shp = shape(array)
862  allocate(array_int(shp(1),shp(2)))
863 
864 
865 ! Convert logical to integer
866 call convert_l2i(array,array_int)
867 
868 ! Set integer array
869 call field_from_array(afield,mpl,array_int,lev2d)
870 
871 ! Release memory
872 deallocate(array_int)
873 
874 ! Probe out
875 
876 
878 # 262 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
879 !----------------------------------------------------------------------
880 ! Subroutine: atlas_field_from_array_logical_r3
881 !> Convert ATLAS field from field
882 !----------------------------------------------------------------------
883 subroutine atlas_field_from_array_logical_r3(afield,mpl,array,lev2d)
884 
885 implicit none
886 
887 ! Passed variables
888 type(atlas_field),intent(inout) :: afield !< ATLAS field
889 type(mpl_type),intent(inout) :: mpl !< MPI data
890 logical,intent(in) :: array(:,:,:) !< Array, the rightmost dimension being the vertical
891 character(len=*),intent(in),optional :: lev2d !< Level for 2D variables
892 
893 ! Local variables
894 integer :: shp(3)
895 integer,allocatable :: array_int(:,:,:)
896 character(len=1024) :: llev2d
897 
898 ! Set name
899 
900 
901 ! Probe in
902 
903 
904 ! Local lev2d
905 llev2d = 'first'
906 if (present(lev2d)) llev2d = lev2d
907 if (.not.((trim(llev2d)=='first').or.(trim(llev2d)=='last'))) call mpl%abort('atlas_field_from_array_logical_r3','wrong lev2d')
908 
909 ! Allocation
910 shp = shape(array)
911 
912  allocate(array_int(shp(1),shp(2),shp(3)))
913 
914 ! Convert logical to integer
915 call convert_l2i(array,array_int)
916 
917 ! Set integer array
918 call field_from_array(afield,mpl,array_int,lev2d)
919 
920 ! Release memory
921 deallocate(array_int)
922 
923 ! Probe out
924 
925 
927 # 311 "/Users/miesch/JEDI/code/working_copy/internal/mpas-bundle/saber/src/saber/util/tools_atlas.fypp"
928 
929 !----------------------------------------------------------------------
930 ! Subroutine: atlas_create_atlas_function_space
931 !> Create ATLAS function space from lon/lat
932 !----------------------------------------------------------------------
933 subroutine atlas_create_atlas_function_space(nmga,lon_mga,lat_mga,afunctionspace)
934 
935 implicit none
936 
937 ! Passed variables
938 integer,intent(in) :: nmga !< Number of nodes
939 real(kind_real),intent(in) :: lon_mga(nmga) !< Longitudes [in degrees]
940 real(kind_real),intent(in) :: lat_mga(nmga) !< Latitudes [in degrees]
941 type(atlas_functionspace),intent(out) :: afunctionspace !< ATLAS function space
942 
943 ! Local variables
944 integer :: imga
945 real(kind_real),pointer :: real_ptr(:,:)
946 type(atlas_field) :: afield
947 
948 ! Set name
949 
950 
951 ! Probe in
952 
953 
954 ! Create lon/lat field
955 afield = atlas_field(name='lonlat',kind=atlas_real(kind_real),shape=(/2,nmga/))
956 call afield%data(real_ptr)
957 do imga=1,nmga
958  real_ptr(1,imga) = lon_mga(imga)
959  real_ptr(2,imga) = lat_mga(imga)
960 end do
961 
962 ! Create function space PointCloud
963 afunctionspace = atlas_functionspace_pointcloud(afield)
964 
965 ! Probe out
966 
967 
969 
970 !----------------------------------------------------------------------
971 ! Function: atlas_get_atlas_field_size
972 !> Get the local horizontal size of an ATLAS field
973 !----------------------------------------------------------------------
974 function atlas_get_atlas_field_size(mpl,afield) result(nmga)
975 
976 implicit none
977 
978 ! Passed variables
979 type(mpl_type),intent(inout) :: mpl !< MPI data
980 type(atlas_field),intent(in) :: afield !< ATLAS field
981 
982 ! Returned variable
983 integer :: nmga
984 
985 ! Local variables
986 type(atlas_functionspace) :: afunctionspace
987 type(atlas_functionspace_nodecolumns) :: afunctionspace_nc
988 type(atlas_functionspace_pointcloud) :: afunctionspace_pc
989 type(atlas_functionspace_structuredcolumns) :: afunctionspace_sc
990 
991 ! Set name
992 
993 
994 ! Probe in
995 
996 
997 ! Get generic functionspace
998 afunctionspace = afield%functionspace()
999 
1000 select case (afunctionspace%name())
1001 case ('NodeColumns')
1002  ! Get NodeColumns function space
1003  afunctionspace_nc = afield%functionspace()
1004 
1005  ! Get number of nodes
1006  nmga = afunctionspace_nc%nb_nodes()
1007 case ('PointCloud')
1008  ! Get PointCloud function space
1009  afunctionspace_pc = afield%functionspace()
1010 
1011  ! Get number of points
1012  nmga = afunctionspace_pc%size()
1013 case ('StructuredColumns')
1014  ! Get StructuredColumns function space
1015  afunctionspace_sc = afield%functionspace()
1016 
1017  ! Get number of nodes
1018  nmga = afunctionspace_sc%size_owned()
1019 case default
1020  call mpl%abort('atlas_get_atlas_field_size','wrong function space for field '//afield%name()//': '//afunctionspace%name())
1021 end select
1022 
1023 ! Probe out
1024 
1025 
1026 end function atlas_get_atlas_field_size
1027 
1028 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.
integer function atlas_get_atlas_field_size(mpl, afield)
Get the local horizontal size of an ATLAS 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:55
Subroutines/functions list.
Definition: tools_func.F90:42
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:31
Generic ranks, dimensions and types.
Generic ranks, dimensions and types.
Definition: type_mpl.F90:42