!-------------------------------------- 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 SU0YOMB 1,18
#if defined (DOC)
C
C**s/r SU0YOMB - Second part of the initialization of the model
C                (after the memory allocation)
*
*Author  : P. Gauthier *ARMA/AES  May 29, 1992
C     .   (Based on a subroutine written by
C     .    Mats Hamrud and Philippe Courtier  *ECMWF*)
*Revision:
*     .   P. Gauthier: initialization of post-processing
C     .   L. Fillion : 93-05-31 *RPN/AES
C                      Introduce normal modes.
*     .   S. Pellerin *ARMA/SMC May 2000
*                   . Logical unit cleanup
*                   . Introduction of nconf 141
*         L. Fillion/C.Page: ARMA/MSC - 30 Nov 2004 - Introduce Limited-Area option.
*         L. Fillion ARMA/MSC May 2006: Upgrade to v10_0_0.
*         L. Fillion ARMA/EC  14 Aug 2007 - Update lam4d to v_10_0_3.
*         L. Fillion ARMA/EC  19 Oct 2009 - Call to sugrdgauss.ftn for Rotated Gaussian analysis grid.
*         L. Fillion ARMA/EC  12 Nov 2009 - Include INMI option.
*         L. Fillion ARMA/EC  4 May 2010 - Upgrade to v_11_01_2b.
*
#endif
      use mod4dv, only : l4dvar
      use modstag, only: lstagwinds
      IMPLICIT NONE
*implicits
#include "comlun.cdk"
#include "comdim.cdk"
#include "comct0.cdk"
#include "comgrd_param.cdk"
#include "comgrd.cdk"
#include "comcva.cdk"
#include "comode.cdk"
*
      integer :: ierr
!
!!
      write(nulout,*) 'su0yomb: au debut: nanalvar = ',nanalvar
      CALL SUMULTI
!
!     1. Initialisation of Gaussian latitudes, weights and related
!        parameters
!
      if (grd_typ.eq.'GU') then
        if (l4dvar.and.(.not.lcva_3db)) then
          lstagwinds = .true.
          call readnml('NAMSTAG',IERR)
        else
          lstagwinds = .false.
        endif      
        CALL SULEG(NULOUT)
      else if (grd_typ.eq.'LU') then
        lstagwinds = .true.
      endif
!
!*    2. Initialisation for the FFT
!        (memory is allocated for the working space needed by the FFT)
!
      if (grd_typ.eq.'LU') then
        call sufftla
      else
        CALL SUFFT(NULOUT)
      endif
!
!*    3. For Limited-Area Option:
!        Initialisation of computational grid for minimization or statistics computations
!
      if(grd_typ.eq.'GU'.and.grd_roule) call sugrdgauss
!
      if (grd_typ.eq.'LU'.or.multi_grd.eq.1) then
        call sugrdlam
        if (grd_typ.eq.'LU'.and.multi_grd.eq.1) then
          call sugrdlam2
        endif
      endif
!
!*    4. Initialisation of the geometry
!
      CALL SUGEM(NULOUT)
      if (grd_typ.eq.'LU') then
        call sugemla ! specific extra fields for LA option
        if (multi_grd.eq.1) then
!cluc          call sugemla2 ! eventuellement....
        endif
      endif
!
!*    5. Precomputation and storage of Legendre functions
!
      if (grd_typ.eq.'GU') then
        CALL SUALP
        if(lstagwinds) call sualp_stag(nulout)
!      call abort3d(nulout,'SU0YOMB after SUALP_Stag')
      endif
!
!*    6. Set Background fields on Analysis Grid ready for
!        Basic-State dependent Control Variable definition
!
      if (grd_typ.eq.'LU') then
        call subggrd
      endif
!
!*    7. Initialization of post-processing
!
      CALL SUPOST   ! keep delayed in sequence to ensure geometry dependence (Luc)
!
!*    8. Initialize normal mode parameters and fields
!
      if(lmod.or.linmi) then
        call sumode(nulout)
      endif
!
!*    9. Initialization of Coriolis field for Limited-Area option
!
      if (grd_typ.eq.'LU') then
        call sucoriol
      endif
!
!
      RETURN
      END