Debian Codegraph @

src/atlas_f/trans/atlas_Trans_module.F90

raw
1 ! (C) Copyright 2013 ECMWF.
2 !
3 ! This software is licensed under the terms of the Apache Licence Version 2.0
4 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5 ! In applying this licence, ECMWF does not waive the privileges and immunities
6 ! granted to it by virtue of its status as an intergovernmental organisation nor
7 ! does it submit to any jurisdiction.
8
9 #include "atlas/atlas_f.h"
10
11 module atlas_Trans_module
12
13
14 use fckit_object_module, only: fckit_object
15 use fckit_owned_object_module, only: fckit_owned_object
16 use atlas_config_module, only : atlas_Config
17 use atlas_field_module, only : atlas_Field
18 use atlas_fieldset_module, only : atlas_FieldSet
19 use atlas_grid_module, only : atlas_Grid
20 use atlas_functionspace_module, only : atlas_functionspace
21
22 implicit none
23
24 public :: atlas_Trans
25
26 private
27
28 !-----------------------------
29 ! atlas_Trans !
30 !-----------------------------
31
32 !------------------------------------------------------------------------------
33 TYPE, extends(fckit_owned_object) :: atlas_Trans
34
35 ! Purpose :
36 ! -------
37 ! *Trans* : To do spectral transforms
38
39 ! Methods :
40 ! -------
41
42 ! Author :
43 ! ------
44 ! 12-Mar-2015 Willem Deconinck *ECMWF*
45
46 !------------------------------------------------------------------------------
47 contains
48 procedure, nopass :: has_backend
49 procedure, nopass :: set_backend
50 procedure, nopass :: backend
51
52 procedure :: handle
53 procedure :: grid
54 procedure :: truncation
55 procedure :: spectral
56 #if 0
57 procedure :: nb_spectral_coefficients
58 procedure :: nb_spectral_coefficients_global
59 procedure :: nb_gridpoints
60 procedure :: nb_gridpoints_global
61 #endif
62
63 procedure, private :: dirtrans_field
64 procedure, private :: dirtrans_fieldset
65 procedure, public :: dirtrans_wind2vordiv => dirtrans_wind2vordiv_field
66 generic, public :: dirtrans => &
67 & dirtrans_field, &
68 & dirtrans_fieldset
69
70 procedure, private :: invtrans_field
71 procedure, private :: invtrans_fieldset
72 procedure, public :: invtrans_vordiv2wind => invtrans_vordiv2wind_field
73 generic, public :: invtrans => &
74 & invtrans_field, &
75 & invtrans_fieldset
76
77 procedure, private :: invtrans_grad_field
78 generic, public :: invtrans_grad => &
79 & invtrans_grad_field
80
81 ! removed
82 #if 0
83 procedure, private :: gathspec_r1
84 procedure, private :: gathspec_r2
85 generic, public :: gathspec => gathspec_r1, gathspec_r2
86
87 procedure, private :: specnorm_r1_scalar
88 procedure, private :: specnorm_r2
89 generic, public :: specnorm => specnorm_r1_scalar, specnorm_r2
90 #endif
91
92 #if FCKIT_FINAL_NOT_INHERITING
93 final :: atlas_Trans__final_auto
94 #endif
95
96 END TYPE atlas_Trans
97
98 !------------------------------------------------------------------------------
99
100 interface atlas_Trans
101 module procedure atlas_Trans__ctor
102 end interface
103
104 !------------------------------------------------------------------------------
105
106 private :: fckit_owned_object
107 private :: fckit_object
108 private :: atlas_Config
109 private :: atlas_Field
110 private :: atlas_FieldSet
111 private :: atlas_Grid
112
113 !========================================================
114 contains
115 !========================================================
116
117 ! -----------------------------------------------------------------------------
118 ! Trans routines
119
120 function backend()
121 use, intrinsic :: iso_c_binding, only: c_size_t, c_ptr
122 use atlas_trans_c_binding
123 use fckit_c_interop_module, only : c_str, c_ptr_to_string, c_ptr_free
124 character(len=:), allocatable :: backend
125 type(c_ptr) :: value_cptr
126 integer(c_size_t) :: value_size
127 call atlas__Trans__backend(value_cptr,value_size)
128 allocate( character(len=value_size) :: backend )
129 backend = c_ptr_to_string(value_cptr)
130 call c_ptr_free(value_cptr)
131 end function
132
133 function has_backend( backend )
134 use, intrinsic :: iso_c_binding, only: c_int
135 use fckit_c_interop_module, only : c_str
136 use atlas_trans_c_binding
137 logical :: has_backend
138 character(len=*) :: backend
139 integer(c_int) :: has_backend_int
140 has_backend_int = atlas__Trans__has_backend( c_str(backend) )
141 if( has_backend_int == 1 ) then
142 has_backend = .True.
143 else
144 has_backend = .False.
145 end if
146 end function
147
148 subroutine set_backend( backend )
149 use atlas_trans_c_binding
150 use fckit_c_interop_module, only : c_str
151 character(len=*), intent(in) :: backend
152 call atlas__Trans__set_backend( c_str(backend) )
153 end subroutine
154
155
156 function atlas_Trans__ctor( grid, nsmax, config ) result(this)
157 use, intrinsic :: iso_c_binding, only: c_null_ptr
158 use atlas_trans_c_binding
159 type(atlas_Trans) :: this
160 class(atlas_Grid), intent(in) :: grid
161 integer, intent(in), optional :: nsmax
162 type(atlas_Config), intent(in), optional :: config
163 if( present( config ) ) then
164 if( present(nsmax) ) then
165 call this%reset_c_ptr( atlas__Trans__new_config( grid%CPTR_PGIBUG_A, nsmax, config%CPTR_PGIBUG_B ) )
166 else
167 call this%reset_c_ptr( atlas__Trans__new_config( grid%CPTR_PGIBUG_A, 0, config%CPTR_PGIBUG_B ) )
168 endif
169 else
170 if( present(nsmax) ) then
171 call this%reset_c_ptr( atlas__Trans__new( grid%CPTR_PGIBUG_A, nsmax ) )
172 else
173 call this%reset_c_ptr( atlas__Trans__new( grid%CPTR_PGIBUG_A, 0 ) )
174 endif
175 endif
176 call this%return()
177 end function atlas_Trans__ctor
178
179 function handle( this )
180 use atlas_trans_c_binding
181 integer :: handle
182 class(atlas_Trans) :: this
183 handle = atlas__Trans__handle (this%CPTR_PGIBUG_A)
184 end function
185
186 function truncation( this )
187 use atlas_trans_c_binding
188 integer :: truncation
189 class(atlas_Trans) :: this
190 truncation = atlas__Trans__truncation (this%CPTR_PGIBUG_A)
191 end function
192
193 function spectral( this )
194 use atlas_trans_c_binding
195 type(atlas_FunctionSpace) :: spectral
196 class(atlas_Trans) :: this
197 spectral = atlas_FunctionSpace( atlas__Trans__spectral (this%CPTR_PGIBUG_A) )
198 call spectral%return()
199 end function
200
201 function grid( this )
202 use, intrinsic :: iso_c_binding, only: c_null_ptr
203 use atlas_trans_c_binding
204 class(atlas_Trans) :: this
205 type(atlas_Grid) :: grid
206 grid = atlas_Grid( atlas__Trans__grid(this%CPTR_PGIBUG_A) )
207 call grid%return()
208 end function
209
210
211 subroutine dirtrans_fieldset(this, gpfields, spfields, config)
212 use atlas_trans_c_binding
213 class(atlas_Trans), intent(in) :: this
214 class(atlas_FieldSet), intent(in) :: gpfields
215 class(atlas_FieldSet), intent(inout) :: spfields
216 class(atlas_Config), intent(in), optional :: config
217 type(atlas_Config) :: p
218
219 if( present(config) ) then
220 call p%reset_c_ptr( config%CPTR_PGIBUG_B )
221 else
222 p = atlas_Config()
223 endif
224
225 call atlas__Trans__dirtrans_fieldset( this%CPTR_PGIBUG_A, &
226 & gpfields%CPTR_PGIBUG_A, &
227 & spfields%CPTR_PGIBUG_A, &
228 & p%CPTR_PGIBUG_B )
229
230 if( .not. present(config) ) then
231 call p%final()
232 endif
233 end subroutine dirtrans_fieldset
234
235
236 subroutine invtrans_fieldset(this, spfields, gpfields, config)
237 use atlas_trans_c_binding
238 class(atlas_Trans), intent(in) :: this
239 class(atlas_FieldSet), intent(in) :: spfields
240 class(atlas_FieldSet), intent(inout) :: gpfields
241 class(atlas_Config), intent(in), optional :: config
242 type(atlas_Config) :: p
243
244 if( present(config) ) then
245 call p%reset_c_ptr( config%CPTR_PGIBUG_B )
246 else
247 p = atlas_Config()
248 endif
249
250 call atlas__Trans__invtrans_fieldset( this%CPTR_PGIBUG_A, &
251 & spfields%CPTR_PGIBUG_A, &
252 & gpfields%CPTR_PGIBUG_A, &
253 & p%CPTR_PGIBUG_B )
254
255 if( .not. present(config) ) then
256 call p%final()
257 endif
258 end subroutine invtrans_fieldset
259
260 subroutine dirtrans_field(this, gpfield, spfield, config)
261 use atlas_trans_c_binding
262 class(atlas_Trans), intent(in) :: this
263 class(atlas_Field), intent(in) :: gpfield
264 class(atlas_Field), intent(inout) :: spfield
265 class(atlas_Config), intent(in), optional :: config
266 type(atlas_Config) :: p
267
268 if( present(config) ) then
269 call p%reset_c_ptr( config%CPTR_PGIBUG_B )
270 else
271 p = atlas_Config()
272 endif
273
274 call atlas__Trans__dirtrans_field( this%CPTR_PGIBUG_A, &
275 & gpfield%CPTR_PGIBUG_A, &
276 & spfield%CPTR_PGIBUG_A, &
277 & p%CPTR_PGIBUG_B )
278
279 if( .not. present(config) ) then
280 call p%final()
281 endif
282 end subroutine dirtrans_field
283
284 subroutine dirtrans_wind2vordiv_field(this, gpwind, spvor, spdiv, config)
285 use atlas_trans_c_binding
286 class(atlas_Trans), intent(in) :: this
287 type(atlas_Field), intent(in) :: gpwind
288 type(atlas_Field), intent(inout) :: spvor
289 type(atlas_Field), intent(inout) :: spdiv
290 type(atlas_Config), intent(in), optional :: config
291 type(atlas_Config) :: p
292
293 if( present(config) ) then
294 call p%reset_c_ptr( config%CPTR_PGIBUG_B )
295 else
296 p = atlas_Config()
297 endif
298
299 call atlas__Trans__dirtrans_wind2vordiv_field( this%CPTR_PGIBUG_A, &
300 & gpwind%CPTR_PGIBUG_A, &
301 & spvor%CPTR_PGIBUG_A, &
302 & spdiv%CPTR_PGIBUG_A, &
303 & p%CPTR_PGIBUG_B )
304
305 if( .not. present(config) ) then
306 call p%final()
307 endif
308
309 end subroutine dirtrans_wind2vordiv_field
310
311
312 subroutine invtrans_field(this, spfield, gpfield, config)
313 use atlas_trans_c_binding
314 class(atlas_Trans), intent(in) :: this
315 class(atlas_Field), intent(in) :: spfield
316 class(atlas_Field), intent(inout) :: gpfield
317 class(atlas_Config), intent(in), optional :: config
318 type(atlas_Config) :: p
319
320 if( present(config) ) then
321 call p%reset_c_ptr( config%CPTR_PGIBUG_B )
322 else
323 p = atlas_Config()
324 endif
325
326 call atlas__Trans__invtrans_field( this%CPTR_PGIBUG_A, &
327 & spfield%CPTR_PGIBUG_A, &
328 & gpfield%CPTR_PGIBUG_A, &
329 & p%CPTR_PGIBUG_B )
330
331 if( .not. present(config) ) then
332 call p%final()
333 endif
334 end subroutine invtrans_field
335
336
337 subroutine invtrans_vordiv2wind_field(this, spvor, spdiv, gpwind, config)
338 use atlas_trans_c_binding
339 class(atlas_Trans), intent(in) :: this
340 class(atlas_Field), intent(in) :: spvor
341 class(atlas_Field), intent(in) :: spdiv
342 class(atlas_Field), intent(inout) :: gpwind
343 class(atlas_Config), intent(in), optional :: config
344 type(atlas_Config) :: p
345
346 if( present(config) ) then
347 call p%reset_c_ptr( config%CPTR_PGIBUG_B )
348 else
349 p = atlas_Config()
350 endif
351
352 call atlas__Trans__invtrans_vordiv2wind_field( this%CPTR_PGIBUG_A, &
353 & spvor%CPTR_PGIBUG_A, &
354 & spdiv%CPTR_PGIBUG_A, &
355 & gpwind%CPTR_PGIBUG_A, &
356 & p%CPTR_PGIBUG_B )
357
358 if( .not. present(config) ) then
359 call p%final()
360 endif
361
362 end subroutine invtrans_vordiv2wind_field
363
364
365 subroutine invtrans_grad_field(this, spfield, gpfield)
366 use atlas_trans_c_binding
367 class(atlas_Trans), intent(in) :: this
368 class(atlas_Field), intent(in) :: spfield
369 class(atlas_Field), intent(inout) :: gpfield
370 type(atlas_Config) :: config
371 config = atlas_Config()
372 call atlas__Trans__invtrans_grad_field( this%CPTR_PGIBUG_A, &
373 & spfield%CPTR_PGIBUG_A, &
374 & gpfield%CPTR_PGIBUG_A, &
375 & config%CPTR_PGIBUG_B)
376 call config%final()
377 end subroutine invtrans_grad_field
378
379 !-------------------------------------------------------------------------------
380
381 #if FCKIT_FINAL_NOT_INHERITING
382 ATLAS_FINAL subroutine atlas_Trans__final_auto(this)
383 type(atlas_Trans), intent(inout) :: this
384 #if FCKIT_FINAL_DEBUGGING
385 write(0,*) "atlas_Trans__final_auto"
386 #endif
387 #if FCKIT_FINAL_NOT_PROPAGATING
388 call this%final()
389 #endif
390 FCKIT_SUPPRESS_UNUSED( this )
391 end subroutine
392 #endif
393
394 ! ----------------------------------------------------------------------------------------
395
396 end module atlas_Trans_module