SUBROUTINE DEALMOD

!**** *DEALMOD* - Deallocate unnecessary model fields for screening

!     Purpose.
!     -------
!           Deallocate unnecessary model fields for screening

!**   Interface.
!**   ---------
!**         DEALMOD is called from routine SCREEN

!     Author.
!     -------
!        H. JARVINEN *ECMWF*

!     Modifications.
!     --------------
!        Original : 96-12-10
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        M.Hamrud      01-Dec-2003 CY28R1 Cleaning
!        JJMorcrette 20070321 Prognostic aerosols for rad and clouds
!        JJMorcrette 20091201 Total and clear-sky direct SW radiation flux at surface 
!        M.Leutbecher  04-Nov-2009  Fields for stochastic tendency pertns
!------------------------------------------------------

USE PARKIND1  ,ONLY : JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMAUXB  , ONLY : GAUXBUF
USE YOMRINC  , ONLY : SPA3I    ,SPA2I
USE YOMSP    , ONLY : SPA3     ,SPA2
USE GRIDPOINT_BUFFERS_MIX , ONLY : ALLOCATED_GRIDPOINT_BUFFER ,&
 & DEALLOCATE_GRIDPOINT_BUFFER  
USE YOMSLPHY , ONLY : SAVTEND
USE YOMRADF  , ONLY : EMTD     ,TRSW     ,EMTC     ,TRSC     ,&
 & TAUAER   ,SRSWD    ,SRLWD    ,SRSWDCS  ,SRLWDCS ,SRSWDV   ,&
 & SRSWDUV  ,EDRO     ,SRSWPAR  ,SRSWUVB  ,SRSWPARC,SRSWTINC ,&
 & SRFDIR   ,SRCDIR
USE YOMSPSDT , ONLY : LSPSDT, YSPSDT_AR1, YGPSDT
USE SPECTRAL_ARP_MOD,     ONLY : DEALLOCATE_ARP
USE GRIDPOINT_FIELDS_MIX, ONLY : DEALLOCATE_GRID

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

IMPLICIT NONE

REAL(KIND=JPRB) :: ZHOOK_HANDLE

!------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('DEALMOD',0,ZHOOK_HANDLE)
!------------------------------------------------------

!*        1.    DEALLOCATE
!               ----------

!*           1.2   DECLARED IN YOMAUXB

IF(ALLOCATED_GRIDPOINT_BUFFER (GAUXBUF)  ) &
 & CALL DEALLOCATE_GRIDPOINT_BUFFER (GAUXBUF)  

!*           1.6   DECLARED IN YOMRINC

IF(ALLOCATED (SPA3I)    )  DEALLOCATE (SPA3I)
IF(ALLOCATED (SPA2I)    )  DEALLOCATE (SPA2I)

!*           1.7   DECLARED IN YOMSP

IF(ALLOCATED (SPA2)     )  DEALLOCATE (SPA2)
IF(ALLOCATED (SPA3)     )  DEALLOCATE (SPA3)

IF(ALLOCATED (SAVTEND)  )  DEALLOCATE (SAVTEND)

IF (ALLOCATED(EMTD      )) DEALLOCATE        (EMTD      )
IF (ALLOCATED(TRSW      )) DEALLOCATE        (TRSW      )
IF (ALLOCATED(EMTC      )) DEALLOCATE        (EMTC      )
IF (ALLOCATED(TRSC      )) DEALLOCATE        (TRSC      )
IF (ALLOCATED(TAUAER    )) DEALLOCATE        (TAUAER    )
IF (ALLOCATED(SRSWD     )) DEALLOCATE        (SRSWD     )
IF (ALLOCATED(SRLWD     )) DEALLOCATE        (SRLWD     )
IF (ALLOCATED(SRSWDCS   )) DEALLOCATE        (SRSWDCS   )
IF (ALLOCATED(SRLWDCS   )) DEALLOCATE        (SRLWDCS   )
IF (ALLOCATED(SRSWDV    )) DEALLOCATE        (SRSWDV    )
IF (ALLOCATED(SRSWDUV   )) DEALLOCATE        (SRSWDUV   )
IF (ALLOCATED(EDRO      )) DEALLOCATE        (EDRO      )
IF (ALLOCATED(SRSWPAR   )) DEALLOCATE        (SRSWPAR   )
IF (ALLOCATED(SRSWUVB   )) DEALLOCATE        (SRSWUVB   )
IF (ALLOCATED(SRSWPARC  )) DEALLOCATE        (SRSWPARC  )
IF (ALLOCATED(SRSWTINC  )) DEALLOCATE        (SRSWTINC  )
IF (ALLOCATED(SRFDIR    )) DEALLOCATE        (SRFDIR    )
IF (ALLOCATED(SRCDIR    )) DEALLOCATE        (SRCDIR    )

!*           1.8   DECLARED IN YOMSPSDT

IF (LSPSDT) THEN
  CALL DEALLOCATE_ARP( YSPSDT_AR1 )
  CALL DEALLOCATE_GRID(YGPSDT)
ENDIF
!------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('DEALMOD',1,ZHOOK_HANDLE)
END SUBROUTINE DEALMOD
