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

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

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

revision 1.1 by molod, Thu Feb 12 16:18:21 2004 UTC revision 1.35 by jmc, Wed Jun 6 17:55:44 2012 UTC
# Line 1  Line 1 
1        subroutine diagnostics_write ( nymd,nhms,nymd0,nhms0,xlabel,  C $Header$
2       .                     vars,grid,earth,ocean,land,physics,coupling,  C $Name$
      .                     diag,plist,nplist,dlist,ndlist,nrtype )  
3    
4    #include "DIAG_OPTIONS.h"
5    
6          SUBROUTINE DIAGNOSTICS_WRITE (
7         I                               modelEnd,
8         I                               myTime, myIter, myThid )
9  C***********************************************************************  C***********************************************************************
10  C  Purpose  C  Purpose
11  C  -------  C  -------
12  C     Output sequence for the (multiple) diagnostics output files  C    Output sequence for the (multiple) diagnostics output files
13  C  C
14  C  Arguments  Description  C  Arguments  Description
15  C  ----------------------  C  ----------------------
16  C     nymd ..... Current   YYMMDD  C     modelEnd :: true if call at end of model run.
17  C     nhms ..... Current   HHMMSS  C     myTime   :: Current time of simulation ( s )
18  C     nymd0 .... Beginning YYMMDD  C     myIter   :: Current Iteration Number
19  C     nhms0 .... Beginning HHMMSS  C     myThid   :: my Thread Id number
 C     xlabel ... Character*80 Description of Experiment  
 C     jobid .... Character*8  Job Identifier  
 C     vars ..... Dynamics State Data Structure  
 C     grid ..... Dynamics Grid  Data Structure  
 C     physics .. Physics  State Data Structure  
 C     land ..... Land State     Data Structure  
 C     earth .... Earth Model    Data Structure  
 C     ocean .... Ocean Model    Data Structure  
 C     coupling . Coupling       Data Structure  
 C     diag ..... Diagnostics    Data Structure  
 C      plist ... Prognostic History List Data Structure  
 C     nplist ... Number of distinct Prognostic History Lists  
 C      dlist ... Diagnostic History List Data Structure  
 C     ndlist ... Number of distinct Diagnostic History Lists  
 C     nrtype ... Output Record Type:  0   After  Analysis or Straight Forecast  
 C                                    -1   Before Analysis  
 C                                     1   Assimilation (w/IAU)  
 C  
20  C***********************************************************************  C***********************************************************************
21  c Diagnostics Common         IMPLICIT NONE
22  c -----------------  #include "EEPARAMS.h"
23  #include "SIZE.h"  #include "SIZE.h"
24  #include "fizhi_SIZE.h"  #include "DIAGNOSTICS_SIZE.h"
25  #include "diagnostics_SIZE.h"  #include "PARAMS.h"
26  #include "diagnostics.h"  #include "DIAGNOSTICS.h"
27    
28        integer   nrtype  C     !INPUT PARAMETERS:
29        integer   ndlist        LOGICAL modelEnd
30        integer   nplist        _RL     myTime
31        integer   ndindx (ndiagt)        INTEGER myIter, myThid
32    
33        character*80 xlabel  C     !FUNCTIONS:
34        character* 8 jobid        LOGICAL  DIFF_PHASE_MULTIPLE
35        integer      nymd,nhms,nymd0,nhms0        EXTERNAL DIFF_PHASE_MULTIPLE
36    #ifdef ALLOW_FIZHI
37          LOGICAL  ALARM2
38          EXTERNAL ALARM2
39    #endif
40    
41  c Local variables  c Local variables
42  c ===============  c ===============
43        integer   nd        INTEGER   n
44        integer   ndsum        INTEGER   myItM1, wrIter
45        integer   n,rc        LOGICAL   dump2fileNow, write2file
46        integer   nymdt,nhmst        _RL       phiSec, freqSec, wrTime
47    #ifdef ALLOW_FIZHI
48          CHARACTER *9 tagname
49    #endif
50    
51          IF ( myIter.NE.nIter0 ) THEN
52            myItM1 = myIter - 1
53    
54    C***********************************************************************
55    C***   Check to see if its time for Diagnostic Output                ***
56    C***********************************************************************
57    
58            write2file = .FALSE.
59            DO n = 1,nlists
60              freqSec = freq(n)
61              phiSec = phase(n)
62    
63              IF ( freqSec.LT.0. ) THEN
64    C--     write snap-shot with suffix = myIter to be consistent with
65    C       time-average diagnostics (e.g., freq=-1 & freq=1):
66    c           wrIter = myIter
67    c           wrTime = myTime
68    C--     write snap-shot with suffix = myIter-1 to be consistent with
69    C       state-variable time-step:
70                wrIter = myItM1
71                wrTime = myTime - deltaTClock
72              ELSE
73                wrIter = myIter
74                wrTime = myTime
75              ENDIF
76              dump2fileNow = DIFF_PHASE_MULTIPLE( phiSec, freqSec,
77         &                                        wrTime, deltaTClock )
78    #ifdef ALLOW_FIZHI
79              IF ( useFIZHI ) THEN
80               WRITE(tagname,'(A,I2.2)')'diagtag',n
81               dump2fileNow = ALARM2(tagname)
82              ENDIF
83    #endif
84    #ifdef ALLOW_CAL
85              IF ( useCAL ) THEN
86                CALL CAL_TIME2DUMP( freqSec, deltaTClock,
87         U                          dump2fileNow,
88         I                          myTime, myIter, myThid )
89              ENDIF
90    #endif /* ALLOW_CAL */
91              IF ( dumpAtLast .AND. modelEnd
92         &                    .AND. freqSec.GE.0. ) dump2fileNow = .TRUE.
93              IF ( dump2fileNow ) THEN
94                write2file = .TRUE.
95                CALL DIAGNOSTICS_OUT(n,wrTime,wrIter,myThid)
96              ENDIF
97            ENDDO
98    
99    C---   Check to see if its time for Statistics Diag. Output
100    
101            DO n = 1,diagSt_nbLists
102              freqSec = diagSt_freq(n)
103              phiSec = diagSt_phase(n)
104    
105              IF ( freqSec.LT.0. ) THEN
106    C--     write snap-shot with suffix = myIter to be consistent with
107    C       time-average diagnostics (e.g., freq=-1 & freq=1):
108    c           wrIter = myIter
109    c           wrTime = myTime
110    C--     write snap-shot with suffix = myIter-1 to be consistent with
111    C       state-variable time-step:
112                wrIter = myItM1
113                wrTime = myTime - deltaTClock
114              ELSE
115                wrIter = myIter
116                wrTime = myTime
117              ENDIF
118              dump2fileNow = DIFF_PHASE_MULTIPLE( phiSec, freqSec,
119         &                                        wrTime, deltaTClock )
120    #ifdef ALLOW_FIZHI
121              IF ( useFIZHI ) THEN
122               WRITE(tagname,'(A,I2.2)')'diagStg',n
123               dump2fileNow = ALARM2(tagname)
124              ENDIF
125    #endif
126    #ifdef ALLOW_CAL
127              IF ( useCAL ) THEN
128                CALL CAL_TIME2DUMP( freqSec, deltaTClock,
129         U                          dump2fileNow,
130         I                          myTime, myIter, myThid )
131              ENDIF
132    #endif /* ALLOW_CAL */
133              IF ( dumpAtLast .AND. modelEnd
134         &                    .AND. freqSec.GE.0. ) dump2fileNow = .TRUE.
135              IF ( dump2fileNow ) THEN
136                write2file = .TRUE.
137                CALL DIAGSTATS_OUTPUT(n,wrTime,wrIter,myThid)
138              ENDIF
139            ENDDO
140    
141    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
142    
143            IF ( write2file ) THEN
144              IF ( debugLevel.GE.debLevC ) THEN
145                CALL DIAGNOSTICS_SUMMARY( myTime, myIter, myThid )
146              ENDIF
147    C-      wait for everyone before setting arrays to zero:
148              _BARRIER
149            ENDIF
150            IF ( modelEnd ) THEN
151    C       Close all Stat-diags output files
152              CALL DIAGSTATS_CLOSE_IO( myThid )
153            ENDIF
154    
155    C--     Clear storage space:
156    
157            DO n = 1,nlists
158              freqSec = freq(n)
159              phiSec = phase(n)
160    
161              wrTime = myTime
162              IF ( freqSec.LT.0. ) wrTime = myTime - deltaTClock
163              dump2fileNow = DIFF_PHASE_MULTIPLE( phiSec, freqSec,
164         &                                        wrTime, deltaTClock )
165    #ifdef ALLOW_FIZHI
166              IF ( useFIZHI ) THEN
167               WRITE(tagname,'(A,I2.2)')'diagtag',n
168               dump2fileNow = ALARM2(tagname)
169              ENDIF
170    #endif
171    #ifdef ALLOW_CAL
172              IF ( useCAL ) THEN
173                CALL CAL_TIME2DUMP( freqSec, deltaTClock,
174         U                          dump2fileNow,
175         I                          myTime, myIter, myThid )
176              ENDIF
177    #endif /* ALLOW_CAL */
178              IF ( dumpAtLast .AND. modelEnd
179         &                    .AND. freqSec.GE.0. ) dump2fileNow = .TRUE.
180              IF ( dump2fileNow ) CALL DIAGNOSTICS_CLEAR(n,myThid)
181            ENDDO
182    
183            DO n = 1,diagSt_nbLists
184              freqSec = diagSt_freq(n)
185              phiSec = diagSt_phase(n)
186              wrTime = myTime
187              IF ( freqSec.LT.0. ) wrTime = myTime - deltaTClock
188              dump2fileNow = DIFF_PHASE_MULTIPLE( phiSec, freqSec,
189         &                                        wrTime, deltaTClock )
190    #ifdef ALLOW_FIZHI
191              IF ( useFIZHI ) THEN
192               WRITE(tagname,'(A,I2.2)')'diagStg',n
193               dump2fileNow = ALARM2(tagname)
194              ENDIF
195    #endif
196    #ifdef ALLOW_CAL
197              IF ( useCAL ) THEN
198                CALL CAL_TIME2DUMP( freqSec, deltaTClock,
199         U                          dump2fileNow,
200         I                          myTime, myIter, myThid )
201              ENDIF
202    #endif /* ALLOW_CAL */
203              IF ( dumpAtLast .AND. modelEnd
204         &                    .AND. freqSec.GE.0. ) dump2fileNow = .TRUE.
205              IF ( dump2fileNow ) CALL DIAGSTATS_CLEAR( n, myThid )
206            ENDDO
207    
208  c HHMMSS event timestep counter  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
209  c =============================        ENDIF
       integer  alarm, nalarm,  mhms  
       alarm( mhms ) = nalarm ( mhms, nymd, nhms, nymd0, 0     )  
210    
211  C***********************************************************************        RETURN
212  C*                      Check for Prognostic Output                    *        END
 C***********************************************************************  
       do n=1,nplist  
       if( alarm(plist(n)%frequency).eq.0 ) then  
        call progsig (nymd,nhms,nymd0,nhms0,xlabel,jobid,nrtype,plist(n),  
      .                   vars,grid,earth,ocean,land,physics,coupling )  
       endif  
       enddo  
 C***********************************************************************  
 C*                      Check for Diagnostic Output                    *  
 C***********************************************************************  
       do n=1,ndlist  
       call chkdiag(dlist(n),nymd,nhms,nymd0,nhms0,ndindx,ndsum,nymdt,  
      .                                  nhmst)  
       if (ndsum.ne.0) then  
       call diagout( nymdt,nhmst,nymd0,nhms0,xlabel,ndindx,nrtype,  
      .     dlist(n),qdiag)  
       endif  
       enddo  
   
 c Clear Outputed Diagnostics  
 c --------------------------  
       do n=1,ndlist  
       call chkdiag(n,nymd,nhms,nymd0,nhms0,ndindx,ndsum,nymdt,nhmst)  
       if (ndsum.ne.0) then  
       call clrindx ( diag,ndindx )  
       endif  
       enddo  
   
       return  
       end  
       subroutine chkdiag(nl,nymd,nhms,nymd0,nhms0,ndindx,ndsum,nymdt,nhmst)  
       implicit none  
   
 #include "SIZE.h"  
 #include "fizhi_SIZE.h"  
 #include "diagnostics_SIZE.h"  
 #include "diagnostics.h"  
   
       integer nymd,nhms,nymd0,nhms0,nymdt,nhmst,ndsum  
       integer ndindx(ndiagt)  
   
       integer nymdd,nhmsd,ntick,nafreq,n,m,ndum  
       integer nsecf,nalarm  
   
       nymdt = nymd  
       nhmst = nhms  
       nymdd = nymd0  
       nhmsd = nhms0  
   
 c Initialize Diagnostic Index  
 c ---------------------------  
       do n=1,ndiagt  
       ndindx(n) = 0  
       enddo  
   
 c Fill Current Diagnostic Index  
 c -----------------------------  
       ndsum  = 0  
       nafreq = frequency(nl)  
       if( nalarm( nafreq,nymd,nhms,nymdd,nhmsd ).eq.0 ) then  
   
       do n=1,nfield(nl)  
          do m=1,ndiagt  
          if( fields(nl,n).eq.cdiag_(m) .and. idiag(m).ne.0 ) then  
          ndsum = ndsum  + 1  
          ndindx (ndsum) = m  
          endif  
          enddo  
       enddo  
   
       endif  
       return  
       end  
   
       function chklist (name,list)  
       implicit none  
 #include "SIZE.h"  
 #include "fizhi_SIZE.h"  
 #include "diagnostics_SIZE.h"  
 #include "diagnostics.h"  
       logical  chklist  
       character*8 name  
       integer n  
       chklist = .false.  
       do n=1,nfield(nl)  
       if( fields(nl,n).eq.name ) chklist = .true.  
       enddo  
       return  
       end  

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.35

  ViewVC Help
Powered by ViewVC 1.1.22