forked from GEOS-ESM/MAPL
-
Notifications
You must be signed in to change notification settings - Fork 1
/
VarConn.F90
295 lines (239 loc) · 9.14 KB
/
VarConn.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#include "MAPL_Exceptions.h"
#include "MAPL_ErrLog.h"
module mapl_VarConn
use ESMF
use MAPL_Constants, only: MAPL_ConnUnknown, MAPL_Self
use MAPL_VarSpecPtrMod
use MAPL_VarSpecMod
use MAPL_VarConnPoint
use MAPL_VarConnType
use MAPL_VarConnVector
use MAPL_ErrorHandlingMod
use pFlogger
implicit none
private
public :: VarConn ! wraps VarConnVector (vector of VarConnType)
! A trivial wrapper to encapsulate management of
! vector under the hood.
type VarConn
!!$ private
type(VarConnVector) :: conn_v
contains
procedure :: append
procedure :: checkReq
procedure :: checkUnused
procedure :: varIsConnected_IE
procedure :: varIsConnected_name
generic :: varIsConnected => varIsConnected_IE
generic :: varIsConnected => varIsConnected_name
procedure :: varIsListed
end type VarConn
contains
subroutine append(CONN, SHORT_NAME, TO_NAME, &
FROM_EXPORT, TO_IMPORT, RC )
class (VarConn ), intent(inout) :: CONN
character (len=*) , intent(IN ) :: SHORT_NAME
character (len=*), optional, intent(IN ) :: TO_NAME
integer, optional, intent(IN ) :: FROM_EXPORT
integer, optional, intent(IN ) :: TO_IMPORT
integer, optional, intent( OUT) :: RC ! Error code:
integer :: usableFROM_EXPORT
integer :: usableTO_IMPORT
type(VarConnType), pointer :: new_conn
character(len=ESMF_MAXSTR) :: usableTONAME
usableFROM_EXPORT=MAPL_ConnUnknown
usableTO_IMPORT=MAPL_ConnUnknown
if(present(TO_NAME)) then
usableTONAME = TO_NAME
else
usableTONAME = SHORT_NAME
endif
if(present(FROM_EXPORT)) then
usableFROM_EXPORT=FROM_EXPORT
end if
if(present(TO_IMPORT)) then
usableTO_IMPORT=TO_IMPORT
end if
! Push and then construct.
call conn%conn_v%resize(conn%conn_v%size()+1)
new_conn => CONN%conn_v%back()
new_conn%From = VarConnPoint(SHORT_NAME, gc_id=usableFROM_EXPORT)
new_conn%To = VarConnPoint(usableTONAME, gc_id=usableTO_IMPORT)
if(short_name == "MAPL_AnyChildImport") new_conn%used = .true.
_RETURN(ESMF_SUCCESS)
end subroutine append
subroutine checkReq(this, ImSpecPtr, ExSpecPtr, RC)
class (VarConn), target, intent(inout) :: this
type (MAPL_VarSpecPtr), pointer :: ImSpecPtr(:)
type (MAPL_VarSpecPtr), pointer :: ExSpecPtr(:)
integer, optional, intent(OUT) :: RC
type(VarConnType), pointer :: conn
integer :: I, J
integer :: IMP
integer :: FI
integer :: TI
integer :: FE
integer :: TE
character(len=ESMF_MAXSTR) :: NAME
associate (conn_v => this%conn_v)
do I = 1, conn_v%size()
conn => conn_v%of(i)
FI = MAPL_ConnUnknown
TI = conn%to%get_gc_id()
IMP = MAPL_ConnUnknown
if(FI /= MAPL_ConnUnknown) then
IMP = FI
NAME = conn%FROM%get_short_name()
else if (TI /= MAPL_ConnUnknown) then
IMP = TI
NAME = conn%TO%get_short_name()
end if
if (IMP /= MAPL_ConnUnknown .and. IMP /= MAPL_Self) then
! check if the component has an import spec
if(.not. associated(ImSpecPtr(IMP)%Spec)) then
conn%notRequired = .true.
cycle
end if
if(MAPL_VarSpecGetIndex(ImSpecPtr(IMP)%Spec, NAME)==-1) then
FE = conn%from%get_gc_id()
TE = MAPL_ConnUnknown
J = MAPL_ConnUnknown
if(FE /= MAPL_ConnUnknown) then
J = FE
NAME = conn%FROM%get_short_name()
else if (TE /= MAPL_ConnUnknown) then
J = TE
NAME = conn%TO%get_short_name()
end if
if(MAPL_VarSpecGetIndex(ExSpecPtr(J)%Spec, NAME)/=-1) then
! Export does exist while import does not - we relax the requirement
conn%notRequired = .true.
end if
endif
end if
end do
end associate
_RETURN(ESMF_SUCCESS)
end subroutine CheckReq
logical function checkUnused(this)
class(VarConn), target, intent(inout) :: this
integer :: I
class(Logger), pointer :: lgr
type(VarConnType), pointer :: conn
character(len=ESMF_MAXSTR) :: from_name, to_name
associate (conn_v => this%conn_v)
checkUnused = .true.
do I = 1, conn_v%size()
conn => conn_v%of(i)
if (conn%notRequired) cycle
if (.not. conn%USED) then
checkUnused = .false.
lgr => logging%get_logger('MAPL.GENERIC')
from_name = conn%FROM%get_short_name()
to_name = conn%TO%get_short_name()
call lgr%error( &
'SRC_NAME: <%a~> DST_NAME: <%a~> is not satisfied', &
trim(from_name),trim(to_name))
end if
end do
end associate
return
end function CheckUnused
logical function varIsConnected_IE(this, IMPORT_NAME, EXPORT_NAME, &
import, EXPORT, RC)
class(VarConn), target, intent(inout) :: this
character (len=*), intent(IN ) :: IMPORT_NAME
character (len=*), optional, intent( OUT) :: EXPORT_NAME
integer, intent(IN ) :: IMPORT
integer, intent(IN ) :: EXPORT
integer, optional, intent( OUT) :: RC ! Error code:
integer :: I
integer :: TI, FE
type(VarConnType), pointer :: conn
character(len=ESMF_MAXSTR) :: name
varIsConnected_IE = .false.
! try to find a match with "TO"
associate (conn_v => this%conn_v)
do I = 1, conn_v%size()
conn => conn_v%of(i)
name = conn%TO%get_short_name()
if (name /= IMPORT_NAME) then
cycle
end if
TI = conn%to%get_gc_id()
FE = conn%from%get_gc_id()
if (TI /= import) then
cycle
end if
if (FE /= EXPORT) then
cycle
end if
varIsConnected_IE = .true.
conn%used = .true.
if (present(EXPORT_NAME)) then
EXPORT_NAME = conn%FROM%get_short_name()
end if
_RETURN(ESMF_SUCCESS)
end do
end associate
varIsConnected_IE = .false.
_RETURN(ESMF_SUCCESS)
end function VarIsConnected_IE
logical function varIsConnected_name(this, IMPORT_NAME, import, RC)
class(VarConn), target, intent(inout):: this
character (len=*), intent(IN ) :: IMPORT_NAME
integer, intent(in ) :: import
integer, optional, intent( OUT) :: RC ! Error code:
integer :: I
integer :: TI
type(VarConnType), pointer :: conn
character(len=ESMF_MAXSTR) :: name
varIsConnected_name = .false.
associate (conn_v => this%conn_v)
! try to find a match with "TO"
do I = 1, conn_v%size()
conn => conn_v%of(i)
name = conn%to%get_short_name()
if (name /= IMPORT_NAME) then
cycle
end if
TI = conn%to%get_gc_id()
if (TI /= import) then
cycle
end if
varIsConnected_name = .true.
_RETURN(ESMF_SUCCESS)
end do
end associate
varIsConnected_name = .false.
_RETURN(ESMF_SUCCESS)
end function VarIsConnected_Name
logical function varIsListed(this, SHORT_NAME, import, RC)
class(VarConn ), target, intent(inout):: this
character (len=*), intent(IN) :: SHORT_NAME
integer, intent(IN) :: IMPORT
integer, optional, intent(OUT) :: RC ! Error code:
type(VarConnType), pointer :: conn
integer :: I
integer :: TI
character(len=ESMF_MAXSTR) :: name
associate (conn_v => this%conn_v)
do I = 1, conn_v%size()
conn => conn_v%of(i)
name = conn%FROM%get_short_name()
if (name /= SHORT_NAME) then
cycle
end if
TI = conn%to%get_gc_id()
! check for a match
if(TI == import) then
varIsListed = .true.
conn%used = .true.
_RETURN(ESMF_SUCCESS)
end if
end do
end associate
varIsListed = .false.
_RETURN(ESMF_SUCCESS)
end function VarIsListed
end module mapl_VarConn