1 |
C $Header: /u/gcmpack/MITgcm/pkg/diagnostics/diagstats_set_regions.F,v 1.3 2006/07/31 16:26:32 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "DIAG_OPTIONS.h" |
5 |
|
6 |
CBOP |
7 |
C !ROUTINE: DIAGSTATS_SET_REGIONS |
8 |
C !INTERFACE: |
9 |
SUBROUTINE DIAGSTATS_SET_REGIONS( myThid ) |
10 |
|
11 |
C !DESCRIPTION: \bv |
12 |
C *================================================================== |
13 |
C | S/R DIAGSTATS_SET_REGIONS |
14 |
C | o set region-mask for regional statistics diagnostics |
15 |
C *================================================================== |
16 |
C \ev |
17 |
|
18 |
C !USES: |
19 |
IMPLICIT NONE |
20 |
|
21 |
C == Global variables === |
22 |
#include "EEPARAMS.h" |
23 |
#include "SIZE.h" |
24 |
#include "PARAMS.h" |
25 |
#include "DIAGNOSTICS_SIZE.h" |
26 |
#include "DIAGSTATS_REGIONS.h" |
27 |
|
28 |
C !INPUT/OUTPUT PARAMETERS: |
29 |
C == Routine arguments == |
30 |
C myThid - Thread number for this instance of the routine. |
31 |
INTEGER myThid |
32 |
CEOP |
33 |
|
34 |
C !LOCAL VARIABLES: |
35 |
C == Local variables == |
36 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
37 |
INTEGER iLen |
38 |
INTEGER i, j |
39 |
INTEGER bi, bj |
40 |
#ifdef DIAGSTATS_REGION_MASK |
41 |
CHARACTER*(MAX_LEN_MBUF) tmpBuf |
42 |
INTEGER ioUnit |
43 |
INTEGER k, nbReg |
44 |
_RS tmpVar(1-OLx:sNx+Olx,1-Oly:sNy+Oly,nSx,nSy) |
45 |
COMMON / SET_REGIONS_LOCAL / tmpVar |
46 |
#else |
47 |
LOGICAL flag |
48 |
#endif |
49 |
INTEGER ILNBLNK |
50 |
EXTERNAL ILNBLNK |
51 |
|
52 |
#ifdef DIAGSTATS_REGION_MASK |
53 |
|
54 |
C-- Initialize region-mask array to zero: |
55 |
DO bj = myByLo(myThid), myByHi(myThid) |
56 |
DO bi = myBxLo(myThid), myBxHi(myThid) |
57 |
DO k=1,sizRegMsk |
58 |
DO j=1-Oly,sNy+Oly |
59 |
DO i=1-Olx,sNx+Olx |
60 |
diagSt_regMask(i,j,k,bi,bj) = 0. |
61 |
ENDDO |
62 |
ENDDO |
63 |
ENDDO |
64 |
ENDDO |
65 |
ENDDO |
66 |
ioUnit = -1 |
67 |
|
68 |
_BEGIN_MASTER( myThid ) |
69 |
ioUnit = standardMessageUnit |
70 |
C-- Check size & parameter first: |
71 |
IF ( (diagSt_regMaskFile.NE.' ' .AND. nSetRegMskFile.EQ.0) |
72 |
& .OR.(diagSt_regMaskFile.EQ.' ' .AND. nSetRegMskFile.GT.0) ) THEN |
73 |
WRITE(msgBuf,'(2A)') 'DIAGSTATS_SET_REGIONS:', |
74 |
& ' regMaskFile and nSetRegMskFile Not consistent' |
75 |
CALL PRINT_ERROR( msgBuf , myThid ) |
76 |
STOP 'ABNORMAL END: S/R DIAGSTATS_SET_REGIONS' |
77 |
ENDIF |
78 |
IF ( nSetRegMskFile.GT.sizRegMsk ) THEN |
79 |
WRITE(msgBuf,'(2A,I4,A,I4)') 'DIAGSTATS_SET_REGIONS:', |
80 |
& ' regMaskFile set-index number=', nSetRegMskFile, |
81 |
& ' exceeds sizRegMsk=', sizRegMsk |
82 |
CALL PRINT_ERROR( msgBuf , myThid ) |
83 |
STOP 'ABNORMAL END: S/R DIAGSTATS_SET_REGIONS' |
84 |
ENDIF |
85 |
_END_MASTER( myThid ) |
86 |
|
87 |
C-- Read region-mask from file |
88 |
IF ( diagSt_regMaskFile .NE. ' ' ) THEN |
89 |
_BARRIER |
90 |
iLen = ILNBLNK(diagSt_regMaskFile) |
91 |
IF (ioUnit.GE.0 ) WRITE(ioUnit,'(2A)') |
92 |
& ' DIAGSTATS_SET_REGIONS: start reading region-mask file: ', |
93 |
& diagSt_regMaskFile(1:iLen) |
94 |
DO k=1,nSetRegMskFile |
95 |
C _BEGIN_MASTER( myThid ) |
96 |
IF (ioUnit.GE.0 ) WRITE(ioUnit,'(A,I3)') |
97 |
& ' DIAGSTATS_SET_REGIONS: reading set k=',k |
98 |
CALL READ_REC_XY_RS( diagSt_regMaskFile, tmpVar, k, |
99 |
& nIter0, myThid ) |
100 |
IF (ioUnit.GE.0 ) WRITE(ioUnit,'(A,I3,A)') |
101 |
& ' DIAGSTATS_SET_REGIONS: set k=',k,' <= done' |
102 |
C _END_MASTER( myThid ) |
103 |
_EXCH_XY_RS( tmpVar, myThid ) |
104 |
DO bj = myByLo(myThid), myByHi(myThid) |
105 |
DO bi = myBxLo(myThid), myBxHi(myThid) |
106 |
DO j=1-Oly,sNy+Oly |
107 |
DO i=1-Olx,sNx+Olx |
108 |
diagSt_regMask(i,j,k,bi,bj) = tmpVar(i,j,bi,bj) |
109 |
ENDDO |
110 |
ENDDO |
111 |
ENDDO |
112 |
ENDDO |
113 |
C- end of k loop |
114 |
ENDDO |
115 |
ENDIF |
116 |
|
117 |
C-- Other way to define regions (e.g., latitude bands): |
118 |
C set corresponding set-index of the region-mask array, |
119 |
C starting from nSetRegMskFile+1 up to nSetRegMask |
120 |
C note: for now, empty ! |
121 |
_BEGIN_MASTER( myThid ) |
122 |
nSetRegMask = nSetRegMskFile |
123 |
_END_MASTER( myThid ) |
124 |
|
125 |
C-- Region Identificator arrays |
126 |
C for now, directly filled when reading data.diagnostics |
127 |
|
128 |
_BEGIN_MASTER( myThid ) |
129 |
C-- Check defined regions |
130 |
nbReg = 0 |
131 |
DO j=1,nRegions |
132 |
C- check for valid region-mask index: |
133 |
IF ( diagSt_kRegMsk(j).LT.0 .OR. |
134 |
& diagSt_kRegMsk(j).GT.sizRegMsk ) THEN |
135 |
WRITE(msgBuf,'(2A,I3,A,I4)') 'DIAGSTATS_SET_REGIONS: ', |
136 |
& '(region',j,') invalid region-mask index :',diagSt_kRegMsk(j) |
137 |
CALL PRINT_ERROR( msgBuf , myThid ) |
138 |
STOP 'ABNORMAL END: S/R DIAGSTATS_SET_REGIONS' |
139 |
C- check for unset region-mask: |
140 |
ELSEIF ( diagSt_kRegMsk(j).GT.nSetRegMask ) THEN |
141 |
WRITE(msgBuf,'(2A,I3,A,I3,A)') 'DIAGSTATS_SET_REGIONS: ', |
142 |
& 'region',j,' , kRegMsk=', diagSt_kRegMsk(j), |
143 |
& ' <- has not been set !' |
144 |
CALL PRINT_ERROR( msgBuf , myThid ) |
145 |
STOP 'ABNORMAL END: S/R DIAGSTATS_SET_REGIONS' |
146 |
ELSEIF ( diagSt_kRegMsk(j).NE.0 ) THEN |
147 |
nbReg = nbReg + 1 |
148 |
C- check for empty region: build temp mask 0 / 1 : |
149 |
c k = diagSt_kRegMsk(j) |
150 |
c IF ( diagSt_regMask(i,j,k,bi,bj).EQ.diagSt_vRegMsk(j) ) THEN |
151 |
c tmpVar(i,j,bi,bj) = 1. |
152 |
c ELSE |
153 |
c tmpVar(i,j,bi,bj) = 0. |
154 |
c ELSE |
155 |
C- print region mask: |
156 |
c IF ( debugLevel.GE.debLevA ) THEN |
157 |
c WRITE(msgBuf,'(A,I3,A)') 'DIAGSTAT Region',j,' mask:' |
158 |
c iLen = ILNBLNK(msgBuf) |
159 |
c CALL PLOT_FIELD_XYRS( tmpVar, msgBuf(1:iLen), -1, myThid ) |
160 |
c ENDIF |
161 |
ENDIF |
162 |
ENDDO |
163 |
|
164 |
C- Global statistics (region # 0) <- done in diagnostics_readparams |
165 |
c diagSt_kRegMsk(0) = 1 |
166 |
c diagSt_vRegMsk(0) = 0. |
167 |
|
168 |
|
169 |
WRITE(msgBuf,'(A,I4,A)') 'DIAGSTATS_SET_REGIONS: define', |
170 |
& nbReg,' regions:' |
171 |
iLen = ILNBLNK(msgBuf) |
172 |
DO j=1,nRegions |
173 |
IF ( diagSt_kRegMsk(j).NE.0 ) THEN |
174 |
iLen = MIN( iLen, MAX_LEN_MBUF -3 ) |
175 |
tmpBuf(1:iLen) = msgBuf(1:iLen) |
176 |
WRITE(msgBuf,'(A,I3)') tmpBuf(1:iLen),j |
177 |
iLen = iLen+3 |
178 |
ENDIF |
179 |
ENDDO |
180 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
181 |
& SQUEEZE_RIGHT , myThid) |
182 |
WRITE(msgBuf,'(2A)') |
183 |
& '------------------------------------------------------------' |
184 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
185 |
& SQUEEZE_RIGHT , myThid) |
186 |
|
187 |
_END_MASTER( myThid ) |
188 |
|
189 |
#else /* DIAGSTATS_REGION_MASK */ |
190 |
|
191 |
C-- Initialize region-mask array to zero: |
192 |
DO bj = myByLo(myThid), myByHi(myThid) |
193 |
DO bi = myBxLo(myThid), myBxHi(myThid) |
194 |
c DO j=1-Oly,sNy+Oly |
195 |
c DO i=1-Olx,sNx+Olx |
196 |
DO j=1-Oly,1-Oly |
197 |
DO i=1-Olx,1-Olx |
198 |
diagSt_regMask(i,j,1,bi,bj) = 0. |
199 |
ENDDO |
200 |
ENDDO |
201 |
ENDDO |
202 |
ENDDO |
203 |
|
204 |
_BEGIN_MASTER( myThid ) |
205 |
C-- Check parameter consitency: |
206 |
flag = .FALSE. |
207 |
DO j=1,nRegions |
208 |
flag = flag .OR. diagSt_kRegMsk(j).NE.0 |
209 |
& .OR. diagSt_vRegMsk(j).NE.0. |
210 |
ENDDO |
211 |
iLen = ILNBLNK(diagSt_regMaskFile) |
212 |
IF ( flag .OR. iLen.GE.1 .OR. nSetRegMskFile.NE.0 ) THEN |
213 |
WRITE(msgBuf,'(2A)') 'DIAGSTATS_SET_REGIONS:', |
214 |
& ' #define DIAGSTATS_REGION_MASK missing in DIAG_OPTIONS.h' |
215 |
CALL PRINT_ERROR( msgBuf , myThid ) |
216 |
STOP 'ABNORMAL END: S/R DIAGSTATS_SET_REGIONS' |
217 |
ENDIF |
218 |
|
219 |
WRITE(msgBuf,'(A)') 'DIAGSTATS_SET_REGIONS: define no region' |
220 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
221 |
& SQUEEZE_RIGHT , myThid) |
222 |
WRITE(msgBuf,'(2A)') |
223 |
& '------------------------------------------------------------' |
224 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
225 |
& SQUEEZE_RIGHT , myThid) |
226 |
|
227 |
_END_MASTER( myThid ) |
228 |
|
229 |
#endif /* DIAGSTATS_REGION_MASK */ |
230 |
|
231 |
RETURN |
232 |
END |