7 |
C !ROUTINE: DIAG_VEGTILE_FILL |
C !ROUTINE: DIAG_VEGTILE_FILL |
8 |
C !INTERFACE: |
C !INTERFACE: |
9 |
SUBROUTINE DIAG_VEGTILE_FILL (field,indx,chfr,ib,numpts,npeice, |
SUBROUTINE DIAG_VEGTILE_FILL (field,indx,chfr,ib,numpts,npeice, |
10 |
. check, chardiag, kLev, nLevs, bi, bj, myThid) |
. check, chardiag, kLev, nLevs, bi, bj, myThid) |
11 |
C !DESCRIPTION: |
C !DESCRIPTION: |
12 |
C*********************************************************************** |
C*********************************************************************** |
13 |
C Increment the diagnostics array with a vegetation tile space field |
C Increment the diagnostics array with a vegetation tile space field |
36 |
C kLev ..... Integer flag for vertical levels: |
C kLev ..... Integer flag for vertical levels: |
37 |
C > 0 (any integer): WHICH single level to increment |
C > 0 (any integer): WHICH single level to increment |
38 |
C 0,-1 to increment "nLevs" levels in qdiag: |
C 0,-1 to increment "nLevs" levels in qdiag: |
39 |
C 0 : fill-in in the same order as the input array |
C 0 : fill-in in the same order as the input array |
40 |
C -1 : fill-in in reverse order. |
C -1 : fill-in in reverse order. |
41 |
C nLevs ...... indicates Number of levels of the input field array |
C nLevs ...... indicates Number of levels of the input field array |
42 |
C bi ...... X-direction tile number |
C bi ...... X-direction tile number |
59 |
|
|
60 |
C !LOCAL VARIABLES: |
C !LOCAL VARIABLES: |
61 |
C =============== |
C =============== |
62 |
INTEGER m, n |
INTEGER m, n |
63 |
INTEGER ndiagnum, ipointer |
INTEGER ndiagnum, ipointer |
64 |
INTEGER k, kFirst, kLast |
INTEGER k, kFirst, kLast |
65 |
INTEGER kd, kd0, ksgn, kStore |
INTEGER kd, kd0, ksgn, kStore |
66 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
67 |
integer i,offset,Lena,newindx,jindx |
integer i,offset,Lena,newindx,jindx |
68 |
_RL undef,getcon |
_RL undef |
69 |
|
INTEGER iSp, ndId, j,l |
70 |
|
INTEGER region2fill(0:nRegions) |
71 |
|
_RL scaleFact |
72 |
|
_RL gridField(sNx*sNy,nlevs), gridFrac(sNx*sNy) |
73 |
|
|
74 |
|
#ifdef ALLOW_FIZHI |
75 |
|
_RL getcon |
76 |
|
EXTERNAL getcon |
77 |
|
#endif |
78 |
|
|
79 |
C Run through list of active diagnostics to make sure |
C Run through list of active diagnostics to make sure |
80 |
C we are trying to fill a valid diagnostic |
C we are trying to fill a valid diagnostic |
81 |
|
|
82 |
|
undef = UNSET_RL |
83 |
ndiagnum = 0 |
ndiagnum = 0 |
84 |
ipointer = 0 |
ipointer = 0 |
85 |
DO n=1,nlists |
DO n=1,nlists |
113 |
ELSE |
ELSE |
114 |
STOP 'ABNORMAL END: S/R DIAGNOSTICS_FILL kLev > nLevs > 0' |
STOP 'ABNORMAL END: S/R DIAGNOSTICS_FILL kLev > nLevs > 0' |
115 |
ENDIF |
ENDIF |
116 |
C- Which part of qdiag to update: kd = 3rd index, |
C- Which part of qdiag to update: kd = 3rd index, |
117 |
C and do the loop >> do k=kFirst,kLast ; kd = kd0 + k*ksgn << |
C and do the loop >> do k=kFirst,kLast ; kd = kd0 + k*ksgn << |
118 |
IF ( kLev.EQ.-1 ) THEN |
IF ( kLev.EQ.-1 ) THEN |
119 |
ksgn = -1 |
ksgn = -1 |
130 |
kStore = kd0 + MAX(ksgn*kFirst,ksgn*kLast) - ipointer + 1 |
kStore = kd0 + MAX(ksgn*kFirst,ksgn*kLast) - ipointer + 1 |
131 |
IF ( kStore.GT.kdiag(ndiagnum) ) THEN |
IF ( kStore.GT.kdiag(ndiagnum) ) THEN |
132 |
_BEGIN_MASTER(myThid) |
_BEGIN_MASTER(myThid) |
133 |
WRITE(msgBuf,'(2A,I3,A)') 'DIAGNOSTICS_FILL: ', |
WRITE(msgBuf,'(2A,I4,A)') 'DIAGNOSTICS_FILL: ', |
134 |
. 'exceed Nb of levels(=',kdiag(ndiagnum),' ) reserved ' |
& 'exceed Nb of levels(=',kdiag(ndiagnum),' ) reserved ' |
135 |
CALL PRINT_ERROR( msgBuf , myThid ) |
CALL PRINT_ERROR( msgBuf , myThid ) |
136 |
WRITE(msgBuf,'(2A,I4,2A)') 'DIAGNOSTICS_FILL: ', |
WRITE(msgBuf,'(2A,I6,2A)') 'DIAGNOSTICS_FILL: ', |
137 |
. 'for Diagnostics #', ndiagnum, ' : ', chardiag |
& 'for Diagnostics #', ndiagnum, ' : ', chardiag |
138 |
CALL PRINT_ERROR( msgBuf , myThid ) |
CALL PRINT_ERROR( msgBuf , myThid ) |
139 |
WRITE(msgBuf,'(2A,2I4,I3)') 'calling DIAGNOSTICS_FILL ', |
WRITE(msgBuf,'(2A,2I4,I3)') 'calling DIAGNOSTICS_FILL ', |
140 |
. 'with kLev,nLevs=', kLev,nLevs |
& 'with kLev,nLevs=', kLev,nLevs |
141 |
CALL PRINT_ERROR( msgBuf , myThid ) |
CALL PRINT_ERROR( msgBuf , myThid ) |
142 |
WRITE(msgBuf,'(2A,I6,A)') 'DIAGNOSTICS_FILL: ', |
WRITE(msgBuf,'(2A,I6,A)') 'DIAGNOSTICS_FILL: ', |
143 |
. '==> trying to store up to ', kStore, ' levels' |
& '==> trying to store up to ', kStore, ' levels' |
144 |
CALL PRINT_ERROR( msgBuf , myThid ) |
CALL PRINT_ERROR( msgBuf , myThid ) |
145 |
STOP 'ABNORMAL END: S/R DIAGNOSTICS_FILL' |
STOP 'ABNORMAL END: S/R DIAGNOSTICS_FILL' |
146 |
_END_MASTER(myThid) |
_END_MASTER(myThid) |
149 |
DO k = kFirst,kLast |
DO k = kFirst,kLast |
150 |
kd = kd0 + ksgn*k |
kd = kd0 + ksgn*k |
151 |
if( check ) then |
if( check ) then |
152 |
|
#ifdef ALLOW_FIZHI |
153 |
undef = getcon('UNDEF') |
undef = getcon('UNDEF') |
154 |
|
#endif |
155 |
do i= 1,Lena |
do i= 1,Lena |
156 |
jindx = 1 + int((indx(i+offset-1)-1)/sNx) |
jindx = 1 + int((indx(i+offset-1)-1)/sNx) |
157 |
newindx = indx(i+offset-1)+(jindx-1)*2*Olx |
newindx = indx(i+offset-1)+(jindx-1)*2*Olx |
158 |
if(qdiag(newindx,1,kd,bi,bj).eq.undef |
if(qdiag(newindx,1,kd,bi,bj).eq.undef |
159 |
. .or.field(i,k).eq.undef)then |
. .or.field(i,k).eq.undef)then |
160 |
qdiag(newindx,1,kd,bi,bj) = undef |
qdiag(newindx,1,kd,bi,bj) = undef |
161 |
else |
else |
179 |
ENDDO |
ENDDO |
180 |
ENDDO |
ENDDO |
181 |
|
|
182 |
1000 format(' ',' Warning: Trying to write to diagnostic ',a8, |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
183 |
. ' But it is not a valid (or active) name ') |
C-- Global/Regional Statistics : |
184 |
RETURN |
scaleFact = 1. _d 0 |
185 |
|
|
186 |
|
C Run through list of active statistics-diagnostics to make sure |
187 |
|
C we are trying to compute & fill a valid diagnostic |
188 |
|
|
189 |
|
DO n=1,diagSt_nbLists |
190 |
|
DO m=1,diagSt_nbActv(n) |
191 |
|
IF ( chardiag.EQ.diagSt_Flds(m,n) .AND. iSdiag(m,n).GT.0 ) THEN |
192 |
|
iSp = iSdiag(m,n) |
193 |
|
IF ( qSdiag(0,0,iSp,bi,bj).GE.0. ) THEN |
194 |
|
ndId = jSdiag(m,n) |
195 |
|
C- Find list of regions to fill: |
196 |
|
DO j=0,nRegions |
197 |
|
region2fill(j) = diagSt_region(j,n) |
198 |
|
ENDDO |
199 |
|
C- if this diagnostics appears in several lists (with same freq) |
200 |
|
C then add regions from other lists |
201 |
|
DO l=1,diagSt_nbLists |
202 |
|
DO k=1,diagSt_nbActv(l) |
203 |
|
IF ( iSdiag(k,l).EQ.-iSp ) THEN |
204 |
|
DO j=0,nRegions |
205 |
|
region2fill(j) = MAX(region2fill(j),diagSt_region(j,l)) |
206 |
|
ENDDO |
207 |
|
ENDIF |
208 |
|
ENDDO |
209 |
|
ENDDO |
210 |
|
|
211 |
|
C- Which part of field to add : k = 3rd index, |
212 |
|
C and do the loop >> do k=kFirst,kLast << |
213 |
|
IF (kLev.LE.0) THEN |
214 |
|
kFirst = 1 |
215 |
|
kLast = nLevs |
216 |
|
ELSE |
217 |
|
kFirst = 1 |
218 |
|
kLast = 1 |
219 |
|
ENDIF |
220 |
|
|
221 |
|
C- Fill local array with grid-space field after conversion. |
222 |
|
offset = ib*(npeice-1) |
223 |
|
Lena = min(ib,numpts-offset) |
224 |
|
offset = offset+1 |
225 |
|
|
226 |
|
DO i=1,sNx*sNy |
227 |
|
gridFrac(i)= 0. |
228 |
|
ENDDO |
229 |
|
DO i=1,Lena |
230 |
|
newindx = indx(i+offset-1) |
231 |
|
gridFrac(newindx)=gridFrac(newindx)+chfr(i) |
232 |
|
ENDDO |
233 |
|
|
234 |
|
DO k = kFirst,kLast |
235 |
|
DO i=1,sNx*sNy |
236 |
|
gridField(i,k)= 0. |
237 |
|
ENDDO |
238 |
|
if( check ) then |
239 |
|
#ifdef ALLOW_FIZHI |
240 |
|
undef = getcon('UNDEF') |
241 |
|
#endif |
242 |
|
do i= 1,Lena |
243 |
|
newindx = indx(i+offset-1) |
244 |
|
if(gridField(newindx,k).eq.undef |
245 |
|
. .or.field(i,k).eq.undef)then |
246 |
|
gridField(newindx,k)= undef |
247 |
|
else |
248 |
|
gridField(newindx,k)=gridField(newindx,k) |
249 |
|
& +field(i,k)*chfr(i)/gridFrac(newindx) |
250 |
|
endif |
251 |
|
enddo |
252 |
|
else |
253 |
|
do i= 1,Lena |
254 |
|
newindx = indx(i+offset-1) |
255 |
|
gridField(newindx,k)=gridField(newindx,k) |
256 |
|
& +field(i,k)*chfr(i)/gridFrac(newindx) |
257 |
|
enddo |
258 |
|
endif |
259 |
|
ENDDO |
260 |
|
|
261 |
|
C- diagnostics is valid and Active: Now do the filling |
262 |
|
CALL DIAGSTATS_FILL( |
263 |
|
I gridField, gridFrac, scaleFact, 1, 1, |
264 |
|
I ndId, iSp, region2fill, kLev, nLevs, |
265 |
|
I 3, bi, bj, myThid ) |
266 |
|
ENDIF |
267 |
|
ENDIF |
268 |
|
ENDDO |
269 |
|
ENDDO |
270 |
|
|
271 |
|
RETURN |
272 |
END |
END |