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

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

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


Revision 1.45 - (hide annotations) (download)
Thu Jan 7 23:48:01 2010 UTC (14 years, 4 months ago) by jmc
Branch: MAIN
Changes since 1.44: +2 -1 lines
fix previous modif for negative time (if baseTime << 0)

1 jmc 1.45 C $Header: /u/gcmpack/MITgcm/pkg/diagnostics/diagnostics_out.F,v 1.44 2010/01/07 01:09:40 jmc Exp $
2 jmc 1.1 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 jmc 1.15 I listId,
13 jmc 1.1 I myIter,
14 edhill 1.14 I myTime,
15 jmc 1.1 I myThid )
16    
17     C !DESCRIPTION:
18     C Write output for diagnostics fields.
19 jmc 1.15
20 jmc 1.1 C !USES:
21 jmc 1.3 IMPLICIT NONE
22 jmc 1.1 #include "SIZE.h"
23     #include "EEPARAMS.h"
24     #include "PARAMS.h"
25 edhill 1.7 #include "GRID.h"
26 jmc 1.3 #include "DIAGNOSTICS_SIZE.h"
27     #include "DIAGNOSTICS.h"
28 jmc 1.1
29 jmc 1.30 INTEGER NrMax
30 jmc 1.33 PARAMETER( NrMax = numLevels )
31 jmc 1.1
32     C !INPUT PARAMETERS:
33 jmc 1.15 C listId :: Diagnostics list number being written
34 jmc 1.3 C myIter :: current iteration number
35 jmc 1.15 C myTime :: current time of simulation (s)
36 jmc 1.3 C myThid :: my Thread Id number
37 edhill 1.14 _RL myTime
38 jmc 1.15 INTEGER listId, myIter, myThid
39 jmc 1.1 CEOP
40    
41 jmc 1.40 C !FUNCTIONS:
42     INTEGER ILNBLNK
43     EXTERNAL ILNBLNK
44     #ifdef ALLOW_FIZHI
45     _RL getcon
46     EXTERNAL getcon
47     #endif
48    
49 jmc 1.3 C !LOCAL VARIABLES:
50 jmc 1.15 C i,j,k :: loop indices
51 jmc 1.29 C lm :: loop index (averageCycle)
52 jmc 1.15 C md :: field number in the list "listId".
53     C ndId :: diagnostics Id number (in available diagnostics list)
54     C mate :: counter mate Id number (in available diagnostics list)
55     C ip :: diagnostics pointer to storage array
56     C im :: counter-mate pointer to storage array
57 jmc 1.32 C
58     C-- COMMON /LOCAL_DIAGNOSTICS_OUT/ local common block (for multi-threaded)
59     C qtmp1 :: thread-shared temporary array (needs to be in common block):
60     C to write a diagnostic field to file, copy it first from (big)
61     C diagnostic storage qdiag into it.
62     COMMON /LOCAL_DIAGNOSTICS_OUT/ qtmp1
63     _RL qtmp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy,NrMax,nSx,nSy)
64    
65 jmc 1.43 INTEGER i, j, k, lm
66 jmc 1.15 INTEGER bi, bj
67     INTEGER md, ndId, ip, im
68     INTEGER mate, mVec
69 jmc 1.35 CHARACTER*10 gcode
70 jmc 1.40 _RL undef
71 jmc 1.30 _RL tmpLev
72 jmc 1.3 INTEGER ilen
73 jmc 1.1
74 jmc 1.6 INTEGER ioUnit
75 jmc 1.11 CHARACTER*(MAX_LEN_FNAM) fn
76 jmc 1.1 CHARACTER*(MAX_LEN_MBUF) suff
77 jmc 1.3 CHARACTER*(MAX_LEN_MBUF) msgBuf
78 jmc 1.44 INTEGER prec, nRec, nTimRec
79     _RL timeRec(2)
80 jmc 1.29 #ifdef ALLOW_MDSIO
81 jmc 1.3 LOGICAL glf
82 jmc 1.29 #endif
83 jmc 1.1 #ifdef ALLOW_MNC
84 jmc 1.41 INTEGER ll, llMx, jj, jjMx
85 jmc 1.43 INTEGER ii, klev
86 jmc 1.1 CHARACTER*(MAX_LEN_FNAM) diag_mnc_bn
87 jmc 1.3 INTEGER CW_DIMS, NLEN
88     PARAMETER ( CW_DIMS = 10 )
89     PARAMETER ( NLEN = 80 )
90     INTEGER dim(CW_DIMS), ib(CW_DIMS), ie(CW_DIMS)
91     CHARACTER*(NLEN) dn(CW_DIMS)
92 edhill 1.7 CHARACTER*(NLEN) d_cw_name
93 jmc 1.3 CHARACTER*(NLEN) dn_blnk
94 jmc 1.20 #ifdef DIAG_MNC_COORD_NEEDSWORK
95     CHARACTER*(5) ctmp
96 jmc 1.30 _RS ztmp(NrMax)
97 jmc 1.20 #endif
98 mlosch 1.39 LOGICAL useMissingValue, useMisValForThisDiag
99 mlosch 1.37 REAL*8 misvalLoc
100     REAL*8 misval_r8(2)
101     REAL*4 misval_r4(2)
102     INTEGER misvalIntLoc, misval_int(2)
103 jmc 1.1 #endif /* ALLOW_MNC */
104    
105 jmc 1.3 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
106    
107 jmc 1.44 C--- set file properties
108 jmc 1.6 ioUnit= standardMessageUnit
109 jmc 1.40 undef = UNSET_RL
110     #ifdef ALLOW_FIZHI
111     c IF ( useFIZHI ) undef = getcon('UNDEF')
112 jmc 1.1 undef = getcon('UNDEF')
113 jmc 1.40 #endif
114 jmc 1.1 WRITE(suff,'(I10.10)') myIter
115 jmc 1.15 ilen = ILNBLNK(fnames(listId))
116     WRITE( fn, '(A,A,A)' ) fnames(listId)(1:ilen),'.',suff(1:10)
117 jmc 1.1
118 jmc 1.44 C-- Set time information:
119     IF ( freq(listId).LT.0. ) THEN
120     C- Snap-shot: store a unique time (which is consistent with State-Var timing)
121     nTimRec = 1
122     timeRec(1) = myTime
123     ELSE
124     C- Time-average: store the 2 edges of the time-averaging interval.
125     C this time is consitent with intermediate Var (i.e., non-state, e.g, flux,
126     C tendencies) timing. For State-Var, this is shifted by + halt time-step.
127     nTimRec = 2
128    
129     C- end of time-averaging interval:
130     timeRec(2) = myTime
131    
132     C- begining of time-averaging interval:
133     c timeRec(1) = myTime - freq(listId)
134     C a) find the time of the previous multiple of output freq:
135     timeRec(1) = myTime-deltaTClock*0.5 _d 0
136     timeRec(1) = (timeRec(1)-phase(listId))/freq(listId)
137     i = INT( timeRec(1) )
138 jmc 1.45 IF ( timeRec(1).LT.0. ) i = i - 1
139 jmc 1.44 timeRec(1) = phase(listId) + freq(listId)*FLOAT(i)
140     c if ( listId.eq.2 ) write(0,*) 'f',i,timeRec(1)/deltaTClock
141     timeRec(1) = MAX( timeRec(1), startTime )
142    
143     C b) round off to nearest multiple of time-step:
144     timeRec(1) = (timeRec(1)-baseTime)/deltaTClock
145     i = NINT( timeRec(1) )
146     C if just half way, NINT will return the next time-step: correct this
147     tmpLev = FLOAT(i) - 0.5 _d 0
148     IF ( timeRec(1).EQ.tmpLev ) i = i - 1
149     timeRec(1) = baseTime + deltaTClock*FLOAT(i)
150     c if ( listId.eq.2 ) write(0,*) i,timeRec(1)/deltaTClock
151     ENDIF
152    
153 jmc 1.1 #ifdef ALLOW_MNC
154 jmc 1.41 C-- this is a trick to reverse the order of the loops on md (= field)
155     C and lm (= averagePeriod): binary output: lm loop inside md loop ;
156     C mnc ouput: md loop inside lm loop.
157 jmc 1.1 IF (useMNC .AND. diag_mnc) THEN
158 jmc 1.41 jjMx = averageCycle(listId)
159     llMx = 1
160     ELSE
161     jjMx = 1
162     llMx = averageCycle(listId)
163     ENDIF
164     DO jj=1,jjMx
165    
166     IF (useMNC .AND. diag_mnc) THEN
167 mlosch 1.39 C Handle missing value attribute (land points)
168 jmc 1.41 useMissingValue = .FALSE.
169 mlosch 1.38 #ifdef DIAGNOSTICS_MISSING_VALUE
170 jmc 1.41 useMissingValue = .TRUE.
171 mlosch 1.39 #endif /* DIAGNOSTICS_MISSING_VALUE */
172 jmc 1.41 IF ( misvalFlt(listId) .NE. UNSET_RL ) THEN
173     misvalLoc = misvalFlt(listId)
174     ELSE
175     misvalLoc = undef
176     ENDIF
177 mlosch 1.38 C Defaults to UNSET_I
178 jmc 1.41 misvalIntLoc = misvalInt(listId)
179     DO ii=1,2
180     C misval_r4(ii) = UNSET_FLOAT4
181     C misval_r8(ii) = UNSET_FLOAT8
182     misval_r4(ii) = misvalLoc
183     misval_r8(ii) = misvalLoc
184     misval_int(ii) = UNSET_I
185     ENDDO
186     DO i = 1,MAX_LEN_FNAM
187     diag_mnc_bn(i:i) = ' '
188     ENDDO
189     DO i = 1,NLEN
190     dn_blnk(i:i) = ' '
191     ENDDO
192     WRITE( diag_mnc_bn, '(A)' ) fnames(listId)(1:ilen)
193 jmc 1.1
194     C Update the record dimension by writing the iteration number
195 jmc 1.41 klev = myIter + jj - jjMx
196     tmpLev = myTime + deltaTClock*(jj -jjMx)
197     CALL MNC_CW_SET_UDIM(diag_mnc_bn, -1, myThid)
198     CALL MNC_CW_RL_W_S('D',diag_mnc_bn,0,0,'T',tmpLev,myThid)
199     CALL MNC_CW_SET_UDIM(diag_mnc_bn, 0, myThid)
200     CALL MNC_CW_I_W_S('I',diag_mnc_bn,0,0,'iter',klev,myThid)
201 edhill 1.21
202     C NOTE: at some point it would be a good idea to add a time_bounds
203     C variable that has dimension (2,T) and clearly denotes the
204     C beginning and ending times for each diagnostics period
205 jmc 1.1
206 jmc 1.41 dn(1)(1:NLEN) = dn_blnk(1:NLEN)
207     WRITE(dn(1),'(a,i6.6)') 'Zmd', nlevels(listId)
208     dim(1) = nlevels(listId)
209     ib(1) = 1
210     ie(1) = nlevels(listId)
211    
212     CALL MNC_CW_ADD_GNAME('diag_levels', 1,
213     & dim, dn, ib, ie, myThid)
214     CALL MNC_CW_ADD_VNAME('diag_levels', 'diag_levels',
215     & 0,0, myThid)
216     CALL MNC_CW_ADD_VATTR_TEXT('diag_levels','description',
217     & 'Idicies of vertical levels within the source arrays',
218     & myThid)
219 mlosch 1.39 C suppress the missing value attribute (iflag = 0)
220 jmc 1.41 IF (useMissingValue)
221 mlosch 1.39 & CALL MNC_CW_VATTR_MISSING('diag_levels', 0,
222 jmc 1.40 I misval_r8, misval_r4, misval_int,
223 mlosch 1.38 I myThid )
224 jmc 1.29
225 jmc 1.41 CALL MNC_CW_RL_W('D',diag_mnc_bn,0,0,
226     & 'diag_levels', levs(1,listId), myThid)
227 jmc 1.1
228 jmc 1.41 CALL MNC_CW_DEL_VNAME('diag_levels', myThid)
229     CALL MNC_CW_DEL_GNAME('diag_levels', myThid)
230 edhill 1.7
231 edhill 1.16 #ifdef DIAG_MNC_COORD_NEEDSWORK
232     C This part has been placed in an #ifdef because, as its currently
233     C written, it will only work with variables defined on a dynamics
234     C grid. As we start using diagnostics for physics grids, ice
235     C levels, land levels, etc. the different vertical coordinate
236     C dimensions will have to be taken into account.
237    
238 edhill 1.25 C 20051021 JMC & EH3 : We need to extend this so that a few
239     C variables each defined on different grids do not have the same
240     C vertical dimension names so we should be using a pattern such
241     C as: Z[uml]td000000 where the 't' is the type as specified by
242     C gdiag(10)
243    
244 edhill 1.7 C Now define: Zmdxxxxxx, Zudxxxxxx, Zldxxxxxx
245 jmc 1.41 ctmp(1:5) = 'mul '
246     DO i = 1,3
247     dn(1)(1:NLEN) = dn_blnk(1:NLEN)
248     WRITE(dn(1),'(3a,i6.6)') 'Z',ctmp(i:i),'d',nlevels(listId)
249     CALL MNC_CW_ADD_GNAME(dn(1), 1, dim, dn, ib, ie, myThid)
250     CALL MNC_CW_ADD_VNAME(dn(1), dn(1), 0,0, myThid)
251 edhill 1.10
252     C The following three ztmp() loops should eventually be modified
253     C to reflect the fractional nature of levs(j,l) -- they should
254     C do something like:
255 jmc 1.29 C ztmp(j) = rC(INT(FLOOR(levs(j,l))))
256     C + ( rC(INT(FLOOR(levs(j,l))))
257 edhill 1.10 C + rC(INT(CEIL(levs(j,l)))) )
258     C / ( levs(j,l) - FLOOR(levs(j,l)) )
259     C for averaged levels.
260 jmc 1.41 IF (i .EQ. 1) THEN
261     DO j = 1,nlevels(listId)
262     ztmp(j) = rC(NINT(levs(j,listId)))
263     ENDDO
264     CALL MNC_CW_ADD_VATTR_TEXT(dn(1),'description',
265     & 'Dimensional coordinate value at the mid point',
266     & myThid)
267     ELSEIF (i .EQ. 2) THEN
268     DO j = 1,nlevels(listId)
269     ztmp(j) = rF(NINT(levs(j,listId)) + 1)
270     ENDDO
271     CALL MNC_CW_ADD_VATTR_TEXT(dn(1),'description',
272     & 'Dimensional coordinate value at the upper point',
273     & myThid)
274     ELSEIF (i .EQ. 3) THEN
275     DO j = 1,nlevels(listId)
276     ztmp(j) = rF(NINT(levs(j,listId)))
277     ENDDO
278     CALL MNC_CW_ADD_VATTR_TEXT(dn(1),'description',
279     & 'Dimensional coordinate value at the lower point',
280     & myThid)
281     ENDIF
282 mlosch 1.39 C suppress the missing value attribute (iflag = 0)
283 jmc 1.41 IF (useMissingValue)
284     & CALL MNC_CW_VATTR_MISSING(dn(1), 0,
285     I misval_r8, misval_r4, misval_int,
286     I myThid )
287     CALL MNC_CW_RS_W('D',diag_mnc_bn,0,0, dn(1), ztmp, myThid)
288     CALL MNC_CW_DEL_VNAME(dn(1), myThid)
289     CALL MNC_CW_DEL_GNAME(dn(1), myThid)
290     ENDDO
291 edhill 1.16 #endif /* DIAG_MNC_COORD_NEEDSWORK */
292 edhill 1.7
293 jmc 1.41 ENDIF
294 jmc 1.1 #endif /* ALLOW_MNC */
295    
296 jmc 1.29 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
297    
298 jmc 1.41 DO md = 1,nfields(listId)
299 jmc 1.15 ndId = jdiag(md,listId)
300 jmc 1.35 gcode = gdiag(ndId)(1:10)
301 jmc 1.29 mate = 0
302     mVec = 0
303 jmc 1.35 IF ( gcode(5:5).EQ.'C' ) THEN
304 jmc 1.29 C- Check for Mate of a Counter Diagnostic
305 jmc 1.35 mate = hdiag(ndId)
306     ELSEIF ( gcode(1:1).EQ.'U' .OR. gcode(1:1).EQ.'V' ) THEN
307 jmc 1.29 C- Check for Mate of a Vector Diagnostic
308 jmc 1.36 mVec = hdiag(ndId)
309 jmc 1.29 ENDIF
310 jmc 1.35 IF ( idiag(md,listId).NE.0 .AND. gcode(5:5).NE.'D' ) THEN
311 jmc 1.3 C-- Start processing 1 Fld :
312 jmc 1.41 #ifdef ALLOW_MNC
313     DO ll=1,llMx
314     lm = jj+ll-1
315     #else
316 jmc 1.29 DO lm=1,averageCycle(listId)
317 jmc 1.41 #endif
318 jmc 1.3
319 jmc 1.29 ip = ABS(idiag(md,listId)) + kdiag(ndId)*(lm-1)
320 jmc 1.15 im = mdiag(md,listId)
321 jmc 1.29 IF (mate.GT.0) im = im + kdiag(mate)*(lm-1)
322     IF (mVec.GT.0) im = im + kdiag(mVec)*(lm-1)
323    
324 jmc 1.15 IF ( ndiag(ip,1,1).EQ.0 ) THEN
325 jmc 1.3 C- Empty diagnostics case :
326    
327     _BEGIN_MASTER( myThid )
328     WRITE(msgBuf,'(A,I10)')
329     & '- WARNING - from DIAGNOSTICS_OUT at iter=', myIter
330 jmc 1.15 CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
331 jmc 1.3 & SQUEEZE_RIGHT, myThid)
332 jmc 1.35 WRITE(msgBuf,'(A,I6,3A,I4,2A)')
333 jmc 1.15 & '- WARNING - diag.#',ndId, ' : ',flds(md,listId),
334     & ' (#',md,' ) in outp.Stream: ',fnames(listId)
335     CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
336 jmc 1.3 & SQUEEZE_RIGHT, myThid)
337 jmc 1.29 IF ( averageCycle(listId).GT.1 ) THEN
338 jmc 1.35 WRITE(msgBuf,'(A,2(I3,A))')
339 jmc 1.29 & '- WARNING - has not been filled (ndiag(lm=',lm,')=',
340     & ndiag(ip,1,1), ' )'
341     ELSE
342 jmc 1.35 WRITE(msgBuf,'(A,2(I3,A))')
343 jmc 1.29 & '- WARNING - has not been filled (ndiag=',
344     & ndiag(ip,1,1), ' )'
345     ENDIF
346 jmc 1.15 CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
347 jmc 1.3 & SQUEEZE_RIGHT, myThid)
348     WRITE(msgBuf,'(A)')
349     & 'WARNING DIAGNOSTICS_OUT => write ZEROS instead'
350 jmc 1.15 CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
351 jmc 1.3 & SQUEEZE_RIGHT, myThid)
352     _END_MASTER( myThid )
353     DO bj = myByLo(myThid), myByHi(myThid)
354     DO bi = myBxLo(myThid), myBxHi(myThid)
355 jmc 1.15 DO k = 1,nlevels(listId)
356 jmc 1.3 DO j = 1-OLy,sNy+OLy
357     DO i = 1-OLx,sNx+OLx
358     qtmp1(i,j,k,bi,bj) = 0. _d 0
359     ENDDO
360     ENDDO
361     ENDDO
362     ENDDO
363     ENDDO
364    
365     ELSE
366     C- diagnostics is not empty :
367    
368 jmc 1.29 IF ( debugLevel.GE.debLevA .AND. myThid.EQ.1 ) THEN
369 jmc 1.35 WRITE(ioUnit,'(A,I6,3A,I8,2A)')
370 jmc 1.15 & ' Computing Diagnostic # ', ndId, ' ', cdiag(ndId),
371     & ' Counter:',ndiag(ip,1,1),' Parms: ',gdiag(ndId)
372 jmc 1.29 IF ( mate.GT.0 ) THEN
373 jmc 1.35 WRITE(ioUnit,'(3A,I6,2A)')
374 jmc 1.15 & ' use Counter Mate for ', cdiag(ndId),
375     & ' Diagnostic # ',mate, ' ', cdiag(mate)
376 jmc 1.29 ELSEIF ( mVec.GT.0 ) THEN
377 jmc 1.15 IF ( im.GT.0 .AND. ndiag(MAX(1,im),1,1).GT.0 ) THEN
378 jmc 1.35 WRITE(ioUnit,'(3A,I6,3A)')
379 jmc 1.15 & ' Vector Mate for ', cdiag(ndId),
380     & ' Diagnostic # ',mVec, ' ', cdiag(mVec),
381     & ' exists '
382 jmc 1.3 ELSE
383 jmc 1.35 WRITE(ioUnit,'(3A,I6,3A)')
384 jmc 1.15 & ' Vector Mate for ', cdiag(ndId),
385     & ' Diagnostic # ',mVec, ' ', cdiag(mVec),
386     & ' not enabled'
387 jmc 1.3 ENDIF
388     ENDIF
389 jmc 1.6 ENDIF
390 jmc 1.3
391 jmc 1.30 IF ( fflags(listId)(2:2).EQ.'P' ) THEN
392     C- get all the levels (for vertical interpolation)
393     DO bj = myByLo(myThid), myByHi(myThid)
394     DO bi = myBxLo(myThid), myBxHi(myThid)
395     DO k = 1,kdiag(ndId)
396     tmpLev = k
397     CALL GETDIAG(
398     I tmpLev,undef,
399     O qtmp1(1-OLx,1-OLy,k,bi,bj),
400     I ndId,mate,ip,im,bi,bj,myThid)
401     ENDDO
402     ENDDO
403     ENDDO
404     ELSE
405     C- get only selected levels:
406     DO bj = myByLo(myThid), myByHi(myThid)
407     DO bi = myBxLo(myThid), myBxHi(myThid)
408     DO k = 1,nlevels(listId)
409     CALL GETDIAG(
410     I levs(k,listId),undef,
411     O qtmp1(1-OLx,1-OLy,k,bi,bj),
412     I ndId,mate,ip,im,bi,bj,myThid)
413     ENDDO
414     ENDDO
415 jmc 1.3 ENDDO
416 jmc 1.30 ENDIF
417 jmc 1.1
418 jmc 1.3 C- end of empty diag / not empty block
419     ENDIF
420 jmc 1.1
421 molod 1.17 C-----------------------------------------------------------------------
422 jmc 1.20 C Check to see if we need to interpolate before output
423 molod 1.17 C-----------------------------------------------------------------------
424 jmc 1.29 IF ( fflags(listId)(2:2).EQ.'P' ) THEN
425 jmc 1.20 C- Do vertical interpolation:
426 jmc 1.30 IF ( fluidIsAir ) THEN
427 jmc 1.29 C jmc: for now, this can only work in an atmospheric set-up (fluidIsAir);
428     CALL DIAGNOSTICS_INTERP_VERT(
429 jmc 1.30 I listId, md, ndId, ip, im, lm,
430 jmc 1.20 U qtmp1,
431 jmc 1.30 I undef, myTime, myIter, myThid )
432 jmc 1.29 ELSE
433     WRITE(msgBuf,'(2A)') 'DIAGNOSTICS_OUT: ',
434 jmc 1.30 & 'INTERP_VERT not allowed in this config'
435 jmc 1.29 CALL PRINT_ERROR( msgBuf , myThid )
436     STOP 'ABNORMAL END: S/R DIAGNOSTICS_OUT'
437     ENDIF
438     ENDIF
439 molod 1.17
440 jmc 1.31 C-- Ready to write field "md", element "lm" in averageCycle(listId)
441    
442     C- write to binary file, using MDSIO pkg:
443 jmc 1.34 IF ( diag_mdsio ) THEN
444 jmc 1.29 nRec = lm + (md-1)*averageCycle(listId)
445 jmc 1.30 C default precision for output files
446     prec = writeBinaryPrec
447     C fFlag(1)=R(or D): force it to be 32-bit(or 64) precision
448     IF ( fflags(listId)(1:1).EQ.'R' ) prec = precFloat32
449     IF ( fflags(listId)(1:1).EQ.'D' ) prec = precFloat64
450 jmc 1.34 C a hack not to write meta files now: pass -nRec < 0 to MDS_WRITE S/R
451     CALL WRITE_REC_LEV_RL(
452     I fn, prec,
453     I NrMax, 1, nlevels(listId),
454     I qtmp1, -nRec, myIter, myThid )
455 jmc 1.3 ENDIF
456 jmc 1.1
457     #ifdef ALLOW_MNC
458 jmc 1.3 IF (useMNC .AND. diag_mnc) THEN
459 jmc 1.1
460 jmc 1.3 _BEGIN_MASTER( myThid )
461 jmc 1.1
462 jmc 1.3 DO ii = 1,CW_DIMS
463 edhill 1.7 d_cw_name(1:NLEN) = dn_blnk(1:NLEN)
464 jmc 1.3 dn(ii)(1:NLEN) = dn_blnk(1:NLEN)
465     ENDDO
466    
467 edhill 1.7 C Note that the "d_cw_name" variable is a hack that hides a
468     C subtlety within MNC. Basically, each MNC-wrapped file is
469     C caching its own concept of what each "grid name" (that is, a
470     C dimension group name) means. So one cannot re-use the same
471     C "grid" name for different collections of dimensions within a
472 jmc 1.15 C given file. By appending the "ndId" values to each name, we
473 edhill 1.7 C guarantee uniqueness within each MNC-produced file.
474 jmc 1.15 WRITE(d_cw_name,'(a,i6.6)') 'd_cw_',ndId
475 edhill 1.7
476 edhill 1.5 C XY dimensions
477     dim(1) = sNx + 2*OLx
478     dim(2) = sNy + 2*OLy
479     ib(1) = OLx + 1
480     ib(2) = OLy + 1
481 jmc 1.29 IF (gdiag(ndId)(2:2) .EQ. 'M') THEN
482 edhill 1.5 dn(1)(1:2) = 'X'
483     ie(1) = OLx + sNx
484     dn(2)(1:2) = 'Y'
485     ie(2) = OLy + sNy
486 jmc 1.15 ELSEIF (gdiag(ndId)(2:2) .EQ. 'U') THEN
487 edhill 1.5 dn(1)(1:3) = 'Xp1'
488     ie(1) = OLx + sNx + 1
489     dn(2)(1:2) = 'Y'
490     ie(2) = OLy + sNy
491 jmc 1.15 ELSEIF (gdiag(ndId)(2:2) .EQ. 'V') THEN
492 edhill 1.5 dn(1)(1:2) = 'X'
493     ie(1) = OLx + sNx
494     dn(2)(1:3) = 'Yp1'
495     ie(2) = OLy + sNy + 1
496 jmc 1.15 ELSEIF (gdiag(ndId)(2:2) .EQ. 'Z') THEN
497 edhill 1.5 dn(1)(1:3) = 'Xp1'
498     ie(1) = OLx + sNx + 1
499     dn(2)(1:3) = 'Yp1'
500     ie(2) = OLy + sNy + 1
501     ENDIF
502 jmc 1.29
503 jmc 1.3 C Z is special since it varies
504 jmc 1.30 WRITE(dn(3),'(a,i6.6)') 'Zd', nlevels(listId)
505 jmc 1.15 IF ( (gdiag(ndId)(10:10) .EQ. 'R')
506     & .AND. (gdiag(ndId)(9:9) .EQ. 'M') ) THEN
507 jmc 1.30 WRITE(dn(3),'(a,i6.6)') 'Zmd', nlevels(listId)
508 edhill 1.7 ENDIF
509 jmc 1.15 IF ( (gdiag(ndId)(10:10) .EQ. 'R')
510     & .AND. (gdiag(ndId)(9:9) .EQ. 'L') ) THEN
511 jmc 1.30 WRITE(dn(3),'(a,i6.6)') 'Zld', nlevels(listId)
512 edhill 1.7 ENDIF
513 jmc 1.15 IF ( (gdiag(ndId)(10:10) .EQ. 'R')
514     & .AND. (gdiag(ndId)(9:9) .EQ. 'U') ) THEN
515 jmc 1.30 WRITE(dn(3),'(a,i6.6)') 'Zud', nlevels(listId)
516 edhill 1.7 ENDIF
517 jmc 1.30 dim(3) = NrMax
518 jmc 1.3 ib(3) = 1
519 jmc 1.30 ie(3) = nlevels(listId)
520 jmc 1.1
521 edhill 1.5 C Time dimension
522     dn(4)(1:1) = 'T'
523     dim(4) = -1
524     ib(4) = 1
525     ie(4) = 1
526    
527 jmc 1.29 CALL MNC_CW_ADD_GNAME(d_cw_name, 4,
528 jmc 1.1 & dim, dn, ib, ie, myThid)
529 jmc 1.29 CALL MNC_CW_ADD_VNAME(cdiag(ndId), d_cw_name,
530 jmc 1.1 & 4,5, myThid)
531 jmc 1.15 CALL MNC_CW_ADD_VATTR_TEXT(cdiag(ndId),'description',
532     & tdiag(ndId),myThid)
533     CALL MNC_CW_ADD_VATTR_TEXT(cdiag(ndId),'units',
534     & udiag(ndId),myThid)
535 edhill 1.28
536 mlosch 1.37 C Missing values only for scalar diagnostics at mass points (so far)
537 mlosch 1.39 useMisValForThisDiag = useMissingValue
538     & .AND.gdiag(ndId)(1:2).EQ.'SM'
539     IF ( useMisValForThisDiag ) THEN
540 mlosch 1.37 C assign missing values and set flag for adding the netCDF atttibute
541     CALL MNC_CW_VATTR_MISSING(cdiag(ndId), 2,
542 jmc 1.40 I misval_r8, misval_r4, misval_int,
543 mlosch 1.37 I myThid )
544     C and now use the missing values for masking out the land points
545     DO bj = myByLo(myThid), myByHi(myThid)
546     DO bi = myBxLo(myThid), myBxHi(myThid)
547     DO k = 1,nlevels(listId)
548     klev = NINT(levs(k,listId))
549     DO j = 1-OLy,sNy+OLy
550     DO i = 1-OLx,sNx+OLx
551 jmc 1.43 IF ( maskC(i,j,klev,bi,bj) .EQ. 0. )
552 mlosch 1.37 & qtmp1(i,j,k,bi,bj) = misvalLoc
553     ENDDO
554     ENDDO
555     ENDDO
556     ENDDO
557     ENDDO
558     ELSE
559     C suppress the missing value attribute (iflag = 0)
560 mlosch 1.38 C Note: We have to call the following subroutine for each mnc that has
561     C been created "on the fly" by mnc_cw_add_vname and will be deleted
562     C by mnc_cw_del_vname, because all of these variables use the same
563 jmc 1.40 C identifier so that mnc_cw_vfmv(indv) needs to be overwritten for
564 mlosch 1.38 C each of these variables
565 mlosch 1.37 CALL MNC_CW_VATTR_MISSING(cdiag(ndId), 0,
566 jmc 1.40 I misval_r8, misval_r4, misval_int,
567 mlosch 1.37 I myThid )
568     ENDIF
569 jmc 1.1
570 jmc 1.41 IF ( ((writeBinaryPrec .EQ. precFloat32)
571     & .AND. (fflags(listId)(1:1) .NE. 'D'))
572     & .OR. (fflags(listId)(1:1) .EQ. 'R') ) THEN
573 edhill 1.13 CALL MNC_CW_RL_W('R',diag_mnc_bn,0,0,
574 jmc 1.15 & cdiag(ndId), qtmp1, myThid)
575 jmc 1.29 ELSEIF ( (writeBinaryPrec .EQ. precFloat64)
576 edhill 1.22 & .OR. (fflags(listId)(1:1) .EQ. 'D') ) THEN
577 edhill 1.13 CALL MNC_CW_RL_W('D',diag_mnc_bn,0,0,
578 jmc 1.15 & cdiag(ndId), qtmp1, myThid)
579 edhill 1.13 ENDIF
580 jmc 1.29
581 jmc 1.15 CALL MNC_CW_DEL_VNAME(cdiag(ndId), myThid)
582 edhill 1.7 CALL MNC_CW_DEL_GNAME(d_cw_name, myThid)
583 jmc 1.1
584 jmc 1.3 _END_MASTER( myThid )
585 jmc 1.1
586 jmc 1.3 ENDIF
587 jmc 1.1 #endif /* ALLOW_MNC */
588    
589 jmc 1.41 C-- end loop on lm (or ll if ALLOW_MNC) counter
590 jmc 1.29 ENDDO
591 jmc 1.15 C-- end of Processing Fld # md
592 jmc 1.3 ENDIF
593 jmc 1.41 ENDDO
594    
595     #ifdef ALLOW_MNC
596     C-- end loop on jj counter
597 jmc 1.3 ENDDO
598 jmc 1.41 #endif
599 jmc 1.1
600 jmc 1.31 #ifdef ALLOW_MDSIO
601     IF (diag_mdsio) THEN
602     C- Note: temporary: since it's a pain to add more arguments to
603     C all MDSIO S/R, uses instead this specific S/R to write only
604     C meta files but with more informations in it.
605 jmc 1.34 glf = globalFiles
606 jmc 1.31 nRec = nfields(listId)*averageCycle(listId)
607     CALL MDS_WR_METAFILES(fn, prec, glf, .FALSE.,
608     & 0, 0, nlevels(listId), ' ',
609 jmc 1.44 & nfields(listId), flds(1,listId), nTimRec, timeRec,
610 jmc 1.31 & nRec, myIter, myThid)
611     ENDIF
612     #endif /* ALLOW_MDSIO */
613    
614 jmc 1.15 RETURN
615 jmc 1.3 END
616 jmc 1.15
617 jmc 1.1 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|

  ViewVC Help
Powered by ViewVC 1.1.22