FV3 Bundle
qg_geom_iter_mod.F90
Go to the documentation of this file.
1 ! (C) Copyright 2009-2016 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 !> Fortran module handling geometry iterator for the QG model
10 
12 
13 use iso_c_binding
14 use config_mod
15 use kinds
16 use qg_geom_mod
17 
18 implicit none
19 private
20 public :: qg_geom_iter
21 public :: qg_geom_iter_registry
22 
23 ! ------------------------------------------------------------------------------
24 
25 !> Fortran derived type to hold geom_iteretry data for the QG model
26 type :: qg_geom_iter
27  type(qg_geom), pointer :: geom => null()
28  integer :: ilat = 1
29  integer :: ilon = 1
30 end type qg_geom_iter
31 
32 #define LISTED_TYPE qg_geom_iter
33 
34 !> Linked list interface - defines registry_t type
35 #include "oops/util/linkedList_i.f"
36 
37 !> Global registry
38 type(registry_t) :: qg_geom_iter_registry
39 
40 ! ------------------------------------------------------------------------------
41 contains
42 ! ------------------------------------------------------------------------------
43 
44 !> Linked list implementation
45 #include "oops/util/linkedList_c.f"
46 
47 ! ------------------------------------------------------------------------------
48 
49 subroutine c_qg_geo_iter_setup(c_key_self, c_key_geom, c_index) bind(c,name='qg_geo_iter_setup_f90')
50 implicit none
51 integer(c_int), intent(inout) :: c_key_self
52 integer(c_int), intent(in) :: c_key_geom
53 integer(c_int), intent(in) :: c_index
54 
55 type(qg_geom_iter), pointer :: self
56 type(qg_geom), pointer :: geom
57 
58 call qg_geom_iter_registry%init()
59 call qg_geom_iter_registry%add(c_key_self)
60 call qg_geom_iter_registry%get(c_key_self,self)
61 
62 call qg_geom_registry%get(c_key_geom, geom)
63 
64 self%geom => geom
65 self%ilat = (c_index-1)/geom%nx + 1
66 self%ilon = c_index - (self%ilat-1)*geom%nx
67 
68 end subroutine c_qg_geo_iter_setup
69 
70 ! ------------------------------------------------------------------------------
71 
72 subroutine c_qg_geo_iter_clone(c_key_self, c_key_other) bind(c,name='qg_geo_iter_clone_f90')
73 implicit none
74 integer(c_int), intent(inout) :: c_key_self
75 integer(c_int), intent(in) :: c_key_other
76 
77 type(qg_geom_iter), pointer :: self, other
78 
79 call qg_geom_iter_registry%init()
80 call qg_geom_iter_registry%add(c_key_self)
81 call qg_geom_iter_registry%get(c_key_self,self)
82 
83 call qg_geom_iter_registry%get(c_key_other, other)
84 
85 self%geom => other%geom
86 self%ilon = other%ilon
87 self%ilat = other%ilat
88 
89 end subroutine c_qg_geo_iter_clone
90 
91 ! ------------------------------------------------------------------------------
92 
93 subroutine c_qg_geo_iter_delete(c_key_self) bind(c,name='qg_geo_iter_delete_f90')
94 implicit none
95 integer(c_int), intent(inout) :: c_key_self
96 
97 call qg_geom_iter_registry%remove(c_key_self)
98 
99 end subroutine c_qg_geo_iter_delete
100 
101 ! ------------------------------------------------------------------------------
102 
103 subroutine c_qg_geo_iter_equals(c_key_self, c_key_other, c_equals) bind(c,name='qg_geo_iter_equals_f90')
104 implicit none
105 integer(c_int), intent(inout) :: c_key_self
106 integer(c_int), intent(in) :: c_key_other
107 integer(c_int), intent(inout) :: c_equals
108 
109 type(qg_geom_iter), pointer :: self, other
110 
111 call qg_geom_iter_registry%get(c_key_self, self)
112 call qg_geom_iter_registry%get(c_key_other, other)
113 
114 c_equals = 0
115 if (associated(self%geom, other%geom) .and. &
116  (self%ilon == other%ilon) .and. (self%ilat == other%ilat)) then
117  c_equals = 1
118 endif
119 
120 end subroutine c_qg_geo_iter_equals
121 
122 ! ------------------------------------------------------------------------------
123 
124 subroutine c_qg_geo_iter_current(c_key_self, c_lat, c_lon) bind(c,name='qg_geo_iter_current_f90')
125 implicit none
126 integer(c_int), intent(in ) :: c_key_self
127 real(c_double), intent(inout) :: c_lat
128 real(c_double), intent(inout) :: c_lon
129 type(qg_geom_iter), pointer :: self
130 
131 call qg_geom_iter_registry%get(c_key_self , self )
132 
133 if (self%ilon*self%ilat > self%geom%nx * self%geom%ny) then
134  print *, 'qg_geo_iter_current: iterator out of bounds'
135  stop
136 endif
137 
138 c_lon = self%geom%lon(self%ilon)
139 c_lat = self%geom%lat(self%ilat)
140 
141 end subroutine c_qg_geo_iter_current
142 
143 ! ------------------------------------------------------------------------------
144 
145 subroutine c_qg_geo_iter_next(c_key_self) bind(c,name='qg_geo_iter_next_f90')
146 implicit none
147 integer(c_int), intent(in ) :: c_key_self
148 type(qg_geom_iter), pointer :: self
149 
150 call qg_geom_iter_registry%get(c_key_self , self )
151 
152 if (self%ilon == self%geom%nx) then
153  self%ilon = 1; self%ilat = self%ilat + 1
154 else
155  self%ilon = self%ilon + 1
156 endif
157 
158 end subroutine c_qg_geo_iter_next
159 
160 
161 end module qg_geom_iter_mod
Fortran module handling geometry iterator for the QG model.
subroutine c_qg_geo_iter_clone(c_key_self, c_key_other)
Fortran derived type to hold geometry data for the QG model.
Definition: qg_geom_mod.F90:26
Fortran derived type to hold geom_iteretry data for the QG model.
type(registry_t), public qg_geom_registry
Linked list interface - defines registry_t type.
Definition: qg_geom_mod.F90:40
subroutine c_qg_geo_iter_next(c_key_self)
subroutine c_qg_geo_iter_equals(c_key_self, c_key_other, c_equals)
Fortran module handling geometry for the QG model.
Definition: qg_geom_mod.F90:11
type(registry_t), public qg_geom_iter_registry
Linked list interface - defines registry_t type.
subroutine c_qg_geo_iter_current(c_key_self, c_lat, c_lon)
subroutine c_qg_geo_iter_setup(c_key_self, c_key_geom, c_index)
Linked list implementation.
subroutine c_qg_geo_iter_delete(c_key_self)