!-------------------------------------- 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 CSE1,5
#if defined (DOC)
*
***s/r CSE1  - Control of Statistical Estimation  at level 1
*
*
*Author  : P. Gauthier *ARMA/AES  March 22, 1994
*Revision:
*     . P. Gauthier *ARMA/AES August 3, 1994: the normalized increments
*     .             can be split on several files and a restart is now
*     .             possible. Control of CSE1 is through the namelist
*     .             NAMCSE1 and COMCSE1
*     . M. Buehner  May 2008
*     .             Added call to cse2_2 when using new approach
*                   for PtoT with localized Tb correlations (NANALVAR=4)
*    -------------------
**    Purpose: to estimate the forecast error correlation from an
*     .        ensemble of normalized and unbiased residuals such
*     .        as differences between 24/48h forecast valid at the
*     .        same time
*Arguments
*    -NONE-
#endif
      IMPLICIT NONE
*implicits
#include "comlun.cdk"
#include "comcse1.cdk"
#include "comdim.cdk"
#include "comcva.cdk"
*
      INTEGER IULSTAT, IULCORNS, IULSTDEV
C
      WRITE(NULOUT,FMT=9000)
 9000 FORMAT(//,3(" *****************"),/,6X
     S     ," CSE1- Computation of Forecast Error Statistics",/
     S     ,3(" *****************"),/
     S     ,"  -- Revised version 8.02 --")
C
C     *    1. Preliminary Initializations
C     .  (read the namelists NAMCSE1 and NAMCVA)
 100  CONTINUE
C
      IULSTAT   = 54
      IULCORNS  = 55
      IULSTDEV  = 56
C
      CALL SU1CSE1(IULSTAT,IULCORNS,IULSTDEV)
      IF(NCSE1.GE.100) GOTO 300
C
C     2. Compute the homogeneous and isotropic component of the
C     .  forecast error correlations of PSI, CHI, PHI' and T-Td
C     .  (and cross-correlations) from a set of unbiased and
C     .  normalized increments
C
 200  CONTINUE
C
C     .  2.1 Do the computations
C
 210  CONTINUE
      if(nanalvar.eq.4) then
        CALL SUMASKLAT
        CALL CSE2_2(IULSTAT,IULCORNS,IULSTDEV)
      else
        CALL CSE2(IULSTAT,IULCORNS,IULSTDEV)
      endif
C
C     .  2.2  Update the statistics on file
C     .
 220  CONTINUE
C
      CALL WRITECORNS(IULCORNS,CFLCORNS,IULSTDEV,CFLSTDEV
     S     ,NDATESTAT,NENSEMBLE)
C
C     *    3. Representation of the correlations in
C     .       physical space and store the results on file
C
 300  CONTINUE
      IF(NCSE1.EQ.102) THEN
c         CALL POSTCORNS
      END IF
C
      RETURN
      END