/[MITgcm]/MITgcm/pkg/diagnostics/diag_vegtile_fill.F
ViewVC logotype

Contents of /MITgcm/pkg/diagnostics/diag_vegtile_fill.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download)
Thu Apr 2 18:52:27 2009 UTC (15 years, 1 month ago) by jmc
Branch: MAIN
CVS Tags: checkpoint61n, checkpoint61o, checkpoint61l, checkpoint61m, checkpoint61t, checkpoint61u, checkpoint61r, checkpoint61s, checkpoint61p, checkpoint61q
Changes since 1.9: +140 -146 lines
- change to avoid indices going deliberately over array-bounds

1 C $Header: /u/gcmpack/MITgcm/pkg/diagnostics/diag_vegtile_fill.F,v 1.9 2008/11/18 21:41:07 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(
10 & field,indx,chfr,ib,numpts,npeice,
11 & check, chardiag, kLev, nLevs, bi, bj, myThid )
12 C !DESCRIPTION:
13 C***********************************************************************
14 C Increment the diagnostics array with a vegetation tile space field
15 C***********************************************************************
16 C !USES:
17 IMPLICIT NONE
18
19 C == Global variables ===
20 #include "EEPARAMS.h"
21 #include "SIZE.h"
22 #include "DIAGNOSTICS_SIZE.h"
23 #include "DIAGNOSTICS.h"
24
25 C !INPUT PARAMETERS:
26 C***********************************************************************
27 C field :: array to be mapped to grid space [ib,levs] and added to qdiag
28 C indx :: array of horizontal indices of grid points to convert to
29 C tile space[numpts]
30 C chfr :: fractional area covered by the tile [ib]
31 C ib :: inner dimension of source array and number of points in
32 C array a that need to be pasted
33 C numpts :: total number of points which were stripped
34 C npeice :: the current strip number to be filled
35 C check :: logical to check for undefined values
36 C chardiag :: Character expression for diag to fill
37 C kLev :: Integer flag for vertical levels:
38 C > 0 (any integer): which single level to increment
39 C 0,-1 to increment "nLevs" levels in qdiag:
40 C 0 : fill-in in the same order as the input array
41 C -1 : fill-in in reverse order.
42 C nLevs :: indicates Number of levels of the input field array
43 C bi :: X-direction tile number
44 C bj :: Y-direction tile number
45 C myThid :: my thread Id number
46 C***********************************************************************
47 CHARACTER*8 chardiag
48 INTEGER kLev, nLevs, bi, bj
49 INTEGER myThid
50 INTEGER ib,numpts,npeice
51 INTEGER indx(numpts)
52 _RL field(ib,nlevs), chfr(ib)
53 LOGICAL check
54 CEOP
55
56 C !LOCAL VARIABLES:
57 C ===============
58 INTEGER m, n
59 INTEGER ndiagnum, ipointer
60 INTEGER k, kFirst, kLast
61 INTEGER kd, kd0, ksgn, kStore
62 CHARACTER*(MAX_LEN_MBUF) msgBuf
63 INTEGER offset, Lena
64 INTEGER ivt, ij, i
65 _RL undef
66 INTEGER iSp, ndId, j,l
67 INTEGER region2fill(0:nRegions)
68 _RL scaleFact
69 _RL gridField(sNx*sNy,nlevs), gridFrac(sNx*sNy)
70
71 #ifdef ALLOW_FIZHI
72 _RL getcon
73 EXTERNAL getcon
74 #endif
75
76 C Run through list of active diagnostics to make sure
77 C we are trying to fill a valid diagnostic
78
79 undef = UNSET_RL
80 #ifdef ALLOW_FIZHI
81 IF ( check ) undef = getcon('UNDEF')
82 #endif
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
101 C- Which part of field to add : k = 3rd index,
102 C and do the loop >> do k=kFirst,kLast <<
103 IF (kLev.LE.0) THEN
104 kFirst = 1
105 kLast = nLevs
106 ELSEIF ( nLevs.EQ.1 ) THEN
107 kFirst = 1
108 kLast = 1
109 ELSEIF ( kLev.LE.nLevs ) THEN
110 kFirst = kLev
111 kLast = kLev
112 ELSE
113 STOP 'ABNORMAL END: S/R DIAGNOSTICS_FILL kLev > nLevs > 0'
114 ENDIF
115 C- Which part of qdiag to update: kd = 3rd index,
116 C and do the loop >> do k=kFirst,kLast ; kd = kd0 + k*ksgn <<
117 IF ( kLev.EQ.-1 ) THEN
118 ksgn = -1
119 kd0 = ipointer + nLevs
120 ELSEIF ( kLev.EQ.0 ) THEN
121 ksgn = 1
122 kd0 = ipointer - 1
123 ELSE
124 ksgn = 0
125 kd0 = ipointer + kLev - 1
126 ENDIF
127
128 C- Check for consistency with Nb of levels reserved in storage array
129 kStore = kd0 + MAX(ksgn*kFirst,ksgn*kLast) - ipointer + 1
130 IF ( kStore.GT.kdiag(ndiagnum) ) THEN
131 _BEGIN_MASTER(myThid)
132 WRITE(msgBuf,'(2A,I4,A)') 'DIAGNOSTICS_FILL: ',
133 & 'exceed Nb of levels(=',kdiag(ndiagnum),' ) reserved '
134 CALL PRINT_ERROR( msgBuf , myThid )
135 WRITE(msgBuf,'(2A,I6,2A)') 'DIAGNOSTICS_FILL: ',
136 & 'for Diagnostics #', ndiagnum, ' : ', chardiag
137 CALL PRINT_ERROR( msgBuf , myThid )
138 WRITE(msgBuf,'(2A,2I4,I3)') 'calling DIAGNOSTICS_FILL ',
139 & 'with kLev,nLevs=', kLev,nLevs
140 CALL PRINT_ERROR( msgBuf , myThid )
141 WRITE(msgBuf,'(2A,I6,A)') 'DIAGNOSTICS_FILL: ',
142 & '==> trying to store up to ', kStore, ' levels'
143 CALL PRINT_ERROR( msgBuf , myThid )
144 STOP 'ABNORMAL END: S/R DIAGNOSTICS_FILL'
145 _END_MASTER(myThid)
146 ENDIF
147
148 DO k = kFirst,kLast
149 kd = kd0 + ksgn*k
150 IF ( check ) THEN
151 DO ivt = 1,Lena
152 ij = indx(ivt+offset) - 1
153 j = 1 + INT(ij/sNx)
154 i = 1 + MOD(ij,sNx)
155 IF ( field(ivt,k).EQ.undef ) THEN
156 qdiag(i,j,kd,bi,bj) = undef
157 ELSEIF ( qdiag(i,j,kd,bi,bj).NE.undef ) THEN
158 qdiag(i,j,kd,bi,bj) = qdiag(i,j,kd,bi,bj)
159 & + field(ivt,k)*chfr(ivt)
160 ENDIF
161 ENDDO
162 ELSE
163 DO ivt = 1,Lena
164 ij = indx(ivt+offset) - 1
165 j = 1 + INT(ij/sNx)
166 i = 1 + MOD(ij,sNx)
167 qdiag(i,j,kd,bi,bj) = qdiag(i,j,kd,bi,bj)
168 & + field(ivt,k)*chfr(ivt)
169 ENDDO
170 ENDIF
171 ENDDO
172
173 C-- do the filling: ends here.
174 ENDIF
175 ENDIF
176 ENDDO
177 ENDDO
178
179 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
180 C-- Global/Regional Statistics :
181 scaleFact = 1. _d 0
182
183 C Run through list of active statistics-diagnostics to make sure
184 C we are trying to compute & fill a valid diagnostic
185
186 DO n=1,diagSt_nbLists
187 DO m=1,diagSt_nbActv(n)
188 IF ( chardiag.EQ.diagSt_Flds(m,n) .AND. iSdiag(m,n).GT.0 ) THEN
189 iSp = iSdiag(m,n)
190 IF ( qSdiag(0,0,iSp,bi,bj).GE.0. ) THEN
191 ndId = jSdiag(m,n)
192 C- Find list of regions to fill:
193 DO j=0,nRegions
194 region2fill(j) = diagSt_region(j,n)
195 ENDDO
196 C- if this diagnostics appears in several lists (with same freq)
197 C then add regions from other lists
198 DO l=1,diagSt_nbLists
199 DO k=1,diagSt_nbActv(l)
200 IF ( iSdiag(k,l).EQ.-iSp ) THEN
201 DO j=0,nRegions
202 region2fill(j) = MAX(region2fill(j),diagSt_region(j,l))
203 ENDDO
204 ENDIF
205 ENDDO
206 ENDDO
207
208 C- Which part of field to add : k = 3rd index,
209 C and do the loop >> do k=kFirst,kLast <<
210 IF (kLev.LE.0) THEN
211 kFirst = 1
212 kLast = nLevs
213 ELSE
214 kFirst = 1
215 kLast = 1
216 ENDIF
217
218 C- Fill local array with grid-space field after conversion.
219 offset = ib*(npeice-1)
220 Lena = MIN(ib,numpts-offset)
221
222 DO ij = 1,sNx*sNy
223 gridFrac(ij)= 0.
224 ENDDO
225 DO ivt = 1,Lena
226 ij = indx(ivt+offset)
227 gridFrac(ij)=gridFrac(ij)+chfr(ivt)
228 ENDDO
229
230 DO k = kFirst,kLast
231 DO ij = 1,sNx*sNy
232 gridField(ij,k)= 0.
233 ENDDO
234 IF ( check ) THEN
235 DO ivt = 1,Lena
236 ij = indx(ivt+offset)
237 IF ( field(ivt,k).EQ.undef ) THEN
238 gridField(ij,k) = undef
239 ELSEIF ( gridFrac(ij).GT.0. _d 0 ) THEN
240 gridField(ij,k) = gridField(ij,k)
241 & + field(ivt,k)*chfr(ivt)/gridFrac(ij)
242 ENDIF
243 ENDDO
244 ELSE
245 DO ivt = 1,Lena
246 ij = indx(ivt+offset)
247 IF ( gridFrac(ij).GT.0. _d 0 ) THEN
248 gridField(ij,k) = gridField(ij,k)
249 & + field(ivt,k)*chfr(ivt)/gridFrac(ij)
250 ENDIF
251 ENDDO
252 ENDIF
253 ENDDO
254
255 C- diagnostics is valid and Active: Now do the filling
256 CALL DIAGSTATS_FILL(
257 I gridField, gridFrac, scaleFact, 1, 1,
258 I ndId, iSp, region2fill, kLev, nLevs,
259 I 3, bi, bj, myThid )
260 ENDIF
261 ENDIF
262 ENDDO
263 ENDDO
264
265 RETURN
266 END

  ViewVC Help
Powered by ViewVC 1.1.22