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

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

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

revision 1.10 by edhill, Tue Mar 1 15:48:03 2005 UTC revision 1.50 by jmc, Sat Jun 11 23:29:44 2011 UTC
# Line 8  CBOP 0 Line 8  CBOP 0
8  C     !ROUTINE: DIAGNOSTICS_OUT  C     !ROUTINE: DIAGNOSTICS_OUT
9    
10  C     !INTERFACE:  C     !INTERFACE:
11        SUBROUTINE  DIAGNOSTICS_OUT(        SUBROUTINE DIAGNOSTICS_OUT(
12       I     listnum,       I     listId,
13         I     myTime,
14       I     myIter,       I     myIter,
15       I     myThid )       I     myThid )
16    
17  C     !DESCRIPTION:  C     !DESCRIPTION:
18  C     Write output for diagnostics fields.  C     Write output for diagnostics fields.
19          
20  C     !USES:  C     !USES:
21        IMPLICIT NONE        IMPLICIT NONE
22  #include "SIZE.h"  #include "SIZE.h"
# Line 25  C     !USES: Line 26  C     !USES:
26  #include "DIAGNOSTICS_SIZE.h"  #include "DIAGNOSTICS_SIZE.h"
27  #include "DIAGNOSTICS.h"  #include "DIAGNOSTICS.h"
28    
29  #ifdef ALLOW_FIZHI        INTEGER NrMax
30  #include "fizhi_SIZE.h"        PARAMETER( NrMax = numLevels )
 #else  
       INTEGER Nrphys  
       PARAMETER (Nrphys=0)  
 #endif  
   
31    
32  C     !INPUT PARAMETERS:  C     !INPUT PARAMETERS:
33  C     listnum :: Diagnostics list number being written  C     listId  :: Diagnostics list number being written
34  C     myIter  :: current iteration number  C     myIter  :: current iteration number
35    C     myTime  :: current time of simulation (s)
36  C     myThid  :: my Thread Id number  C     myThid  :: my Thread Id number
37        INTEGER listnum, myIter, myThid        _RL     myTime
38          INTEGER listId, myIter, myThid
39  CEOP  CEOP
40    
41  C     !LOCAL VARIABLES:  C     !FUNCTIONS:
       INTEGER i, j, k, m, n, bi, bj  
       CHARACTER*8 parms1  
       CHARACTER*3 mate_index  
       INTEGER mate, mVec  
       _RL qtmp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr+Nrphys,nSx,nSy)  
       _RL undef, getcon  
       EXTERNAL getcon  
42        INTEGER ILNBLNK        INTEGER ILNBLNK
43        EXTERNAL ILNBLNK        EXTERNAL ILNBLNK
44        INTEGER ilen  #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        INTEGER ioUnit
78        CHARACTER*(MAX_LEN_FNAM) pref        CHARACTER*(MAX_LEN_FNAM) fn
79        CHARACTER*(MAX_LEN_MBUF) suff        CHARACTER*(MAX_LEN_MBUF) suff
80        CHARACTER*(MAX_LEN_MBUF) msgBuf        CHARACTER*(MAX_LEN_MBUF) msgBuf
81        CHARACTER*(80) fn        INTEGER prec, nRec, nTimRec
82          _RL     timeRec(2)
83    #ifdef ALLOW_MDSIO
84        LOGICAL glf        LOGICAL glf
85    #endif
86  #ifdef ALLOW_MNC  #ifdef ALLOW_MNC
87        INTEGER ii        INTEGER ll, llMx, jj, jjMx
88        CHARACTER*(MAX_LEN_FNAM) diag_mnc_bn        CHARACTER*(MAX_LEN_FNAM) diag_mnc_bn
89        CHARACTER*(5) ctmp        LOGICAL useMissingValue
90        INTEGER CW_DIMS, NLEN        REAL*8 misValLoc
       PARAMETER ( CW_DIMS = 10 )  
       PARAMETER ( NLEN    = 80 )  
       INTEGER dim(CW_DIMS), ib(CW_DIMS), ie(CW_DIMS)  
       CHARACTER*(NLEN) dn(CW_DIMS)  
       CHARACTER*(NLEN) d_cw_name  
       CHARACTER*(NLEN) dn_blnk  
       _RS ztmp(Nr+Nrphys)  
91  #endif /*  ALLOW_MNC  */  #endif /*  ALLOW_MNC  */
92    
93  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
94    
95    C---  set file properties
96        ioUnit= standardMessageUnit        ioUnit= standardMessageUnit
97        undef = getcon('UNDEF')        undef = UNSET_RL
98        glf = globalFiles  #ifdef ALLOW_FIZHI
99          IF ( useFIZHI ) undef = getcon('UNDEF')
100    #endif
101        WRITE(suff,'(I10.10)') myIter        WRITE(suff,'(I10.10)') myIter
102        pref = fnames(listnum)        iLen = ILNBLNK(fnames(listId))
103        ilen=ILNBLNK( pref )        WRITE( fn, '(A,A,A)' ) fnames(listId)(1:iLen),'.',suff(1:10)
104        WRITE( fn, '(A,A,A)' ) pref(1:ilen),'.',suff(1:10)  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  #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        IF (useMNC .AND. diag_mnc) THEN
155          DO i = 1,MAX_LEN_FNAM          jjMx = averageCycle(listId)
156            diag_mnc_bn(i:i) = ' '          llMx = 1
157          ENDDO        ELSE
158          DO i = 1,NLEN          jjMx = 1
159            dn_blnk(i:i) = ' '          llMx = averageCycle(listId)
         ENDDO  
 c       WRITE( diag_mnc_bn, '(A,A)' ) 'diag.', pref(1:ilen)  
         WRITE( diag_mnc_bn, '(A)' ) pref(1:ilen)  
   
 C       Update the record dimension by writing the iteration number  
         CALL MNC_CW_SET_UDIM(diag_mnc_bn, -1, myThid)  
         CALL MNC_CW_I_W_S('I',diag_mnc_bn,0,0,'T',myIter,myThid)  
         CALL MNC_CW_SET_UDIM(diag_mnc_bn, 0, myThid)  
   
         dn(1)(1:NLEN) = dn_blnk(1:NLEN)  
         WRITE(dn(1),'(a,i6.6)') 'Zmd', nlevels(listnum)  
         dim(1) = nlevels(listnum)  
         ib(1)  = 1  
         ie(1)  = nlevels(listnum)  
   
         CALL MNC_CW_ADD_GNAME('diag_levels', 1,  
      &       dim, dn, ib, ie, myThid)  
         CALL MNC_CW_ADD_VNAME('diag_levels', 'diag_levels',  
      &       0,0, myThid)  
         CALL MNC_CW_ADD_VATTR_TEXT('diag_levels','description',  
      &       'Idicies of vertical levels within the source arrays',  
      &       myThid)  
           
         CALL MNC_CW_RL_W('D',diag_mnc_bn,0,0,  
      &       'diag_levels', levs(1,listnum), myThid)  
   
         CALL MNC_CW_DEL_VNAME('diag_levels', myThid)  
         CALL MNC_CW_DEL_GNAME('diag_levels', myThid)  
   
 C       Now define:  Zmdxxxxxx, Zudxxxxxx, Zldxxxxxx  
         ctmp(1:5) = 'mul  '  
         DO i = 1,3  
           dn(1)(1:NLEN) = dn_blnk(1:NLEN)  
           WRITE(dn(1),'(3a,i6.6)') 'Z',ctmp(i:i),'d',nlevels(listnum)  
           CALL MNC_CW_ADD_GNAME(dn(1), 1, dim, dn, ib, ie, myThid)  
           CALL MNC_CW_ADD_VNAME(dn(1), dn(1), 0,0, myThid)  
   
 C         The following three ztmp() loops should eventually be modified  
 C         to reflect the fractional nature of levs(j,l) -- they should  
 C         do something like:  
 C            ztmp(j) = rC(INT(FLOOR(levs(j,l))))  
 C                      + ( rC(INT(FLOOR(levs(j,l))))  
 C                          + rC(INT(CEIL(levs(j,l)))) )  
 C                        / ( levs(j,l) - FLOOR(levs(j,l)) )  
 C         for averaged levels.  
           IF (i .EQ. 1) THEN  
             DO j = 1,nlevels(listnum)  
               ztmp(j) = rC(NINT(levs(j,listnum)))  
             ENDDO  
             CALL MNC_CW_ADD_VATTR_TEXT(dn(1),'description',  
      &           'Dimensional coordinate value at the mid point',  
      &           myThid)  
           ELSEIF (i .EQ. 2) THEN  
             DO j = 1,nlevels(listnum)  
               ztmp(j) = rF(NINT(levs(j,listnum)) + 1)  
             ENDDO  
             CALL MNC_CW_ADD_VATTR_TEXT(dn(1),'description',  
      &           'Dimensional coordinate value at the upper point',  
      &           myThid)  
           ELSEIF (i .EQ. 3) THEN  
             DO j = 1,nlevels(listnum)  
               ztmp(j) = rF(NINT(levs(j,listnum)))  
             ENDDO  
             CALL MNC_CW_ADD_VATTR_TEXT(dn(1),'description',  
      &           'Dimensional coordinate value at the lower point',  
      &           myThid)  
           ENDIF  
           CALL MNC_CW_RS_W('D',diag_mnc_bn,0,0, dn(1), ztmp, myThid)  
           CALL MNC_CW_DEL_VNAME(dn(1), myThid)  
           CALL MNC_CW_DEL_GNAME(dn(1), myThid)  
         ENDDO  
   
160        ENDIF        ENDIF
161          DO jj=1,jjMx
162    
163           IF (useMNC .AND. diag_mnc) THEN
164             CALL DIAGNOSTICS_MNC_SET(
165         I                    nLevOutp, listId, jj,
166         O                    diag_mnc_bn,
167         O                    useMissingValue, misValLoc,
168         I                    myTime, myIter, myThid )
169           ENDIF
170  #endif /*  ALLOW_MNC  */  #endif /*  ALLOW_MNC  */
171    
172        DO n = 1,nfields(listnum)  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
173          m = jdiag(n,listnum)  
174          parms1 = gdiag(m)(1:8)         DO md = 1,nfields(listId)
175          IF ( idiag(m).NE.0 .AND. parms1(5:5).NE.'D' ) THEN          ndId = jdiag(md,listId)
176            gcode = gdiag(ndId)(1:10)
177            mate = 0
178            mVec = 0
179            IF ( gcode(5:5).EQ.'C' ) THEN
180    C-      Check for Mate of a Counter Diagnostic
181               mate = hdiag(ndId)
182            ELSEIF ( gcode(1:1).EQ.'U' .OR. gcode(1:1).EQ.'V' ) THEN
183    C-      Check for Mate of a Vector Diagnostic
184               mVec = hdiag(ndId)
185            ENDIF
186            IF ( idiag(md,listId).NE.0 .AND. gcode(5:5).NE.'D' ) THEN
187  C--     Start processing 1 Fld :  C--     Start processing 1 Fld :
188    #ifdef ALLOW_MNC
189             DO ll=1,llMx
190              lm = jj+ll-1
191    #else
192             DO lm=1,averageCycle(listId)
193    #endif
194    
195              ip = ABS(idiag(md,listId)) + kdiag(ndId)*(lm-1)
196              im = mdiag(md,listId)
197              IF (mate.GT.0) im = im + kdiag(mate)*(lm-1)
198              IF (mVec.GT.0) im = im + kdiag(mVec)*(lm-1)
199    
200            IF ( ndiag(m).EQ.0 ) THEN            IF ( ndiag(ip,1,1).EQ.0 ) THEN
201  C-        Empty diagnostics case :  C-        Empty diagnostics case :
202    
203              _BEGIN_MASTER( myThid )              _BEGIN_MASTER( myThid )
204              WRITE(msgBuf,'(A,I10)')              WRITE(msgBuf,'(A,I10)')
205       &        '- WARNING - from DIAGNOSTICS_OUT at iter=', myIter       &        '- WARNING - from DIAGNOSTICS_OUT at iter=', myIter
206              CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,              CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
207       &                          SQUEEZE_RIGHT, myThid)       &                          SQUEEZE_RIGHT, myThid)
208              WRITE(msgBuf,'(A,I4,3A,I3,2A)')              WRITE(msgBuf,'(A,I6,3A,I4,2A)')
209       &       '- WARNING -   diag.#',m, ' : ',flds(n,listnum),       &       '- WARNING -   diag.#',ndId, ' : ',flds(md,listId),
210       &       ' (#',n,' ) in outp.Stream: ',fnames(listnum)       &       ' (#',md,' ) in outp.Stream: ',fnames(listId)
211              CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,              CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
212       &                          SQUEEZE_RIGHT, myThid)       &                          SQUEEZE_RIGHT, myThid)
213              WRITE(msgBuf,'(A,I2,A)')              IF ( averageCycle(listId).GT.1 ) THEN
214       &       '- WARNING -   has not been filled (ndiag=',ndiag(m),' )'               WRITE(msgBuf,'(A,2(I3,A))')
215              CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,       &        '- WARNING -   has not been filled (ndiag(lm=',lm,')=',
216         &                                            ndiag(ip,1,1), ' )'
217                ELSE
218                 WRITE(msgBuf,'(A,2(I3,A))')
219         &        '- WARNING -   has not been filled (ndiag=',
220         &                                            ndiag(ip,1,1), ' )'
221                ENDIF
222                CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
223       &                          SQUEEZE_RIGHT, myThid)       &                          SQUEEZE_RIGHT, myThid)
224              WRITE(msgBuf,'(A)')              WRITE(msgBuf,'(A)')
225       &       'WARNING DIAGNOSTICS_OUT  => write ZEROS instead'       &       'WARNING DIAGNOSTICS_OUT  => write ZEROS instead'
226              CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,              CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
227       &                          SQUEEZE_RIGHT, myThid)       &                          SQUEEZE_RIGHT, myThid)
228              _END_MASTER( myThid )              _END_MASTER( myThid )
229              DO bj = myByLo(myThid), myByHi(myThid)              DO bj = myByLo(myThid), myByHi(myThid)
230                DO bi = myBxLo(myThid), myBxHi(myThid)                DO bi = myBxLo(myThid), myBxHi(myThid)
231                  DO k = 1,nlevels(listnum)                  DO k = 1,nLevOutp
232                    DO j = 1-OLy,sNy+OLy                    DO j = 1-OLy,sNy+OLy
233                      DO i = 1-OLx,sNx+OLx                      DO i = 1-OLx,sNx+OLx
234                        qtmp1(i,j,k,bi,bj) = 0. _d 0                        qtmp1(i,j,k,bi,bj) = 0. _d 0
# Line 207  C-        Empty diagnostics case : Line 241  C-        Empty diagnostics case :
241            ELSE            ELSE
242  C-        diagnostics is not empty :  C-        diagnostics is not empty :
243    
244              IF ( myThid.EQ.1 )              IF ( debugLevel.GE.debLevB .AND. myThid.EQ.1 ) THEN
245       &             WRITE(ioUnit,2000) m,cdiag(m),ndiag(m),gdiag(m)                WRITE(ioUnit,'(A,I6,3A,I8,2A)')
246         &         ' Computing Diagnostic # ', ndId, '  ', cdiag(ndId),
247              IF ( parms1(5:5).EQ.'C' ) THEN       &         '     Counter:',ndiag(ip,1,1),'   Parms: ',gdiag(ndId)
248  C             Check for Mate of a Counter Diagnostic                IF ( mate.GT.0 ) THEN
249  C             --------------------------------------                 WRITE(ioUnit,'(3A,I6,2A)')
250                mate_index = parms1(6:8)       &         '       use Counter Mate for  ', cdiag(ndId),
251                READ (mate_index,'(I3)') mate       &         '     Diagnostic # ',mate, '  ', cdiag(mate)
252                IF ( myThid.EQ.1 )                ELSEIF ( mVec.GT.0 ) THEN
253       &                 WRITE(ioUnit,2003) cdiag(m),mate,cdiag(mate)                  IF ( im.GT.0 .AND. ndiag(MAX(1,im),1,1).GT.0 ) THEN
254              ELSE                   WRITE(ioUnit,'(3A,I6,3A)')
255                mate = 0       &             '           Vector  Mate for  ', cdiag(ndId),
256         &             '     Diagnostic # ',mVec, '  ', cdiag(mVec),
257  C             Check for Mate of a Vector Diagnostic       &             ' exists '
 C             -------------------------------------  
               IF ( parms1(1:1).EQ.'U' .OR. parms1(1:1).EQ.'V' ) THEN  
                 mate_index = parms1(6:8)  
                 READ (mate_index,'(I3)') mVec  
                 IF ( idiag(mVec).NE.0 ) THEN  
                   IF ( myThid.EQ.1 )  
      &                 WRITE(ioUnit,2001) cdiag(m),mVec,cdiag(mVec)  
258                  ELSE                  ELSE
259                    IF ( myThid.EQ.1 )                   WRITE(ioUnit,'(3A,I6,3A)')
260       &                 WRITE(ioUnit,2002) cdiag(m),mVec,cdiag(mVec)       &             '           Vector  Mate for  ', cdiag(ndId),
261         &             '     Diagnostic # ',mVec, '  ', cdiag(mVec),
262         &             ' not enabled'
263                  ENDIF                  ENDIF
264                ENDIF                ENDIF
265              ENDIF              ENDIF
266    
267              DO bj = myByLo(myThid), myByHi(myThid)              IF ( fflags(listId)(2:2).NE.' ' ) THEN
268               DO bi = myBxLo(myThid), myBxHi(myThid)  C-       get all the levels (for vertical post-processing)
269                DO k = 1,nlevels(listnum)                DO bj = myByLo(myThid), myByHi(myThid)
270                  CALL GETDIAG(                 DO bi = myBxLo(myThid), myBxHi(myThid)
271       I                       levs(k,listnum),undef,                  DO k = 1,kdiag(ndId)
272       O                       qtmp1(1-OLx,1-OLy,k,bi,bj),                    tmpLev = k
273       I                       m,mate,bi,bj,myThid)                    CALL GETDIAG(
274         I                         tmpLev,undef,
275         O                         qtmp1(1-OLx,1-OLy,k,bi,bj),
276         I                         ndId,mate,ip,im,bi,bj,myThid)
277                    ENDDO
278                   ENDDO
279                  ENDDO
280                ELSE
281    C-       get only selected levels:
282                  DO bj = myByLo(myThid), myByHi(myThid)
283                   DO bi = myBxLo(myThid), myBxHi(myThid)
284                    DO k = 1,nlevels(listId)
285                      CALL GETDIAG(
286         I                         levs(k,listId),undef,
287         O                         qtmp1(1-OLx,1-OLy,k,bi,bj),
288         I                         ndId,mate,ip,im,bi,bj,myThid)
289                    ENDDO
290                   ENDDO
291                ENDDO                ENDDO
              ENDDO  
             ENDDO  
   
 C-        end of empty diag / not empty block  
           ENDIF  
   
 #ifdef ALLOW_MDSIO  
 C         Prepare for mdsio optionality  
           IF (diag_mdsio) THEN  
             CALL mdswritefield_new(fn,writeBinaryPrec,glf,'RL',  
      &           Nr+Nrphys,nlevels(listnum),qtmp1,n,myIter,myThid)  
           ENDIF  
 #endif /*  ALLOW_MDSIO  */  
   
 #ifdef ALLOW_MNC  
           IF (useMNC .AND. diag_mnc) THEN  
   
             _BEGIN_MASTER( myThid )  
   
             DO ii = 1,CW_DIMS  
               d_cw_name(1:NLEN) = dn_blnk(1:NLEN)  
               dn(ii)(1:NLEN) = dn_blnk(1:NLEN)  
             ENDDO  
   
 C           Note that the "d_cw_name" variable is a hack that hides a  
 C           subtlety within MNC.  Basically, each MNC-wrapped file is  
 C           caching its own concept of what each "grid name" (that is, a  
 C           dimension group name) means.  So one cannot re-use the same  
 C           "grid" name for different collections of dimensions within a  
 C           given file.  By appending the "m" values to each name, we  
 C           guarantee uniqueness within each MNC-produced file.  
             WRITE(d_cw_name,'(a,i6.6)') 'd_cw_',m  
   
 C           XY dimensions  
             dim(1)       = sNx + 2*OLx  
             dim(2)       = sNy + 2*OLy  
             ib(1)        = OLx + 1  
             ib(2)        = OLy + 1  
             IF (gdiag(m)(2:2) .EQ. 'M') THEN  
               dn(1)(1:2) = 'X'  
               ie(1)      = OLx + sNx  
               dn(2)(1:2) = 'Y'  
               ie(2)      = OLy + sNy  
             ELSEIF (gdiag(m)(2:2) .EQ. 'U') THEN  
               dn(1)(1:3) = 'Xp1'  
               ie(1)      = OLx + sNx + 1  
               dn(2)(1:2) = 'Y'  
               ie(2)      = OLy + sNy  
             ELSEIF (gdiag(m)(2:2) .EQ. 'V') THEN  
               dn(1)(1:2) = 'X'  
               ie(1)      = OLx + sNx  
               dn(2)(1:3) = 'Yp1'  
               ie(2)      = OLy + sNy + 1  
             ELSEIF (gdiag(m)(2:2) .EQ. 'Z') THEN  
               dn(1)(1:3) = 'Xp1'  
               ie(1)      = OLx + sNx + 1  
               dn(2)(1:3) = 'Yp1'  
               ie(2)      = OLy + sNy + 1  
             ENDIF  
               
 C           Z is special since it varies  
             WRITE(dn(3),'(a,i6.6)') 'Zd', nlevels(listnum)  
             IF ( (gdiag(m)(10:10) .EQ. 'R')  
      &           .AND. (gdiag(m)(9:9) .EQ. 'M') ) THEN  
               WRITE(dn(3),'(a,i6.6)') 'Zmd', nlevels(listnum)  
292              ENDIF              ENDIF
293              IF ( (gdiag(m)(10:10) .EQ. 'R')  
294       &           .AND. (gdiag(m)(9:9) .EQ. 'L') ) THEN  C-----------------------------------------------------------------------
295                WRITE(dn(3),'(a,i6.6)') 'Zld', nlevels(listnum)  C--     Apply specific post-processing (e.g., interpolate) before output
296    C-----------------------------------------------------------------------
297                IF ( fflags(listId)(2:2).EQ.'P' ) THEN
298    C-          Do vertical interpolation:
299                 IF ( fluidIsAir ) THEN
300    C jmc: for now, this can only work in an atmospheric set-up (fluidIsAir);
301                  CALL DIAGNOSTICS_INTERP_VERT(
302         I                         listId, md, ndId, ip, im, lm,
303         U                         qtmp1,
304         I                         undef, myTime, myIter, myThid )
305                 ELSE
306                   WRITE(msgBuf,'(2A)') 'DIAGNOSTICS_OUT: ',
307         &           'INTERP_VERT not allowed in this config'
308                   CALL PRINT_ERROR( msgBuf , myThid )
309                   STOP 'ABNORMAL END: S/R DIAGNOSTICS_OUT'
310                 ENDIF
311              ENDIF              ENDIF
312              IF ( (gdiag(m)(10:10) .EQ. 'R')              IF ( fflags(listId)(2:2).EQ.'I' ) THEN
313       &           .AND. (gdiag(m)(9:9) .EQ. 'U') ) THEN  C-          Integrate vertically: for now, output field has just 1 level:
314                WRITE(dn(3),'(a,i6.6)') 'Zud', nlevels(listnum)                CALL DIAGNOSTICS_SUM_LEVELS(
315         I                         listId, md, ndId, ip, im, lm,
316         U                         qtmp1,
317         I                         undef, myTime, myIter, myThid )
318              ENDIF              ENDIF
             dim(3) = Nr+Nrphys  
             ib(3)  = 1  
             ie(3)  = nlevels(listnum)  
   
 C           Time dimension  
             dn(4)(1:1) = 'T'  
             dim(4) = -1  
             ib(4)  = 1  
             ie(4)  = 1  
   
             CALL MNC_CW_ADD_GNAME(d_cw_name, 4,  
      &             dim, dn, ib, ie, myThid)  
             CALL MNC_CW_ADD_VNAME(cdiag(m), d_cw_name,  
      &             4,5, myThid)  
             CALL MNC_CW_ADD_VATTR_TEXT(cdiag(m),'description',  
      &             tdiag(m),myThid)  
             CALL MNC_CW_ADD_VATTR_TEXT(cdiag(m),'units',  
      &             udiag(m),myThid)  
319    
320              CALL MNC_CW_RL_W('D',diag_mnc_bn,0,0,  C--     End of empty diag / not-empty diag block
321       &             cdiag(m), qtmp1, myThid)            ENDIF
322    
323              CALL MNC_CW_DEL_VNAME(cdiag(m), myThid)  C--     Ready to write field "md", element "lm" in averageCycle(listId)
             CALL MNC_CW_DEL_GNAME(d_cw_name, myThid)  
324    
325              _END_MASTER( myThid )  C-        write to binary file, using MDSIO pkg:
326              IF ( diag_mdsio ) THEN
327                nRec = lm + (md-1)*averageCycle(listId)
328    C           default precision for output files
329                prec = writeBinaryPrec
330    C           fFlag(1)=R(or D): force it to be 32-bit(or 64) precision
331                IF ( fflags(listId)(1:1).EQ.'R' ) prec = precFloat32
332                IF ( fflags(listId)(1:1).EQ.'D' ) prec = precFloat64
333    C         a hack not to write meta files now: pass -nRec < 0 to MDS_WRITE S/R
334                CALL WRITE_REC_LEV_RL(
335         I                            fn, prec,
336         I                            NrMax, 1, nLevOutp,
337         I                            qtmp1, -nRec, myIter, myThid )
338              ENDIF
339    
340    #ifdef ALLOW_MNC
341              IF (useMNC .AND. diag_mnc) THEN
342                CALL DIAGNOSTICS_MNC_OUT(
343         I                       NrMax, nLevOutp, listId, ndId,
344         I                       diag_mnc_bn,
345         I                       useMissingValue, misValLoc,
346         I                       qtmp1,
347         I                       myTime, myIter, myThid )
348            ENDIF            ENDIF
349  #endif /*  ALLOW_MNC  */  #endif /*  ALLOW_MNC  */
350    
351  C--     end of Processing Fld # n  C--      end loop on lm (or ll if ALLOW_MNC) counter
352             ENDDO
353    C--     end of Processing Fld # md
354          ENDIF          ENDIF
355           ENDDO
356    
357    #ifdef ALLOW_MNC
358    C--   end loop on jj counter
359        ENDDO        ENDDO
360    #endif
361    
362   2000 format(1x,'Computing Diagnostic # ',i3,2x,a8,5x,'Counter: ',  #ifdef ALLOW_MDSIO
363       &     i4,6x,'Parms: ',a16)        IF (diag_mdsio) THEN
364   2001 format(1x,'          Vector  Mate for  ',a8,5x,  C-    Note: temporary: since it is a pain to add more arguments to
365       &     'Diagnostic # ',i3,2x,a8,' exists ')  C     all MDSIO S/R, uses instead this specific S/R to write only
366   2002 format(1x,'        Vector  Mate for  ',a8,5x,  C     meta files but with more informations in it.
367       &     'Diagnostic # ',i3,2x,a8,' not enabled')              glf = globalFiles
368   2003 format(1x,'      use Counter Mate for  ',a8,5x,              nRec = nfields(listId)*averageCycle(listId)
369       &     'Diagnostic # ',i3,2x,a8)              CALL MDS_WR_METAFILES(fn, prec, glf, .FALSE.,
370               &              0, 0, nLevOutp, ' ',
371        RETURN       &              nfields(listId), flds(1,listId), nTimRec, timeRec,
372         &              nRec, myIter, myThid)
373          ENDIF
374    #endif /*  ALLOW_MDSIO  */
375    
376          RETURN
377        END        END
378                                                                        
379  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.50

  ViewVC Help
Powered by ViewVC 1.1.22