/[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.7 - (hide annotations) (download)
Wed Sep 21 19:35:29 2005 UTC (18 years, 7 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint58l_post, checkpoint57t_post, checkpoint58e_post, mitgcm_mapl_00, checkpoint58u_post, checkpoint58w_post, checkpoint58r_post, checkpoint57y_post, checkpoint58n_post, checkpoint58x_post, checkpoint58t_post, checkpoint58h_post, checkpoint57y_pre, checkpoint58q_post, checkpoint57v_post, checkpoint58j_post, checkpoint59e, checkpoint59d, checkpoint59g, checkpoint59f, checkpoint59a, checkpoint59c, checkpoint59b, checkpoint59m, checkpoint59l, checkpoint59i, checkpoint59h, checkpoint59k, checkpoint59j, checkpoint59, checkpoint58, checkpoint58f_post, checkpoint57x_post, checkpoint58d_post, checkpoint58c_post, checkpoint57w_post, checkpint57u_post, checkpoint58a_post, checkpoint58i_post, checkpoint58g_post, checkpoint58o_post, checkpoint57z_post, checkpoint58y_post, checkpoint58k_post, checkpoint58v_post, checkpoint58s_post, checkpoint58p_post, checkpoint58b_post, checkpoint58m_post
Changes since 1.6: +92 -1 lines
add Stat-Diag filling ; give the right mean value, but min.max & std-dev
 are a mixture of vegetation-tile and grid-cell statistics.

1 jmc 1.7 C $Header: /u/gcmpack/MITgcm/pkg/diagnostics/diag_vegtile_fill.F,v 1.6 2005/06/26 16:51:49 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     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,getcon
69 jmc 1.7 INTEGER iSp, ndId, j,l
70     INTEGER region2fill(0:nRegions)
71     _RL scaleFact
72     _RL gridField(sNx*sNy,nlevs), gridFrac(sNx*sNy)
73 molod 1.1
74     C Run through list of active diagnostics to make sure
75     C we are trying to fill a valid diagnostic
76    
77     ndiagnum = 0
78     ipointer = 0
79     DO n=1,nlists
80     DO m=1,nActive(n)
81 jmc 1.6 IF ( chardiag.EQ.flds(m,n) .AND. idiag(m,n).GT.0 ) THEN
82 molod 1.1 ndiagnum = jdiag(m,n)
83 jmc 1.6 ipointer = idiag(m,n)
84     IF ( ndiagnum.NE.0 .AND. ndiag(ipointer,1,1).GE.0 ) THEN
85     C-- do the filling: start here:
86    
87     IF ( (ABS(kLev).LE.1) .AND. (npeice.eq.1) ) THEN
88     C Increment the counter for the diagnostic
89     ndiag(ipointer,bi,bj) = ndiag(ipointer,bi,bj) + 1
90     ENDIF
91 molod 1.1
92     offset = ib*(npeice-1)
93     Lena = min(ib,numpts-offset)
94     offset = offset+1
95    
96     C- Which part of field to add : k = 3rd index,
97     C and do the loop >> do k=kFirst,kLast <<
98     IF (kLev.LE.0) THEN
99     kFirst = 1
100     kLast = nLevs
101     ELSEIF ( nLevs.EQ.1 ) THEN
102     kFirst = 1
103     kLast = 1
104     ELSEIF ( kLev.LE.nLevs ) THEN
105     kFirst = kLev
106     kLast = kLev
107     ELSE
108     STOP 'ABNORMAL END: S/R DIAGNOSTICS_FILL kLev > nLevs > 0'
109     ENDIF
110     C- Which part of qdiag to update: kd = 3rd index,
111     C and do the loop >> do k=kFirst,kLast ; kd = kd0 + k*ksgn <<
112     IF ( kLev.EQ.-1 ) THEN
113     ksgn = -1
114     kd0 = ipointer + nLevs
115     ELSEIF ( kLev.EQ.0 ) THEN
116     ksgn = 1
117     kd0 = ipointer - 1
118     ELSE
119     ksgn = 0
120     kd0 = ipointer + kLev - 1
121     ENDIF
122    
123     C- Check for consistency with Nb of levels reserved in storage array
124     kStore = kd0 + MAX(ksgn*kFirst,ksgn*kLast) - ipointer + 1
125     IF ( kStore.GT.kdiag(ndiagnum) ) THEN
126     _BEGIN_MASTER(myThid)
127     WRITE(msgBuf,'(2A,I3,A)') 'DIAGNOSTICS_FILL: ',
128     . 'exceed Nb of levels(=',kdiag(ndiagnum),' ) reserved '
129     CALL PRINT_ERROR( msgBuf , myThid )
130     WRITE(msgBuf,'(2A,I4,2A)') 'DIAGNOSTICS_FILL: ',
131     . 'for Diagnostics #', ndiagnum, ' : ', chardiag
132     CALL PRINT_ERROR( msgBuf , myThid )
133     WRITE(msgBuf,'(2A,2I4,I3)') 'calling DIAGNOSTICS_FILL ',
134     . 'with kLev,nLevs=', kLev,nLevs
135     CALL PRINT_ERROR( msgBuf , myThid )
136     WRITE(msgBuf,'(2A,I6,A)') 'DIAGNOSTICS_FILL: ',
137     . '==> trying to store up to ', kStore, ' levels'
138     CALL PRINT_ERROR( msgBuf , myThid )
139     STOP 'ABNORMAL END: S/R DIAGNOSTICS_FILL'
140     _END_MASTER(myThid)
141     ENDIF
142    
143     DO k = kFirst,kLast
144     kd = kd0 + ksgn*k
145     if( check ) then
146     undef = getcon('UNDEF')
147     do i= 1,Lena
148 molod 1.3 jindx = 1 + int((indx(i+offset-1)-1)/sNx)
149 molod 1.4 newindx = indx(i+offset-1)+(jindx-1)*2*Olx
150 molod 1.1 if(qdiag(newindx,1,kd,bi,bj).eq.undef
151     . .or.field(i,k).eq.undef)then
152     qdiag(newindx,1,kd,bi,bj) = undef
153     else
154     qdiag(newindx,1,kd,bi,bj)=qdiag(newindx,1,kd,bi,bj)+
155 molod 1.4 . field(i,k)*chfr(i)
156 molod 1.1 endif
157     enddo
158     else
159     do i= 1,Lena
160 molod 1.3 jindx = 1 + int((indx(i+offset-1)-1)/sNx)
161 molod 1.4 newindx = indx(i+offset-1)+(jindx-1)*2*Olx
162 molod 1.1 qdiag(newindx,1,kd,bi,bj)=qdiag(newindx,1,kd,bi,bj)+
163 molod 1.4 . field(i,k)*chfr(i)
164 molod 1.1 enddo
165     endif
166     ENDDO
167    
168 jmc 1.6 C-- do the filling: ends here.
169     ENDIF
170     ENDIF
171     ENDDO
172     ENDDO
173 molod 1.1
174 jmc 1.7 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
175     C-- Global/Regional Statistics :
176     scaleFact = 1. _d 0
177    
178     C Run through list of active statistics-diagnostics to make sure
179     C we are trying to compute & fill a valid diagnostic
180    
181     DO n=1,diagSt_nbLists
182     DO m=1,diagSt_nbActv(n)
183     IF ( chardiag.EQ.diagSt_Flds(m,n) .AND. iSdiag(m,n).GT.0 ) THEN
184     iSp = iSdiag(m,n)
185     IF ( qSdiag(0,0,iSp,bi,bj).GE.0. ) THEN
186     ndId = jSdiag(m,n)
187     C- Find list of regions to fill:
188     DO j=0,nRegions
189     region2fill(j) = diagSt_region(j,n)
190     ENDDO
191     C- if this diagnostics appears in several lists (with same freq)
192     C then add regions from other lists
193     DO l=1,diagSt_nbLists
194     DO k=1,diagSt_nbActv(l)
195     IF ( iSdiag(k,l).EQ.-iSp ) THEN
196     DO j=0,nRegions
197     region2fill(j) = MAX(region2fill(j),diagSt_region(j,l))
198     ENDDO
199     ENDIF
200     ENDDO
201     ENDDO
202    
203     C- Which part of field to add : k = 3rd index,
204     C and do the loop >> do k=kFirst,kLast <<
205     IF (kLev.LE.0) THEN
206     kFirst = 1
207     kLast = nLevs
208     ELSE
209     kFirst = 1
210     kLast = 1
211     ENDIF
212    
213     C- Fill local array with grid-space field after conversion.
214     offset = ib*(npeice-1)
215     Lena = min(ib,numpts-offset)
216     offset = offset+1
217    
218     DO i=1,sNx*sNy
219     gridFrac(i)= 0.
220     ENDDO
221     DO i=1,Lena
222     newindx = indx(i+offset-1)
223     gridFrac(newindx)=gridFrac(newindx)+chfr(i)
224     ENDDO
225    
226     DO k = kFirst,kLast
227     DO i=1,sNx*sNy
228     gridField(i,k)= 0.
229     ENDDO
230     if( check ) then
231     undef = getcon('UNDEF')
232     do i= 1,Lena
233     newindx = indx(i+offset-1)
234     if(gridField(newindx,k).eq.undef
235     . .or.field(i,k).eq.undef)then
236     gridField(newindx,k)= undef
237     else
238     gridField(newindx,k)=gridField(newindx,k)
239     & +field(i,k)*chfr(i)/gridFrac(newindx)
240     endif
241     enddo
242     else
243     do i= 1,Lena
244     newindx = indx(i+offset-1)
245     gridField(newindx,k)=gridField(newindx,k)
246     & +field(i,k)*chfr(i)/gridFrac(newindx)
247     enddo
248     endif
249     ENDDO
250    
251     C- diagnostics is valid and Active: Now do the filling
252     CALL DIAGSTATS_FILL(
253     I gridField, gridFrac, scaleFact, 1, 1,
254     I ndId, iSp, region2fill, kLev, nLevs,
255     I 3, bi, bj, myThid )
256     ENDIF
257     ENDIF
258     ENDDO
259     ENDDO
260    
261 molod 1.1 1000 format(' ',' Warning: Trying to write to diagnostic ',a8,
262     . ' But it is not a valid (or active) name ')
263     RETURN
264     END

  ViewVC Help
Powered by ViewVC 1.1.22