-
Notifications
You must be signed in to change notification settings - Fork 237
/
grdchk_loc.F
366 lines (346 loc) · 11 KB
/
grdchk_loc.F
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#include "GRDCHK_OPTIONS.h"
#ifdef ALLOW_CTRL
# include "CTRL_OPTIONS.h"
#endif
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
CBOP
C !ROUTINE: GRDCHK_LOC
C !INTERFACE:
SUBROUTINE GRDCHK_LOC(
I icomp,
I ichknum,
O icvrec,
O itile,
O jtile,
O layer,
O obcspos,
O itilepos,
O jtilepos,
O icglom1,
O itest,
O ierr,
I myThid )
C !DESCRIPTION:
C ==================================================================
C SUBROUTINE GRDCHK_LOC
C ==================================================================
C o Get the location of a given component of the control vector for
C the current process.
C started: Christian Eckert eckert@mit.edu 04-Apr-2000
C continued: heimbach@mit.edu: 13-Jun-2001
C ==================================================================
C !USES:
IMPLICIT NONE
C == Global variables ===
#include "EEPARAMS.h"
#include "SIZE.h"
#include "GRID.h"
#include "CTRL_SIZE.h"
#include "CTRL.h"
#ifdef ALLOW_OBCS_CONTROL
C CTRL_OBCS.h must be included before GRDCHK.h
# include "CTRL_OBCS.h"
#endif
#include "GRDCHK.h"
#ifdef ALLOW_OBCS
# include "OBCS_GRID.h"
#endif
#ifdef ALLOW_SHELFICE
# include "SHELFICE.h"
#endif /* ALLOW_SHELFICE */
C !INPUT/OUTPUT PARAMETERS:
INTEGER icomp
INTEGER ichknum
INTEGER icvrec
INTEGER jtile
INTEGER itile
INTEGER layer
INTEGER obcspos
INTEGER itilepos
INTEGER jtilepos
INTEGER itest
INTEGER ierr
INTEGER myThid
#ifdef ALLOW_GRDCHK
C-- == external ==
INTEGER ILNBLNK
EXTERNAL ILNBLNK
C !LOCAL VARIABLES:
INTEGER bi,bj
INTEGER i,j,k
INTEGER itmp,jtmp
INTEGER iobcs
c INTEGER biwrk,bjwrk
INTEGER iwrk, jwrk, kwrk
c INTEGER iobcswrk
INTEGER irec, irecwrk
INTEGER icglo, icglom1
INTEGER icomptest
INTEGER icomploc
INTEGER nobcsmax
CEOP
_BEGIN_MASTER( myThid )
C initialise parameters
ierr = -5
icglom1 = 0
icomploc= 0
cph(
print *, 'ph-test icomp, ncvarcomp, ichknum ',
& icomp, ncvarcomp, ichknum
cph)
IF ( icomp .GT. 0 ) THEN
IF ( icomp .LE. ncvarcomp ) THEN
C-- A valid component of the control variable has been selected.
IF ( ichknum .EQ. 1 ) THEN
itest = 0
icomptest = 0
irecwrk = 1
c bjwrk = 1
c biwrk = 1
kwrk = 1
c iobcswrk = 1
jwrk = 1
iwrk = 1
icglo = 0
ELSE
itest = itestmem (ichknum-1)
icomptest = icompmem (ichknum-1)
irecwrk = irecmem (ichknum-1)
c bjwrk = bjmem (ichknum-1)
c biwrk = bimem (ichknum-1)
kwrk = klocmem (ichknum-1)
c iobcswrk = iobcsmem (ichknum-1)
icglo = icglomem (ichknum-1)
jwrk = jlocmem (ichknum-1)
iwrk = ilocmem (ichknum-1)
iwrk = iwrk + 1
ENDIF
C-- set max loop index for obcs multiplicities
IF ( ncvargrd(grdchkvarindex) .EQ. 'm' ) THEN
#ifdef ALLOW_OBCS_CONTROL
nobcsmax = nobcs
#else
print *, 'S/R grdchk_loc: Ooops!'
#endif
ELSE
nobcsmax = 1
ENDIF
cph(
cph-print print *, 'ph-grd _loc: icomp, ichknum ',
cph-print & icomp, ichknum, ncvarcomp
cpj)
C-- Start to loop over records.
DO irec = irecwrk, ncvarrecs(grdchkvarindex)
c do iobcs = iobcswrk, nobcsmax
iobcs = MOD((irec-1),nobcsmax) + 1
c do bj = bjwrk, nSy
c do bi = biwrk, nSx
bj = jLocTile
bi = iLocTile
DO k = kwrk, ncvarnrmax(grdchkvarindex)
icglo = icglo + nwettile(bi,bj,k,iobcs)
icglom1 = icglo - nwettile(bi,bj,k,iobcs)
cph(
print *, 'ph-grd _loc: bi, bj, icomptest, ichknum ',
& bi, bj, icomptest, ichknum
cph-print print *, 'ph-grd _loc: icglo ',
cph-print & k, icglo, icglom1, iwetsum(bi,bj,k)
cpj)
IF ( (ierr .NE. 0) .AND.
& (icomp .GT. icglom1 .AND. icomp .LE. icglo) ) THEN
cph
cph if ( (ierr .NE. 0) .AND.
cph & (icomp .GT.
cph & (iobcs-1)*iwetsum(bi,bj,nr)+iwetsum(bi,bj,k-1))
cph & .AND.
cph & (icomp .LE.
cph & (iobcs-1)*iwetsum(bi,bj,nr)+iwetsum(bi,bj,k))) then
cph
IF ( icomptest .EQ. 0 ) THEN
icomptest = icglom1
ENDIF
icomploc = icomp
icvrec = irec
itile = bi
jtile = bj
cph(
cph-print print *, 'ph-grd irec, bj, bi, k ', irec, bj, bi, k
cpj)
DO j = jwrk, ncvarymax(grdchkvarindex)
DO i = iwrk, ncvarxmax(grdchkvarindex)
IF (ierr .NE. 0) THEN
IF ( ncvargrd(grdchkvarindex) .EQ. 'c' ) THEN
IF ( maskC(i,j,k,bi,bj) .GT. 0.) THEN
icomptest = icomptest + 1
itmp = i
jtmp = j
ENDIF
ELSEIF ( ncvargrd(grdchkvarindex) .EQ. 's' ) THEN
IF ( _maskS(i,j,k,bi,bj) .GT. 0.) THEN
icomptest = icomptest + 1
itmp = i
jtmp = j
ENDIF
ELSEIF ( ncvargrd(grdchkvarindex) .EQ. 'w' ) THEN
IF ( _maskW(i,j,k,bi,bj) .GT. 0.) THEN
icomptest = icomptest + 1
itmp = i
jtmp = j
ENDIF
#ifdef ALLOW_SHELFICE
ELSEIF ( ncvargrd(grdchkvarindex) .EQ. 'i' ) THEN
IF ( maskSHI(i,j,k,bi,bj) .GT. 0.) THEN
icomptest = icomptest + 1
itmp = i
jtmp = j
ENDIF
#endif /* ALLOW_SHELFICE */
#ifdef ALLOW_OBCS_CONTROL
ELSEIF ( ncvargrd(grdchkvarindex) .EQ. 'm' ) THEN
IF ( ncvarfname(grdchkvarindex)
& .EQ.xx_obcsn_file ) THEN
#ifdef ALLOW_OBCSN_CONTROL
IF ( grdchk_maskxz(i,k,bi,bj,iobcs) .GT. 0.
& .AND. j.EQ. OB_Jn(i,bi,bj) ) THEN
icomptest = icomptest + 1
itmp = i
jtmp = OB_Jn(i,bi,bj)
ENDIF
#endif
ELSEIF ( ncvarfname(grdchkvarindex)
& .EQ.xx_obcss_file ) THEN
#ifdef ALLOW_OBCSS_CONTROL
IF ( grdchk_maskxz(i,k,bi,bj,iobcs) .GT. 0.
& .AND. j.EQ. OB_Js(i,bi,bj) ) THEN
icomptest = icomptest + 1
itmp = i
jtmp = OB_Js(i,bi,bj)
ENDIF
#endif
ELSEIF ( ncvarfname(grdchkvarindex)
& .EQ.xx_obcse_file ) THEN
#ifdef ALLOW_OBCSE_CONTROL
IF ( grdchk_maskyz(j,k,bi,bj,iobcs) .GT. 0.
& .AND. i.EQ. OB_Ie(j,bi,bj) ) THEN
icomptest = icomptest + 1
itmp = OB_Ie(j,bi,bj)
jtmp = j
ENDIF
#endif
ELSEIF ( ncvarfname(grdchkvarindex)
& .EQ.xx_obcsw_file ) THEN
#ifdef ALLOW_OBCSW_CONTROL
IF ( grdchk_maskyz(j,k,bi,bj,iobcs) .GT. 0.
& .AND. i.EQ. OB_Iw(j,bi,bj) ) THEN
icomptest = icomptest + 1
itmp = OB_Iw(j,bi,bj)
jtmp = j
ENDIF
#endif
ENDIF
#endif /* ALLOW_OBCS_CONTROL */
ENDIF
cph(
cph-print print *, 'ph-grd icomp, icomptest, icomploc, i, j ',
cph-print & icomp, icomptest, icomploc, i, j
cpj)
IF ( icomploc .EQ. icomptest ) THEN
itilepos = itmp
jtilepos = jtmp
layer = k
obcspos = iobcs
ierr = 0
cph itest = iwetsum(bi,bj,k)
cph(
print *, 'ph-grd -->hit<-- ', itmp,jtmp,k,iobcs
goto 1234
cph)
ENDIF
ENDIF
ENDDO
iwrk = 1
ENDDO
jwrk = 1
ELSEIF (ierr .NE. 0) THEN
IF (icomptest .EQ. icomp-1) THEN
icomptest = icomptest
ELSE
icomptest = icomptest + nwettile(bi,bj,k,iobcs)
ENDIF
cph(
cph-print print *, 'ph-grd after loop icomptest, icomploc, k ',
cph-print & icomptest, icomploc, k
cph)
iwrk = 1
jwrk = 1
ENDIF
C-- End of loop over k
ENDDO
kwrk = 1
C-- End of loop over bi
c enddo
c biwrk = 1
C-- End of loop over bj
c enddo
c bjwrk = 1
C-- End of loop over iobcs
c enddo
c iobcswrk = 1
C-- End of loop over irec records.
ENDDO
ELSE
C-- else icomp > ncvarcomp
IF ( icomp .GT. maxncvarcomps ) THEN
C-- Such a component does not exist.
ierr = -4
icvrec = -1
jtile = -1
itile = -1
layer = -1
obcspos = -1
jtilepos = -1
itilepos = -1
ELSE
C-- The component is a land point.
ierr = -3
icvrec = -1
jtile = -1
itile = -1
layer = -1
obcspos = -1
jtilepos = -1
itilepos = -1
ENDIF
C-- End if/else block icomp =< ncvarcomp
ENDIF
ELSE
C-- else not( icomp > 0 )
IF ( icomp .LT. 0 ) THEN
C-- Such a component does not exist.
ierr = -2
icvrec = -1
jtile = -1
itile = -1
layer = -1
obcspos = -1
jtilepos = -1
itilepos = -1
ELSE
C-- Component zero.
ierr = -1
icvrec = -1
jtile = -1
itile = -1
layer = -1
obcspos = -1
jtilepos = -1
itilepos = -1
ENDIF
C-- End if/else block icomp > 0
ENDIF
1234 CONTINUE
_END_MASTER( myThid )
_BARRIER
#endif /* ALLOW_GRDCHK */
RETURN
END