!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer,
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer
!version 3 or (at your option) any later version that should be found at:
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software;
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec),
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
!

      subroutine sustatsgl 2,8
#if defined (DOC)
*
***s/r sustatsgl  - Initialize the LAM4D Background Error Statistics.
*
*Author:  Luc Fillion - ARMA/MSC  12 Oct 2005
*Revision: L. Fillion - ARMA/MSC - 18 Jan 2006 - Clean-up.
*     L. Fillion ARMA/MSC May 2006: Upgrade to v10_0_0.
*     L. Fillion ARMA/EC 24 Mar 2010 - Call to sutg.ftn to initialize tg st-dev.
*                                      Only Grd_typ = 'GU' option supported for the moment.
*                                      Include  CALL READNML('NAMPSTAT',IERR)
*     L. Fillion ARMA/EC 6 Jul 2010 -  avoid reading st-dev when in stats computation mode ...
**
#endif
      IMPLICIT NONE
*
*     implicits
*
#include "taglam4d.cdk"
#include "pardim.cdk"
#include "comct0.cdk"
#include "comdim.cdk"
#include "comcva.cdk"
#include "comlun.cdk"
#include "comgdpar.cdk"
#include "compstat.cdk"
#include "comstate.cdk"
#include "comgrd_param.cdk"
#include "comspg.cdk"
*
*     Arguments: None.
*
      logical llprep
      integer ierr
!
!!
      WRITE(NULOUT,FMT=9100)
 9100 FORMAT(//,6X,'sustatsgl: Sets Global/LAM Hemispheric Background Error Statistics')
!
!*1.  Initialize amplification factor
!     -------------------------------
!
      damplibg(:,:,:) = 1.0d0
!
!*2.  Prepare control variable: (1)  spectral correlations CORNS and ST-DEV
!                               (2)  ST-DEV
!     ---------------------------------------------------------------------
!
      CALL READNML('NAMPSTAT',IERR)
!
      if(lsimulcor) then
        call sucovgu
      else
!
!*2.1   spectral correlations CORNS
!
        if(lcornsmin) then
          call readcorns_min
        else
          call readcornsgl
          IF(nsexist(nstg).eq.1) THEN
            call sutg_cor(nulbgst) ! will overwrite Tg corns if already built in stats program and read above by readcornsgl
          endif
        endif
!
!*2.2   Standard-Deviations
!
        if(nconf.ne.300) then  ! avoid reading st-dev when in stats computation mode ...
          if(lsdevsim) then
            call sim_cv_gusdev_gl
          else
            call readcv_gusdev_gl
          endif
        endif
      endif
!
!*3.  Print Horizontal Correlation Lengths if appropriate
!     ---------------------------------------------------
!
      if(nanalvar.eq.3.and.(.not.lcornsmin)) then
        call corrlengthglb(999,.false.,.true.) ! final diagnostic and ensure rhcorl array is representative. 
      endif
!
      return
      end