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

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

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


Revision 1.11 - (hide annotations) (download)
Thu Sep 3 20:46:12 2009 UTC (14 years, 8 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint62, checkpoint61v, checkpoint61w, checkpoint61z, checkpoint61x, checkpoint61y
Changes since 1.10: +7 -2 lines
keep same S/R name (without _RL) for the RL version and update interface
calls to DIAGNOSTICS_FILL_FIELD & DIAGSTATS_FILL (which now handle RS array)

1 jmc 1.11 C $Header: /u/gcmpack/MITgcm/pkg/diagnostics/diag_vegtile_fill.F,v 1.10 2009/04/02 18:52:27 jmc Exp $
2 molod 1.1 C $Name: $
3    
4     #include "DIAG_OPTIONS.h"
5    
6     CBOP
7     C !ROUTINE: DIAG_VEGTILE_FILL
8     C !INTERFACE:
9 jmc 1.10 SUBROUTINE DIAG_VEGTILE_FILL(
10     & field,indx,chfr,ib,numpts,npeice,
11     & check, chardiag, kLev, nLevs, bi, bj, myThid )
12 molod 1.1 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 jmc 1.10 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 molod 1.1 C 0,-1 to increment "nLevs" levels in qdiag:
40 jmc 1.10 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 molod 1.1 C***********************************************************************
47     CHARACTER*8 chardiag
48     INTEGER kLev, nLevs, bi, bj
49     INTEGER myThid
50 jmc 1.10 INTEGER ib,numpts,npeice
51     INTEGER indx(numpts)
52 molod 1.1 _RL field(ib,nlevs), chfr(ib)
53 jmc 1.10 LOGICAL check
54 molod 1.1 CEOP
55    
56     C !LOCAL VARIABLES:
57     C ===============
58 jmc 1.8 INTEGER m, n
59 molod 1.1 INTEGER ndiagnum, ipointer
60     INTEGER k, kFirst, kLast
61     INTEGER kd, kd0, ksgn, kStore
62     CHARACTER*(MAX_LEN_MBUF) msgBuf
63 jmc 1.10 INTEGER offset, Lena
64     INTEGER ivt, ij, i
65 jmc 1.9 _RL undef
66 jmc 1.7 INTEGER iSp, ndId, j,l
67     INTEGER region2fill(0:nRegions)
68     _RL scaleFact
69     _RL gridField(sNx*sNy,nlevs), gridFrac(sNx*sNy)
70 jmc 1.11 _RS dummyRS(1)
71 molod 1.1
72 jmc 1.9 #ifdef ALLOW_FIZHI
73     _RL getcon
74     EXTERNAL getcon
75     #endif
76    
77 molod 1.1 C Run through list of active diagnostics to make sure
78     C we are trying to fill a valid diagnostic
79    
80 jmc 1.9 undef = UNSET_RL
81 jmc 1.10 #ifdef ALLOW_FIZHI
82     IF ( check ) undef = getcon('UNDEF')
83     #endif
84 molod 1.1 ndiagnum = 0
85     ipointer = 0
86     DO n=1,nlists
87     DO m=1,nActive(n)
88 jmc 1.6 IF ( chardiag.EQ.flds(m,n) .AND. idiag(m,n).GT.0 ) THEN
89 molod 1.1 ndiagnum = jdiag(m,n)
90 jmc 1.6 ipointer = idiag(m,n)
91     IF ( ndiagnum.NE.0 .AND. ndiag(ipointer,1,1).GE.0 ) THEN
92     C-- do the filling: start here:
93    
94 jmc 1.10 IF ( (ABS(kLev).LE.1) .AND. (npeice.EQ.1) ) THEN
95 jmc 1.6 C Increment the counter for the diagnostic
96 jmc 1.10 ndiag(ipointer,bi,bj) = ndiag(ipointer,bi,bj) + 1
97     ENDIF
98 molod 1.1
99 jmc 1.10 offset = ib*(npeice-1)
100     Lena = MIN(ib,numpts-offset)
101 molod 1.1
102     C- Which part of field to add : k = 3rd index,
103     C and do the loop >> do k=kFirst,kLast <<
104 jmc 1.10 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 jmc 1.8 C- Which part of qdiag to update: kd = 3rd index,
117 molod 1.1 C and do the loop >> do k=kFirst,kLast ; kd = kd0 + k*ksgn <<
118 jmc 1.10 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 molod 1.1
129     C- Check for consistency with Nb of levels reserved in storage array
130 jmc 1.10 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     DO ivt = 1,Lena
153     ij = indx(ivt+offset) - 1
154     j = 1 + INT(ij/sNx)
155     i = 1 + MOD(ij,sNx)
156     IF ( field(ivt,k).EQ.undef ) THEN
157     qdiag(i,j,kd,bi,bj) = undef
158     ELSEIF ( qdiag(i,j,kd,bi,bj).NE.undef ) THEN
159     qdiag(i,j,kd,bi,bj) = qdiag(i,j,kd,bi,bj)
160     & + field(ivt,k)*chfr(ivt)
161     ENDIF
162     ENDDO
163     ELSE
164     DO ivt = 1,Lena
165     ij = indx(ivt+offset) - 1
166     j = 1 + INT(ij/sNx)
167     i = 1 + MOD(ij,sNx)
168     qdiag(i,j,kd,bi,bj) = qdiag(i,j,kd,bi,bj)
169     & + field(ivt,k)*chfr(ivt)
170     ENDDO
171     ENDIF
172     ENDDO
173 molod 1.1
174 jmc 1.6 C-- do the filling: ends here.
175     ENDIF
176     ENDIF
177     ENDDO
178     ENDDO
179 molod 1.1
180 jmc 1.7 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
181     C-- Global/Regional Statistics :
182     scaleFact = 1. _d 0
183    
184     C Run through list of active statistics-diagnostics to make sure
185     C we are trying to compute & fill a valid diagnostic
186    
187     DO n=1,diagSt_nbLists
188     DO m=1,diagSt_nbActv(n)
189     IF ( chardiag.EQ.diagSt_Flds(m,n) .AND. iSdiag(m,n).GT.0 ) THEN
190     iSp = iSdiag(m,n)
191     IF ( qSdiag(0,0,iSp,bi,bj).GE.0. ) THEN
192     ndId = jSdiag(m,n)
193     C- Find list of regions to fill:
194     DO j=0,nRegions
195     region2fill(j) = diagSt_region(j,n)
196     ENDDO
197     C- if this diagnostics appears in several lists (with same freq)
198     C then add regions from other lists
199     DO l=1,diagSt_nbLists
200     DO k=1,diagSt_nbActv(l)
201     IF ( iSdiag(k,l).EQ.-iSp ) THEN
202     DO j=0,nRegions
203     region2fill(j) = MAX(region2fill(j),diagSt_region(j,l))
204     ENDDO
205     ENDIF
206     ENDDO
207     ENDDO
208    
209     C- Which part of field to add : k = 3rd index,
210     C and do the loop >> do k=kFirst,kLast <<
211 jmc 1.10 IF (kLev.LE.0) THEN
212     kFirst = 1
213     kLast = nLevs
214     ELSE
215     kFirst = 1
216     kLast = 1
217     ENDIF
218 jmc 1.7
219     C- Fill local array with grid-space field after conversion.
220 jmc 1.10 offset = ib*(npeice-1)
221     Lena = MIN(ib,numpts-offset)
222 jmc 1.7
223 jmc 1.10 DO ij = 1,sNx*sNy
224     gridFrac(ij)= 0.
225     ENDDO
226     DO ivt = 1,Lena
227     ij = indx(ivt+offset)
228     gridFrac(ij)=gridFrac(ij)+chfr(ivt)
229     ENDDO
230 jmc 1.7
231 jmc 1.10 DO k = kFirst,kLast
232     DO ij = 1,sNx*sNy
233     gridField(ij,k)= 0.
234     ENDDO
235     IF ( check ) THEN
236     DO ivt = 1,Lena
237     ij = indx(ivt+offset)
238     IF ( field(ivt,k).EQ.undef ) THEN
239     gridField(ij,k) = undef
240     ELSEIF ( gridFrac(ij).GT.0. _d 0 ) THEN
241     gridField(ij,k) = gridField(ij,k)
242     & + field(ivt,k)*chfr(ivt)/gridFrac(ij)
243     ENDIF
244     ENDDO
245     ELSE
246     DO ivt = 1,Lena
247     ij = indx(ivt+offset)
248     IF ( gridFrac(ij).GT.0. _d 0 ) THEN
249     gridField(ij,k) = gridField(ij,k)
250     & + field(ivt,k)*chfr(ivt)/gridFrac(ij)
251     ENDIF
252     ENDDO
253     ENDIF
254     ENDDO
255 jmc 1.7
256     C- diagnostics is valid and Active: Now do the filling
257     CALL DIAGSTATS_FILL(
258 jmc 1.11 I gridField, gridFrac,
259     #ifndef REAL4_IS_SLOW
260     I dummyRS, dummyRS,
261     #endif
262     I scaleFact, 1, 0, 1,
263 jmc 1.7 I ndId, iSp, region2fill, kLev, nLevs,
264     I 3, bi, bj, myThid )
265     ENDIF
266     ENDIF
267     ENDDO
268     ENDDO
269    
270 jmc 1.8 RETURN
271 molod 1.1 END

  ViewVC Help
Powered by ViewVC 1.1.22