include file: compstat.cdk 15
#if defined (DOC)
!
!     . J. Halle    *CMDA/AES Oct 99.
!             - Added ground temperature (TG) to the model state.
!
!     . J. Halle    *CMDA/AES April 2003.
!             - Added RFACTHUM variable in the common block.
!Revision:
!        Y. Yang  Oct. 2003
!             - Expand dimension of arrays that are related to species
!       . M. Buehner  *ARMA/MSC Sept 2004
!              - Make DAMPLIBG a 3D field
!        Y.J. Rochon, May 2005
!             - Removed OZ-related parameters as these are now included
!               as TR paremeters
!             - Changed *CORBG(NFLEV,NKSDIM-NVSP2D) to 
!               *CORBG(NFLEV,NFLEV) for *.ne.''
!      .  N. Wagneur CMDA Sept 2006
!             - Added LLIMTG and RLIMSUPTG
!               to allow and control upper limit forecast error.
!             - Added NCMTMAX dimension to TRCORBG.
!
!     COMDECK COMPSTAT  :  background error statistics
!     --------------
!     1.     INFORMATION CONTAINED WITHIN A STATISTICS FILE
!     .
!     a. Forecast error standard deviations as a function of latitude
!        and altitude.
!        ----------------------------------
!     UUSTDBG(NJ,NFLEV) : wind error
!     GZSTDBG(NJ,NFLEV) : Height error
!     .                   (currently PHI' but will be changed)
!     QSTDBG(NJ,NFLEV)  : specific humidity error
!     TTSTDBG(NJ,NFLEV) : temperature  error(not used)
!     TRSTDBG(NJ,NFLEV*NCMTMAX) : chemical species
!     TGSTDBG(NI,NJ   ) : ground temperature
!
!     b. Forecast error vertical correlations
!        ------------------------------------
!     UUCORBG(NFLEV,NFLEV) : wind correlations
!     GZCORBG(NFLEV,NFLEV) : height correlations
!     QCORBG(NFLEV,NFLEV)  : correlations for specific humidity
!     TTCORBG(NFLEV,NFLEV) : temperature correlations
!     TRCORBG(NFLEV,NFLEV*NCMTMAX) : chemical species correlations
!
!     c. Horizontal characteristic lengths as a function of height
!        ---------------------------------------------------------
!     RCSCLVO(NFLEV)       : for PSI
!     RCSCLDI(NFLEV)       : for CHI
!     RCSCLGZ(NFLEV)       : for PHI'
!     RCSCLQ(NFLEV)        : for specific humidity
!     RCSCLTT(NFLEV)       : for temperature
!     RCSCLTR(NFLEV*NCMTMAX) : for chemical species
!     RCSCLPS              : for surface pressure
!     RCSCLTG              : for ground temperature
!
!     d. Miscellaneous
!        -------------
!     MLVSTBG(NFLEV)       : list of levels in the statistics file
!     DAMPLIBG(NI,NKGDIM,NJ) : 3D field used for the amplification
!     .                      factor
!     RNU2BG (NJ,NFLEV)    : ratio of divergent component of the
!     .                      divergent to the total kinetic energy
!     .                      of the forecast error (see Daley, 1990)
!
!     2. NAMELIST CONTROLLED PARAMETERS FOR THE STATISTICS
!     .  -------------------------------------------------
!     a.  Horizontal correlation type to be used for the model variable
!
!     NXXXCORRTYP : = 1  Gaussian
!     NXXXCORRTYP : = 2  TOAR
!     NXXXCORRTYP : = 3  forecast error determined from a lagged
!     .                  forecast estimate (non-separable statistics)
!     NPSICORRTYP : correlation type of PSI
!     NCHICORRTYP : correlation type of CHI
!     NGZCORRTYP  : correlation type of PHI'
!     NQCORRTYP   : correlation type of specific humidity
!     NTTCORRTYP  : correlation type of temperature
!     NTRCORRTYP(NCMTMAX)  : correlation type of chemical species
!     NPSCORRTYP  : correlation type of surface pressure
!     NTGCORRTYP  : correlation type of ground temperature
!
!     b.  Error growth factor (or amplification factor)
!     NAMPLIFACT  :  = 1    none is applied
!     .              = 2    a 2D field is read from the statistics file
!     .                     and used for all model variables
!     .              = 3    a 3D field is read from the statistics file
!     .                     and used for all model variables
!     .              = 4    several 3D fields are read from the statistics
!     .                     file to define the amplification (in 3D) for each
!     .                     analysis variable.
!     CETIKETFD   :         label used for the amplification factor field
!     .                     in the forecast error statistics file
!     NU2         :  = 1    the constant value of RNU2 specified in the NAMELIST
!     .                     used to initialize RNU2BG to a constant
!     .                     (default is set to zero)
!     .           :  = 2    a latitude-altitude field for RNU2BG is read from file
!
!     3. Additional parameters necessary to characterize the correlations
!
!     a. Parameters associated with autoregressive correlations
!     .  (see Mitchell et al., 1990)
!     NTOAR       :  = 3    (default)
!     RALPHATOAR  :  = 0.2  (default)
!
!  -> Filtering parameters:
!
!     leigfilt    : Logical controling eigenvalues filtering of vertical
!                   correlations. If .true., the following thresholds
!                   are used on individuals block diagonals
! threshold values of vercical correlation eigenvalues for block diagonal of ...
!     reigmintt   : .. unbalance temperature
!     reigminpsi  : .. streamfunction
!     reigminchi  : .. unbalance potential velocity
!     reigminlq   : .. log(q)
!
!  N.B. Default values are set to 0
!
!  <- End of filtering parameters
!
!     lbgsto      : logical that control writing of vertically
!                   interpated BG stat. in file 'newstat'
!
!     RFACTHUM    : factor apllied to the background std errors for LQ. Default= 1.0
!
!     RLIMSUPTG   : Limit to background error for ground temperature TG. Default = 3.0
!     LLIMTG      : Logical value allows the upper limit of TG background error. Default=.false.
!
#endif
!
      REAL*8     UUSTDBG(NJ,NFLEV), GZSTDBG(NJ,NFLEV), QSTDBG(NJ,NFLEV)
      REAL*8     TTSTDBG(NJ,NFLEV), TRSTDBG(NJ,NFLEV*NCMTMAX)
      REAL*8     TGSTDBG(NI,NJ   )
      REAL*8     DAMPLIBG(NI,NKGDIM,NJ)
      REAL*8     RNU2BG(JPLAT,JPNFLEV)
      CHARACTER*12 CETIKETFD
!
      REAL*8     CORBG(NFLEV,NKSDIM-NVSP2D)
      REAL*8     UUCORBG(NFLEV,NFLEV),VVCORBG(NFLEV,NFLEV)
      REAL*8     GZCORBG(NFLEV,NFLEV)
      REAL*8     QCORBG(NFLEV,NFLEV), TTCORBG(NFLEV,NFLEV)
      REAL*8     TRCORBG(NFLEV,NFLEV*NCMTMAX)
      REAL*8     RCSCLVO(JPNFLEV),RCSCLDI(JPNFLEV),RCSCLGZ(JPNFLEV)
      REAL*8     RCSCLQ(JPNFLEV),RCSCLTT(JPNFLEV)
      REAL*8     RCSCLTR(JPNFLEV*NCMTMAX)
      REAL*8     RCSCLPS,RCSCLTG,RFACTHUM,RLIMSUPTG
      INTEGER  MLVSTBG(JPNFLEV)
!
      INTEGER NPSICORRTYP, NCHICORRTYP, NGZCORRTYP, NQCORRTYP
      INTEGER NPSCORRTYP,NTGCORRTYP,NAMPLIFACT, NU2
      INTEGER NTOAR, NTRCORRTYP(NCMTMAX), NTTCORRTYP
      REAL*8 RALPHATOAR
      REAL*8 reigmintt,reigminpsi,reigminchi,reigminlq
      logical leigfilt,lbgsto,LLIMTG
!
      POINTER  (PTCORBG,CORBG)
      POINTER  (PTUUSTDBG,UUSTDBG),(PTGZSTDBG,GZSTDBG)
      POINTER  (PTTTSTDBG,TTSTDBG),(PTTRSTDBG,TRSTDBG)
      POINTER  (PTTGSTDBG,TGSTDBG),(PTQSTDBG,QSTDBG)
      POINTER  (PTUUCORBG,UUCORBG),(PTQCORBG,QCORBG)
      POINTER  (PTTTCORBG,TTCORBG),(PTGZCORBG,GZCORBG)
      POINTER  (PTTRCORBG,TRCORBG),(PTVVCORBG,VVCORBG)
      POINTER  (PTDAMPLIBG,DAMPLIBG)
!
      COMMON/COMRPSTAT/RCSCLVO,RCSCLDI,RCSCLGZ,RCSCLQ
      COMMON/COMRPSTAT/RCSCLTT,RCSCLTR,RCSCLPS,RCSCLTG
      COMMON/COMRPSTAT/RALPHATOAR,RNU2BG
      COMMON/COMRPSTAT/reigmintt,reigminpsi,reigminchi,reigminlq
      COMMON/COMRPSTAT/RFACTHUM,RLIMSUPTG
!
      common/comnpstat/MLVSTBG
      common/comnpstat/NPSICORRTYP, NCHICORRTYP, NGZCORRTYP,NTTCORRTYP
      common/comnpstat/NQCORRTYP ,NPSCORRTYP ,NTGCORRTYP
      common/comnpstat/NTRCORRTYP, NAMPLIFACT, NU2, NTOAR
      COMMON/COMCPSTAT/CETIKETFD

      COMMON/POMPSTAT/PTCORBG,PTUUSTDBG,PTGZSTDBG,PTQSTDBG
      COMMON/POMPSTAT/PTTTSTDBG,PTTRSTDBG,PTTGSTDBG
      COMMON/POMPSTAT/PTUUCORBG,PTGZCORBG,PTQCORBG
      COMMON/POMPSTAT/PTTTCORBG,PTTRCORBG
      COMMON/POMPSTAT/PTVVCORBG, PTDAMPLIBG
      common/comlpstat/leigfilt,lbgsto