!-------------------------------------- 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 su1cse1la(KULSTAT,KULCORNS,KULSTDEV) 2,2
#if defined (DOC)
*
***s/r su1cse1la  - Set-up for the computations of forecast error
*     .           correlations based on normalized increments
*
*Author  : L. Fillion  - ARMA/EC - 27 Feb 2009
*Revision: 
**L. Fillion  - ARMA/EC - 28 Jun 2010 - Better check on mflt_trunc w.r.t ntrunc.
*    -------------------
*     .
*Arguments
*     KULSTAT: logical unit on which the file is located
*     KULCORNS: logical unit number
*     KULSTDEV: logical unit number
*
*     Remark: the parameters that define the files and their content
*     ------  are within COMCSE1 and controlled by the corresponding
*     .       namelist NAMCSE1. The way the file is accessed is controlled
*     .       as usual through COMGDPAR
#endif
      IMPLICIT NONE
*implicits
#include "comdim.cdk"
#include "comlun.cdk"
#include "comgrd_param.cdk"
#include "comcorr.cdk"
#include "comcva.cdk"
#include "comcse1.cdk"
#include "comgrd.cdk"
#include "comfftla.cdk"
C
      INTEGER KULSTAT, KULCORNS, KULSTDEV
C	
      INTEGER IERR, JN, JK1, JK2, J, jband, jm
C
C*    1. Default values
C     -----------------
C
      NFLSTAT = 1
      CFLNAMES(1 ) = 'FSTSTAT '
C
      DO J =2, 200
         CFLNAMES(J) = '--'
      END DO
C
      NENSEMBLE   = 0
      LSTATREAD    = .FALSE.
      LSTATCON    = .FALSE.
C
      cstats_step='ALL    '
      CFLCORNS  = '  '
      CFLSTDEV  = '  '
      if(grd_typ.ne.'LU') then
        CFLPTOT   = 'p_to_t.fst'
        CFLCORNS  = 'corr.fst'
        CFLSTDEV  = 'rstd.fst'
      endif
!
      NCSE1 = 3
      lhelm = .true.
      LBALDIV   = .TRUE.
      lnodiv    = .FALSE.
      NREGION   = 0
      lvloc  = .FALSE.
      lsqrt_bgstat  = .FALSE.
      lmcstats  = .FALSE.
      lpsifromglb  = .FALSE.
      lpsifromlam  = .FALSE.
      lflt_low  = .FALSE.
      lflt_high  = .FALSE.
      mflt_trunc  = -999
C
C*    2.  Read the NAMELIST NAMCSE1
C     -----------------------------
C
      WRITE(NULOUT, 9210)
 9210 FORMAT(///,5X,"su1cse1la- Set-up for the computations of"
     S     ," forecast error correlations based on"
     S     ,/,14x," normalized increments")
C
      CALL READNML('NAMCSE1',IERR)
C
      IF(NCSE1.EQ.100) LSTATREAD = .TRUE.
C
      WRITE(NULOUT,*) 'su1cse1la: cstats_step:',cstats_step
      WRITE(NULOUT,*) 'su1cse1la: CETIKETERR:',CETIKETERR
      WRITE(NULOUT,*) 'su1cse1la: CFLCORNS:',CFLCORNS
      WRITE(NULOUT,*) 'su1cse1la: NFLSTAT:',NFLSTAT
      WRITE(NULOUT,*) 'su1cse1la: LMCSTATS:',LMCSTATS
      WRITE(NULOUT,*) 'su1cse1la: mbal_order:',mbal_order
      WRITE(NULOUT,*) 'su1cse1la: lpsifromglb:',lpsifromglb
      WRITE(NULOUT,*) 'su1cse1la: lpsifromlam:',lpsifromlam
      WRITE(NULOUT,*) 'su1cse1la: lvloc:',lvloc
      WRITE(NULOUT,*) 'su1cse1la: lsqrt_bgstat:',lsqrt_bgstat
      WRITE(NULOUT,*) 'su1cse1la: lflt_low:',lflt_low
      WRITE(NULOUT,*) 'su1cse1la: lflt_high:',lflt_high
      WRITE(NULOUT,*) 'su1cse1la: lhelm:',lhelm
      if(mflt_trunc.gt.ntrunc) mflt_trunc = ntrunc
      WRITE(NULOUT,*) 'su1cse1la: mflt_trunc:',mflt_trunc
C
C     2.1 Reset LBALDIV
C
      IF (LNODIV) THEN
         LBALDIV = .FALSE.
      ENDIF
C
C*    3. Initializing CORNS and RSTDDEV
C     ---------------------------------
C
      IF(LSTATREAD) THEN
*
*     .  3.1 Read CORNS and RSTDDEV from a file
*
         CALL READCORNS(KULCORNS,CFLCORNS,KULSTDEV,CFLSTDEV,
     S                  NDATESTAT,NENSEMBLE)
C
      ELSE
C
C*    .   3.2 Case where the computation is started from scratch.
C
        NENSEMBLE = 0
        NDATESTAT = 010189000
        rstddev(:,:) = 0.
        corns(:,:,:,:) = 0.
      END IF
C
      WRITE(NULOUT,9411)NENSEMBLE, NDATESTAT
 9411 FORMAT(//,4X,"Current estimate of the correlations is based"
     S     ," on an ensemble of ",I3," members starting at date"
     S     ,1X,I10)
C
      RETURN
      END