!-------------------------------------- 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 prep_fcst_diff 1,2
#if defined (DOC)
*
***s/r prep_fcst_diff  - Prepare and write fcst_diff into source file.
*
*Author  : L. Fillion - ARMA/EC - 17 Apr 2009
*Revision: 
* L. Fillion - ARMA/EC - 27 Jan 2010 - Clean-up.
* L. Fillion - ARMA/EC - 4 Feb 2010 - Replace call to su1cse1.ftn by su1cse1la.ftn
*    -------------------
**    Purpose: To be used by LAM4D statistics program.
*Arguments
*    -NONE-
#endif
      IMPLICIT NONE
*implicits
#include "taglam4d.cdk"
#include "comct0.cdk"
#include "comlun.cdk"
#include "comdim.cdk"
#include "comcva.cdk"
#include "comcse1.cdk"
#include "comgrd_param.cdk"
*
      logical llhelm,llfplane,lltb_psi
      INTEGER IULSTAT, IULCORNS, IULSTDEV, iultemp, ierr
      INTEGER FNOM, FSTOUV, FSTFRM, FCLOS,VFSTECR
C
      WRITE(NULOUT,FMT=9000)
 9000 FORMAT(//,3(" *****************"),/,6X
     S     ," prep_fcst_diff- Prepare and write fcst_diff into source file ",/
     S     ,3(" *****************"))
!
!*1.  Preliminary Initializations
!
      iulstat   = 54  ! file unit for ensemble of forecast error samples
      iulcorns  = 55  ! not effective really...
      iulstdev  = 56  ! file unit to write PSI/CHI fields
!
      call su1cse1la(iulstat,iulcorns,iulstdev) ! also reads namelist namcse1
!
      IERR = FNOM(iulstdev,cflstdev,'RND',0)
      IERR = FSTOUV(iulstdev,'RND')
!
!*2.  Compute Global PSI/CHI and interpolate directly to target LAM4D grid if desired
!     --------------------------------------------------------------------------------
!
      call prep_fcst_diff_1(iulstat,iulstdev)
!
      IERR =  FSTFRM(iulstdev)
!
      return
      end