OOPS
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 
10 
11 use iso_c_binding
12 use kinds
13 use qg_geom_mod
14 
15 implicit none
16 
17 private
18 public :: qg_geom_iter
19 public :: qg_geom_iter_registry
21 ! ------------------------------------------------------------------------------
22 type :: qg_geom_iter
23  type(qg_geom),pointer :: geom => null() !< Geometry
24  integer :: ilon = 1 !< Longitude index
25  integer :: ilat = 1 !< Latitude index
26 end type qg_geom_iter
27 
28 #define LISTED_TYPE qg_geom_iter
29 
30 !> Linked list interface - defines registry_t type
31 #include "oops/util/linkedList_i.f"
32 
33 !> Global registry
34 type(registry_t) :: qg_geom_iter_registry
35 ! ------------------------------------------------------------------------------
36 contains
37 ! ------------------------------------------------------------------------------
38 ! Public
39 ! ------------------------------------------------------------------------------
40 !> Linked list implementation
41 #include "oops/util/linkedList_c.f"
42 ! ------------------------------------------------------------------------------
43 !> Setup for the QG model's geometry iterator
44 subroutine qg_geom_iter_setup(self,geom,ind)
45 
46 ! Passed variables
47 type(qg_geom_iter),intent(inout) :: self !< Geometry iterator
48 type(qg_geom),pointer,intent(in) :: geom !< Geometry
49 integer,intent(in) :: ind !< Index
50 
51 ! Associate geometry
52 self%geom => geom
53 
54 ! Define ilon/ilat
55 self%ilat = (ind-1)/geom%nx+1
56 self%ilon = ind-(self%ilat-1)*geom%nx
57 
58 end subroutine qg_geom_iter_setup
59 ! ------------------------------------------------------------------------------
60 !> Clone for the QG model's geometry iterator
61 subroutine qg_geom_iter_clone(self,other)
62 
63 ! Passed variables
64 type(qg_geom_iter),intent(inout) :: self !< Geometry iterator
65 type(qg_geom_iter),intent(in) :: other !< Other geometry iterator
66 
67 ! Associate geometry
68 self%geom => other%geom
69 
70 ! Copy ilon/ilat
71 self%ilon = other%ilon
72 self%ilat = other%ilat
73 
74 end subroutine qg_geom_iter_clone
75 ! ------------------------------------------------------------------------------
76 !> Check for the QG model's geometry iterator equality
77 subroutine qg_geom_iter_equals(self,other,equals)
78 
79 ! Passed variables
80 type(qg_geom_iter),intent(in) :: self !< Geometry iterator
81 type(qg_geom_iter),intent(in) :: other !< Other geometry iterator
82 integer,intent(out) :: equals !< Equality flag
83 
84 ! Initialization
85 equals = 0
86 
87 ! Check equality
88 if (associated(self%geom,other%geom).and.(self%ilon==other%ilon).and.(self%ilat==other%ilat)) equals = 1
89 
90 end subroutine qg_geom_iter_equals
91 ! ------------------------------------------------------------------------------
92 !> Get geometry iterator current lat/lon
93 subroutine qg_geom_iter_current(self,lat,lon)
94 
95 ! Passed variables
96 type(qg_geom_iter),intent(in) :: self !< Geometry iterator
97 real(kind_real),intent(out) :: lat !< Latitude
98 real(kind_real),intent(out) :: lon !< Longitude
99 
100 ! Check ilon/ilat
101 if (self%ilon*self%ilat>self%geom%nx*self%geom%ny) call abor1_ftn('qg_geom_iter_current: iterator out of bounds')
102 
103 ! Get lat/lon
104 lat = self%geom%lat(self%ilon,self%ilat)
105 lon = self%geom%lon(self%ilon,self%ilat)
106 
107 end subroutine qg_geom_iter_current
108 ! ------------------------------------------------------------------------------
109 !> Update geometry iterator to next point
110 subroutine qg_geom_iter_next(self)
111 
112 ! Passed variables
113 type(qg_geom_iter),intent(inout) :: self !< Geometry iterator
114 
115 ! Update ilon/ilat
116 if (self%ilon==self%geom%nx) then
117  self%ilon = 1
118  self%ilat = self%ilat+1
119 else
120  self%ilon = self%ilon+1
121 endif
122 
123 end subroutine qg_geom_iter_next
124 ! ------------------------------------------------------------------------------
125 end module qg_geom_iter_mod
subroutine, public qg_geom_iter_setup(self, geom, ind)
Linked list implementation.
subroutine, public qg_geom_iter_clone(self, other)
Clone for the QG model's geometry iterator.
subroutine, public qg_geom_iter_equals(self, other, equals)
Check for the QG model's geometry iterator equality.
subroutine, public qg_geom_iter_next(self)
Update geometry iterator to next point.
subroutine, public qg_geom_iter_current(self, lat, lon)
Get geometry iterator current lat/lon.
type(registry_t), public qg_geom_iter_registry
Linked list interface - defines registry_t type.