Index: /trunk/LMDZ.VENUS/libf/phyvenus/photolysis_online.F
===================================================================
--- /trunk/LMDZ.VENUS/libf/phyvenus/photolysis_online.F	(revision 2973)
+++ /trunk/LMDZ.VENUS/libf/phyvenus/photolysis_online.F	(revision 2974)
@@ -2,5 +2,5 @@
 
       subroutine photolysis_online(nlayer, nb_phot_max,
-     $           alt, press, temp, zmmean, 
+     $           alt, press, temp, mmean, 
      $           i_co2, i_co, i_o, i_o1d, i_o2, i_o3,i_h2,
      $           i_oh, i_ho2, i_h2o2, i_h2o,i_h,i_hcl,
@@ -25,5 +25,5 @@
      $                       i_no2,i_no, i_n2, i_n2d, i_h2 
 
-      real, dimension(nlayer), intent(in) :: press, temp,  zmmean    ! pressure (hpa)/temperature (k)/mean molecular mass (g.mol-1)
+      real, dimension(nlayer), intent(in) :: press, temp, mmean      ! pressure (hpa)/temperature (k)/mean molecular mass (g.mol-1)
       real, dimension(nlayer), intent(in) :: alt                     ! altitude (km)
       real, dimension(nlayer,nesp), intent(in) :: rm                 ! mixing ratios 
@@ -47,20 +47,22 @@
 !     atmosphere
 
-      real, dimension(nlayer) :: colinc                              ! air column increment (molecule.cm-2) 
-      real, dimension(nlayer,nw) :: dtrl                             ! rayleigh optical depth 
-      real, dimension(nlayer,nw) :: dtaer                            ! aerosol optical depth 
-      real, dimension(nlayer,nw) :: omaer                            ! aerosol single scattering albedo 
-      real, dimension(nlayer,nw) :: gaer                             ! aerosol asymmetry parameter
-      real, dimension(nlayer,nw) :: dtcld                            ! cloud optical depth 
-      real, dimension(nlayer,nw) :: omcld                            ! cloud single scattering albedo 
-      real, dimension(nlayer,nw) :: gcld                             ! cloud asymmetry parameter
-      real, dimension(nlayer,nw,nabs) :: dtgas                       ! optical depth for each gas 
-      real, dimension(nlayer,nw) :: dagas                            ! total gas optical depth
-      real, dimension(nlayer) :: edir, edn, eup                      ! normalised irradiances
-      real, dimension(nlayer) :: fdir, fdn, fup                      ! normalised actinic fluxes
-      real, dimension(nlayer) :: saflux                              ! total actinic flux
-
-      integer, dimension(0:nlayer) :: nid
-      real, dimension(0:nlayer,nlayer) :: dsdh
+      real, dimension(nlayer+1) :: zpress, zalt, ztemp, zmmean       ! pressure (hpa)/altitude (km)/temperature (k)/mean molecular mass (g.mol-1)
+
+      real, dimension(nlayer+1) :: colinc                            ! air column increment (molecule.cm-2) 
+      real, dimension(nlayer+1,nw) :: dtrl                           ! rayleigh optical depth 
+      real, dimension(nlayer+1,nw) :: dtaer                          ! aerosol optical depth 
+      real, dimension(nlayer+1,nw) :: omaer                          ! aerosol single scattering albedo 
+      real, dimension(nlayer+1,nw) :: gaer                           ! aerosol asymmetry parameter
+      real, dimension(nlayer+1,nw) :: dtcld                          ! cloud optical depth 
+      real, dimension(nlayer+1,nw) :: omcld                          ! cloud single scattering albedo 
+      real, dimension(nlayer+1,nw) :: gcld                           ! cloud asymmetry parameter
+      real, dimension(nlayer+1,nw,nabs) :: dtgas                     ! optical depth for each gas 
+      real, dimension(nlayer+1,nw) :: dagas                          ! total gas optical depth
+      real, dimension(nlayer+1) :: edir, edn, eup                    ! normalised irradiances
+      real, dimension(nlayer+1) :: fdir, fdn, fup                    ! normalised actinic fluxes
+      real, dimension(nlayer+1) :: saflux                            ! total actinic flux
+
+      integer, dimension(0:nlayer+1) :: nid
+      real, dimension(0:nlayer+1,nlayer+1) :: dsdh
 
       integer :: j_o2_o, j_o2_o1d, j_co2_o, j_co2_o1d, j_o3_o1d, j_o3_o,
@@ -72,5 +74,5 @@
      $           a_hocl, a_so2, a_so, a_so3, a_s2, a_clo, a_ocs,
      $           a_cocl2, a_h2so4, a_no2, a_no, a_n2, a_h2
-      integer :: i, ilay, iw, ialt
+      integer :: nlev, i, ilay, ilev, iw, ialt
       real    :: deltaj
       logical :: deutchem
@@ -131,9 +133,27 @@
 !     j_hdo_d   =        ! hdo + hv    -> d + oh
 
+!==== define working vertical grid for the uv radiative code
+
+      nlev = nlayer + 1
+
+      do ilev = 1,nlev-1
+         zpress(ilev) = press(ilev)
+         zalt(ilev)   = alt(ilev)
+         ztemp(ilev)  = temp(ilev)
+         zmmean(ilev) = mmean(ilev)
+      end do
+
+      zpress(nlev) = 0.                  ! top of the atmosphere
+      zalt(nlev)   = zalt(nlev-1) + (zalt(nlev-1) - zalt(nlev-2))
+      ztemp(nlev)  = ztemp(nlev-1)
+      zmmean(nlev) = zmmean(nlev-1)
+
 !==== air column increments and rayleigh optical depth
 
-      call setair(nlayer, nw, wl, wc, press, temp, zmmean, colinc, dtrl)
+      call setair(nlev, nw, wl, wc, zpress, ztemp, zmmean, colinc, dtrl)
 
 !==== set temperature-dependent cross-sections and optical depths
+
+      dtgas(:,:,:) = 0.
 
 !     o2:
@@ -141,5 +161,6 @@
       call seto2(nphot, nlayer, nw, wc, mopt, temp, xso2_150, xso2_200, 
      $           xso2_250, xso2_300, yieldo2, j_o2_o, j_o2_o1d,
-     $           colinc, rm(:,i_o2), dtgas(:,:,a_o2), sj)
+     $           colinc(1:nlayer), rm(:,i_o2), 
+     $           dtgas(1:nlayer,:,a_o2), sj)
 
 !     co2:
@@ -147,22 +168,24 @@
       call setco2(nphot, nlayer, nw, wc, temp, xsco2_195, xsco2_295, 
      $            xsco2_370, yieldco2, j_co2_o, j_co2_o1d,
-     $            colinc, rm(:,i_co2), dtgas(:,:,a_co2), sj)
+     $            colinc(1:nlayer), rm(:,i_co2), 
+     $            dtgas(1:nlayer,:,a_co2), sj)
      
 !     o3:
 
       call seto3(nphot, nlayer, nw, wc, temp, xso3_218, xso3_298, 
-     $           j_o3_o, j_o3_o1d,
-     $           colinc, rm(:,i_o3), dtgas(:,:,a_o3), sj)
+     $           j_o3_o, j_o3_o1d, colinc(1:nlayer), rm(:,i_o3), 
+     $           dtgas(1:nlayer,:,a_o3), sj)
 
 !     h2o2:
 
       call seth2o2(nphot, nlayer, nw, wc, temp, xsh2o2, j_h2o2,
-     $             colinc, rm(:,i_h2o2), dtgas(:,:,a_h2o2), sj)
+     $             colinc(1:nlayer), rm(:,i_h2o2), 
+     $             dtgas(1:nlayer,:,a_h2o2), sj)
 
 !     so2:
 
       call setso2(nphot, nlayer, nw, wc, temp, xsso2_200,xsso2_298,
-     $            xsso2_360, j_so2,colinc, rm(:,i_so2),
-     $            dtgas(:,:,a_so2), sj)
+     $            xsso2_360, j_so2,colinc(1:nlayer), rm(:,i_so2),
+     $            dtgas(1:nlayer,:,a_so2), sj)
 
 !     no2:
@@ -170,5 +193,6 @@
       call setno2(nphot, nlayer, nw, wc, temp, xsno2, xsno2_220,
      $            xsno2_294, yldno2_248, yldno2_298, j_no2,
-     $            colinc, rm(:,i_no2), dtgas(:,:,a_no2), sj)
+     $            colinc(1:nlayer), rm(:,i_no2), 
+     $            dtgas(1:nlayer,:,a_no2), sj)
 
 !==== temperature independent optical depths and cross-sections
@@ -236,12 +260,12 @@
 
 !      if (deutchem) then
-!         do ilay=1,nlayer
-!            do iw=1,nw-1
-!               !Two chanels for HDO, with same cross section
+!         do ilay = 1,nlayer
+!            do iw = 1,nw-1
+!               !Two chanels for hdo, with same cross section
 !               sj(ilay,iw,j_hdo_od) = 0.5*xshdo(iw) ! hdo -> od + h
 !               sj(ilay,iw,j_hdo_d)  = 0.5*xshdo(iw) ! hdo -> d + oh
-!            enddo
-!         enddo
-!      endif
+!            end do
+!         end do
+!      end if
 
 !==== set aerosol properties and optical depth
@@ -249,13 +273,13 @@
       tau = 0. ! no solid aerosols for the present time
 
-      call setaer(nlayer,alt,tau,nw,dtaer,omaer,gaer)
+      call setaer(nlev,zalt,tau,nw,dtaer,omaer,gaer)
 
 !==== set cloud properties and optical depth
 
-      call setcld(nlayer,alt,nw,wl,dtcld,omcld,gcld)
+      call setcld(nlev,zalt,nw,wl,dtcld,omcld,gcld)
 
 !==== slant path lengths in spherical geometry
 
-      call sphers(nlayer,alt,sza,dsdh,nid)
+      call sphers(nlev,zalt,sza,dsdh,nid)
 
 !==== solar flux at venus
@@ -280,5 +304,5 @@
 !     dir = direct beam, dn = down-welling diffuse, up = up-welling diffuse
 
-         call rtlink(nlayer, nw, iw, albedo(iw), sza, dsdh, nid, dtrl,
+         call rtlink(nlev, nw, iw, albedo(iw), sza, dsdh, nid, dtrl,
      $               dagas, dtcld, omcld, gcld, dtaer, omaer, gaer,
      $               edir, edn, eup, fdir, fdn, fup)
@@ -348,5 +372,5 @@
          colinc(ilev) = avo*0.1*dp/(zmmean(ilev)*g)
       end do
-      colinc(nlev) = avo*0.1*press(nlev)*100./(zmmean(nlev)*g)
+      colinc(nlev) = 0.
 
       do iw = 1, nw - 1
@@ -834,5 +858,5 @@
 !==============================================================================
 
-      subroutine setaer(nlayer,alt,tau,nw,dtaer,omaer,gaer)
+      subroutine setaer(nlev,zalt,tau,nw,dtaer,omaer,gaer)
 
 !-----------------------------------------------------------------------------*
@@ -846,19 +870,19 @@
 !     input
 
-      integer :: nlayer                              ! number of vertical layers
-      integer :: nw                                  ! number of wavelength grid points
-      real, dimension(nlayer) :: alt                 ! altitude (km)
-      real :: tau                                    ! integrated aerosol optical depth at the surface
+      integer :: nlev                              ! number of vertical layers
+      integer :: nw                                ! number of wavelength grid points
+      real, dimension(nlev) :: zalt                ! altitude (km)
+      real :: tau                                  ! integrated aerosol optical depth at the surface
 
 !     output 
 
-      real, dimension(nlayer,nw) :: dtaer            ! aerosol optical depth 
-      real, dimension(nlayer,nw) :: omaer            ! aerosol single scattering albedo 
-      real, dimension(nlayer,nw) :: gaer             ! aerosol asymmetry parameter
+      real, dimension(nlev,nw) :: dtaer            ! aerosol optical depth 
+      real, dimension(nlev,nw) :: omaer            ! aerosol single scattering albedo 
+      real, dimension(nlev,nw) :: gaer             ! aerosol asymmetry parameter
 
 !     local
 
-      integer :: ilay, iw
-      real, dimension(nlayer) :: aer                                 ! dust extinction
+      integer :: ilev, iw
+      real, dimension(nlev) :: aer                 ! dust extinction
       real :: omega, g, scaleh, gamma
       real :: dz, tautot, q0
@@ -879,15 +903,15 @@
 
        tautot = 0.
-       do ilay = 1, nlayer-1
-          dz = alt(ilay+1) - alt(ilay)
-          tautot = tautot + exp(gamma*(1. - exp(alt(ilay)/scaleh)))*dz
+       do ilev = 1, nlev-1
+          dz = zalt(ilev+1) - zalt(ilev)
+          tautot = tautot + exp(gamma*(1. - exp(zalt(ilev)/scaleh)))*dz
        end do
       
        q0 = tau/tautot
-       do ilay = 1, nlayer-1
-          dz = alt(ilay+1) - alt(ilay)
-          dtaer(ilay,:) = q0*exp(gamma*(1. - exp(alt(ilay)/scaleh)))*dz
-          omaer(ilay,:) = omega
-          gaer(ilay,:)  = g
+       do ilev = 1, nlev-1
+          dz = zalt(ilev+1) - zalt(ilev)
+          dtaer(ilev,:) = q0*exp(gamma*(1. - exp(zalt(ilev)/scaleh)))*dz
+          omaer(ilev,:) = omega
+          gaer(ilev,:)  = g
        end do
 
