SUBROUTINE SUPREPJCDFI(KULOUT)

!     Purpose.
!     --------
!**   Interface.
!     ----------
!        *CALL* *SUPREPJCDFI

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

!     Reference.
!     ----------
!     Author.
!     -------
!        P. Gauthier   *CNRM/GMAP*

!     Modifications.
!     --------------
!        Original : 98-10-21
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM, JPRB
USE YOMHOOK   ,ONLY : LHOOK, DR_HOOK
USE YOMDIM    ,ONLY : NFD2D, NFLSUR, NFLEVL, NS3D, NSMAX, NVARMAX  
USE YOMJCDFI  ,ONLY : QNORM1, QNORM2, QNORM3 ,RSUMJCDFI

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KULOUT 
INTEGER(KIND=JPIM) :: ILEN
LOGICAL :: LLALLOC
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "suqnorm.intfb.h"

!     1. Allocating space for the QNORM

IF (LHOOK) CALL DR_HOOK('SUPREPJCDFI',0,ZHOOK_HANDLE)
LLALLOC = ALLOCATED(QNORM1)
IF(.NOT.LLALLOC) THEN
  ILEN = 2*NFLEVL
  WRITE(KULOUT,*)'  SUPREPJCDFI-  allocating QNORM1. Length = ',ILEN
  ALLOCATE(QNORM1(NFLEVL,2))
ENDIF

LLALLOC = ALLOCATED(QNORM2)
IF(.NOT.LLALLOC) THEN
  ILEN = (NSMAX+1)*NFD2D
  WRITE(KULOUT,*)'  SUPREPJCDFI-  allocating QNORM2. Length = ',ILEN
  ALLOCATE(QNORM2(0:NSMAX,NFD2D))
ENDIF

LLALLOC = ALLOCATED(QNORM3)
IF(.NOT.LLALLOC) THEN
  ILEN = (NSMAX+1)*NS3D*NFLSUR
  WRITE(KULOUT,*)'  SUPREPJCDFI-  allocating QNORM3. Length = ',ILEN
  ALLOCATE(QNORM3(NFLSUR,0:NSMAX,NS3D))
ENDIF

!     2. Allocating space for the cost-function

LLALLOC = ALLOCATED(RSUMJCDFI)
IF(.NOT.LLALLOC) THEN
  ILEN = NVARMAX+1
  WRITE(KULOUT,*)'  SUPREPJCDFI-  allocating RSUMJCDFI.', ' Length = ',ILEN
  ALLOCATE(RSUMJCDFI(0:NVARMAX))
ENDIF

!     2. Defining the norm to be used for Jc when based on DFI

CALL SUQNORM(QNORM1,QNORM2,QNORM3)

IF (LHOOK) CALL DR_HOOK('SUPREPJCDFI',1,ZHOOK_HANDLE)
END SUBROUTINE SUPREPJCDFI
