1 |
C $Header: /u/gcmpack/MITgcm/pkg/grdchk/grdchk_loc.F,v 1.2.6.4 2003/07/07 16:18:18 heimbach Exp $ |
2 |
|
3 |
#include "CTRL_CPPOPTIONS.h" |
4 |
|
5 |
|
6 |
subroutine grdchk_loc( |
7 |
I icomp, |
8 |
I ichknum, |
9 |
O icvrec, |
10 |
O itile, |
11 |
O jtile, |
12 |
O layer, |
13 |
O obcspos, |
14 |
O itilepos, |
15 |
O jtilepos, |
16 |
O itest, |
17 |
O ierr, |
18 |
I mythid |
19 |
& ) |
20 |
|
21 |
c ================================================================== |
22 |
c SUBROUTINE grdchk_loc |
23 |
c ================================================================== |
24 |
c |
25 |
c o Get the location of a given component of the control vector for |
26 |
c the current process. |
27 |
c |
28 |
c started: Christian Eckert eckert@mit.edu 04-Apr-2000 |
29 |
c continued: heimbach@mit.edu: 13-Jun-2001 |
30 |
c |
31 |
c ================================================================== |
32 |
c SUBROUTINE grdchk_loc |
33 |
c ================================================================== |
34 |
|
35 |
implicit none |
36 |
|
37 |
c == global variables == |
38 |
|
39 |
#include "EEPARAMS.h" |
40 |
#include "SIZE.h" |
41 |
#include "GRID.h" |
42 |
#include "ctrl.h" |
43 |
#include "grdchk.h" |
44 |
|
45 |
c == routine arguments == |
46 |
|
47 |
integer icomp |
48 |
integer ichknum |
49 |
integer icvrec |
50 |
integer jtile |
51 |
integer itile |
52 |
integer layer |
53 |
integer obcspos |
54 |
integer itilepos |
55 |
integer jtilepos |
56 |
integer itest |
57 |
integer ierr |
58 |
integer mythid |
59 |
|
60 |
#ifdef ALLOW_GRDCHK |
61 |
c == local variables == |
62 |
|
63 |
integer bi,bj |
64 |
integer i,j,k |
65 |
integer iobcs |
66 |
integer biwrk,bjwrk |
67 |
integer iwrk, jwrk, kwrk |
68 |
integer iobcswrk |
69 |
integer irec, irecwrk |
70 |
integer itlo,ithi |
71 |
integer jtlo,jthi |
72 |
integer jmin,jmax |
73 |
integer imin,imax |
74 |
integer icomptest |
75 |
integer nobcsmax |
76 |
|
77 |
c == end of interface == |
78 |
|
79 |
jtlo = 1 |
80 |
jthi = nsy |
81 |
itlo = 1 |
82 |
ithi = nsx |
83 |
jmin = 1 |
84 |
jmax = sny |
85 |
imin = 1 |
86 |
imax = snx |
87 |
|
88 |
_BEGIN_MASTER( mythid ) |
89 |
|
90 |
c initialise parameters |
91 |
ierr = -5 |
92 |
|
93 |
if ( icomp .gt. 0 ) then |
94 |
if ( icomp .le. ncvarcomp ) then |
95 |
c-- A valid component of the control variable has been selected. |
96 |
if ( ichknum .EQ. 1 ) then |
97 |
itest = 0 |
98 |
icomptest = 0 |
99 |
irecwrk = 1 |
100 |
bjwrk = 1 |
101 |
biwrk = 1 |
102 |
kwrk = 1 |
103 |
iobcswrk = 1 |
104 |
jwrk = 1 |
105 |
iwrk = 1 |
106 |
else |
107 |
itest = itestmem (ichknum-1) |
108 |
icomptest = icompmem (ichknum-1) |
109 |
irecwrk = irecmem (ichknum-1) |
110 |
bjwrk = bjmem (ichknum-1) |
111 |
biwrk = bimem (ichknum-1) |
112 |
kwrk = klocmem (ichknum-1) |
113 |
iobcswrk = iobcsmem (ichknum-1) |
114 |
jwrk = jlocmem (ichknum-1) |
115 |
iwrk = ilocmem (ichknum-1) |
116 |
iwrk = iwrk + 1 |
117 |
end if |
118 |
|
119 |
c-- set max loop index for obcs multiplicities |
120 |
if ( ncvargrd(grdchkvarindex) .eq. 'm' ) then |
121 |
nobcsmax = nobcs |
122 |
else |
123 |
nobcsmax = 1 |
124 |
endif |
125 |
|
126 |
c-- Start to loop over records. |
127 |
do irec = irecwrk, ncvarrecs(grdchkvarindex) |
128 |
cph do iobcs = iobcswrk, nobcsmax |
129 |
iobcs = MOD((irec-1),nobcsmax) + 1 |
130 |
do bj = bjwrk, jthi |
131 |
do bi = biwrk, ithi |
132 |
do k = kwrk, ncvarnrmax(grdchkvarindex) |
133 |
|
134 |
if ( (ierr .ne. 0) .and. |
135 |
& (icomp .gt. itest) .and. |
136 |
& (icomp .le. itest + nwettile(bi,bj,k,iobcs))) then |
137 |
icvrec = irec |
138 |
itile = bi |
139 |
jtile = bj |
140 |
|
141 |
do j = jwrk, ncvarymax(grdchkvarindex) |
142 |
do i = iwrk, ncvarxmax(grdchkvarindex) |
143 |
if (ierr .ne. 0) then |
144 |
if ( ncvargrd(grdchkvarindex) .eq. 'c' ) then |
145 |
if ( maskC(i,j,k,bi,bj) .gt. 0.) then |
146 |
icomptest = icomptest + 1 |
147 |
endif |
148 |
else if ( ncvargrd(grdchkvarindex) .eq. 's' ) then |
149 |
if ( _maskS(i,j,k,bi,bj) .gt. 0.) then |
150 |
icomptest = icomptest + 1 |
151 |
endif |
152 |
else if ( ncvargrd(grdchkvarindex) .eq. 'w' ) then |
153 |
if ( _maskW(i,j,k,bi,bj) .gt. 0.) then |
154 |
icomptest = icomptest + 1 |
155 |
endif |
156 |
else if ( ncvargrd(grdchkvarindex) .eq. 'm' ) then |
157 |
if ( grdchkvarindex .EQ. 11 ) then |
158 |
#ifdef ALLOW_OBCSN_CONTROL |
159 |
if (grdchk_maskxz(i,k,bi,bj,iobcs) .gt. 0.) then |
160 |
icomptest = icomptest + 1 |
161 |
endif |
162 |
#endif |
163 |
else if ( grdchkvarindex .EQ. 12 ) then |
164 |
#ifdef ALLOW_OBCSS_CONTROL |
165 |
if (grdchk_maskxz(i,k,bi,bj,iobcs) .gt. 0.) then |
166 |
icomptest = icomptest + 1 |
167 |
endif |
168 |
#endif |
169 |
else if ( grdchkvarindex .EQ. 13 ) then |
170 |
#ifdef ALLOW_OBCSW_CONTROL |
171 |
if (grdchk_maskyz(j,k,bi,bj,iobcs) .gt. 0.) then |
172 |
icomptest = icomptest + 1 |
173 |
endif |
174 |
#endif |
175 |
else if ( grdchkvarindex .EQ. 14 ) then |
176 |
#ifdef ALLOW_OBCSE_CONTROL |
177 |
if (grdchk_maskyz(j,k,bi,bj,iobcs) .gt. 0.) then |
178 |
icomptest = icomptest + 1 |
179 |
endif |
180 |
#endif |
181 |
endif |
182 |
endif |
183 |
if ( icomp .eq. icomptest ) then |
184 |
itilepos = i |
185 |
jtilepos = j |
186 |
layer = k |
187 |
obcspos = iobcs |
188 |
ierr = 0 |
189 |
endif |
190 |
endif |
191 |
enddo |
192 |
iwrk = 1 |
193 |
enddo |
194 |
jwrk = 1 |
195 |
else if (ierr .NE. 0) then |
196 |
itest = itest + nwettile(bi,bj,k,iobcs) |
197 |
iwrk = 1 |
198 |
jwrk = 1 |
199 |
else |
200 |
c |
201 |
endif |
202 |
c-- End of loop over k |
203 |
enddo |
204 |
kwrk = 1 |
205 |
c-- End of loop over bi |
206 |
enddo |
207 |
biwrk = 1 |
208 |
c-- End of loop over bj |
209 |
enddo |
210 |
bjwrk = 1 |
211 |
c-- End of loop over iobcs |
212 |
cph enddo |
213 |
cph iobcswrk = 1 |
214 |
c-- End of loop over irec records. |
215 |
enddo |
216 |
c |
217 |
else |
218 |
if ( icomp .gt. maxncvarcomps ) then |
219 |
c-- Such a component does not exist. |
220 |
ierr = -4 |
221 |
icvrec = -1 |
222 |
jtile = -1 |
223 |
itile = -1 |
224 |
layer = -1 |
225 |
obcspos = -1 |
226 |
jtilepos = -1 |
227 |
itilepos = -1 |
228 |
else |
229 |
c-- The component is a land point. |
230 |
ierr = -3 |
231 |
icvrec = -1 |
232 |
jtile = -1 |
233 |
itile = -1 |
234 |
layer = -1 |
235 |
obcspos = -1 |
236 |
jtilepos = -1 |
237 |
itilepos = -1 |
238 |
endif |
239 |
endif |
240 |
else |
241 |
if ( icomp .lt. 0 ) then |
242 |
c-- Such a component does not exist. |
243 |
ierr = -2 |
244 |
icvrec = -1 |
245 |
jtile = -1 |
246 |
itile = -1 |
247 |
layer = -1 |
248 |
obcspos = -1 |
249 |
jtilepos = -1 |
250 |
itilepos = -1 |
251 |
else |
252 |
c-- Component zero. |
253 |
ierr = -1 |
254 |
icvrec = -1 |
255 |
jtile = -1 |
256 |
itile = -1 |
257 |
layer = -1 |
258 |
obcspos = -1 |
259 |
jtilepos = -1 |
260 |
itilepos = -1 |
261 |
endif |
262 |
endif |
263 |
|
264 |
_END_MASTER( mythid ) |
265 |
|
266 |
_BARRIER |
267 |
|
268 |
#endif /* ALLOW_GRDCHK */ |
269 |
|
270 |
end |
271 |
|