1 |
C $Header: /u/gcmpack/MITgcm/pkg/diagnostics/diag_vegtile_fill.F,v 1.8 2008/02/05 15:31:19 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "DIAG_OPTIONS.h" |
5 |
|
6 |
CBOP |
7 |
C !ROUTINE: DIAG_VEGTILE_FILL |
8 |
C !INTERFACE: |
9 |
SUBROUTINE DIAG_VEGTILE_FILL (field,indx,chfr,ib,numpts,npeice, |
10 |
. check, chardiag, kLev, nLevs, bi, bj, myThid) |
11 |
C !DESCRIPTION: |
12 |
C*********************************************************************** |
13 |
C Increment the diagnostics array with a vegetation tile space field |
14 |
C*********************************************************************** |
15 |
C !USES: |
16 |
IMPLICIT NONE |
17 |
|
18 |
C == Global variables === |
19 |
#include "EEPARAMS.h" |
20 |
#include "SIZE.h" |
21 |
#include "DIAGNOSTICS_SIZE.h" |
22 |
#include "DIAGNOSTICS.h" |
23 |
|
24 |
C !INPUT PARAMETERS: |
25 |
C*********************************************************************** |
26 |
C field - array to be mapped to grid space [ib,levs] and added to qdiag |
27 |
C indx - array of horizontal indeces of grid points to convert to |
28 |
C tile space[numpts] |
29 |
C chfr - fractional area covered by the tile [ib] |
30 |
C ib - inner dimension of source array AND number of points in |
31 |
C array a that need to be pasted |
32 |
C numpts - total number of points which were stripped |
33 |
C npeice - the current strip number to be filled |
34 |
C check - logical to check for undefined values |
35 |
C chardiag ... Character expression for diag to fill |
36 |
C kLev ..... Integer flag for vertical levels: |
37 |
C > 0 (any integer): WHICH single level to increment |
38 |
C 0,-1 to increment "nLevs" levels in qdiag: |
39 |
C 0 : fill-in in the same order as the input array |
40 |
C -1 : fill-in in reverse order. |
41 |
C nLevs ...... indicates Number of levels of the input field array |
42 |
C bi ...... X-direction tile number |
43 |
C bj ...... Y-direction tile number |
44 |
C myThid :: my thread Id number |
45 |
C |
46 |
c IMPORTANT NOTE: |
47 |
c |
48 |
c This routine will result in roundoff differences if called from |
49 |
c within a parallel region. |
50 |
C*********************************************************************** |
51 |
CHARACTER*8 chardiag |
52 |
INTEGER kLev, nLevs, bi, bj |
53 |
INTEGER myThid |
54 |
integer ib,numpts,npeice |
55 |
integer indx(numpts) |
56 |
_RL field(ib,nlevs), chfr(ib) |
57 |
logical check |
58 |
CEOP |
59 |
|
60 |
C !LOCAL VARIABLES: |
61 |
C =============== |
62 |
INTEGER m, n |
63 |
INTEGER ndiagnum, ipointer |
64 |
INTEGER k, kFirst, kLast |
65 |
INTEGER kd, kd0, ksgn, kStore |
66 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
67 |
integer i,offset,Lena,newindx,jindx |
68 |
_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 |
80 |
C we are trying to fill a valid diagnostic |
81 |
|
82 |
undef = UNSET_RL |
83 |
ndiagnum = 0 |
84 |
ipointer = 0 |
85 |
DO n=1,nlists |
86 |
DO m=1,nActive(n) |
87 |
IF ( chardiag.EQ.flds(m,n) .AND. idiag(m,n).GT.0 ) THEN |
88 |
ndiagnum = jdiag(m,n) |
89 |
ipointer = idiag(m,n) |
90 |
IF ( ndiagnum.NE.0 .AND. ndiag(ipointer,1,1).GE.0 ) THEN |
91 |
C-- do the filling: start here: |
92 |
|
93 |
IF ( (ABS(kLev).LE.1) .AND. (npeice.eq.1) ) THEN |
94 |
C Increment the counter for the diagnostic |
95 |
ndiag(ipointer,bi,bj) = ndiag(ipointer,bi,bj) + 1 |
96 |
ENDIF |
97 |
|
98 |
offset = ib*(npeice-1) |
99 |
Lena = min(ib,numpts-offset) |
100 |
offset = offset+1 |
101 |
|
102 |
C- Which part of field to add : k = 3rd index, |
103 |
C and do the loop >> do k=kFirst,kLast << |
104 |
IF (kLev.LE.0) THEN |
105 |
kFirst = 1 |
106 |
kLast = nLevs |
107 |
ELSEIF ( nLevs.EQ.1 ) THEN |
108 |
kFirst = 1 |
109 |
kLast = 1 |
110 |
ELSEIF ( kLev.LE.nLevs ) THEN |
111 |
kFirst = kLev |
112 |
kLast = kLev |
113 |
ELSE |
114 |
STOP 'ABNORMAL END: S/R DIAGNOSTICS_FILL kLev > nLevs > 0' |
115 |
ENDIF |
116 |
C- Which part of qdiag to update: kd = 3rd index, |
117 |
C and do the loop >> do k=kFirst,kLast ; kd = kd0 + k*ksgn << |
118 |
IF ( kLev.EQ.-1 ) THEN |
119 |
ksgn = -1 |
120 |
kd0 = ipointer + nLevs |
121 |
ELSEIF ( kLev.EQ.0 ) THEN |
122 |
ksgn = 1 |
123 |
kd0 = ipointer - 1 |
124 |
ELSE |
125 |
ksgn = 0 |
126 |
kd0 = ipointer + kLev - 1 |
127 |
ENDIF |
128 |
|
129 |
C- Check for consistency with Nb of levels reserved in storage array |
130 |
kStore = kd0 + MAX(ksgn*kFirst,ksgn*kLast) - ipointer + 1 |
131 |
IF ( kStore.GT.kdiag(ndiagnum) ) THEN |
132 |
_BEGIN_MASTER(myThid) |
133 |
WRITE(msgBuf,'(2A,I4,A)') 'DIAGNOSTICS_FILL: ', |
134 |
& 'exceed Nb of levels(=',kdiag(ndiagnum),' ) reserved ' |
135 |
CALL PRINT_ERROR( msgBuf , myThid ) |
136 |
WRITE(msgBuf,'(2A,I6,2A)') 'DIAGNOSTICS_FILL: ', |
137 |
& 'for Diagnostics #', ndiagnum, ' : ', chardiag |
138 |
CALL PRINT_ERROR( msgBuf , myThid ) |
139 |
WRITE(msgBuf,'(2A,2I4,I3)') 'calling DIAGNOSTICS_FILL ', |
140 |
& 'with kLev,nLevs=', kLev,nLevs |
141 |
CALL PRINT_ERROR( msgBuf , myThid ) |
142 |
WRITE(msgBuf,'(2A,I6,A)') 'DIAGNOSTICS_FILL: ', |
143 |
& '==> trying to store up to ', kStore, ' levels' |
144 |
CALL PRINT_ERROR( msgBuf , myThid ) |
145 |
STOP 'ABNORMAL END: S/R DIAGNOSTICS_FILL' |
146 |
_END_MASTER(myThid) |
147 |
ENDIF |
148 |
|
149 |
DO k = kFirst,kLast |
150 |
kd = kd0 + ksgn*k |
151 |
if( check ) then |
152 |
#ifdef ALLOW_FIZHI |
153 |
undef = getcon('UNDEF') |
154 |
#endif |
155 |
do i= 1,Lena |
156 |
jindx = 1 + int((indx(i+offset-1)-1)/sNx) |
157 |
newindx = indx(i+offset-1)+(jindx-1)*2*Olx |
158 |
if(qdiag(newindx,1,kd,bi,bj).eq.undef |
159 |
. .or.field(i,k).eq.undef)then |
160 |
qdiag(newindx,1,kd,bi,bj) = undef |
161 |
else |
162 |
qdiag(newindx,1,kd,bi,bj)=qdiag(newindx,1,kd,bi,bj)+ |
163 |
. field(i,k)*chfr(i) |
164 |
endif |
165 |
enddo |
166 |
else |
167 |
do i= 1,Lena |
168 |
jindx = 1 + int((indx(i+offset-1)-1)/sNx) |
169 |
newindx = indx(i+offset-1)+(jindx-1)*2*Olx |
170 |
qdiag(newindx,1,kd,bi,bj)=qdiag(newindx,1,kd,bi,bj)+ |
171 |
. field(i,k)*chfr(i) |
172 |
enddo |
173 |
endif |
174 |
ENDDO |
175 |
|
176 |
C-- do the filling: ends here. |
177 |
ENDIF |
178 |
ENDIF |
179 |
ENDDO |
180 |
ENDDO |
181 |
|
182 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
183 |
C-- Global/Regional Statistics : |
184 |
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 |