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

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

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


Revision 1.51 - (show annotations) (download)
Sun Jun 12 13:58:33 2011 UTC (12 years, 11 months ago) by jmc
Branch: MAIN
Changes since 1.50: +6 -4 lines
fix previous modif

1 C $Header: /u/gcmpack/MITgcm/pkg/diagnostics/diagnostics_out.F,v 1.50 2011/06/11 23:29:44 jmc Exp $
2 C $Name: $
3
4 #include "DIAG_OPTIONS.h"
5
6 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
7 CBOP 0
8 C !ROUTINE: DIAGNOSTICS_OUT
9
10 C !INTERFACE:
11 SUBROUTINE DIAGNOSTICS_OUT(
12 I listId,
13 I myTime,
14 I myIter,
15 I myThid )
16
17 C !DESCRIPTION:
18 C Write output for diagnostics fields.
19
20 C !USES:
21 IMPLICIT NONE
22 #include "SIZE.h"
23 #include "EEPARAMS.h"
24 #include "PARAMS.h"
25 #include "GRID.h"
26 #include "DIAGNOSTICS_SIZE.h"
27 #include "DIAGNOSTICS.h"
28
29 INTEGER NrMax
30 PARAMETER( NrMax = numLevels )
31
32 C !INPUT PARAMETERS:
33 C listId :: Diagnostics list number being written
34 C myIter :: current iteration number
35 C myTime :: current time of simulation (s)
36 C myThid :: my Thread Id number
37 _RL myTime
38 INTEGER listId, myIter, myThid
39 CEOP
40
41 C !FUNCTIONS:
42 INTEGER ILNBLNK
43 EXTERNAL ILNBLNK
44 #ifdef ALLOW_FIZHI
45 _RL getcon
46 EXTERNAL getcon
47 #endif
48
49 C !LOCAL VARIABLES:
50 C i,j,k :: loop indices
51 C bi,bj :: tile indices
52 C lm :: loop index (averageCycle)
53 C md :: field number in the list "listId".
54 C ndId :: diagnostics Id number (in available diagnostics list)
55 C mate :: counter mate Id number (in available diagnostics list)
56 C ip :: diagnostics pointer to storage array
57 C im :: counter-mate pointer to storage array
58 C nLevOutp :: number of levels to write in output file
59 C
60 C-- COMMON /LOCAL_DIAGNOSTICS_OUT/ local common block (for multi-threaded)
61 C qtmp1 :: thread-shared temporary array (needs to be in common block):
62 C to write a diagnostic field to file, copy it first from (big)
63 C diagnostic storage qdiag into it.
64 COMMON /LOCAL_DIAGNOSTICS_OUT/ qtmp1
65 _RL qtmp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy,NrMax,nSx,nSy)
66
67 INTEGER i, j, k, lm
68 INTEGER bi, bj
69 INTEGER md, ndId, ip, im
70 INTEGER mate, mVec
71 CHARACTER*10 gcode
72 _RL undef
73 _RL tmpLev
74 INTEGER iLen
75 INTEGER nLevOutp
76
77 INTEGER ioUnit
78 CHARACTER*(MAX_LEN_FNAM) fn
79 CHARACTER*(MAX_LEN_MBUF) suff
80 CHARACTER*(MAX_LEN_MBUF) msgBuf
81 INTEGER prec, nRec, nTimRec
82 _RL timeRec(2)
83 #ifdef ALLOW_MDSIO
84 LOGICAL glf
85 #endif
86 #ifdef ALLOW_MNC
87 INTEGER ll, llMx, jj, jjMx
88 CHARACTER*(MAX_LEN_FNAM) diag_mnc_bn
89 LOGICAL useMissingValue
90 REAL*8 misValLoc
91 #endif /* ALLOW_MNC */
92
93 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
94
95 C--- set file properties
96 ioUnit= standardMessageUnit
97 undef = UNSET_RL
98 #ifdef ALLOW_FIZHI
99 IF ( useFIZHI ) undef = getcon('UNDEF')
100 #endif
101 WRITE(suff,'(I10.10)') myIter
102 iLen = ILNBLNK(fnames(listId))
103 WRITE( fn, '(A,A,A)' ) fnames(listId)(1:iLen),'.',suff(1:10)
104 C- for now, if integrate vertically, output field has just 1 level:
105 nLevOutp = nlevels(listId)
106 IF ( fflags(listId)(2:2).EQ.'I' ) nLevOutp = 1
107
108 C-- Set time information:
109 IF ( freq(listId).LT.0. ) THEN
110 C- Snap-shot: store a unique time (which is consistent with State-Var timing)
111 nTimRec = 1
112 timeRec(1) = myTime
113 ELSE
114 C- Time-average: store the 2 edges of the time-averaging interval.
115 C this time is consitent with intermediate Var (i.e., non-state, e.g, flux,
116 C tendencies) timing. For State-Var, this is shifted by + halt time-step.
117 nTimRec = 2
118
119 C- end of time-averaging interval:
120 timeRec(2) = myTime
121
122 C- begining of time-averaging interval:
123 c timeRec(1) = myTime - freq(listId)
124 C a) find the time of the previous multiple of output freq:
125 timeRec(1) = myTime-deltaTClock*0.5 _d 0
126 timeRec(1) = (timeRec(1)-phase(listId))/freq(listId)
127 i = INT( timeRec(1) )
128 IF ( timeRec(1).LT.0. ) THEN
129 tmpLev = FLOAT(i)
130 IF ( timeRec(1).NE.tmpLev ) i = i - 1
131 ENDIF
132 timeRec(1) = phase(listId) + freq(listId)*FLOAT(i)
133 c if ( listId.eq.2 ) write(0,*) 'f',i,timeRec(1)/deltaTClock
134 timeRec(1) = MAX( timeRec(1), startTime )
135
136 C b) round off to nearest multiple of time-step:
137 timeRec(1) = (timeRec(1)-baseTime)/deltaTClock
138 i = NINT( timeRec(1) )
139 C if just half way, NINT will return the next time-step: correct this
140 tmpLev = FLOAT(i) - 0.5 _d 0
141 IF ( timeRec(1).EQ.tmpLev ) i = i - 1
142 timeRec(1) = baseTime + deltaTClock*FLOAT(i)
143 c if ( listId.eq.2 ) write(0,*) i,timeRec(1)/deltaTClock
144 ENDIF
145 C-- Convert time to iteration number (debug)
146 c DO i=1,nTimRec
147 c timeRec(i) = timeRec(i)/deltaTClock
148 c ENDDO
149
150 #ifdef ALLOW_MNC
151 C-- this is a trick to reverse the order of the loops on md (= field)
152 C and lm (= averagePeriod): binary output: lm loop inside md loop ;
153 C mnc ouput: md loop inside lm loop.
154 IF (useMNC .AND. diag_mnc) THEN
155 jjMx = averageCycle(listId)
156 llMx = 1
157 ELSE
158 jjMx = 1
159 llMx = averageCycle(listId)
160 ENDIF
161 DO jj=1,jjMx
162
163 IF (useMNC .AND. diag_mnc) THEN
164 misValLoc = undef
165 IF ( misvalFlt(listId).NE.UNSET_RL )
166 & misValLoc = misvalFlt(listId)
167 CALL DIAGNOSTICS_MNC_SET(
168 I nLevOutp, listId, jj,
169 O diag_mnc_bn, useMissingValue,
170 I misValLoc, myTime, myIter, myThid )
171 ENDIF
172 #endif /* ALLOW_MNC */
173
174 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
175
176 DO md = 1,nfields(listId)
177 ndId = jdiag(md,listId)
178 gcode = gdiag(ndId)(1:10)
179 mate = 0
180 mVec = 0
181 IF ( gcode(5:5).EQ.'C' ) THEN
182 C- Check for Mate of a Counter Diagnostic
183 mate = hdiag(ndId)
184 ELSEIF ( gcode(1:1).EQ.'U' .OR. gcode(1:1).EQ.'V' ) THEN
185 C- Check for Mate of a Vector Diagnostic
186 mVec = hdiag(ndId)
187 ENDIF
188 IF ( idiag(md,listId).NE.0 .AND. gcode(5:5).NE.'D' ) THEN
189 C-- Start processing 1 Fld :
190 #ifdef ALLOW_MNC
191 DO ll=1,llMx
192 lm = jj+ll-1
193 #else
194 DO lm=1,averageCycle(listId)
195 #endif
196
197 ip = ABS(idiag(md,listId)) + kdiag(ndId)*(lm-1)
198 im = mdiag(md,listId)
199 IF (mate.GT.0) im = im + kdiag(mate)*(lm-1)
200 IF (mVec.GT.0) im = im + kdiag(mVec)*(lm-1)
201
202 IF ( ndiag(ip,1,1).EQ.0 ) THEN
203 C- Empty diagnostics case :
204
205 _BEGIN_MASTER( myThid )
206 WRITE(msgBuf,'(A,I10)')
207 & '- WARNING - from DIAGNOSTICS_OUT at iter=', myIter
208 CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
209 & SQUEEZE_RIGHT, myThid)
210 WRITE(msgBuf,'(A,I6,3A,I4,2A)')
211 & '- WARNING - diag.#',ndId, ' : ',flds(md,listId),
212 & ' (#',md,' ) in outp.Stream: ',fnames(listId)
213 CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
214 & SQUEEZE_RIGHT, myThid)
215 IF ( averageCycle(listId).GT.1 ) THEN
216 WRITE(msgBuf,'(A,2(I3,A))')
217 & '- WARNING - has not been filled (ndiag(lm=',lm,')=',
218 & ndiag(ip,1,1), ' )'
219 ELSE
220 WRITE(msgBuf,'(A,2(I3,A))')
221 & '- WARNING - has not been filled (ndiag=',
222 & ndiag(ip,1,1), ' )'
223 ENDIF
224 CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
225 & SQUEEZE_RIGHT, myThid)
226 WRITE(msgBuf,'(A)')
227 & 'WARNING DIAGNOSTICS_OUT => write ZEROS instead'
228 CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
229 & SQUEEZE_RIGHT, myThid)
230 _END_MASTER( myThid )
231 DO bj = myByLo(myThid), myByHi(myThid)
232 DO bi = myBxLo(myThid), myBxHi(myThid)
233 DO k = 1,nLevOutp
234 DO j = 1-OLy,sNy+OLy
235 DO i = 1-OLx,sNx+OLx
236 qtmp1(i,j,k,bi,bj) = 0. _d 0
237 ENDDO
238 ENDDO
239 ENDDO
240 ENDDO
241 ENDDO
242
243 ELSE
244 C- diagnostics is not empty :
245
246 IF ( debugLevel.GE.debLevB .AND. myThid.EQ.1 ) THEN
247 WRITE(ioUnit,'(A,I6,3A,I8,2A)')
248 & ' Computing Diagnostic # ', ndId, ' ', cdiag(ndId),
249 & ' Counter:',ndiag(ip,1,1),' Parms: ',gdiag(ndId)
250 IF ( mate.GT.0 ) THEN
251 WRITE(ioUnit,'(3A,I6,2A)')
252 & ' use Counter Mate for ', cdiag(ndId),
253 & ' Diagnostic # ',mate, ' ', cdiag(mate)
254 ELSEIF ( mVec.GT.0 ) THEN
255 IF ( im.GT.0 .AND. ndiag(MAX(1,im),1,1).GT.0 ) THEN
256 WRITE(ioUnit,'(3A,I6,3A)')
257 & ' Vector Mate for ', cdiag(ndId),
258 & ' Diagnostic # ',mVec, ' ', cdiag(mVec),
259 & ' exists '
260 ELSE
261 WRITE(ioUnit,'(3A,I6,3A)')
262 & ' Vector Mate for ', cdiag(ndId),
263 & ' Diagnostic # ',mVec, ' ', cdiag(mVec),
264 & ' not enabled'
265 ENDIF
266 ENDIF
267 ENDIF
268
269 IF ( fflags(listId)(2:2).NE.' ' ) THEN
270 C- get all the levels (for vertical post-processing)
271 DO bj = myByLo(myThid), myByHi(myThid)
272 DO bi = myBxLo(myThid), myBxHi(myThid)
273 DO k = 1,kdiag(ndId)
274 tmpLev = k
275 CALL GETDIAG(
276 I tmpLev,undef,
277 O qtmp1(1-OLx,1-OLy,k,bi,bj),
278 I ndId,mate,ip,im,bi,bj,myThid)
279 ENDDO
280 ENDDO
281 ENDDO
282 ELSE
283 C- get only selected levels:
284 DO bj = myByLo(myThid), myByHi(myThid)
285 DO bi = myBxLo(myThid), myBxHi(myThid)
286 DO k = 1,nlevels(listId)
287 CALL GETDIAG(
288 I levs(k,listId),undef,
289 O qtmp1(1-OLx,1-OLy,k,bi,bj),
290 I ndId,mate,ip,im,bi,bj,myThid)
291 ENDDO
292 ENDDO
293 ENDDO
294 ENDIF
295
296 C-----------------------------------------------------------------------
297 C-- Apply specific post-processing (e.g., interpolate) before output
298 C-----------------------------------------------------------------------
299 IF ( fflags(listId)(2:2).EQ.'P' ) THEN
300 C- Do vertical interpolation:
301 IF ( fluidIsAir ) THEN
302 C jmc: for now, this can only work in an atmospheric set-up (fluidIsAir);
303 CALL DIAGNOSTICS_INTERP_VERT(
304 I listId, md, ndId, ip, im, lm,
305 U qtmp1,
306 I undef, myTime, myIter, myThid )
307 ELSE
308 WRITE(msgBuf,'(2A)') 'DIAGNOSTICS_OUT: ',
309 & 'INTERP_VERT not allowed in this config'
310 CALL PRINT_ERROR( msgBuf , myThid )
311 STOP 'ABNORMAL END: S/R DIAGNOSTICS_OUT'
312 ENDIF
313 ENDIF
314 IF ( fflags(listId)(2:2).EQ.'I' ) THEN
315 C- Integrate vertically: for now, output field has just 1 level:
316 CALL DIAGNOSTICS_SUM_LEVELS(
317 I listId, md, ndId, ip, im, lm,
318 U qtmp1,
319 I undef, myTime, myIter, myThid )
320 ENDIF
321
322 C-- End of empty diag / not-empty diag block
323 ENDIF
324
325 C-- Ready to write field "md", element "lm" in averageCycle(listId)
326
327 C- write to binary file, using MDSIO pkg:
328 IF ( diag_mdsio ) THEN
329 nRec = lm + (md-1)*averageCycle(listId)
330 C default precision for output files
331 prec = writeBinaryPrec
332 C fFlag(1)=R(or D): force it to be 32-bit(or 64) precision
333 IF ( fflags(listId)(1:1).EQ.'R' ) prec = precFloat32
334 IF ( fflags(listId)(1:1).EQ.'D' ) prec = precFloat64
335 C a hack not to write meta files now: pass -nRec < 0 to MDS_WRITE S/R
336 CALL WRITE_REC_LEV_RL(
337 I fn, prec,
338 I NrMax, 1, nLevOutp,
339 I qtmp1, -nRec, myIter, myThid )
340 ENDIF
341
342 #ifdef ALLOW_MNC
343 IF (useMNC .AND. diag_mnc) THEN
344 CALL DIAGNOSTICS_MNC_OUT(
345 I NrMax, nLevOutp, listId, ndId,
346 I diag_mnc_bn,
347 I useMissingValue, misValLoc,
348 I qtmp1,
349 I myTime, myIter, myThid )
350 ENDIF
351 #endif /* ALLOW_MNC */
352
353 C-- end loop on lm (or ll if ALLOW_MNC) counter
354 ENDDO
355 C-- end of Processing Fld # md
356 ENDIF
357 ENDDO
358
359 #ifdef ALLOW_MNC
360 C-- end loop on jj counter
361 ENDDO
362 #endif
363
364 #ifdef ALLOW_MDSIO
365 IF (diag_mdsio) THEN
366 C- Note: temporary: since it is a pain to add more arguments to
367 C all MDSIO S/R, uses instead this specific S/R to write only
368 C meta files but with more informations in it.
369 glf = globalFiles
370 nRec = nfields(listId)*averageCycle(listId)
371 CALL MDS_WR_METAFILES(fn, prec, glf, .FALSE.,
372 & 0, 0, nLevOutp, ' ',
373 & nfields(listId), flds(1,listId), nTimRec, timeRec,
374 & nRec, myIter, myThid)
375 ENDIF
376 #endif /* ALLOW_MDSIO */
377
378 RETURN
379 END
380
381 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|

  ViewVC Help
Powered by ViewVC 1.1.22