SUBROUTINE WRITECHET(KTSNO)

USE PARKIND1  ,ONLY : JPIM     ,JPRB 
USE YOMCHET   ,ONLY : GCHET ,GCHETN
USE YOMCT0    ,ONLY : CNMEXP
USE YOMDYN    ,ONLY : TSTEP
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

IMPLICIT NONE

#ifdef DOC
!**** *WRITECHET

!     Purpose.
!     -------
!         Writes frequency distributions of logarithms of physical 
!         tendencies absolute values to the output file.

!**   Interface.
!     ----------
!        *CALL* *WRITECHET()*

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

!    INPUT:
!    ------
!      KTSNO     : number of the timestep

!        Implicit arguments :
!        --------------------

!   Method
!   -------

!   Externals
!   ---------

!   References
!   ----------

!   Author
!   ------
!   2004-03-01: T.Kovacic, J.M.Piriou, F.Bouyssel

!   Modifications
!   -------------

!----------------------------------------------------------------
#endif

INTEGER(KIND=JPIM),INTENT(IN)     :: KTSNO 
INTEGER(KIND=JPIM)                :: JVAR
CHARACTER(55)                     :: CLDESCR
REAL(KIND=JPRB) :: ZHOOK_HANDLE
  
IF (LHOOK) CALL DR_HOOK('WRITECHET',0,ZHOOK_HANDLE)

CALL LFAOUV(GCHET%NULFREQ,  GCHET%CFICFREQ, 'A')
CALL LFAPRECI(GCHET%NULFREQ, 4)
CALL LFAPRECR(GCHET%NULFREQ, 8) 
CALL LFAECRC(GCHET%NULFREQ, 'INDEXP', CNMEXP,1)
CALL LFAECRR(GCHET%NULFREQ, 'TIME_STEP',TSTEP,1)
DO JVAR= 1, GCHET%NVPHT
  WRITE(CLDESCR,FMT='(A2,1x,A20,1x,A2,1x,F6.2,1x,A2,1x,F6.2,1x,A3,1x,I6)') &
   & 'V=',GCHET%CVARNA(JVAR),'W=',GCHETN%AWIDTH,'P=',GCHETN%APREC,&
   & 'TS=',KTSNO    
  CALL LFAECRI(GCHET%NULFREQ,CLDESCR,GCHET%NQDIST(JVAR,:),GCHET%NWIDTH+1)
ENDDO
CALL LFAFER(GCHET%NULFREQ)
GCHET%NPHTEXTH = 0
GCHET%NQDIST   = 0

IF (LHOOK) CALL DR_HOOK('WRITECHET',1,ZHOOK_HANDLE)

END SUBROUTINE WRITECHET
