SUBROUTINE CVARU2I

!**** *CVARU2I*    - INVERSE TRANSFORMATION OF MODEL FIELDS

!     PURPOSE.
!     --------

!        TRANSFORM FROM T, ln Ps to P - Inverse

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

!        *CALL* *CVARU2I*

!        INPUT:

!        OUTPUT:

!     METHOD.
!     -------

!     EXTERNALS.
!     ----------
!             *MATMUL*- Fortran 90 intrinsic

!     REFERENCE.
!     ----------

!        ECMWF Research Department documentation of the IFS

!     AUTHOR.
!     -------

!        P Courtier, E Andersson and W Heckley *ECMWF*

!     MODIFICATIONS.
!     --------------
!        Original: 07:06:93
!     E Andersson  06:07:93  - Non-separable structure functions
!     L Isaksen    06:06:95  - Reordering of spectral arrays
!     F.Veerse     13:10:95  - NFLEV/NFLSUR bug correction
!     M.Hamrud     15:12:95  - Removed NOT LNONSEP
!     L Isaksen    05:05:96  - Adapted for Message Passing
!     E Holm       20:08:97  - Call to trmtos/trstom includes ozone
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        M.Hamrud      10-Jan-2004 CY28R1 Cleaning

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

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMDIM   , ONLY : NFLEVG, NSPEC2
USE YOMLAP   , ONLY : NVALUE
USE YOMSPJB  , ONLY : SPJB
USE YOMJG    , ONLY : FP2TPS
USE YOMMP    , ONLY : MYSETN   ,NPTRSV   ,NSPEC2V, NPSP

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

IMPLICIT NONE

INTEGER(KIND=JPIM) :: IN, JSP

REAL(KIND=JPRB) :: ZTPS(NFLEVG+1)
REAL(KIND=JPRB) :: ZSPTG(NFLEVG,NSPEC2V), ZSPSPG(NSPEC2V)
REAL(KIND=JPRB) :: ZSP(NSPEC2)
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

INTERFACE
#include "mxmaop.h"
END INTERFACE

#include "trmtos.intfb.h"
#include "trstom.intfb.h"

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

IF (LHOOK) CALL DR_HOOK('CVARU2I',0,ZHOOK_HANDLE)

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

!*    1.    Transpose data to vertical columns
!           ----------------------------------

IF (NPSP==1) ZSP=SPJB%SPR
CALL TRMTOS(PSPT =SPJB%TEM,PSPSP=ZSP,&
 &          PSPTG=ZSPTG,PSPSPG=ZSPSPG)

!*    2.    Convert from P to T and ln(Ps)
!           ------------------------------

DO JSP=1,NSPEC2V
  IN=NVALUE(JSP+NPTRSV(MYSETN)-1)

  CALL MXMAOP(FP2TPS(1,1,IN),1,NFLEVG+1,&
   & ZSPTG(1,JSP),1,NFLEVG,ZTPS,1,NFLEVG+1,&
   & NFLEVG+1,NFLEVG,1)  

  ZSPTG(1:NFLEVG,JSP) = ZTPS(1:NFLEVG)
  ZSPSPG(JSP) = ZTPS(NFLEVG+1)
ENDDO

!*    3.    Transpose data from vertical columns back to level structure
!           ------------------------------------------------------------

CALL TRSTOM(PSPTG=ZSPTG,PSPSPG=ZSPSPG,&
 &          PSPT =SPJB%TEM,PSPSP=ZSP)
IF (NPSP==1) SPJB%SPR=ZSP

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

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