1 |
C $Header: /u/gcmpack/MITgcm/pkg/exch2/exch2_get_uv_bounds.F,v 1.3 2012/03/26 19:13:15 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CPP_EEOPTIONS.h" |
5 |
|
6 |
CBOP |
7 |
C !ROUTINE: EXCH2_GET_UV_BOUNDS |
8 |
|
9 |
C !INTERFACE: |
10 |
SUBROUTINE EXCH2_GET_UV_BOUNDS( |
11 |
I fCode, eWdth, updateCorners, |
12 |
I tgTile, tgNb, |
13 |
O tIlo1, tIhi1, tJlo1, tJhi1, |
14 |
O tIlo2, tIhi2, tJlo2, tJhi2, |
15 |
O tiStride, tjStride, |
16 |
O e2_oi1, e2_oj1, e2_oi2, e2_oj2, |
17 |
I myThid ) |
18 |
|
19 |
C !DESCRIPTION: |
20 |
C Return the index range & step of the part of the array (overlap-region) |
21 |
C which is going to be updated by the exchange with 1 neighbour. |
22 |
C 2 components vector field (UV) version. |
23 |
|
24 |
|
25 |
C !USES: |
26 |
IMPLICIT NONE |
27 |
C == Global data == |
28 |
#include "SIZE.h" |
29 |
#include "W2_EXCH2_SIZE.h" |
30 |
#include "W2_EXCH2_TOPOLOGY.h" |
31 |
|
32 |
C !INPUT/OUTPUT PARAMETERS: |
33 |
C fCode :: field code (position on staggered grid) |
34 |
C eWdth :: width of data region to exchange |
35 |
C updateCorners :: flag, do update corner halo region if true |
36 |
C tgTile :: target tile |
37 |
C tgNb :: target Neighbour entry |
38 |
C tIlo1, tIhi1 :: index range in I that will be filled in 1rst comp. array |
39 |
C tJlo1, tJhi1 :: index range in J that will be filled in 1rst comp. array |
40 |
C tIlo2, tIhi2 :: index range in I that will be filled in 2nd comp. array |
41 |
C tJlo2, tJhi2 :: index range in J that will be filled in 2nd comp. array |
42 |
C tiStride :: index step in I that will be filled in target arrays |
43 |
C tjStride :: index step in J that will be filled in target arrays |
44 |
C e2_oi1 :: index offset in target to source-1 index relation |
45 |
C e2_oj1 :: index offset in target to source-1 index relation |
46 |
C e2_oi2 :: index offset in target to source-2 index relation |
47 |
C e2_oj2 :: index offset in target to source-2 index relation |
48 |
C myThid :: my Thread Id. number |
49 |
|
50 |
CHARACTER*2 fCode |
51 |
INTEGER eWdth |
52 |
LOGICAL updateCorners |
53 |
INTEGER tgTile, tgNb |
54 |
INTEGER tIlo1, tIhi1, tJlo1, tJhi1 |
55 |
INTEGER tIlo2, tIhi2, tJlo2, tJhi2 |
56 |
INTEGER tiStride, tjStride |
57 |
INTEGER e2_oi1, e2_oj1 |
58 |
INTEGER e2_oi2, e2_oj2 |
59 |
INTEGER myThid |
60 |
C |
61 |
C !LOCAL VARIABLES: |
62 |
C soTile :: source tile |
63 |
C soNb :: source Neighbour entry |
64 |
INTEGER soTile |
65 |
INTEGER soNb |
66 |
INTEGER tIlo, tIhi, tJlo, tJhi |
67 |
INTEGER i, e2_pij(4) |
68 |
|
69 |
C--- exch2 target to source index relation: |
70 |
C is = pij(1)*it + pij(2)*jt + oi |
71 |
C js = pij(3)*it + pij(4)*jt + oj |
72 |
|
73 |
C--- Initialise index range from Topology values: |
74 |
tIlo = exch2_iLo(tgNb,tgTile) |
75 |
tIhi = exch2_iHi(tgNb,tgTile) |
76 |
tJlo = exch2_jLo(tgNb,tgTile) |
77 |
tJhi = exch2_jHi(tgNb,tgTile) |
78 |
soNb = exch2_opposingSend(tgNb,tgTile) |
79 |
soTile = exch2_neighbourId(tgNb,tgTile) |
80 |
e2_oi1 = exch2_oi(soNb,soTile) |
81 |
e2_oj1 = exch2_oj(soNb,soTile) |
82 |
DO i=1,4 |
83 |
e2_pij(i) = exch2_pij(i,soNb,soTile) |
84 |
ENDDO |
85 |
|
86 |
C--- Expand index range according to exchange-Width "eWdth" |
87 |
IF ( tIlo.EQ.tIhi .AND. tIlo.EQ.0 ) THEN |
88 |
C Filling a west edge overlap |
89 |
tIlo1 = 1-eWdth |
90 |
tIhi1 = 0 |
91 |
tiStride = 1 |
92 |
IF ( tJlo.LE.tJhi ) THEN |
93 |
tjStride=1 |
94 |
ELSE |
95 |
tjStride=-1 |
96 |
ENDIF |
97 |
IF ( updateCorners ) THEN |
98 |
tJlo1 = tJlo-tjStride*(eWdth-1) |
99 |
tJhi1 = tJhi+tjStride*(eWdth-1) |
100 |
ELSE |
101 |
tJlo1 = tJlo+tjStride |
102 |
tJhi1 = tJhi-tjStride |
103 |
ENDIF |
104 |
ENDIF |
105 |
IF ( tIlo.EQ.tIhi .AND. tIlo.GT.1 ) THEN |
106 |
C Filling an east edge overlap |
107 |
tIlo1 = tIlo |
108 |
tIhi1 = tIhi+eWdth-1 |
109 |
tiStride = 1 |
110 |
IF ( tJlo.LE.tJhi ) THEN |
111 |
tjStride = 1 |
112 |
ELSE |
113 |
tjStride =-1 |
114 |
ENDIF |
115 |
IF ( updateCorners ) THEN |
116 |
tJlo1 = tJlo-tjStride*(eWdth-1) |
117 |
tJhi1 = tJhi+tjStride*(eWdth-1) |
118 |
ELSE |
119 |
tJlo1 = tJlo+tjStride |
120 |
tJhi1 = tJhi-tjStride |
121 |
ENDIF |
122 |
ENDIF |
123 |
IF ( tJlo.EQ.tJhi .AND. tJlo.EQ.0 ) THEN |
124 |
C Filling a south edge overlap |
125 |
tJlo1 = 1-eWdth |
126 |
tJhi1 = 0 |
127 |
tjStride = 1 |
128 |
IF ( tIlo .LE. tIhi ) THEN |
129 |
tiStride = 1 |
130 |
ELSE |
131 |
tiStride =-1 |
132 |
ENDIF |
133 |
IF ( updateCorners ) THEN |
134 |
tIlo1 = tIlo-tiStride*(eWdth-1) |
135 |
tIhi1 = tIhi+tiStride*(eWdth-1) |
136 |
ELSE |
137 |
tIlo1 = tIlo+tiStride |
138 |
tIhi1 = tIhi-tiStride |
139 |
ENDIF |
140 |
ENDIF |
141 |
IF ( tJlo.EQ.tJhi .AND. tJlo.GT.1 ) THEN |
142 |
C Filling a north edge overlap |
143 |
tJlo1 = tJlo |
144 |
tJhi1 = tJhi+eWdth-1 |
145 |
tjStride = 1 |
146 |
IF ( tIlo.LE.tIhi ) THEN |
147 |
tiStride = 1 |
148 |
ELSE |
149 |
tiStride =-1 |
150 |
ENDIF |
151 |
IF ( updateCorners ) THEN |
152 |
tIlo1 = tIlo-tiStride*(eWdth-1) |
153 |
tIhi1 = tIhi+tiStride*(eWdth-1) |
154 |
ELSE |
155 |
tIlo1 = tIlo+tiStride |
156 |
tIhi1 = tIhi-tiStride |
157 |
ENDIF |
158 |
ENDIF |
159 |
|
160 |
C--- copy to 2nd set of indices |
161 |
tIlo2 = tIlo1 |
162 |
tIhi2 = tIhi1 |
163 |
tJlo2 = tJlo1 |
164 |
tJhi2 = tJhi1 |
165 |
e2_oi2 = e2_oi1 |
166 |
e2_oj2 = e2_oj1 |
167 |
|
168 |
IF ( fCode.EQ.'Cg' ) THEN |
169 |
C--- UV C-Grid specific code: start here |
170 |
|
171 |
C--- half grid-cell location with inverse index relation |
172 |
C => increase the offset by 1 (relative to tracer cell-centered offset) |
173 |
C if pij(1) is -1 then +i in source aligns with -i in target |
174 |
C if pij(3) is -1 then +j in source aligns with -i in target |
175 |
IF ( e2_pij(1) .EQ. -1 ) THEN |
176 |
e2_oi1 = e2_oi1 + 1 |
177 |
ENDIF |
178 |
IF ( e2_pij(3) .EQ. -1 ) THEN |
179 |
e2_oj1 = e2_oj1 + 1 |
180 |
ENDIF |
181 |
C if pij(2) is -1 then +i in source aligns with -j in target |
182 |
C if pij(4) is -1 then +j in source aligns with -j in target |
183 |
IF ( e2_pij(2) .EQ. -1 ) THEN |
184 |
e2_oi2 = e2_oi2 + 1 |
185 |
ENDIF |
186 |
IF ( e2_pij(4) .EQ. -1 ) THEN |
187 |
e2_oj2 = e2_oj2 + 1 |
188 |
ENDIF |
189 |
|
190 |
C--- adjust index lower and upper bounds (fct of updateCorners): |
191 |
IF ( updateCorners ) THEN |
192 |
|
193 |
C-- as a consequence, need also to increase the index lower bound |
194 |
C (avoid "out-of bounds" problems ; formerly itlreduce,jtlreduce) |
195 |
IF ( e2_pij(1).EQ.-1 .OR. e2_pij(3).EQ.-1 ) tIlo1 = tIlo1+1 |
196 |
IF ( e2_pij(2).EQ.-1 .OR. e2_pij(4).EQ.-1 ) tJlo2 = tJlo2+1 |
197 |
|
198 |
C--- Avoid updating (some) tile-corner halo region if across faces |
199 |
c IF ( tIlo.EQ.tIhi .AND. tIlo.EQ.0 ) THEN |
200 |
c IF ( exch2_isSedge(tgTile).EQ.1 ) THEN |
201 |
C- West edge is touching the face S edge |
202 |
c tJlo1 = tJlo+1 |
203 |
c tJlo2 = tJlo+1 |
204 |
c ENDIF |
205 |
c IF ( exch2_isNedge(tgTile).EQ.1 ) THEN |
206 |
C- West edge is touching the face N edge |
207 |
c tJhi1 = tJhi-1 |
208 |
c tJhi2 = tJhi |
209 |
c ENDIF |
210 |
c ENDIF |
211 |
IF ( tIlo.EQ.tIhi .AND. tIlo.GT.1 ) THEN |
212 |
IF ( exch2_isSedge(tgTile).EQ.1 ) THEN |
213 |
C- East edge is touching the face S edge |
214 |
tJlo1 = tJlo+1 |
215 |
tJlo2 = tJlo+1 |
216 |
ENDIF |
217 |
IF ( exch2_isNedge(tgTile).EQ.1 ) THEN |
218 |
C- East edge is touching the face N edge |
219 |
tJhi1 = tJhi-1 |
220 |
tJhi2 = tJhi |
221 |
ENDIF |
222 |
ENDIF |
223 |
c IF ( tJlo.EQ.tJhi .AND. tJlo.EQ.0 ) THEN |
224 |
c IF ( exch2_isWedge(tgTile).EQ.1 ) THEN |
225 |
C- South edge is touching the face W edge |
226 |
c tIlo1 = tIlo+1 |
227 |
c tIlo2 = tIlo+1 |
228 |
c ENDIF |
229 |
c IF ( exch2_isEedge(tgTile).EQ.1 ) THEN |
230 |
C- South Edge is touching the face E edge |
231 |
c tIhi1 = tIhi |
232 |
c tIhi2 = tIhi-1 |
233 |
c ENDIF |
234 |
c ENDIF |
235 |
IF ( tJlo.EQ.tJhi .AND. tJlo.GT.1 ) THEN |
236 |
IF ( exch2_isWedge(tgTile).EQ.1 ) THEN |
237 |
C- North edge is touching the face W edge |
238 |
tIlo1 = tIlo+1 |
239 |
tIlo2 = tIlo+1 |
240 |
ENDIF |
241 |
IF ( exch2_isEedge(tgTile).EQ.1 ) THEN |
242 |
C- North Edge is touching the face E edge |
243 |
tIhi1 = tIhi |
244 |
tIhi2 = tIhi-1 |
245 |
ENDIF |
246 |
ENDIF |
247 |
|
248 |
ELSE |
249 |
C--- adjust index lower and upper bounds (updateCorners = F case): |
250 |
IF ( e2_pij(1).EQ.-1 .OR. e2_pij(3).EQ.-1 ) THEN |
251 |
tIlo1 = tIlo1+1 |
252 |
tIhi1 = tIhi1+1 |
253 |
ENDIF |
254 |
IF ( e2_pij(2).EQ.-1 .OR. e2_pij(4).EQ.-1 ) THEN |
255 |
tJlo2 = tJlo2+1 |
256 |
tJhi2 = tJhi2+1 |
257 |
ENDIF |
258 |
ENDIF |
259 |
|
260 |
C--- UV C-Grid specific code: end |
261 |
|
262 |
ELSEIF ( fCode.NE.'Ag' ) THEN |
263 |
STOP 'ABNORMAL END: S/R EXCH2_GET_UV_BOUNDS (wrong fCode)' |
264 |
ENDIF |
265 |
|
266 |
RETURN |
267 |
END |