SUBROUTINE MUPDTS (LDSCALE,LDMEMO,KDPROB,KMUPD,KMTRA)

!***  *MUPDTS* initialize the hessian management.

!**   PURPOSE.
!     --------
!     This routine has to return:
!       kmupd:  the numer of updates to form the approximate hessien h,
!       ldmemo = .true.  if the vectors y and s used to form h are
!                        stored in core memory,
!                .false. otherwise,
!     when ldmemo=.false., the routine `ystbl', which stores and
!     restores (y,s) pairs, has to be rewritten.

!**   INTERFACE.
!     ----------

!       *CALL MUPDTS(...)*  called from M1QN3

!     EXPLICIT ARGUMENTS :
!     --------------------
!     In: LDSCALE =.T. if warm restart.
!     Out: LDMEMO in-core/disk switch.
!     In: KDPROB dimension of the problem
!     Out: KMUPD  number of updates of the hessian
!     In: KMTRA  dimension of the working array.

!     IMPLICIT ARGUMENTS :
!     --------------------

!     METHOD.
!     -------
!        See documentation : The modules M1QN2,N1QN2,M1QN3,N1QN3
!                            version 1.1.b (February 1989)
!                            J.C Gilbert and C. Lemarechal
!     AUTHOR.
!     -------
!        Jean-Noel Thepaut  and Mats Hamrud *ECMWF*

!     MODIFICATIONS.
!     --------------
!        Original : 92-02-26
!        95-12-22 F. Bouttier : remove Hessian MIO reading (done before M1QN3)
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

USE YOMLUN   , ONLY : NULOUT
USE YOMIOMI  , ONLY : NMUPD

IMPLICIT NONE

LOGICAL           ,INTENT(IN)    :: LDSCALE 
LOGICAL           ,INTENT(OUT)   :: LDMEMO 
INTEGER(KIND=JPIM),INTENT(IN)    :: KDPROB 
INTEGER(KIND=JPIM),INTENT(INOUT) :: KMUPD 
INTEGER(KIND=JPIM),INTENT(IN)    :: KMTRA 
REAL(KIND=JPRB) :: ZHOOK_HANDLE

!*    1.  DEFINE NUMBER OF UPDATES AND INITIALIZE LDMEMO.
!     ---------------------------------------------------

IF (LHOOK) CALL DR_HOOK('MUPDTS',0,ZHOOK_HANDLE)
LDMEMO=.TRUE.
IF(LDSCALE) THEN
  KMUPD=(KMTRA-3*KDPROB)/(2*KDPROB+1)
ELSE
  KMUPD=(KMTRA-4*KDPROB)/(2*KDPROB+1)
ENDIF
IF(KMUPD /= NMUPD)&
 & WRITE(NULOUT,*) 'MUPDTS WARNING: Update number inconsistency'  

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