SUBROUTINE HOUSPE3AD(PFI,PVORO,PDIVO,PHGTO,KVMO,KM)

!**** *HOUSPE3AD* - ROUTINE TO FORM SPECTRAL FIELDS FROM DEFINED
!                  HOUGH COEFFICIENTS, FOR A GIVEN VERTICAL MODE.ADJOINT

!     PURPOSE.   TRANSFORM FROM HOUGH SPACE TO "STANDARD SPACE"
!     --------

!**   INTERFACE.
!     ----------
!        *CALL* *HOUSPE3AD(PFI,PVORO,PDIVO,PHGTO,KVMO,KM)*

!        EXPLICIT ARGUMENTS :  PFI - HOUGH COMPONENTS         - OUTPUT
!                              PVORO- VORTICITY            \
!                              PDIVO- DIVERGENCE           \  - INPUT
!                              PHGTO- GEOPOTENTIAL         \
!                              KVMO - VERTICAL MODE INDEX     - INPUT
!                              KM   - ZONAL WAVE NUMBER INDEX - INPUT
!        IMPLICIT ARGUMENTS
!        --------------------

!   METHOD.     THE SPECTRUM OF HOUGH MODES IS INPUT THROUGH PFI.
!   -------     THIS SPECTRUM IS THEN PROJECTED BACK INTO "STANDARD SPACE"
!               BY MULTIPLYING BY THE MATRIX CONTAINING THE NORMAL MODES.
!               THIS MATRIX HAS BEEN PREVIOUSLY COMPUTED BY SUMODE3. THE
!               FIELDS ARE PUT INTO PVOR-PHGT.

!     EXTERNALS.  REORDO3AD - REORDER AND NORMALIZE FIELDS
!     ----------  MIO...  - IO ROUTINES
!                 MXMAOP  - MATRIX MULTIPLY ( SGEMMX )

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

!     AUTHOR.
!     -------
!        JEAN-NOEL THEPAUT  *METEO FRANCE EERM/CRMD*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 90-03-15
!        MATS  HAMRUD    : 93-02-08 : MULTITASKING, IO-SCHEME
!        LARS  ISAKSEN   : 95-01-10 : MULTITASKING MOVED TO HIGHER LEVEL
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------

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

USE YOMDIM   , ONLY : NCMAX    ,NXMAX
USE YOMHOUB  , ONLY : HOUBUF   ,NSTAHOUB

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KM 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFI(6*(NXMAX+1-KM)) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVORO(2*(NCMAX+1-KM)) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDIVO(2*(NCMAX+1-KM)) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PHGTO(2*(NCMAX+1-KM)) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KVMO 
REAL(KIND=JPRB) ::ZF2(6*(NXMAX+1-KM))
INTEGER(KIND=JPIM) ::  IORDR, IREC, JJ
REAL(KIND=JPRB) :: ZHOOK_HANDLE

INTERFACE
#include "mxmaop.h"
END INTERFACE

#include "reordo3ad.intfb.h"

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

!*       0.    INITIALIZE LOCAL ARRAY TO 0.
!              -----------------------------
IF (LHOOK) CALL DR_HOOK('HOUSPE3AD',0,ZHOOK_HANDLE)
DO JJ=1,6*(NXMAX+1-KM)
  ZF2(JJ)=0.0_JPRB
ENDDO
!     ------------------------------------------------------------------

!*       2.    REPLACE STATE VARIABLES.
!              ------------------------

CALL REORDO3AD(ZF2,PVORO,PDIVO,PHGTO,KVMO,KM,-1)

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

!*       1.    GO BACK TO SPECTRAL SPACE.
!              --------------------------

IREC=(KVMO-1)*(NXMAX+1)+KM+1
IORDR=3*(NXMAX-KM+1)
CALL MXMAOP(HOUBUF(NSTAHOUB(IREC)+1),IORDR,1,ZF2,2,1,PFI,2,1,IORDR,IORDR,2)

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

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

