SUBROUTINE SUDIM2

USE PARKIND1 , ONLY : JPIM     ,JPRB
USE YOMHOOK  , ONLY : LHOOK    ,DR_HOOK
USE YOMDIM   , ONLY : NDGLG    ,NDGNH    ,NDGSUR   ,&
 & NDGSAG   ,NDGENG   ,NDLON    ,&
 & NDSUR1   ,NDLSUR   ,NDLSM    ,&
 & NFLEVL   ,NFLEVLMX ,&
 & NFLEVG   ,NFTHER   ,NFAUX    ,NF3D     ,&
 & NFD2D    ,NFC2D    ,NPROMA   ,&
 & NFLSUR   ,NFLSUL   ,NFLSA    ,&
 & NFLEN    ,&
 & NPPM     ,&
 & NPROMB   ,NPROMC   ,&
 & NPROMM   ,&
 & NVARMAX  ,NMSMAX   ,&
 & NSMAX    ,NSEFRE   ,NSPECG   ,NSPEC2G  ,NS3D     ,&
 & NS2D     ,NS1D     ,NSAUX    ,NSMIN    ,&
 & NCMAX    ,NTCMAX   ,NMTCMAX  ,&
 & NDGUNG   ,NDGUXG   ,NDLUNG   ,&
 & NDLUXG   ,NXMAX    ,NXPECG   ,NTMAX    ,&
 & NFPPYX   ,NFPPYE   ,NRLEVX   ,NPROMNH  ,LVOR     ,&
 & LADER    ,LUVDER   ,LSPT     ,&
 & NPROMVC  ,NPROMDLW ,NPROMDLR ,NPROMDLR2,NPROMDLG
USE YOMDIMT  , ONLY : NPROMT
USE YOMLUN   , ONLY : NULOUT   
USE YOMCT0   , ONLY : NCONF    ,NPRTRV   ,&
 & LSLAG    ,LTWOTL   ,LFPOS    ,&
 & LNHDYN   ,LELAM    ,&
 & LRUBC    ,LVERCOR
USE YOMPHY   , ONLY : LMPHYS   
USE YOEPHY   , ONLY : LEPHYS   ,LAGPHY   
USE YOMMP    , ONLY : MYSETV   ,NUMLL    ,NPSURF   ,NPSP
USE YOMSIMPHL, ONLY : LSIMPH
USE YOMRCOEF , ONLY : LRCOEF   ,NG3SR    ,NGMTR    ,&
 & NLATWR   ,NLATRD   ,&
 & NPCKFSR  ,NPCKFTHR , NEXPBSR ,NEXPBTHR  
USE YOMGRB   , ONLY : NGRBQ, NGRBO3, NGRBCLWC, NGRBCIWC, NGRBCC, &
                    & NGRBGP2, NGRBGP3
USE YOMCVER  , ONLY : LVSPLIP
USE YOM_YGFL , ONLY : YGFL,YQ,YO3,YL,YI,YR,YS,YA
USE YOMDYNA  , ONLY : LNHX     ,LRWSDLW  ,LRWSDLR  ,LRWSDLR2 ,LRWSDLG

!**** *SUDIM2* - Setting up of the dimensioning of the model

!     Purpose.
!     --------
!           Initialization of YOMDIM, and some prints
!**   Interface.
!     ----------
!        *CALL* *SUDIM2*

!        Explicit arguments :
!        --------------------

!        Implicit arguments :
!        --------------------
!           Common YOMDIM
!           Common YOMDPHY
!           Common YOMARG

!     Method.
!     -------

!     Externals.
!     ----------
!        SUDIMO - DIMENSIONS OF OBS. RELATED ARRAYS

!     Reference.
!     ----------
!        ECMWF Research Department documentation of the IFS

!     Author.
!     -------
!        Mats Hamrud and Philippe Courtier  *ECMWF*

! Modifications
! -------------
!   Original : 87-10-15
!   D. VASILJEVIC  : 90-06-19 DIMENSIONS FOR OBS. RELATED ARRAYS
!   Christian Blondin : 90-09-19 Dimensioning for O.I job.
!   D. VASILJEVIC  : 90-11-20 REORGANISTION REGARDING OBS./GUESS
!   Modified 91-02-28 by Michel Deque (Relaxation of deep soil values
!   Modified 91-03-15 by Michel Deque (Ozone parameterization)
!   Modified 91-04-01 by Michel Deque (pseudo-historical cloudiness)
!   Modified 91-05-21 by A.Lasserre-Bigorry (scalar variables)
!   Modified 91-07-02 by Philippe Courtier (u-v formulation)
!   Modified 91-07-02 by Philippe Courtier (cleaning)
!   Modified 91-07-02 by Philippe Courtier (Legendre transforms)
!   Modified 91-07-07 by Pascal Marquet (check NMI values)
!   Modified 91-10-01 by M. Deque (anisotropic orography variance)
!   Modified 91-05-11 YOMNMI --> (YOMNMIA and YOMNMIB)
!   Modified 91-11-06 by P. Courtier and M.Hamrud security JPARITY
!   Modified 91-11-20 by P. Moll (Trajectory array positioning)
!   Modified 92-02-16 by M. Deque (2d  and 3d fields for ozone,
!                                          2d fields for vegetation)
!   Modified 92-01-19 by D. Giard (NMI tests)
!   Modified 92-04-28 by Bill Heckley (Initialization of First-guess)
!   Modified 30/5/92 by A. Joly (Introduction of dyn.met. pp)
!   Modified 92-07-15 by D. Giard (NG3DTN suppressed)
!   Modified 93-04-13 by L. Labbe (Dim. for inverse Legendre transfor
!   Modified 93-03-19 by D. Giard : NTMAX,NTEFRE added
!    (NTMAX=truncation for tendencies on the transformed sphere)
!                                 : direct Legendre transf. modified
!   Modified 93-??-?? by L. Labbe :Dim. for GT0    (add orography)
!                                  Dim. for GT0BUF (add orography)
!                                  Dim. for YOMGC5 (trajectory orogra
!   Modified by R. EL Khatib : 93-04-02 Set-up defaults controled by
!   Modified by R. El Khatib  :93-05-06 Set-up through command line
!   Modified by M. Hamrud     :93-07-05 Make use of above for ECMWF
!   Modified by C. Temperton  :93-11-01 Specification of NXMAX
!   Modified by R. Buizza     :93-12-01 Set up to run conf 601
!   Modified by C. Temperton  :94-01-13 Fix for T21 diabatic NMI
!   Modified by D. Giard      :94-02-08 corrections, set-up of NXTIDE
!   Modified by R. EL Khatib : 94-03-03 Full-POS implementation
!   Modified by M. Deque     : 94-09-05 Aerosols
!   K. YESSAD (APRIL 1994): Unified horizontal diffusion scheme.
!   Modified by C. Temperton  :94-05-18 Spectral RT option
!   Modified by M. Hamrud    : 94-04-09 Upper air gridpoint fields
!   Modified by R. EL Khatib : 94-03-03 More Full-POS implementation
!   Modified by C. Temperton  :94-05-18 Spectral RT option
!   Modified by M. Hamrud    : 94-04-09 Upper air gridpoint fields
!   Modified by J. N Thepaut : 94-07-14 number of surf fields for TL
!                              incremental.
!   Modified by R. EL Khatib : 94-11-10 Non-hydrostatic dynamics
!   Modified by M. Tolstykh  : 94-08-31 CUD interpolation in
!                              semi-Lag scheme
!   Modified by Ph. Dandin   : 94-11-17 FMR scheme with MF physics
!   Modified by C. Temperton : 95-02-06 Two-time-level scheme
!   Modified by G. Radnoti   : 95-01-23 NDGSUR for ALADIN full-pos
!                              as well
!   Modified by M. Deque     : 95-04-26 ice coupler
!   Modified by K. Yessad    : 95-05-05 Add new variable NOSIHEG.
!   Modified by L. Isaksen   : 95-06-06 Reordering of spectral arrays
!   Modified by D. Giard     : 95-08-30 NXEFRE, NTEFRE suppressed
!   Modified by J. N Thepaut : 95-01-10 disabling of obs dimensioning
!                              during Full-Pos.
!   Modified by C. Temperton : 95-10-13 Bugfix for two-time-level scheme.
!   Modified by K. YESSAD (AUGUST 1995):
!     - change value of NG3D9 for 2TL SL scheme.
!     - rewritting according to F90 norms.
!   Modified by R. EL Khatib : 95-11-16 Fullpos LFPART2 without command line
!   Modified by M. Deque     : 95-11-27 2nd call to APLPAR (NPROMB)
!   Modified by N. Wedi      : 95-12-10 FULL_POS in LECMWF mode
!   Modified L. Isaksen      : 96-02-20 Remove NFLSURL,NFLSURG
!                                       Introduce NFLEVLMX
!   Modified by A. Untch     : 96-03 grid-point prognostic ozone (EC)
!   Modified by C. Temperton : 96-10-23 Check semi-Lag is being used
!                                       on linear grid
!   Modified by F. Rabier    : 96-10 dimensioning for conf 801
!   Modified by K. YESSAD    : 96-04-03 NDGSUR=5 instead of 6 for CUD5.
!   Modified by R. EL Khatib : 96-05-13 NDLSUR/NDSUR1 for "under-linear" grid
!   Modified by T. Lagarde   : 96-06-01 2nd call to APLPAR (NPROMC)
!   Modified by M. Deque     : 96-07-01 Nudging (NVCLIU)
!   Modified by R. EL Khatib : 96-07-30 NFGPNH : number of gridpoint NH
!     fields moved from aladin to Arpege/Ifs
!   Modified by J.M. Piriou  : 97-02-28 initialization of NVCLIN in case of
!                              LNEBN
!   Modified OCT 1996 by K. YESSAD: removal of variable uncentering.
!   Modified MAY 1997 by M. DEQUE : frozen FMR
!   Modified by M. Janiskova : 95-12-12 set physics dimensioning for
!                              simpl.phys.par.
!   Modified SEPT 1996 by K. YESSAD:
!       - Spectral transforms for transmission coefficients.
!   Modified by G. Hello : 97-08 dimensioning for conf 801 MF.
!   Modified by J. Bidlot    : 97-06-12 implement wave fields
!   Modified by E.Andersson  : 97-11-17 Flexible GOM arrays.
!   Modified by E.Holm       : 98-01-08 Include spectral ozone switch
!                                       for data assimilation
!   Modified by C. Temperton : 98-01-19 2TL SL scheme for SWE.
!   Modified by C. Temperton : 98-03-04 Fix for TL/AD of SWE.
!   Modified by C. Madeira, A. Dziedzic : 97-07-23 ISBA Fields in FULL-POS
!   Modified by E. Bazile    : 97-11-18 Soil freezing (LFGEL)
!   Modified by M. Janiskova : 97-11-14 dimensioning NVCLIN for conf.131 MF
!   Modified by J.M. Piriou  : 97-12-22 dimensioning NVCLIN after NAMDIM read.
!   Modified by J.M. Piriou  : 97-12-23
!    - dimensioning NVCLIN independent from LNOINI.
!   Modified by M. Deque     : 98-02-20 NVCLIN when LNEBR AND LNEBCO
!   Modified by M. Janiskova : 98-11-18 dimensioning for MF conf.131,401,501
!                            : 99-02-21 specified variables for rad.coef.
!   Modified by V. Lorant    : 98-08-05 NVCLIN whith mixing length
!                              NVCLIS variables stored as 1d fields (NTOZ1D)
!   Modified by T. Bergot  : 98-08 dimensioning for conf 601 MF.
!   Modified by K. YESSAD    : 98-08-07 : rewrite the computation of NG3D9 and
!     NG2D9 in a more readable way for 3D and 2D models, make this part of
!     code consistent with the number of t-dt variables read/written in
!     SC2RDT9/SC2WRT9 (and probably correct some bugs).
!   Modified 98-08-10 by K. YESSAD: removal of LRPOLE option.
!     - removal of LRPOLE in YOMCT0.
!     - removal of code under LRPOLE.
!   Modified by R. El Khatib : 98-08-31 Adiabatic pp.
!   Modified by Z. Bencetic Klaic: 98-10-20
!    - switch for ozone coefficients (LOZSP);
!   Modified by R. El Khatib : 98-11-03
!    - IPROM2 in namelist replaces NPROMA if fullpos LFPART2
!   Modified by J. Teixeira  : 99-03-26 Surface tiling
!   Modified by C. Temperton : 99-08-31 Fix for TL/AD of SL (3D model)
!   Modified by E. Bazile    : 99-01-04 Surface soil freezing (NVRS=4)
!   Modified by M. Charron   : 99-02-01 non-hydrostatic NPROMT
!   Modified 99-02-17 by K. YESSAD: options LRETCFOU, LWRTCFOU.
!   Modified by K. YESSAD : 98-12-04 New option 'lradvtoro'.
!   Modified 99-03-31 by P. SMOLIKOVA: option LRDAORG (double averaging).
!   Modified 99-06-04 by K. YESSAD: correct default for (NSMIN,NSMAX,NDGL)
!     in configurations 911 and 912. 
!     - if command line, correct bugs (false and fancy previous code).
!     - if not command line, allow options letting SUDIM to compute
!       some adequate default values for NSMAX, NDGL.
!   Modified by C. Fischer   : 99-06-30 nvarmax for cost-functions
!   Modified 00-05-15 by C. Jakob: new EC surface dimensions
!   Modified NOV 1999 by K. YESSAD:
!    - in 'lacudw', compute PDLAT and ILA as in 'lascaw' =>
!      'nrlatx', 'nindlat' and 'rdllat' become useless.
!   R. El Khatib : 00-01-28
!    - Fix to enable in-line fullpos + any initialisation witout integration.
!   Modified by K. YESSAD : 00-08-21 relaxation of thin layer hypothesis.
!   R. El Khatib : 00-0-31 NAFPOS initialization moved from SUAFPDS.
!   Modified by D. Giard     : 00-09-12 cleaning old 923
!   Modified by D. Giard     : 00-09-25 bugfix for 923-DM (NFAUX)
!   Modified by D. Giard     : 00-10-25 Snow & Vegetation (NVCLIV=10,LVGSN)
!   Modified by E. Holm      : 00-11-28
!    - Heterogeneous chemistry coefficient added (NVCLIS=8)
!   Modified by E. Bazile    : 00-12-12 NVRS=4 by default.
!   Modified by M. Hamrud    : 01-03-25 Split SUDIM in SUDIM1 and SUDIM2
!   R. El Khatib : 02-21-20 Fullpos B-level distribution + remove IO scheme
!   D.Salmond (15-10-01) FULLIMP mods
!   J.Vivoda (03-2002) PC schemes for NH dynamics
!   Modified by C. Moussy   : 02-09-06 set NG2D9=3 for 2TL tendency coupling
!   Modified by P.Smolikova  : 02-09-30 option NVDVAR=4 for d4 in NH
!   Modified 08-2002 C. Smith : use "w" as prognostic variable in the
!    semi-lag advection of vertical divergence in the NH model.
!   Modified 09-2002 K. YESSAD: some cleanings and bug corrections in part 5.
!   Modified by JM Audoin : 02-11-29 reset NG2D9=3*IFD2DD 2TL tendency coupling
!   Modified 03-01-31 P.Smolikova : variable d4 in 2tl PC NH
!   Modified 03-06-26 G.Mozdzynski : set NDGSUR=2 unconditionally when LELAM=F
!   C. Fischer 03-04-01 : Added NS1D for aladin consistency
!   01-Oct-2003 M. Hamrud  CY28 Cleaning
!   10-Jun-2004 J. Masek   NH cleaning (LPC_NOTR)
!   06-Jul-2004 K. Yessad  Calculation of NFGPNH has moved in susc2b.
!    R. El Khatib : 04-08-05 call suedim for aladin instead of ellips
!   Modified 01-2005 M.Janiskova : NFGNEWC for stat.cloud scheme
!   Modified by C. Temperton : 04-01-21 Fix for SWE
!        Y.Tremolet    27-Jul-2004 Model error setup
!        R.Engelen     20-Jul-2005 Add greenhouse gases
!   20-Feb-2005 J. Vivoda     GWADV scheme for PC_FULL (d3,d4)
!        M. Drusch     22-Jan-2007 introduce nconf 302
!   K. Yessad 07-03-2007: Remove useless (gw)_surf interpolations in NH+LGWADV.
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!   K. Yessad (Sep 2008): prune conf 951.
! End Modifications
!-------------------------------------------------------------------------------

IMPLICIT NONE

INTEGER(KIND=JPIM) :: IAL1, IAL2, IDLSUR, IFD2DD, IFD2DU, &
 & ILEVPP, IPRUSED, IREST, IWIND, JJ, II, JROCB

LOGICAL :: LL2D, LLAEQB,  LLGRID, LLSHW, LLVEQ
REAL(KIND=JPRB) :: ZHOOK_HANDLE

!     ------------------------------------------------------------------

#include "abor1.intfb.h"
#include "suedim.intfb.h"

!     ------------------------------------------------------------------

IF (LHOOK) CALL DR_HOOK('SUDIM2',0,ZHOOK_HANDLE)

!     ------------------------------------------------------------------
!*       1. DEFINE SOME SWITCHES.
!        --------------------------

LLSHW=NCONF == 201.OR.NCONF == 421.OR.NCONF == 521
LLVEQ=NCONF == 202.OR.NCONF == 422.OR.NCONF == 522
LL2D=LLSHW.OR.LLVEQ
!     IWIND=0 allows to suppress the wind from the model working arrays
IWIND =1
IF(ANY(SPREAD(NCONF,1,2) == (/911,912/))) THEN
  IWIND =0
ELSEIF (ANY(SPREAD(NCONF,1,3) == (/923,931,932/))) THEN
  IWIND =0
ENDIF
!     KEEP TRACK OF THE NAMELIST WILL "NPROMA=NPROMB" BEFORE ADAPTING NPROMA
LLAEQB=(NPROMA == NPROMB)

IF(ANY(SPREAD(NCONF,1,14) == (/1,131,201,302,401,421,&
   & 501,521,601,701,801,901,903,940/))) THEN  
  IFD2DD=1
  IF(LRUBC) THEN
    IFD2DU=1
  ELSE
    IFD2DU=0
  ENDIF
ELSEIF(ANY(SPREAD(NCONF,1,4) ==&
   & (/421,422,521,522/))) THEN  
  IFD2DD=1
  IFD2DU=0
ELSEIF(ANY(SPREAD(NCONF,1,2) == (/911,912/))) THEN
  IFD2DD=0
  IFD2DU=0
ELSEIF (ANY(SPREAD(NCONF,1,3) == (/923,931,932/))) THEN
  IFD2DD=0
  IFD2DU=0
ENDIF

!     ------------------------------------------------------------------
!*       2. Initialize collocation grid dimensioning.
!           -----------------------------------------

!*       2.1 CHECK FOR ALIASING.

IAL1=3*NSMAX+2-(2*NDGLG-1)
IAL2=3*NSMAX+2-(NDLON-1)
IF(IAL1 > 0.OR.IAL2 > 0)THEN
  WRITE(UNIT=NULOUT,FMT='('' ******* ALIASING IN THE STRETCHED ''&
   & ,'' COORDINATE MODEL ******** '')')  
ENDIF
IF(IAL1 > 2.OR.IAL2 > 2)THEN
  WRITE(UNIT=NULOUT,FMT='('' ******* ALIASING IN THE UNIFORM   ''&
   & ,'' COORDINATE MODEL ******** '')')  
ENDIF

!*       2.2 Initialize collocation grid dimensioning.

NDGNH =(NDGLG+1)/2
IF (LELAM) THEN
  NDGSUR=0
ELSE
! number of extra-latitudes needed for SL, OBS, FULL-POS 
! and RADIATION interpolations
  NDGSUR=2
ENDIF
NDGSAG=1-NDGSUR
NDGENG=NDGLG+NDGSUR
IF (.NOT.LELAM) THEN
  NDGUNG = NDGSAG
  NDGUXG = NDGENG
  NDLUNG = 1
  NDLUXG = NDLON
ENDIF
IF (LELAM) THEN
  IDLSUR=MAX(NDLON,2*NMSMAX+1)
ELSE
  IDLSUR=MAX(NDLON,2*NSMAX+1)
ENDIF
IF (NCONF == 911.OR.NCONF == 912)THEN
  NDSUR1=0
ELSE
  NDSUR1=3-MOD(NDLON,2)
ENDIF
NDLSUR=IDLSUR+NDSUR1
IF (NPROMC  /=  0) THEN
  NPROMC=NPROMC+1-MOD(NPROMC,2)
ENDIF
IF(LMPHYS.OR.(LEPHYS.AND..NOT.LAGPHY)) THEN
  NPROMM=NPROMA
ELSE
  NPROMM=0
ENDIF
IF(LSIMPH) THEN
  NPROMM=NPROMA
ENDIF
IF ((LNHDYN.AND..NOT.LTWOTL).OR.LSIMPH) THEN
  NPROMT=NPROMA
ELSE
  NPROMT=NPROMM
ENDIF
IF(LNHDYN) THEN
  NPROMNH=NPROMA
ELSE
  NPROMNH=1
ENDIF
IF(LVERCOR) THEN
  NPROMVC=NPROMA
ELSE
  NPROMVC=1
ENDIF
IF(LRWSDLW) THEN
  NPROMDLW=NPROMA
ELSE
  NPROMDLW=1
ENDIF
IF(LRWSDLR) THEN
  NPROMDLR=NPROMA
ELSE
  NPROMDLR=1
ENDIF
IF(LRWSDLR2) THEN
  NPROMDLR2=NPROMA
ELSE
  NPROMDLR2=1
ENDIF
IF(LRWSDLG) THEN
  NPROMDLG=NPROMA
ELSE
  NPROMDLG=1
ENDIF
NDLSM=NDLSUR-1
!     RESTORE THE NAMELIST WILL "NPROMA=NPROMB"
IF(LLAEQB)NPROMB=NPROMA

WRITE(NULOUT,'('' COLLOCATION GRID DIMENSIONING '')')
WRITE(UNIT=NULOUT,FMT='('' NDGLG ='',I6,'' NDGNH ='',I6,&
 & '' NDGSUR='',I6,'' NDGSAG ='',I6,'' NDGENG ='',I6,/,&
 & '' NDLON ='',I6,'' NDSUR1='',I6,'' NDLSUR='',I6,&
 & '' NDLSM ='',I6,/,&
 & '' NDGUNG ='',I6,'' NDGUXG ='',I6,'' NDLUNG ='',I6,&
 & '' NDLUXG ='',I6,/,&
 & '' NPROMA='',I6,'' NPROMM='',I6,&
 & '' NPROMNH='',I6,/,&
 & '' NPROMB='',I6,'' NPROMC='',I6,'' NPROMVC='',I6 &
 & )')&
 & NDGLG ,NDGNH ,NDGSUR,NDGSAG,NDGENG,NDLON ,NDSUR1,NDLSUR,NDLSM,&
 & NDGUNG,NDGUXG,NDLUNG,NDLUXG,NPROMA,NPROMM,&
 & NPROMNH,NPROMB,NPROMC,NPROMVC  
WRITE(UNIT=NULOUT,FMT='('' NPROMDLW ='',I6,'' NPROMDLR ='',I6,&
 & '' NPROMDLR2 ='',I6,'' NPROMDLG ='',I6)')&
 & NPROMDLW,NPROMDLR,NPROMDLR2,NPROMDLG

!*       2.3 check that Eulerian scheme is not being used on linear grid

IF( .NOT.LELAM )THEN
  LLGRID=NSMAX > (NDLON+3)/3
ELSE
  LLGRID=NSMAX > (NDGLG -1)/3 .OR. NMSMAX > (NDLON -1)/3
ENDIF

! k.y.: do not put an abort here, only a warning!
!       It is highly recommended to avoid the use of an Eulerian scheme
!       on linear grids, because of aliasing, but such a possibility
!       must be kept at least for informatical validation.
!       Such a recommandation is valid for all configurations using
!       an advection scheme, not only for configuration 1.
IF(.NOT.LFPOS) THEN
  IF ((NCONF == 1.OR.NCONF == 302).AND.LLGRID.AND..NOT.LSLAG) THEN
    WRITE(NULOUT,*) 'WARNING IN SUDIM2:SL SHOULD BE USED ON LINEAR GRID'
  ENDIF
ENDIF

!     ------------------------------------------------------------------
!*       3. Initialize the number of fields in model
!           ----------------------------------------

NFTHER=0
IF(LSPT)  NFTHER=NFTHER+1
IF(LNHDYN) THEN
  NFTHER=NFTHER+2
  ! Add X term among NFTHER
  IF(LNHX) NFTHER=NFTHER+1
ENDIF

NF3D  =2*IWIND+NFTHER+YGFL%NUMSPFLDS

ii=0
IF (YQ%LGP)  ii=ii+1
IF (YO3%LGP) ii=ii+1
IF (YL%LGP)  ii=ii+1
IF (YI%LGP)  ii=ii+1
IF (YR%LGP)  ii=ii+1
IF (YS%LGP)  ii=ii+1
IF (YA%LGP)  ii=ii+1
IF (.NOT.ALLOCATED(NGRBGP3)) ALLOCATE(NGRBGP3(ii))
ii=0
IF (YQ%LGP)  THEN
  ii=ii+1
  NGRBGP3(ii)=NGRBQ
ENDIF
IF (YO3%LGP) THEN
  ii=ii+1
  NGRBGP3(ii)=NGRBO3
ENDIF
IF (YL%LGP)  THEN
  ii=ii+1
  NGRBGP3(ii)=NGRBCLWC
ENDIF
IF (YI%LGP)  THEN
  ii=ii+1
  NGRBGP3(ii)=NGRBCIWC
ENDIF
IF (YR%LGP)  THEN
  ii=ii+1
  NGRBGP3(ii)=NGRBCIWC
ENDIF
IF (YS%LGP)  THEN
  ii=ii+1
  NGRBGP3(ii)=NGRBCIWC
ENDIF
IF (YA%LGP)  THEN
  ii=ii+1
  NGRBGP3(ii)=NGRBCC
ENDIF
write(nulout,*)'SUDIM2 NGRBGP3=',NGRBGP3
ii=0
! Add 2D fields here if needed
IF (.NOT.ALLOCATED(NGRBGP2)) ALLOCATE(NGRBGP2(ii))
IF (ii>0) write(nulout,*)'SUDIM2 NGRBGP2=',NGRBGP2

IF(.NOT.LADER)THEN
  LVOR=.FALSE.
  LUVDER=.FALSE.
ENDIF
! ------------------------------------------------------------------

!     Determine number of local levels for Fourier and Legendre calculations
!     This is based on the supplied NFLEVG and NPRTRV

IPRUSED=MIN(NFLEVG+1,NPRTRV)
ILEVPP=NFLEVG/NPRTRV
IREST=NFLEVG-ILEVPP*NPRTRV

DO JROCB=1,NPRTRV
  IF(JROCB <= IREST) THEN
    NUMLL(JROCB)=ILEVPP+1
  ELSE
    NUMLL(JROCB)=ILEVPP
  ENDIF
ENDDO
NUMLL(IPRUSED+1:NPRTRV+1)=0

!     Define local definitions for this processor set

NFLEVL=NUMLL(MYSETV)
NFLEVLMX=NUMLL(1)
IF(LVSPLIP.AND.NFLEVL /= NFLEVG) CALL ABOR1&
 & (' ABORT IN SUDIM2: NFLEVL /= NFLEVG => GLOBAL VERTICAL SPLINE&
 & INTERPOLATION NOT POSSIBLE! Set LVSPLIP=.F. in suct0.')  

DO JROCB=1,IPRUSED
  NPSURF(JROCB)=0
ENDDO
NPSURF(IPRUSED)=1
NPSP=NPSURF(MYSETV)
!!li  NFLSUR =NFLEVL+1-MOD(NFLEVL,2)
!!li  Fix until IFS works if NFLSUR>NFLEVL
NFLSUR=NFLEVL

IF (LL2D) THEN
  NFLSUL=0
ELSE
  IF(LSLAG) THEN
    NFLSUL=1
  ELSE
    NFLSUL=0
  ENDIF
ENDIF
NFLSA=1-NFLSUL
NFLEN=NFLEVG+NFLSUL
NFD2D=IFD2DD+IFD2DU

!     Some printings

WRITE(NULOUT,'('' NUMBER OF FIELDS '')')
WRITE(UNIT=NULOUT,FMT='('' NFLEVG ='',I6,'' NFLEVL ='',I6,&
 & '' NPSP='',I6,'' NFTHER='',I6,&
 & '' NFAUX ='',I6,'' NF3D  ='',I6,&
 & '' NFD2D ='',I6,'' NFC2D ='',I6)')&
 & NFLEVG, NFLEVL,NPSP,NFTHER,NFAUX,NF3D,NFD2D ,NFC2D  
WRITE(UNIT=NULOUT,FMT='(&
 & '' NFLSUR ='',I6,'' NPPM = '',I6,/,&
 & '' NFLSUL='',I6,'' NFLSA ='',I6,'' NFLEN ='',I6)')&
 & NFLSUR,NPPM,NFLSUL,NFLSA,NFLEN  
WRITE(UNIT=NULOUT,FMT='('' NFPPYX='',I6,'' NFPPYE='',I6)')NFPPYX,NFPPYE
WRITE(UNIT=NULOUT,FMT='('' NRLEVX='',I10)')NRLEVX

!     ------------------------------------------------------------------
!*       5. Initialize grid point array dimensioning.
!           ----------------------------------------

!*       5.4      SPECIFIC VARIABLES FOR TRANSMISSION COEFFICIENTS.

IF (LRCOEF) THEN
  NG3SR=17
  NGMTR=1
ELSE
  NG3SR=0
  NGMTR=0
ENDIF

NLATWR=0
NLATRD=0
NPCKFSR=1
NPCKFTHR=1
NEXPBSR=6
NEXPBTHR=6

!*       5.5      PRINTINGS.

WRITE(NULOUT,'('' GRID POINT ARRAY DIMENSIONING '')')
WRITE(UNIT=NULOUT,FMT='(&
 & '' LVOR  ='',L2,'' LADER ='',L2,&
 & '' LUVDER='',L2)')&
 & LVOR  ,LADER, LUVDER  
WRITE(UNIT=NULOUT,FMT='('' NG3SR = '',I6,'' NGMTR = '',I6)') NG3SR,NGMTR

!     ------------------------------------------------------------------
!*       6. Initialize Laplace space dimensioning.
!           --------------------------------------

NS3D  =NF3D
NS2D  =NFD2D+NFC2D
NS1D  =2
NSAUX=NFAUX
NXPECG=(NXMAX+1)*(NXMAX+2)/2

!     Local view versions of NSPEC, NSPEC2, .. are defined in sump.F
!     Calculation of NSEFRE in the case of ALADIN and ARPEGE

IF (LELAM) THEN
  CALL SUEDIM(NSEFRE,NSPECG)
ELSE
  NSEFRE=(NSMAX+1)*(NSMAX+1)
  NSPECG=(NSMAX+1)*(NSMAX+2)/2
ENDIF
NSPEC2G=NSPECG*2

WRITE(NULOUT,'('' LAPLACE SPACE DIMENSIONING '')')
WRITE(NULOUT,'('' NSMAX ='',I6,'' NMSMAX='',I6,&
 & '' NSEFRE='',I8,'' NSPECG ='',I6,&
 & '' NSPEC2G='',I8,'' NS3D  ='',I6,&
 & '' NS2D  ='',I6,'' NS1D  ='',I6,&
 & '' NSAUX ='',I6)')&
 & NSMAX ,NMSMAX,NSEFRE,NSPECG,NSPEC2G,NS3D,NS2D,NS1D,NSAUX  
WRITE(NULOUT,'('' NVARMAX ='',I6)') NVARMAX
WRITE(NULOUT,'('' NTCMAX ='',I6,'' NMTCMAX='',I6)') NTCMAX,NMTCMAX
WRITE(NULOUT,'('' NSMIN ='',I6)') NSMIN 
WRITE(NULOUT,'('' NCMAX ='',I6,&
 & '' NXMAX ='',I6,'' NXPECG='',I6,'' NTMAX ='',I6)')&
 & NCMAX ,NXMAX ,NXPECG ,NTMAX  
WRITE(NULOUT,'('' NPSURF '')')
WRITE(UNIT=NULOUT,FMT='(20(1X,I4))')(NPSURF(JJ),JJ=1,NPRTRV)

!     ------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('SUDIM2',1,ZHOOK_HANDLE)
END SUBROUTINE SUDIM2
