Debian Codegraph @

src/atlas_f/field/atlas_State_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_State_module
12
13 use fckit_owned_object_module, only: fckit_owned_object
14 use atlas_Field_module, only: atlas_Field
15 use atlas_kinds_module, only: ATLAS_KIND_IDX
16 implicit none
17
18 private :: fckit_owned_object
19 private :: atlas_Field
20
21 public :: atlas_State
22
23 private
24
25 !----------------------------!
26 ! atlas_State !
27 !----------------------------!
28
29 ! (C) Copyright 2013-2015 ECMWF.
30
31 !------------------------------------------------------------------------------
32 TYPE, extends(fckit_owned_object) :: atlas_State
33
34 ! Purpose :
35 ! -------
36 ! *atlas_State* :
37 ! Container type of fields that are defined on the same points
38 ! Describes how nodes are ordered
39 ! Describes how parallelisation for fields is done
40 ! Describes interpolation between nodes
41
42 ! Methods :
43 ! -------
44 ! name : The name or tag this function space was created with
45 ! create_field : Create a new real field in this function space with given name
46 ! remove : Remove a field with given name
47 ! field : Access to a field with given name
48 ! parallelise : Setup halo-exchange information
49 ! halo_exchange : Perform halo exchange on field_data
50
51 ! Author :
52 ! ------
53 ! 20-Nov-2013 Willem Deconinck *ECMWF*
54
55 !------------------------------------------------------------------------------
56 contains
57
58 !-- Field
59 procedure, public :: add => atlas_State__add
60 procedure, public :: remove => atlas_State__remove
61 procedure, public :: has => atlas_State__has
62 procedure, public :: size => atlas_State__size
63 procedure, private :: field_by_name => atlas_State__field_by_name
64 procedure, private :: field_by_index => atlas_State__field_by_index
65 generic, public :: field => field_by_name, field_by_index
66 procedure, public :: metadata => atlas_State__metadata
67
68 #if FCKIT_FINAL_NOT_INHERITING
69 final :: atlas_State__final_auto
70 #endif
71 END TYPE atlas_State
72
73 interface atlas_State
74 module procedure atlas_State__new
75 module procedure atlas_State__generate
76 end interface
77
78 !------------------------------------------------------------------------------
79
80 !========================================================
81 contains
82 !========================================================
83 ! -----------------------------------------------------------------------------
84 ! State routines
85
86
87 function atlas_State__new() result(this)
88 use atlas_state_c_binding
89 type(atlas_State) :: this
90 call this%reset_c_ptr( atlas__State__new() )
91 call this%return()
92 end function
93
94 function atlas_State__generate(generator, params) result(this)
95 use fckit_c_interop_module, only: c_str
96 use atlas_state_c_binding
97 use atlas_Config_module, only: atlas_Config
98 type(atlas_State) :: this
99 character(len=*), intent(in) :: generator
100 class(atlas_Config), intent(in), optional :: params
101
102 type(atlas_Config) :: p
103
104 call this%reset_c_ptr( atlas__State__new() )
105
106 if( present(params) ) then
107 call atlas__State__initialize(this%CPTR_PGIBUG_A,c_str(generator),params%CPTR_PGIBUG_B)
108 else
109 p = atlas_Config()
110 call atlas__State__initialize(this%CPTR_PGIBUG_A,c_str(generator),p%CPTR_PGIBUG_B)
111 call p%final()
112 endif
113 call this%return()
114 end function
115
116 subroutine atlas_State__add(this,field)
117 use atlas_state_c_binding
118 class(atlas_State), intent(inout) :: this
119 class(atlas_Field), intent(in) :: field
120 call atlas__State__add(this%CPTR_PGIBUG_A,field%CPTR_PGIBUG_A)
121 end subroutine
122
123 subroutine atlas_State__remove(this,name)
124 use fckit_c_interop_module, only: c_str
125 use atlas_state_c_binding
126 class(atlas_State), intent(inout) :: this
127 character(len=*), intent(in) :: name
128 call atlas__State__remove(this%CPTR_PGIBUG_A,c_str(name))
129 end subroutine
130
131 function atlas_State__has(this,name) result(has)
132 use fckit_c_interop_module, only: c_str
133 use atlas_state_c_binding
134 logical :: has
135 class(atlas_State), intent(in) :: this
136 character(len=*), intent(in) :: name
137 integer :: has_int
138 has_int = atlas__State__has(this%CPTR_PGIBUG_A,c_str(name))
139 has = .False.
140 if( has_int == 1 ) has = .True.
141 end function
142
143 function atlas_State__size(this) result(size)
144 use atlas_state_c_binding
145 integer(ATLAS_KIND_IDX) :: size
146 class(atlas_State), intent(in) :: this
147 size = atlas__State__size(this%CPTR_PGIBUG_A)
148 end function
149
150 function atlas_State__field_by_name(this,name) result(field)
151 use fckit_c_interop_module, only: c_str
152 use atlas_state_c_binding
153 type(atlas_Field) :: field
154 class(atlas_State), intent(inout) :: this
155 character(len=*), intent(in) :: name
156 field = atlas_Field( atlas__State__field_by_name(this%CPTR_PGIBUG_A,c_str(name)) )
157 call field%return()
158 end function
159
160 function atlas_State__field_by_index(this,index) result(field)
161 use atlas_state_c_binding
162 type(atlas_Field) :: field
163 class(atlas_State), intent(in) :: this
164 integer, intent(in) :: index
165 field = atlas_Field( atlas__State__field_by_index(this%CPTR_PGIBUG_A,int(index-1,ATLAS_KIND_IDX)) )
166 call field%return()
167 end function
168
169 function atlas_State__metadata(this) result(metadata)
170 use atlas_state_c_binding
171 use atlas_Metadata_module, only: atlas_Metadata
172 type(atlas_Metadata) :: metadata
173 class(atlas_State), intent(in) :: this
174 call metadata%reset_c_ptr( atlas__State__metadata(this%CPTR_PGIBUG_A) )
175 end function
176
177 !-------------------------------------------------------------------------------
178
179 #if FCKIT_FINAL_NOT_INHERITING
180 ATLAS_FINAL subroutine atlas_State__final_auto(this)
181 type(atlas_State), intent(inout) :: this
182 #if FCKIT_FINAL_DEBUGGING
183 write(0,*) "atlas_State__final_auto"
184 #endif
185 #if FCKIT_FINAL_NOT_PROPAGATING
186 call this%final()
187 #endif
188 FCKIT_SUPPRESS_UNUSED( this )
189 end subroutine
190 #endif
191
192 ! ----------------------------------------------------------------------------------------
193
194 end module atlas_State_module