Debian Codegraph @

src/atlas_f/functionspace/atlas_functionspace_Spectral_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_functionspace_Spectral_module
12
13 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
14 use fckit_c_interop_module, only : c_str, c_ptr_to_string, c_ptr_free
15 use atlas_functionspace_module, only : atlas_FunctionSpace
16 use atlas_Field_module, only: atlas_Field
17 use atlas_FieldSet_module, only: atlas_FieldSet
18 use atlas_Config_module, only: atlas_Config
19
20 implicit none
21
22 private :: c_ptr, c_int
23 private :: c_str, c_ptr_to_string, c_ptr_free
24 private :: atlas_FunctionSpace
25 private :: atlas_Field
26 private :: atlas_FieldSet
27 private :: atlas_Config
28
29 public :: atlas_functionspace_Spectral
30
31 private
32
33 !------------------------------------------------------------------------------
34 TYPE, extends(atlas_FunctionSpace) :: atlas_functionspace_Spectral
35
36 ! Purpose :
37 ! -------
38 ! *atlas_functionspace_Spectral* : Interpretes spectral fields
39
40 ! Methods :
41 ! -------
42
43 ! Author :
44 ! ------
45 ! August-2015 Willem Deconinck *ECMWF*
46
47 !------------------------------------------------------------------------------
48 contains
49
50 procedure, private :: gather_field
51 procedure, private :: scatter_field
52 procedure, private :: gather_fieldset
53 procedure, private :: scatter_fieldset
54
55 generic, public :: gather => gather_field, gather_fieldset
56 generic, public :: scatter => scatter_field, scatter_fieldset
57
58 procedure, private :: norm_scalar
59 procedure, private :: norm_array
60 generic, public :: norm => norm_scalar, norm_array
61
62 procedure, public :: truncation
63 procedure, public :: nb_spectral_coefficients
64 procedure, public :: nb_spectral_coefficients_global
65 procedure, public :: levels
66
67 procedure, public :: nump
68 procedure, public :: nmyms
69 procedure, public :: nasm0
70 procedure, public :: nvalue
71
72 #if FCKIT_FINAL_NOT_INHERITING
73 final :: atlas_functionspace_Spectral__final_auto
74 #endif
75
76 END TYPE atlas_functionspace_Spectral
77
78 interface atlas_functionspace_Spectral
79 module procedure atlas_functionspace_Spectral__cptr
80 module procedure atlas_functionspace_Spectral__config
81 end interface
82
83 !------------------------------------------------------------------------------
84
85 !========================================================
86 contains
87 !========================================================
88
89 function atlas_functionspace_Spectral__cptr(cptr) result(this)
90 type(atlas_functionspace_Spectral) :: this
91 type(c_ptr), intent(in) :: cptr
92 call this%reset_c_ptr( cptr )
93 call this%return()
94 end function
95
96 function atlas_functionspace_Spectral__config(truncation,levels) result(this)
97 use atlas_functionspace_spectral_c_binding
98 type(atlas_functionspace_Spectral) :: this
99 integer(c_int), intent(in) :: truncation
100 integer(c_int), intent(in), optional :: levels
101
102 type(atlas_Config) :: options
103 options = atlas_Config()
104
105 call options%set("truncation",truncation)
106 if( present(levels) ) call options%set("levels",levels)
107
108 call this%reset_c_ptr( atlas__SpectralFunctionSpace__new__config(options%CPTR_PGIBUG_B) )
109 call options%final()
110
111 call this%return()
112 end function
113
114 subroutine gather_field(this,local,global)
115 use atlas_functionspace_spectral_c_binding
116 class(atlas_functionspace_Spectral), intent(in) :: this
117 type(atlas_Field), intent(in) :: local
118 type(atlas_Field), intent(inout) :: global
119 call atlas__SpectralFunctionSpace__gather(this%CPTR_PGIBUG_A,local%CPTR_PGIBUG_A,global%CPTR_PGIBUG_A)
120 end subroutine
121
122 subroutine scatter_field(this,global,local)
123 use atlas_functionspace_spectral_c_binding
124 class(atlas_functionspace_Spectral), intent(in) :: this
125 type(atlas_Field), intent(in) :: global
126 type(atlas_Field), intent(inout) :: local
127 call atlas__SpectralFunctionSpace__scatter(this%CPTR_PGIBUG_A,global%CPTR_PGIBUG_A,local%CPTR_PGIBUG_A)
128 end subroutine
129
130 subroutine gather_fieldset(this,local,global)
131 use atlas_functionspace_spectral_c_binding
132 class(atlas_functionspace_Spectral), intent(in) :: this
133 type(atlas_FieldSet), intent(in) :: local
134 type(atlas_FieldSet), intent(inout) :: global
135 call atlas__SpectralFunctionSpace__gather_fieldset(this%CPTR_PGIBUG_A,local%CPTR_PGIBUG_A,global%CPTR_PGIBUG_A)
136 end subroutine
137
138 subroutine scatter_fieldset(this,global,local)
139 use atlas_functionspace_spectral_c_binding
140 class(atlas_functionspace_Spectral), intent(in) :: this
141 type(atlas_FieldSet), intent(in) :: global
142 type(atlas_FieldSet), intent(inout) :: local
143 call atlas__SpectralFunctionSpace__scatter_fieldset(this%CPTR_PGIBUG_A,global%CPTR_PGIBUG_A,local%CPTR_PGIBUG_A)
144 end subroutine
145
146 subroutine norm_scalar(this,field,norm,rank)
147 use, intrinsic :: iso_c_binding, only : c_int, c_double
148 use atlas_functionspace_spectral_c_binding
149 class(atlas_functionspace_Spectral), intent(in) :: this
150 type(atlas_Field), intent(in) :: field
151 real(c_double), intent(out) :: norm
152 integer(c_int), optional :: rank
153 integer :: opt_rank
154 real(c_double) :: norm_array(1)
155 opt_rank = 0
156 if( present(rank) ) opt_rank = rank
157 call atlas__SpectralFunctionSpace__norm(this%CPTR_PGIBUG_A,field%CPTR_PGIBUG_A,norm_array,opt_rank)
158 norm = norm_array(1)
159 end subroutine
160
161 subroutine norm_array(this,field,norm,rank)
162 use, intrinsic :: iso_c_binding, only : c_int, c_double
163 use atlas_functionspace_spectral_c_binding
164 class(atlas_functionspace_Spectral), intent(in) :: this
165 type(atlas_Field), intent(in) :: field
166 real(c_double), intent(inout) :: norm(:)
167 integer(c_int), optional :: rank
168 integer :: opt_rank
169 opt_rank = 0
170 if( present(rank) ) opt_rank = rank
171 call atlas__SpectralFunctionSpace__norm(this%CPTR_PGIBUG_A,field%CPTR_PGIBUG_A,norm,opt_rank)
172 end subroutine
173
174 function levels( this )
175 use atlas_functionspace_spectral_c_binding
176 integer :: levels
177 class(atlas_functionspace_Spectral) :: this
178 call atlas__SpectralFunctionSpace__levels( this%c_ptr(), levels )
179 end function
180
181 !-------------------------------------------------------------------------------
182 ! Experimental
183
184 function truncation( this )
185 use atlas_functionspace_spectral_c_binding
186 integer :: truncation
187 class(atlas_functionspace_Spectral) :: this
188 call atlas__SpectralFunctionSpace__truncation( this%c_ptr(), truncation )
189 end function
190
191 function nb_spectral_coefficients( this )
192 use atlas_functionspace_spectral_c_binding
193 integer :: nb_spectral_coefficients
194 class(atlas_functionspace_Spectral) :: this
195 call atlas__SpectralFunctionSpace__nspec2( this%c_ptr(), nb_spectral_coefficients )
196 end function
197
198
199 function nb_spectral_coefficients_global( this )
200 use atlas_functionspace_spectral_c_binding
201 integer :: nb_spectral_coefficients_global
202 class(atlas_functionspace_Spectral) :: this
203 call atlas__SpectralFunctionSpace__nspec2g( this%c_ptr(), nb_spectral_coefficients_global )
204 end function
205
206
207 function nump( this )
208 use atlas_functionspace_spectral_c_binding
209 integer :: nump
210 class(atlas_functionspace_Spectral) :: this
211 call atlas__SpectralFunctionSpace__nump( this%c_ptr(), nump )
212 end function
213
214 function nmyms(this)
215 use atlas_functionspace_spectral_c_binding
216 use, intrinsic :: iso_c_binding, only : c_int, c_f_pointer, c_ptr
217 integer(c_int), pointer :: nmyms(:)
218 class(atlas_functionspace_Spectral), intent(in) :: this
219 type(c_ptr) :: nmyms_c_ptr
220 integer(c_int) :: size
221 call atlas__SpectralFunctionSpace__nmyms(this%c_ptr(), nmyms_c_ptr, size)
222 call c_f_pointer ( nmyms_c_ptr , nmyms , (/size/) )
223 end function
224
225 function nasm0(this)
226 use atlas_functionspace_spectral_c_binding
227 use, intrinsic :: iso_c_binding, only : c_int, c_f_pointer, c_ptr
228 integer(c_int), pointer :: nasm0(:)
229 class(atlas_functionspace_Spectral), intent(in) :: this
230 type(c_ptr) :: nasm0_c_ptr
231 integer(c_int), pointer :: nasm0_f_ptr(:)
232 integer(c_int) :: size
233 call atlas__SpectralFunctionSpace__nasm0(this%c_ptr(), nasm0_c_ptr, size)
234 call c_f_pointer ( nasm0_c_ptr , nasm0_f_ptr , (/size/) )
235 nasm0(0:) => nasm0_f_ptr(:)
236 end function
237
238 function nvalue(this)
239 use atlas_functionspace_spectral_c_binding
240 use, intrinsic :: iso_c_binding, only : c_int, c_f_pointer, c_ptr
241 integer(c_int), pointer :: nvalue(:)
242 class(atlas_functionspace_Spectral), intent(in) :: this
243 type(c_ptr) :: nvalue_c_ptr
244 integer(c_int) :: size
245 call atlas__SpectralFunctionSpace__nvalue(this%c_ptr(), nvalue_c_ptr, size)
246 call c_f_pointer ( nvalue_c_ptr , nvalue , (/size/) )
247 end function
248
249
250
251
252 !-------------------------------------------------------------------------------
253
254 #if FCKIT_FINAL_NOT_INHERITING
255 ATLAS_FINAL subroutine atlas_functionspace_Spectral__final_auto(this)
256 type(atlas_functionspace_Spectral), intent(inout) :: this
257 #if FCKIT_FINAL_DEBUGGING
258 write(0,*) "atlas_functionspace_Spectral__final_auto"
259 #endif
260 #if FCKIT_FINAL_NOT_PROPAGATING
261 call this%final()
262 #endif
263 FCKIT_SUPPRESS_UNUSED( this )
264 end subroutine
265 #endif
266
267 end module atlas_functionspace_Spectral_module
268