1 |
C $Header: /u/gcmpack/MITgcm/pkg/diagnostics/diag_vegtile_fill.F,v 1.3 2005/02/18 16:20:26 molod 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,getcon |
69 |
|
70 |
C Run through list of active diagnostics to make sure |
71 |
C we are trying to fill a valid diagnostic |
72 |
|
73 |
ndiagnum = 0 |
74 |
ipointer = 0 |
75 |
DO n=1,nlists |
76 |
DO m=1,nActive(n) |
77 |
IF ( chardiag.EQ.flds(m,n) ) THEN |
78 |
ndiagnum = jdiag(m,n) |
79 |
IF (ndiag(ndiagnum).GE.0) ipointer = idiag(ndiagnum) |
80 |
ENDIF |
81 |
ENDDO |
82 |
ENDDO |
83 |
|
84 |
print *,' in diag_vegtile_fill for ',chardiag, |
85 |
. ' ndiagnum ',ndiagnum,' ipointer ',ipointer |
86 |
|
87 |
C If-sequence to see if we are a valid and an active diagnostic |
88 |
|
89 |
IF ( ndiagnum.NE.0 .AND. ipointer.NE.0 ) THEN |
90 |
|
91 |
C Increment the counter for the diagnostic (if we are at bi=bj=myThid=1) |
92 |
_BEGIN_MASTER(myThid) |
93 |
IF((bi.EQ.1).AND.(bj.EQ.1).AND.(ABS(kLev).LE.1) |
94 |
. .AND.(npeice.eq.1)) |
95 |
. ndiag(ndiagnum) = ndiag(ndiagnum) + 1 |
96 |
_END_MASTER(myThid) |
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,I3,A)') 'DIAGNOSTICS_FILL: ', |
134 |
. 'exceed Nb of levels(=',kdiag(ndiagnum),' ) reserved ' |
135 |
CALL PRINT_ERROR( msgBuf , myThid ) |
136 |
WRITE(msgBuf,'(2A,I4,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 |
print *,' level slot in qdiag= ',kd, ' level from input= ',k |
152 |
if( check ) then |
153 |
undef = getcon('UNDEF') |
154 |
do i= 1,Lena |
155 |
jindx = 1 + int((indx(i+offset-1)-1)/sNx) |
156 |
newindx = indx(i+offset-1)+(jindx-1)*2*Olx |
157 |
if(qdiag(newindx,1,kd,bi,bj).eq.undef |
158 |
. .or.field(i,k).eq.undef)then |
159 |
qdiag(newindx,1,kd,bi,bj) = undef |
160 |
else |
161 |
qdiag(newindx,1,kd,bi,bj)=qdiag(newindx,1,kd,bi,bj)+ |
162 |
. field(i,k)*chfr(i) |
163 |
endif |
164 |
enddo |
165 |
else |
166 |
do i= 1,Lena |
167 |
jindx = 1 + int((indx(i+offset-1)-1)/sNx) |
168 |
newindx = indx(i+offset-1)+(jindx-1)*2*Olx |
169 |
qdiag(newindx,1,kd,bi,bj)=qdiag(newindx,1,kd,bi,bj)+ |
170 |
. field(i,k)*chfr(i) |
171 |
enddo |
172 |
endif |
173 |
ENDDO |
174 |
|
175 |
ELSE |
176 |
C IF (myThid.EQ.1) WRITE(6,1000) chardiag |
177 |
ENDIF |
178 |
|
179 |
1000 format(' ',' Warning: Trying to write to diagnostic ',a8, |
180 |
. ' But it is not a valid (or active) name ') |
181 |
RETURN |
182 |
END |