SUBROUTINE RADGHG ( KIDIA, KFDIA, KLON, KLEV, &
  & KRINT, KDLON, KSHIFT,&
  & PAPRS, PGEMU,&
  & PCO2 , PCH4 , PN2O , PNO2 , PC11 , PC12, POZO, PC22, PCL4 )

!***********************************************************************
! CAUTION: THIS ROUTINE WORKS ONLY ON A NON-ROTATED, UNSTRETCHED GRID
!***********************************************************************

!**** *RADGHG* - COMPUTES DISTRIBUTION OF GREENHOUSE GASES FROM CLIMATOLOGY

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

!**   INTERFACE.
!     ----------
!        CALL *RADGHG* FROM *RADINTG*

!        EXPLICIT ARGUMENTS :
!        --------------------
!     ==== INPUTS ===
!     ==== OUTPUTS ===

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

!     METHOD.
!     -------

!     EXTERNALS.
!     ----------

!          NONE

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

!        SEE RADIATION'S PART OF THE MODEL'S DOCUMENTATION AND
!        ECMWF RESEARCH DEPARTMENT DOCUMENTATION OF THE "I.F.S"

!     AUTHOR.
!     -------
!     J.-J. MORCRETTE  E.C.M.W.F.  20080424

!     MODIFICATIONS.
!     --------------
!        D.SALMOND   ECMWF 1999-06-14  Optimisation
!        M.Hamrud    ECMWF 2003-10-01  CY28 Cleaning
!        JJMorcrette ECMWF 20090217    vertical interpolation from 91 lev climatol.

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

USE PARKIND1  ,ONLY : JPIM ,   JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMCT0    ,ONLY : NPRINTLEV, NSTART
USE YOERADGHG , ONLY : RSINCL ,RCLCO2, RCLCH4, RCLN2O, RCLNO2, &
  & RCLC11, RCLC12, RCLOZO, RCLC22, RCLCCL4, RCLPR
USE YOERAD    , ONLY : NGHGRAD
USE YOMCT3    , ONLY : NSTEP
USE YOMLUN    , ONLY : NULOUT

IMPLICIT NONE

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

!*       0.1   ARGUMENTS.
!              ----------

INTEGER(KIND=JPIM),INTENT(IN)    :: KLON 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEV 
INTEGER(KIND=JPIM),INTENT(IN)    :: KDLON 
INTEGER(KIND=JPIM),INTENT(IN)    :: KIDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KRINT 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSHIFT 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRS(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEMU(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCO2(KLON,KLEV), PCH4(KLON,KLEV), PN2O(KLON,KLEV), &
  & PNO2(KLON,KLEV), PC11(KLON,KLEV), PC12(KLON,KLEV), POZO(KLON,KLEV), &
  & PC22(KLON,KLEV), PCL4(KLON,KLEV)

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

!*       0.2   LOCAL ARRAYS.
!              -------------

REAL(KIND=JPRB) :: ZCO2(KLON,0:91), ZCH4(KLON,0:91), ZN2O(KLON,0:91), &
  & ZNO2(KLON,0:91), ZC11(KLON,0:91), ZC12(KLON,0:91), ZOZO(KLON,0:91), &
  & ZC22(KLON,0:91), ZCL4(KLON,0:91)
REAL(KIND=JPRB) :: ZCO2VI(KLON,0:91), ZCH4VI(KLON,0:91), ZN2OVI(KLON,0:91), &
  & ZNO2VI(KLON,0:91), ZC11VI(KLON,0:91), ZC12VI(KLON,0:91), ZOZOVI(KLON,0:91), &
  & ZC22VI(KLON,0:91), ZCL4VI(KLON,0:91)
REAL(KIND=JPRB) :: ZVICO2(KLON,0:KLEV), ZVICH4(KLON,0:KLEV), &
  & ZVIN2O(KLON,0:KLEV), ZVINO2(KLON,0:KLEV), ZVIC11(KLON,0:KLEV), &
  & ZVIC12(KLON,0:KLEV), ZVIOZO(KLON,0:KLEV), ZVIC22(KLON,0:KLEV), ZVICL4(KLON,0:KLEV)
REAL(KIND=JPRB) :: ZSINLAT(KLON)

INTEGER(KIND=JPIM) :: IL, INLA, JC, JI, JK, JL

REAL(KIND=JPRB) :: ZDP, ZINT, ZSIN

REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"
!     ------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('RADGHG',0,ZHOOK_HANDLE)

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

!*         1.     LATITUDE INDEX WITHIN OZONE CLIMATOLOGY
!                 ---------------------------------------

DO JI=KIDIA,KFDIA
  ZSIN=PGEMU(JI)
  INLA=0
  ZSINLAT(JI)=-9999._JPRB
  DO JL=63,1,-1
    IF (ZSIN <= RSINCL(JL+1).AND.ZSIN >= RSINCL(JL)) THEN
      INLA=JL
    ENDIF
  ENDDO
  IF (ZSIN > RSINCL(64)) INLA=64
  IF (ZSIN < RSINCL(1)) INLA=1
  IF (INLA == 0) THEN
    CALL ABOR1(' Problem with lat. interpolation in radozc!')
  ENDIF
  ZSINLAT(JI)=(ZSIN-RSINCL(INLA))/(RSINCL(INLA+1)-RSINCL(INLA))

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

!*         2.     LATITUDE INTERPOLATED FIELD
!                 ---------------------------

  IF(INLA == 64 .OR. INLA == 1) THEN
    DO JC=0,91
      ZCO2(JI,JC)=RCLCO2(INLA,JC)
      ZCH4(JI,JC)=RCLCH4(INLA,JC)
      ZN2O(JI,JC)=RCLN2O(INLA,JC)
      ZNO2(JI,JC)=RCLNO2(INLA,JC)
      ZC11(JI,JC)=RCLC11(INLA,JC)
      ZC12(JI,JC)=RCLC12(INLA,JC)
      ZOZO(JI,JC)=RCLOZO(INLA,JC)
      ZC22(JI,JC)=RCLC22(INLA,JC)
      ZCL4(JI,JC)=RCLCCL4(INLA,JC)
    ENDDO
  ELSE
    DO JC=0,91
      ZCO2(JI,JC)=RCLCO2(INLA,JC)+ZSINLAT(JI)*(RCLCO2(INLA+1,JC)-RCLCO2(INLA,JC))
      ZCH4(JI,JC)=RCLCH4(INLA,JC)+ZSINLAT(JI)*(RCLCH4(INLA+1,JC)-RCLCH4(INLA,JC))
      ZN2O(JI,JC)=RCLN2O(INLA,JC)+ZSINLAT(JI)*(RCLN2O(INLA+1,JC)-RCLN2O(INLA,JC))
      ZNO2(JI,JC)=RCLNO2(INLA,JC)+ZSINLAT(JI)*(RCLNO2(INLA+1,JC)-RCLNO2(INLA,JC))
      ZC11(JI,JC)=RCLC11(INLA,JC)+ZSINLAT(JI)*(RCLC11(INLA+1,JC)-RCLC11(INLA,JC))
      ZC12(JI,JC)=RCLC12(INLA,JC)+ZSINLAT(JI)*(RCLC12(INLA+1,JC)-RCLC12(INLA,JC))
      ZOZO(JI,JC)=RCLOZO(INLA,JC)+ZSINLAT(JI)*(RCLOZO(INLA+1,JC)-RCLOZO(INLA,JC))
      ZC22(JI,JC)=RCLC22(INLA,JC)+ZSINLAT(JI)*(RCLC22(INLA+1,JC)-RCLC22(INLA,JC))
      ZCL4(JI,JC)=RCLCCL4(INLA,JC)+ZSINLAT(JI)*(RCLCCL4(INLA+1,JC)-RCLCCL4(INLA,JC))
    ENDDO
  ENDIF
ENDDO

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

!*    3.     ACCUMULATE FROM TOP TO BOTTOM THE LATITUDE INTERPOLATED FIELDS
!            --------------------------------------------------------------

ZCO2VI(KIDIA:KFDIA,0)=0._JPRB
ZCH4VI(KIDIA:KFDIA,0)=0._JPRB
ZN2OVI(KIDIA:KFDIA,0)=0._JPRB
ZNO2VI(KIDIA:KFDIA,0)=0._JPRB
ZC11VI(KIDIA:KFDIA,0)=0._JPRB
ZC12VI(KIDIA:KFDIA,0)=0._JPRB
ZOZOVI(KIDIA:KFDIA,0)=0._JPRB
ZC22VI(KIDIA:KFDIA,0)=0._JPRB
ZCL4VI(KIDIA:KFDIA,0)=0._JPRB
DO JC=1,91
  ZCO2VI(KIDIA:KFDIA,JC)=ZCO2VI(KIDIA:KFDIA,JC-1)+ZCO2(KIDIA:KFDIA,JC)
  ZCH4VI(KIDIA:KFDIA,JC)=ZCH4VI(KIDIA:KFDIA,JC-1)+ZCH4(KIDIA:KFDIA,JC)
  ZN2OVI(KIDIA:KFDIA,JC)=ZN2OVI(KIDIA:KFDIA,JC-1)+ZN2O(KIDIA:KFDIA,JC)
  ZNO2VI(KIDIA:KFDIA,JC)=ZNO2VI(KIDIA:KFDIA,JC-1)+ZNO2(KIDIA:KFDIA,JC)
  ZC11VI(KIDIA:KFDIA,JC)=ZC11VI(KIDIA:KFDIA,JC-1)+ZC11(KIDIA:KFDIA,JC)
  ZC12VI(KIDIA:KFDIA,JC)=ZC12VI(KIDIA:KFDIA,JC-1)+ZC12(KIDIA:KFDIA,JC)
  ZOZOVI(KIDIA:KFDIA,JC)=ZOZOVI(KIDIA:KFDIA,JC-1)+ZOZO(KIDIA:KFDIA,JC)
  ZC22VI(KIDIA:KFDIA,JC)=ZC22VI(KIDIA:KFDIA,JC-1)+ZC22(KIDIA:KFDIA,JC)
  ZCL4VI(KIDIA:KFDIA,JC)=ZCL4VI(KIDIA:KFDIA,JC-1)+ZCL4(KIDIA:KFDIA,JC)
ENDDO

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

!*    4.     REDISTRIBUTE THE VERTIC. INTEGR. CLIM. GHG ON THE MODEL GRID
!            ------------------------------------------------------------

JK=0
ZVICO2(KIDIA:KFDIA,0)=0._JPRB
ZVICH4(KIDIA:KFDIA,0)=0._JPRB
ZVIN2O(KIDIA:KFDIA,0)=0._JPRB
ZVINO2(KIDIA:KFDIA,0)=0._JPRB
ZVIC11(KIDIA:KFDIA,0)=0._JPRB
ZVIC12(KIDIA:KFDIA,0)=0._JPRB
ZVIOZO(KIDIA:KFDIA,0)=0._JPRB
ZVIC22(KIDIA:KFDIA,0)=0._JPRB
ZVICL4(KIDIA:KFDIA,0)=0._JPRB

DO JK=1,KLEV
  IL=KSHIFT
  DO JL=KIDIA,KFDIA,KRINT
    IL=IL+1
    DO JC=0,90
      IF( PAPRS(JL,JK) >= RCLPR(JC) .AND. PAPRS(JL,JK) < RCLPR(JC+1)) THEN
        ZINT=(PAPRS(JL,JK)-RCLPR(JC))/(RCLPR(JC+1)-RCLPR(JC)) 
        ZVICO2(IL,JK) = ZCO2VI(JL,JC) + ZINT * (ZCO2VI(JL,JC+1)-ZCO2VI(JL,JC))
        ZVICH4(IL,JK) = ZCH4VI(JL,JC) + ZINT * (ZCH4VI(JL,JC+1)-ZCH4VI(JL,JC))
        ZVIN2O(IL,JK) = ZN2OVI(JL,JC) + ZINT * (ZN2OVI(JL,JC+1)-ZN2OVI(JL,JC))
        ZVINO2(IL,JK) = ZNO2VI(JL,JC) + ZINT * (ZNO2VI(JL,JC+1)-ZNO2VI(JL,JC))
        ZVIC11(IL,JK) = ZC11VI(JL,JC) + ZINT * (ZC11VI(JL,JC+1)-ZC11VI(JL,JC))
        ZVIC12(IL,JK) = ZC12VI(JL,JC) + ZINT * (ZC12VI(JL,JC+1)-ZC12VI(JL,JC))
        ZVIOZO(IL,JK) = ZOZOVI(JL,JC) + ZINT * (ZOZOVI(JL,JC+1)-ZOZOVI(JL,JC))
        ZVIC22(IL,JK) = ZC22VI(JL,JC) + ZINT * (ZC22VI(JL,JC+1)-ZC22VI(JL,JC))
        ZVICL4(IL,JK) = ZCL4VI(JL,JC) + ZINT * (ZCL4VI(JL,JC+1)-ZCL4VI(JL,JC))
      ENDIF
    ENDDO
  ENDDO
ENDDO

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

!*    5.     COMPUTE THE MASS MIXING RATIO 
!            -----------------------------

DO JK=1,KLEV
  IL=KSHIFT
  DO JL=KIDIA,KFDIA,KRINT
    IL=IL+1
    ZDP=(PAPRS(JL,JK)-PAPRS(JL,JK-1))
    PCO2(IL,JK)=(ZVICO2(IL,JK)-ZVICO2(IL,JK-1)) / ZDP
    PCH4(IL,JK)=(ZVICH4(IL,JK)-ZVICH4(IL,JK-1)) / ZDP
    PN2O(IL,JK)=(ZVIN2O(IL,JK)-ZVIN2O(IL,JK-1)) / ZDP
    PNO2(IL,JK)=(ZVINO2(IL,JK)-ZVINO2(IL,JK-1)) / ZDP
    PC11(IL,JK)=(ZVIC11(IL,JK)-ZVIC11(IL,JK-1)) / ZDP
    PC12(IL,JK)=(ZVIC12(IL,JK)-ZVIC12(IL,JK-1)) / ZDP
    POZO(IL,JK)=(ZVIOZO(IL,JK)-ZVIOZO(IL,JK-1)) / ZDP
    PC22(IL,JK)=(ZVIC22(IL,JK)-ZVIC22(IL,JK-1)) / ZDP
    PCL4(IL,JK)=(ZVICL4(IL,JK)-ZVICL4(IL,JK-1)) / ZDP
  ENDDO
ENDDO

IF (NSTEP == NSTART.AND.NPRINTLEV>0) THEN
  WRITE(NULOUT,9011) NGHGRAD,KLEV
9011 FORMAT(1X,'NGHGRAD=',I3,' climatologies on',I4,' levels')
! DO JK=1,KLEV,10
!   WRITE(NULOUT,9012) JK,(PCO2(JL,JK),JL=KSHIFT+1,IL)
9012 FORMAT(1X,'RADGHG CO2 ',I3,(10E12.5))
! ENDDO
! DO JK=1,KLEV,10
!   WRITE(NULOUT,9013) JK,(PCH4(JL,JK),JL=KSHIFT+1,IL)
9013 FORMAT(1X,'RADGHG CH4 ',I3,(10E12.5))
! ENDDO
! DO JK=1,KLEV,10
!   WRITE(NULOUT,9014) JK,(PN2O(JL,JK),JL=KSHIFT+1,IL)
9014 FORMAT(1X,'RADGHG N2O ',I3,(10E12.5))
! ENDDO
! DO JK=1,KLEV,10
!   WRITE(NULOUT,9015) JK,(POZO(JL,JK),JL=KSHIFT+1,IL)
9015 FORMAT(1X,'RADGHG OZO ',I3,(10E12.5))
! ENDDO
! DO JK=1,KLEV,10
!   WRITE(NULOUT,9016) JK,(PC11(JL,JK),JL=KSHIFT+1,IL)
9016 FORMAT(1X,'RADGHG C11 ',I3,(10E12.5))
! ENDDO
! DO JK=1,KLEV,10
!   WRITE(NULOUT,9017) JK,(PC12(JL,JK),JL=KSHIFT+1,IL)
9017 FORMAT(1X,'RADGHG C12 ',I3,(10E12.5))
! ENDDO
! DO JK=1,KLEV,10
!   WRITE(NULOUT,9018) JK,(PC22(JL,JK),JL=KSHIFT+1,IL)
9018 FORMAT(1X,'RADGHG C22 ',I3,(10E12.5))
! ENDDO
! DO JK=1,KLEV,10
!   WRITE(NULOUT,9019) JK,(PCL4(JL,JK),JL=KSHIFT+1,IL)
9019 FORMAT(1X,'RADGHG CL4 ',I3,(10E12.5))
! ENDDO
ENDIF

!     ------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('RADGHG',1,ZHOOK_HANDLE)
END SUBROUTINE RADGHG
