*=*=*=*= lwu.html =*=*=*=*
subroutine lwu

subroutine lwu


      subroutine lwu (kdlon,kflev,dp,plev,tlay,paer
     .                ,aer_u,aer_t,co2_u,co2_up)

c----------------------------------------------------------------------
c     LWU   computes  - co2: longwave effective absorber amounts including
c                      pressure and temperature effects
c                     - aerosols: amounts for every band
c                                transmission for bandes 1 and 2 of co2
c----------------------------------------------------------------------

c-----------------------------------------------------------------------
c ATTENTION AUX UNITES:
c le facteur 10*rg fait passer des kg m-2 aux g cm-2
c-----------------------------------------------------------------------
c! modif diffusion
c! on ne change rien a la bande CO2 : les quantites d'absorbant CO2
c! sont multipliees par 1.66
c! pview= 1/cos(teta0)=1.66
c-----------------------------------------------------------------------

      implicit none

#include "dimensions.h"
#include "dimphys.h"
#include "dimradmars.h"

#include "yomcst.h"
#include "yomrad.h"
#include "yomaer.h"
#include "yomlw.h"
#include "yomsw.h"
#include "yomrdu.h"

c----------------------------------------------------------------------
c         0.1   arguments
c               ---------
c                                                            inputs:
c                                                            -------
      integer kdlon            ! part of ngrid
      integer kflev            ! part of nalyer

      real dp (ndlo2,kflev)         ! layer pressure thickness (Pa)
      real plev (ndlo2,kflev+1)     ! level pressure (Pa)
      real tlay (ndlo2,kflev)       ! layer temperature (K)
      real paer (ndlo2,kflev)       ! optical thickness of the aerosols

c                                                            outputs:
c                                                            --------
      real aer_u (ndlo2,nir,kflev+1)     ! absorber amounts (aer)
      real aer_t (ndlo2,nuco2,kflev+1)   ! transmission (aer)
      real co2_u (ndlo2,nuco2,kflev+1)   ! absorber amounts (co2)
      real co2_up (ndlo2,nuco2,kflev+1)  ! idem scaled by the pressure (co2)

c----------------------------------------------------------------------
c         0.2   local arrays
c               ------------

      integer jl,jk,jkl,ja

      real co2c           ! co2 concentration (pa/pa)
      real pview          ! cosecant of viewing angle
      real pref           ! reference pressure (1013 mb = 101325 Pa)
      real tx,tx2
      real phi (ndlon,nuco2)
      real psi (ndlon,nuco2)
      real plev2 (ndlon,nflev+1)
      real zzz

c************************************************************************
c----------------------------------------------------------------------
c         0.3  Initialisation
c               -------------

      pview = 1.66
      co2c = 0.95
      pref = 101325.

      do jk=1,kflev+1
        do jl=1,kdlon
          plev2(jl,jk)=plev(jl,jk)*plev(jl,jk)
        enddo
      enddo

c----------------------------------------------------------------------
c         1.0   cumulative (aerosol) amounts (for every band)
c               ----------------------------

      jk=kflev+1
      do ja=1,nir
        do jl = 1 , kdlon
          aer_u(jl,ja,jk)=0.
        enddo
      enddo

      do jk=1,kflev
                      jkl=kflev+1-jk
        do ja=1,nir
          do jl=1,kdlon
            aer_u(jl,ja,jkl)=aer_u(jl,ja,jkl+1)
     .                  + qextaer(ja)*paer(jl,jkl)
          enddo
        enddo
      enddo

c----------------------------------------------------------------------
c         1.0   bands 1 and 2 of co2
c               --------------------

      jk=kflev+1
      do ja=1,nuco2
        do jl = 1 , kdlon
          co2_u(jl,ja,jk)=0.
          co2_up(jl,ja,jk)=0.
          aer_t(jl,ja,jk)=1.
        enddo
      enddo

      do jk=1,kflev
                       jkl=kflev+1-jk
        do ja=1,nuco2
          do jl=1,kdlon

c                 introduces temperature effects on absorber(co2) amounts
c                 -------------------------------------------------------
            tx = sign(min(abs(tlay(jl,jkl)-tref),70.)
     .         ,tlay(jl,jkl)-tref)
            tx2=tx*tx
            phi(jl,ja)=at(1,ja)*tx+bt(1,ja)*tx2
            psi(jl,ja)=at(2,ja)*tx+bt(2,ja)*tx2
            phi(jl,ja)=exp(phi(jl,ja)/cst_voigt(2,ja))
            psi(jl,ja)=exp(2.*psi(jl,ja))

c                                        cumulative absorber(co2) amounts
c                                        --------------------------------
            co2_u(jl,ja,jkl)=co2_u(jl,ja,jkl+1)
     .     +         pview/(10*rg)*phi(jl,ja)*dp(jl,jkl)*co2c

            co2_up(jl,ja,jkl)=co2_up(jl,ja,jkl+1)
     .     +         pview/(10*rg*2*pref)*psi(jl,ja)
     .     *        (plev2(jl,jkl)-plev2(jl,jkl+1))*co2c


c                                                  (aerosol) transmission
c                                                  ----------------------
c   on calcule directement les transmissions pour les aerosols.
c   on multiplie le Qext  par 1-omega dans la bande du CO2.
c   et pourquoi pas d'abord?  hourdin@lmd.ens.fr

           zzz=pview*(1.-omegaer(ja))
           aer_t(jl,ja,jkl)=exp(-zzz*aer_u(jl,ja,jkl))

          enddo
        enddo
      enddo

c----------------------------------------------------------------------
      return
      end