Index: /trunk/LMDZ.GENERIC/libf/aeronostd/calchim_asis.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/calchim_asis.F90	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/calchim_asis.F90	(revision 1796)
@@ -0,0 +1,532 @@
+      subroutine calchim_asis(ngrid,nlayer,nq,                              &
+                         ptimestep,pplay,pplev,pt,pdt,dist_sol,mu0,fract,   &
+                         zzlev,zzlay,zday,pq,pdq,dqchim,dqschim,            &
+                         tauref,co2ice,                                     &
+                         pu,pdu,pv,pdv,surfdust,surfice)
+
+      use tracer_h, only:   igcm_co2, igcm_co, igcm_o, igcm_o1d, igcm_o2, &
+                            igcm_o3, igcm_h, igcm_h2, igcm_oh, igcm_ho2,  &
+                            igcm_h2o2, igcm_ch4, igcm_n2, igcm_h2o_vap,   &
+                            igcm_n, igcm_no, igcm_no2, igcm_n2d,   &
+                            mmol
+
+      use conc_mod, only: mmean ! mean molecular mass of the atmosphere
+      USE comcstfi_mod
+      use callkeys_mod
+
+      implicit none
+
+!=======================================================================
+!
+!   subject:
+!   --------
+!
+!  Prepare the call for the photochemical module, and send back the
+!  tendencies from photochemistry in the chemical species mass mixing ratios
+!
+!   Author:   Sebastien Lebonnois (08/11/2002)
+!   -------
+!    update 12/06/2003 for water ice clouds and compatibility with dust
+!    update 07/2003 for coupling with thermosphere (Monica Angelats-i-Coll)
+!    update 03/05/2005 cosmetic changes (Franck Lefevre)
+!    update sept. 2008 identify tracers by their names (Ehouarn Millour)
+!    update 05/12/2011 synchronize with latest version of chemistry (Franck Lefevre)
+!    update 16/03/2012 optimization (Franck Lefevre)
+!    update 11/12/2013 optimization (Franck Lefevre)
+!
+!   Arguments:
+!   ----------
+!
+!  Input:
+!
+!    ptimestep                  timestep (s)
+!    pplay(ngrid,nlayer)    Pressure at the middle of the layers (Pa)
+!    pplev(ngrid,nlayer+1)  Intermediate pressure levels (Pa)
+!    pt(ngrid,nlayer)       Temperature (K)
+!    pdt(ngrid,nlayer)      Temperature tendency (K)
+!    pu(ngrid,nlayer)       u component of the wind (ms-1)
+!    pdu(ngrid,nlayer)      u component tendency (K)
+!    pv(ngrid,nlayer)       v component of the wind (ms-1)
+!    pdv(ngrid,nlayer)      v component tendency (K)
+!    dist_sol                   distance of the sun (AU)
+!    mu0(ngrid)               cos of solar zenith angle (=1 when sun at zenith)
+!    fract(ngrid)           day fraction (for diurnal=false)
+!    pq(ngrid,nlayer,nq)  Advected fields, ie chemical species here
+!    pdq(ngrid,nlayer,nq) Previous tendencies on pq
+!    tauref(ngrid)            Optical depth at 7 hPa
+!    co2ice(ngrid)            co2 ice surface layer (kg.m-2)
+!    surfdust(ngrid,nlayer) dust surface area (m2/m3)
+!    surfice(ngrid,nlayer)  ice surface area (m2/m3)
+!
+!  Output:
+!
+!    dqchim(ngrid,nlayer,nq) ! tendencies on pq due to chemistry
+!    dqschim(ngrid,nq)         ! tendencies on qsurf 
+!
+!=======================================================================
+
+#include "chimiedata.h"
+
+!     input:
+
+      integer,intent(in) :: ngrid    ! number of atmospheric columns
+      integer,intent(in) :: nlayer   ! number of atmospheric layers
+      integer,intent(in) :: nq       ! number of tracers
+      real :: ptimestep
+      real :: pplay(ngrid,nlayer)    ! pressure at the middle of the layers
+      real :: zzlay(ngrid,nlayer)    ! pressure at the middle of the layers
+      real :: pplev(ngrid,nlayer+1)  ! intermediate pressure levels
+      real :: zzlev(ngrid,nlayer+1)  ! altitude at layer boundaries
+      real :: pt(ngrid,nlayer)       ! temperature
+      real :: pdt(ngrid,nlayer)      ! temperature tendency
+      real :: pu(ngrid,nlayer)       ! u component of the wind (m.s-1)
+      real :: pdu(ngrid,nlayer)      ! u component tendency
+      real :: pv(ngrid,nlayer)       ! v component of the wind (m.s-1)
+      real :: pdv(ngrid,nlayer)      ! v component tendency
+      real :: dist_sol               ! distance of the sun (AU)
+      real :: mu0(ngrid)             ! cos of solar zenith angle (=1 when sun at zenith)
+      real :: pq(ngrid,nlayer,nq)    ! tracers mass mixing ratio
+      real :: pdq(ngrid,nlayer,nq)   ! previous tendencies
+      real :: zday                   ! date (time since Ls=0, in martian days)
+      real :: tauref(ngrid)          ! optical depth at 7 hPa
+      real :: co2ice(ngrid)          ! co2 ice surface layer (kg.m-2)
+      real :: surfdust(ngrid,nlayer) ! dust surface area (m2/m3)
+      real :: surfice(ngrid,nlayer)  !  ice surface area (m2/m3)
+
+!     output:
+
+      real :: dqchim(ngrid,nlayer,nq)   ! tendencies on pq due to chemistry
+      real :: dqschim(ngrid,nq)         ! tendencies on qsurf 
+
+!     local variables:
+
+      integer,save :: nbq                   ! number of tracers used in the chemistry
+      integer,allocatable,save :: niq(:)    ! array storing the indexes of the tracers
+      integer :: iloc(1)                    ! index of major species
+      integer :: ig,l,i,iq,iqmax
+      integer :: foundswitch, lswitch
+      integer,save :: chemthermod
+
+      integer,save :: i_co2  = 0
+      integer,save :: i_co   = 0
+      integer,save :: i_o    = 0
+      integer,save :: i_o1d  = 0
+      integer,save :: i_o2   = 0
+      integer,save :: i_o3   = 0
+      integer,save :: i_h    = 0
+      integer,save :: i_h2   = 0
+      integer,save :: i_oh   = 0
+      integer,save :: i_ho2  = 0
+      integer,save :: i_h2o2 = 0
+      integer,save :: i_ch4  = 0
+      integer,save :: i_n2   = 0
+      integer,save :: i_h2o  = 0
+      integer,save :: i_n    = 0
+      integer,save :: i_no    = 0
+      integer,save :: i_no2    = 0
+      integer,save :: i_n2d    = 0
+
+      integer :: ig_vl1
+
+      real    :: latvl1, lonvl1
+      real    :: zq(ngrid,nlayer,nq)   ! pq+pdq*ptimestep before chemistry
+                                       ! new mole fraction after
+      real    :: zt(ngrid,nlayer)      ! temperature
+      real    :: zu(ngrid,nlayer)      ! u component of the wind
+      real    :: zv(ngrid,nlayer)      ! v component of the wind
+      real    :: taucol                ! optical depth at 7 hPa
+
+      logical,save :: firstcall = .true.
+      logical,save :: depos = .false.  ! switch for dry deposition
+
+!     for each column of atmosphere:
+
+      real :: zpress(nlayer)       ! Pressure (mbar)
+      real :: zdens(nlayer)        ! Density  (cm-3)
+      real :: ztemp(nlayer)        ! Temperature (K)
+      real :: zlocal(nlayer)       ! Altitude (km)
+      real :: zycol(nlayer,nq)     ! Composition (mole fractions)
+      real :: zmmean(nlayer)       ! Mean molecular mass (g.mole-1)
+      real :: szacol               ! Solar zenith angle
+      real :: fract(ngrid)         ! day fraction
+      real :: fractcol             ! day fraction
+      real :: surfice1d(nlayer)    ! Ice surface area (cm2/cm3)
+      real :: surfdust1d(nlayer)   ! Dust surface area (cm2/cm3)
+      real :: jo3(nlayer)          ! Photodissociation rate O3->O1D (s-1)
+
+      integer :: iter(nlayer)      !  Number of chemical iterations
+                                   !  within one physical timestep 
+
+!     for output:
+
+      logical :: output             ! to issue calls to writediagfi and stats
+      parameter (output = .true.)
+      real :: jo3_3d(ngrid,nlayer)  ! Photodissociation rate O3->O1D (s-1)
+      real :: iter_3d(ngrid,nlayer) ! Number of chemical iterations
+                                    !  within one physical timestep
+
+!=======================================================================
+!     initialization of the chemistry (first call only)
+!=======================================================================
+
+      if (firstcall) then
+
+         if (photochem) then
+            print*,'calchim: Read photolysis lookup table'
+            call read_phototable
+         end if
+         ! find index of chemical tracers to use
+         allocate(niq(nq))
+         ! Listed here are all tracers that can go into photochemistry
+         nbq = 0 ! to count number of tracers
+         ! Species ALWAYS present if photochem=.T. or thermochem=.T.
+         i_co2 = igcm_co2
+         if (i_co2 == 0) then
+            write(*,*) "calchim: Error; no CO2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_co2
+         end if
+         i_co = igcm_co
+         if (i_co == 0) then
+            write(*,*) "calchim: Error; no CO tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_co
+         end if
+         i_o = igcm_o
+         if (i_o == 0) then
+            write(*,*) "calchim: Error; no O tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_o
+         end if
+         i_o1d = igcm_o1d
+         if (i_o1d == 0) then
+            write(*,*) "calchim: Error; no O1D tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_o1d
+         end if
+         i_o2 = igcm_o2
+         if (i_o2 == 0) then
+            write(*,*) "calchim: Error; no O2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_o2
+         end if
+         i_o3 = igcm_o3
+         if (i_o3 == 0) then
+            write(*,*) "calchim: Error; no O3 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_o3
+         end if
+         i_h = igcm_h
+         if (i_h == 0) then
+            write(*,*) "calchim: Error; no H tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_h
+         end if
+         i_h2 = igcm_h2
+         if (i_h2 == 0) then
+            write(*,*) "calchim: Error; no H2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_h2
+         end if
+         i_oh = igcm_oh
+         if (i_oh == 0) then
+            write(*,*) "calchim: Error; no OH tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_oh
+         end if
+         i_ho2 = igcm_ho2
+         if (i_ho2 == 0) then
+            write(*,*) "calchim: Error; no HO2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_ho2
+         end if
+         i_h2o2 = igcm_h2o2
+         if (i_h2o2 == 0) then
+            write(*,*) "calchim: Error; no H2O2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_h2o2
+         end if
+         i_ch4 = igcm_ch4
+         if (i_ch4 == 0) then
+            write(*,*) "calchim: Error; no CH4 tracer !!!"
+            write(*,*) "CH4 will be ignored in the chemistry"
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_ch4
+         end if
+         i_n2 = igcm_n2
+         if (i_n2 == 0) then
+            write(*,*) "calchim: Error; no N2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_n2
+         end if
+         i_n = igcm_n
+         if (i_n == 0) then
+            if (photochem) then
+               write(*,*) "calchim: Error; no N tracer !!!"
+               write(*,*) "N will be ignored in the chemistry"
+            end if
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_n
+         end if
+         i_n2d = igcm_n2d
+         if (i_n2d == 0) then
+            if (photochem) then
+               write(*,*) "calchim: Error; no N2D tracer !!!"
+               write(*,*) "N2d will be ignored in the chemistry"
+            end if
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_n2d
+         end if
+         i_no = igcm_no
+         if (i_no == 0) then
+            if (photochem) then
+               write(*,*) "calchim: Error; no NO tracer !!!"
+               write(*,*) "NO will be ignored in the chemistry"
+            end if
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_no
+         end if
+         i_no2 = igcm_no2
+         if (i_no2 == 0) then
+            if (photochem) then
+               write(*,*) "calchim: Error; no NO2 tracer !!!"
+               write(*,*) "NO2 will be ignored in the chemistry"
+            end if
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_no2
+         end if
+         i_h2o = igcm_h2o_vap
+         if (i_h2o == 0) then
+            write(*,*) "calchim: Error; no water vapor tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_h2o
+         end if
+         !Check tracers needed for thermospheric chemistry
+!         if(thermochem) then
+!            chemthermod=0  !Default: C/O/H chemistry
+!            !Nitrogen chemistry
+!            !NO is used to determine if N chemistry is wanted
+!            !chemthermod=2 -> N chemistry
+!            if (i_no == 0) then
+!               write(*,*) "calchim: no NO tracer"
+!               write(*,*) "C/O/H themosp chemistry only "
+!            else
+!               chemthermod=2
+!               write(*,*) "calchim: NO in traceur.def"
+!               write(*,*) "Nitrogen chemistry included"
+!            end if
+!            ! N
+!            if(chemthermod == 2) then
+!               if (i_n == 0) then
+!                  write(*,*) "calchim: Error; no N tracer !!!"
+!                  write(*,*) "N is needed if NO is in traceur.def"
+!                  stop
+!               end if
+!            ! NO2
+!               if (i_no2 == 0) then
+!                  write(*,*) "calchim: Error; no NO2 tracer !!!"
+!                  write(*,*) "NO2 is needed if NO is in traceur.def"
+!                  stop
+!               end if
+!            ! N(2D)
+!               if (i_n2d == 0) then
+!                  write(*,*) "calchim: Error; no N2D !!!"
+!                  write(*,*) "N2D is needed if NO is in traceur.def"
+!                  stop
+!               end if
+!            endif    !Of if(chemthermod == 2)
+!         endif      !Of thermochem
+
+         write(*,*) 'calchim: found nbq    = ',nbq,' tracers'
+               
+         firstcall = .false.
+      end if ! if (firstcall)
+
+! Initializations
+
+      zycol(:,:)    = 0.
+      dqchim(:,:,:) = 0.
+      dqschim(:,:)  = 0.
+
+!     latvl1= 22.27
+!     lonvl1= -47.94
+!     ig_vl1= 1+ int( (1.5-(latvl1-90.)*jjm/180.)  -2 )*iim +    &
+!             int(1.5+(lonvl1+180)*iim/360.)
+
+!=======================================================================
+!     loop over grid
+!=======================================================================
+
+      do ig = 1,ngrid
+         
+         foundswitch = 0
+         do l = 1,nlayer
+            do i = 1,nbq
+               iq = niq(i) ! get tracer index
+               zq(ig,l,iq) = pq(ig,l,iq) + pdq(ig,l,iq)*ptimestep
+               zycol(l,iq) = zq(ig,l,iq)*mmean(ig,l)/mmol(iq)
+            end do
+            zt(ig,l)  = pt(ig,l) + pdt(ig,l)*ptimestep
+            zu(ig,l)  = pu(ig,l) + pdu(ig,l)*ptimestep
+            zv(ig,l)  = pv(ig,l) + pdv(ig,l)*ptimestep
+            zpress(l) = pplay(ig,l)/100.
+            ztemp(l)  = zt(ig,l)
+            zdens(l)  = zpress(l)/(kb*1.e4*ztemp(l))
+            zlocal(l) = zzlay(ig,l)/1000.
+            zmmean(l) = mmean(ig,l)
+
+!           surfdust1d and surfice1d: conversion from m2/m3 to cm2/cm3
+
+            surfdust1d(l) = surfdust(ig,l)*1.e-2
+            surfice1d(l)  = surfice(ig,l)*1.e-2
+
+!           search for switch index between regions
+
+!            if (photochem .and. thermochem) then
+!               if (foundswitch == 0 .and. pplay(ig,l) < 1.e-1) then
+!                  lswitch = l
+!                  foundswitch = 1
+!               end if
+!            end if
+            if (.not. photochem) then
+               lswitch = 22
+            end if
+!            if (.not. thermochem) then
+               lswitch = min(50,nlayer+1)
+!            end if
+
+         end do ! of do l=1,nlayer
+
+         szacol = acos(mu0(ig))*180./pi
+         taucol = tauref(ig)*(700./610.)  ! provisoire en attente de nouveau jmars
+         fractcol=fract(ig)
+
+!=======================================================================
+!     call chemical subroutines
+!=======================================================================
+
+!        chemistry in lower atmosphere
+
+         if (photochem) then
+
+            call photochemistry_asis(nlayer,nq,ngrid,                          &
+                                ig,lswitch,zycol,szacol,fractcol,ptimestep,    &
+                                zpress,ztemp,zdens,zmmean,dist_sol,            &
+                                surfdust1d,surfice1d,jo3,taucol,iter)
+
+!        ozone photolysis, for output
+
+            do l = 1,nlayer
+               jo3_3d(ig,l) = jo3(l)
+               iter_3d(ig,l) = iter(l)
+            end do
+
+!        condensation of h2o2
+
+!            call perosat(ngrid, nlayer, nq,                        &
+!                         ig,ptimestep,pplev,pplay,                 &
+!                         ztemp,zycol,dqcloud,dqscloud)
+         end if
+
+!        chemistry in upper atmosphere
+        
+!         if (thermochem) then
+!            call chemthermos(ig,nlayer,lswitch,chemthermod,zycol,ztemp,&
+!                             zdens,zpress,zlocal,szacol,ptimestep,zday)
+!         end if
+
+!        dry deposition
+
+!         if (depos) then
+!            call deposition(ngrid, nlayer, nq,                      &
+!                            ig, ig_vl1, pplay, pplev, zzlay, zzlev, & 
+!                            zu, zv, zt, zycol, ptimestep, co2ice)
+!         end if
+
+!=======================================================================
+!     tendencies
+!=======================================================================
+
+!     index of the most abundant species at each level
+
+!         major(:) = maxloc(zycol, dim = 2)
+
+!     tendency for the most abundant species = - sum of others
+
+         do l = 1,nlayer
+            iloc=maxloc(zycol(l,:))
+            iqmax=iloc(1)
+            do i = 1,nbq
+               iq = niq(i) ! get tracer index
+               if (iq /= iqmax) then
+                  dqchim(ig,l,iq) = (zycol(l,iq)*mmol(iq)/mmean(ig,l) - zq(ig,l,iq))/ptimestep
+                  dqchim(ig,l,iq) = max(dqchim(ig,l,iq),-zq(ig,l,iq)/ptimestep)
+                  dqchim(ig,l,iqmax) = dqchim(ig,l,iqmax) - dqchim(ig,l,iq) 
+               end if
+            end do
+         end do ! of do l = 1,nlayer
+
+
+
+
+
+
+!=======================================================================
+!     end of loop over grid
+!=======================================================================
+
+      end do ! of do ig=1,ngrid
+
+!=======================================================================
+!     write outputs
+!=======================================================================
+
+! value of parameter 'output' to trigger writting of outputs
+! is set above at the declaration of the variable.
+
+      if (photochem .and. output) then
+            call writediagfi(ngrid,'jo3','j o3->o1d',    &
+                             's-1',3,jo3_3d(1,1))
+            call writediagfi(ngrid,'iter','iterations',  &
+                             ' ',3,iter_3d(1,1))
+            if (callstats) then
+               call wstats(ngrid,'jo3','j o3->o1d',       &
+                           's-1',3,jo3_3d(1,1))
+               call wstats(ngrid,'mmean','mean molecular mass',       &
+                           'g.mole-1',3,mmean(1,1))
+            endif
+      end if ! of if (output)
+
+      return
+      end
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/calchim_asis_early_earth.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/calchim_asis_early_earth.F90	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/calchim_asis_early_earth.F90	(revision 1796)
@@ -0,0 +1,665 @@
+      subroutine calchim_asis_early_earth(ngrid,nlayer,nq,                  &
+                         ptimestep,pplay,pplev,pt,pdt,dist_sol,mu0,fract,   &
+                         zzlev,zzlay,zday,pq,pdq,dqchim,dqschim,            &
+                         tauref,co2ice,                                     &
+                         pu,pdu,pv,pdv,surfdust,surfice)
+
+      use tracer_h, only:   igcm_co2, igcm_co, igcm_o, igcm_o1d, igcm_o2, &
+                            igcm_o3, igcm_h, igcm_h2, igcm_oh, igcm_ho2,  &
+                            igcm_h2o2, igcm_ch4, igcm_n2, igcm_h2o_vap,   &
+                            igcm_no, igcm_n, igcm_no2, igcm_n2d,          &
+                            igcm_ch3, igcm_ch, igcm_3ch2, igcm_1ch2,      &
+                            igcm_cho, igcm_ch2o, igcm_ch3o,               &
+                            igcm_c, igcm_c2, igcm_c2h, igcm_c2h2,         &
+                            igcm_c2h3, igcm_c2h4, igcm_c2h6, igcm_ch2co,  &
+                            igcm_ch3co, igcm_hcaer, mmol
+
+      use conc_mod, only: mmean ! mean molecular mass of the atmosphere
+      USE comcstfi_mod
+      use callkeys_mod
+
+      implicit none
+
+!=======================================================================
+!
+!   subject:
+!   --------
+!
+!  Prepare the call for the photochemical module, and send back the
+!  tendencies from photochemistry in the chemical species mass mixing ratios
+!
+!   Author:   Sebastien Lebonnois (08/11/2002)
+!   -------
+!    update 12/06/2003 for water ice clouds and compatibility with dust
+!    update 07/2003 for coupling with thermosphere (Monica Angelats-i-Coll)
+!    update 03/05/2005 cosmetic changes (Franck Lefevre)
+!    update sept. 2008 identify tracers by their names (Ehouarn Millour)
+!    update 05/12/2011 synchronize with latest version of chemistry (Franck Lefevre)
+!    update 16/03/2012 optimization (Franck Lefevre)
+!    update 11/12/2013 optimization (Franck Lefevre)
+!
+!   Arguments:
+!   ----------
+!
+!  Input:
+!
+!    ptimestep                  timestep (s)
+!    pplay(ngrid,nlayer)    Pressure at the middle of the layers (Pa)
+!    pplev(ngrid,nlayer+1)  Intermediate pressure levels (Pa)
+!    pt(ngrid,nlayer)       Temperature (K)
+!    pdt(ngrid,nlayer)      Temperature tendency (K)
+!    pu(ngrid,nlayer)       u component of the wind (ms-1)
+!    pdu(ngrid,nlayer)      u component tendency (K)
+!    pv(ngrid,nlayer)       v component of the wind (ms-1)
+!    pdv(ngrid,nlayer)      v component tendency (K)
+!    dist_sol                   distance of the sun (AU)
+!    mu0(ngrid)               cos of solar zenith angle (=1 when sun at zenith)
+!    fract(ngrid)           day fraction (for diurnal=false)
+!    pq(ngrid,nlayer,nq)  Advected fields, ie chemical species here
+!    pdq(ngrid,nlayer,nq) Previous tendencies on pq
+!    tauref(ngrid)            Optical depth at 7 hPa
+!    co2ice(ngrid)            co2 ice surface layer (kg.m-2)
+!    surfdust(ngrid,nlayer) dust surface area (m2/m3)
+!    surfice(ngrid,nlayer)  ice surface area (m2/m3)
+!
+!  Output:
+!
+!    dqchim(ngrid,nlayer,nq) ! tendencies on pq due to chemistry
+!    dqschim(ngrid,nq)         ! tendencies on qsurf 
+!
+!=======================================================================
+
+#include "chimiedata.h"
+
+!     input:
+
+      integer,intent(in) :: ngrid    ! number of atmospheric columns
+      integer,intent(in) :: nlayer   ! number of atmospheric layers
+      integer,intent(in) :: nq       ! number of tracers
+      real :: ptimestep
+      real :: pplay(ngrid,nlayer)    ! pressure at the middle of the layers
+      real :: zzlay(ngrid,nlayer)    ! pressure at the middle of the layers
+      real :: pplev(ngrid,nlayer+1)  ! intermediate pressure levels
+      real :: zzlev(ngrid,nlayer+1)  ! altitude at layer boundaries
+      real :: pt(ngrid,nlayer)       ! temperature
+      real :: pdt(ngrid,nlayer)      ! temperature tendency
+      real :: pu(ngrid,nlayer)       ! u component of the wind (m.s-1)
+      real :: pdu(ngrid,nlayer)      ! u component tendency
+      real :: pv(ngrid,nlayer)       ! v component of the wind (m.s-1)
+      real :: pdv(ngrid,nlayer)      ! v component tendency
+      real :: dist_sol               ! distance of the sun (AU)
+      real :: mu0(ngrid)             ! cos of solar zenith angle (=1 when sun at zenith)
+      real :: pq(ngrid,nlayer,nq)    ! tracers mass mixing ratio
+      real :: pdq(ngrid,nlayer,nq)   ! previous tendencies
+      real :: zday                   ! date (time since Ls=0, in martian days)
+      real :: tauref(ngrid)          ! optical depth at 7 hPa
+      real :: co2ice(ngrid)          ! co2 ice surface layer (kg.m-2)
+      real :: surfdust(ngrid,nlayer) ! dust surface area (m2/m3)
+      real :: surfice(ngrid,nlayer)  !  ice surface area (m2/m3)
+
+!     output:
+
+      real :: dqchim(ngrid,nlayer,nq)   ! tendencies on pq due to chemistry
+      real :: dqschim(ngrid,nq)         ! tendencies on qsurf 
+
+!     local variables:
+
+      integer,save :: nbq                   ! number of tracers used in the chemistry
+      integer,allocatable,save :: niq(:)    ! array storing the indexes of the tracers
+      integer :: iloc(1)                    ! index of major species
+      integer :: ig,l,i,iq,iqmax
+      integer :: foundswitch, lswitch
+      integer,save :: chemthermod
+
+      integer,save :: i_co2  = 0
+      integer,save :: i_co   = 0
+      integer,save :: i_o    = 0
+      integer,save :: i_o1d  = 0
+      integer,save :: i_o2   = 0
+      integer,save :: i_o3   = 0
+      integer,save :: i_h    = 0
+      integer,save :: i_h2   = 0
+      integer,save :: i_oh   = 0
+      integer,save :: i_ho2  = 0
+      integer,save :: i_h2o2 = 0
+      integer,save :: i_ch4  = 0
+      integer,save :: i_n2   = 0
+      integer,save :: i_h2o  = 0
+      integer,save :: i_n    = 0
+      integer,save :: i_no   = 0
+      integer,save :: i_no2  = 0
+      integer,save :: i_n2d  = 0
+      integer,save :: i_ch3  = 0
+      integer,save :: i_ch  = 0
+      integer,save :: i_3ch2  = 0
+      integer,save :: i_1ch2  = 0
+      integer,save :: i_cho  = 0
+      integer,save :: i_ch2o  = 0
+      integer,save :: i_ch3o  = 0
+      integer,save :: i_c  = 0
+      integer,save :: i_c2  = 0
+      integer,save :: i_c2h  = 0
+      integer,save :: i_c2h2  = 0
+      integer,save :: i_c2h3  = 0
+      integer,save :: i_c2h4  = 0
+      integer,save :: i_c2h6  = 0
+      integer,save :: i_ch2co  = 0
+      integer,save :: i_ch3co  = 0
+      integer,save :: i_hcaer  = 0
+
+      integer :: ig_vl1
+
+      real    :: latvl1, lonvl1
+      real    :: zq(ngrid,nlayer,nq)   ! pq+pdq*ptimestep before chemistry
+                                       ! new mole fraction after
+      real    :: zt(ngrid,nlayer)      ! temperature
+      real    :: zu(ngrid,nlayer)      ! u component of the wind
+      real    :: zv(ngrid,nlayer)      ! v component of the wind
+      real    :: taucol                ! optical depth at 7 hPa
+ 
+      logical,save :: firstcall = .true.
+      logical,save :: depos = .true.  ! switch for dry deposition
+
+!     for each column of atmosphere:
+
+      real :: zpress(nlayer)       ! Pressure (mbar)
+      real :: zdens(nlayer)        ! Density  (cm-3)
+      real :: ztemp(nlayer)        ! Temperature (K)
+      real :: zlocal(nlayer)       ! Altitude (km)
+      real :: zycol(nlayer,nq)     ! Composition (mole fractions)
+      real :: zmmean(nlayer)       ! Mean molecular mass (g.mole-1)
+      real :: szacol               ! Solar zenith angle
+      real :: fract(ngrid)         ! day fraction
+      real :: fractcol             ! day fraction
+      real :: surfice1d(nlayer)    ! Ice surface area (cm2/cm3)
+      real :: surfdust1d(nlayer)   ! Dust surface area (cm2/cm3)
+      real :: jo3(nlayer)          ! Photodissociation rate O3->O1D (s-1)
+      real :: jch4(nlayer)          ! Photodissociation rate CH4->CH3 (s-1)
+
+      integer :: iter(nlayer)      !  Number of chemical iterations
+                                   !  within one physical timestep 
+
+!     for output:
+
+      logical :: output             ! to issue calls to writediagfi and stats
+      parameter (output = .true.)
+      real :: jo3_3d(ngrid,nlayer)  ! Photodissociation rate O3->O1D (s-1)
+      real :: jch4_3d(ngrid,nlayer)  ! Photodissociation rate CH4->CH3 (s-1)
+      real :: iter_3d(ngrid,nlayer) ! Number of chemical iterations
+                                    !  within one physical timestep
+
+!=======================================================================
+!     initialization of the chemistry (first call only)
+!=======================================================================
+
+      if (firstcall) then
+
+         if (photochem) then
+            print*,'calchim: Read photolysis lookup table'
+            call read_phototable_early_earth
+         end if
+         ! find index of chemical tracers to use
+         allocate(niq(nq))
+         ! Listed here are all tracers that can go into photochemistry
+         nbq = 0 ! to count number of tracers
+         ! Species ALWAYS present if photochem=.T. or thermochem=.T.
+         i_co2 = igcm_co2
+         if (i_co2 == 0) then
+            write(*,*) "calchim: Error; no CO2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_co2
+         end if
+         i_co = igcm_co
+         if (i_co == 0) then
+            write(*,*) "calchim: Error; no CO tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_co
+         end if
+         i_o = igcm_o
+         if (i_o == 0) then
+            write(*,*) "calchim: Error; no O tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_o
+         end if
+         i_o1d = igcm_o1d
+         if (i_o1d == 0) then
+            write(*,*) "calchim: Error; no O1D tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_o1d
+         end if
+         i_o2 = igcm_o2
+         if (i_o2 == 0) then
+            write(*,*) "calchim: Error; no O2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_o2
+         end if
+         i_o3 = igcm_o3
+         if (i_o3 == 0) then
+            write(*,*) "calchim: Error; no O3 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_o3
+         end if
+         i_h = igcm_h
+         if (i_h == 0) then
+            write(*,*) "calchim: Error; no H tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_h
+         end if
+         i_h2 = igcm_h2
+         if (i_h2 == 0) then
+            write(*,*) "calchim: Error; no H2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_h2
+         end if
+         i_oh = igcm_oh
+         if (i_oh == 0) then
+            write(*,*) "calchim: Error; no OH tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_oh
+         end if
+         i_ho2 = igcm_ho2
+         if (i_ho2 == 0) then
+            write(*,*) "calchim: Error; no HO2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_ho2
+         end if
+         i_h2o2 = igcm_h2o2
+         if (i_h2o2 == 0) then
+            write(*,*) "calchim: Error; no H2O2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_h2o2
+         end if
+         i_h2o = igcm_h2o_vap
+         if (i_h2o == 0) then
+            write(*,*) "calchim: Error; no water vapor tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_h2o
+         end if
+         i_n = igcm_n
+         if (i_n == 0) then
+            if (photochem) then
+               write(*,*) "calchim: Error; no N tracer !!!"
+               write(*,*) "N will be ignored in the chemistry"
+               stop
+            end if
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_n
+         end if
+         i_n2d = igcm_n2d
+         if (i_n2d == 0) then
+            if (photochem) then
+               write(*,*) "calchim: Error; no N2D tracer !!!"
+               write(*,*) "N2d will be ignored in the chemistry"
+               stop
+            end if
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_n2d
+         end if
+         i_no = igcm_no
+         if (i_no == 0) then
+            if (photochem) then
+               write(*,*) "calchim: Error; no NO tracer !!!"
+               write(*,*) "NO will be ignored in the chemistry"
+               stop
+            end if
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_no
+         end if
+         i_no2 = igcm_no2
+         if (i_no2 == 0) then
+            if (photochem) then
+               write(*,*) "calchim: Error; no NO2 tracer !!!"
+               write(*,*) "NO2 will be ignored in the chemistry"
+               stop
+            end if
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_no2
+         end if
+         i_n2 = igcm_n2
+         if (i_n2 == 0) then
+            write(*,*) "calchim: Error; no N2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_n2
+         end if
+         i_ch4 = igcm_ch4
+         if (i_ch4 == 0) then
+            write(*,*) "calchim: Error; no CH4 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_ch4
+         end if
+         i_ch3 = igcm_ch3
+         if (i_ch3 == 0) then
+            write(*,*) "calchim: Error; no ch3 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_ch3
+         end if
+         i_ch = igcm_ch
+         if (i_ch == 0) then
+            write(*,*) "calchim: Error; no ch3 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_ch
+         end if
+         i_3ch2 = igcm_3ch2
+         if (i_3ch2 == 0) then
+            write(*,*) "calchim: Error; no 3ch2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_3ch2
+         end if
+         i_1ch2 = igcm_1ch2
+         if (i_1ch2 == 0) then
+            write(*,*) "calchim: Error; no 1ch2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_1ch2
+         end if
+         i_cho = igcm_cho
+         if (i_cho == 0) then
+            write(*,*) "calchim: Error; no cho tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_cho
+         end if
+         i_ch2o = igcm_ch2o
+         if (i_ch2o == 0) then
+            write(*,*) "calchim: Error; no ch2o tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_ch2o
+         end if
+         i_ch3o = igcm_ch3o
+         if (i_ch3o == 0) then
+            write(*,*) "calchim: Error; no ch3o tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_ch3o
+         end if
+         i_c = igcm_c
+         if (i_c == 0) then
+            write(*,*) "calchim: Error; no c tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_c
+         end if
+         i_c2 = igcm_c2
+         if (i_c2 == 0) then
+            write(*,*) "calchim: Error; no c2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_c2
+         end if
+         i_c2h = igcm_c2h
+         if (i_c2h == 0) then
+            write(*,*) "calchim: Error; no c2h tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_c2h
+         end if
+         i_c2h2 = igcm_c2h2
+         if (i_c2h2 == 0) then
+            write(*,*) "calchim: Error; no c2h2 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_c2h2
+         end if
+         i_c2h3 = igcm_c2h3
+         if (i_c2h3 == 0) then
+            write(*,*) "calchim: Error; no c2h3 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_c2h3
+         end if
+         i_c2h4 = igcm_c2h4
+         if (i_c2h4 == 0) then
+            write(*,*) "calchim: Error; no c2h4 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_c2h4
+         end if
+         i_c2h6 = igcm_c2h6
+         if (i_c2h6 == 0) then
+            write(*,*) "calchim: Error; no c2h6 tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_c2h6
+         end if
+         i_ch2co = igcm_ch2co
+         if (i_ch2co == 0) then
+            write(*,*) "calchim: Error; no ch2co tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_ch2co
+         end if
+         i_ch3co = igcm_ch3co
+         if (i_ch3co == 0) then
+            write(*,*) "calchim: Error; no ch3co tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_ch3co
+         end if
+         i_hcaer = igcm_hcaer
+         if (i_hcaer == 0) then
+            write(*,*) "calchim: Error; no hcaer tracer !!!"
+            stop
+         else
+            nbq = nbq + 1
+            niq(nbq) = i_hcaer
+         end if
+
+         write(*,*) 'calchim: found nbq    = ',nbq,' tracers'
+               
+         firstcall = .false.
+      end if ! if (firstcall)
+
+! Initializations
+
+      zycol(:,:)    = 0.
+      dqchim(:,:,:) = 0.
+      dqschim(:,:)  = 0.
+
+!     latvl1= 22.27
+!     lonvl1= -47.94
+!     ig_vl1= 1+ int( (1.5-(latvl1-90.)*jjm/180.)  -2 )*iim +    &
+!             int(1.5+(lonvl1+180)*iim/360.)
+
+!=======================================================================
+!     loop over grid
+!=======================================================================
+
+      do ig = 1,ngrid
+         
+         foundswitch = 0
+         do l = 1,nlayer
+            do i = 1,nbq
+               iq = niq(i) ! get tracer index
+               zq(ig,l,iq) = pq(ig,l,iq) + pdq(ig,l,iq)*ptimestep
+               zycol(l,iq) = zq(ig,l,iq)*mmean(ig,l)/mmol(iq)
+            end do
+
+            zt(ig,l)  = pt(ig,l) + pdt(ig,l)*ptimestep
+            zu(ig,l)  = pu(ig,l) + pdu(ig,l)*ptimestep
+            zv(ig,l)  = pv(ig,l) + pdv(ig,l)*ptimestep
+            zpress(l) = pplay(ig,l)/100.
+            ztemp(l)  = zt(ig,l)
+            zdens(l)  = zpress(l)/(kb*1.e4*ztemp(l))
+            zlocal(l) = zzlay(ig,l)/1000.
+            zmmean(l) = mmean(ig,l)
+
+!           surfdust1d and surfice1d: conversion from m2/m3 to cm2/cm3
+
+            surfdust1d(l) = surfdust(ig,l)*1.e-2
+            surfice1d(l)  = surfice(ig,l)*1.e-2
+
+!           search for switch index between regions
+
+            if (photochem .and. thermochem) then
+               if (foundswitch == 0 .and. pplay(ig,l) < 1.e-1) then
+                  lswitch = l
+                  foundswitch = 1
+               end if
+            end if
+            if (.not. photochem) then
+               lswitch = 22
+            end if
+            if (.not. thermochem) then
+               lswitch = min(50,nlayer+1)
+            end if
+
+         end do ! of do l=1,nlayer
+
+         szacol = acos(mu0(ig))*180./pi
+         taucol = tauref(ig)*(700./610.)  ! provisoire en attente de nouveau jmars
+         fractcol=fract(ig)
+!=======================================================================
+!     call chemical subroutines
+!=======================================================================
+
+!        chemistry in lower atmosphere
+
+         if (photochem) then
+
+            call photochemistry_asis_early_earth(nlayer,nq,ngrid,          &
+                                ig,lswitch,zycol,szacol,fractcol,ptimestep,&
+                                zpress,ztemp,zdens,zmmean,dist_sol,        &
+                                surfdust1d,surfice1d,jo3,jch4,taucol,iter)
+
+!        ozone photolysis, for output
+
+            do l = 1,nlayer
+               jo3_3d(ig,l) = jo3(l)
+               jch4_3d(ig,l) = jch4(l)
+               iter_3d(ig,l) = iter(l)
+            end do
+
+!        condensation of h2o2
+
+!            call perosat(ngrid, nlayer, nq,                        &
+!                         ig,ptimestep,pplev,pplay,                 &
+!                         ztemp,zycol,dqcloud,dqscloud)
+         end if
+
+!        chemistry in upper atmosphere
+        
+!         if (thermochem) then
+!            call chemthermos(ig,nlayer,lswitch,chemthermod,zycol,ztemp,&
+!                             zdens,zpress,zlocal,szacol,ptimestep,zday)
+!         end if
+
+!        dry deposition
+
+         if (depos) then
+            call deposition_source_early_earth(ngrid, nlayer, nq,   &
+                            ig, zzlay, zzlev,zdens, zycol, ptimestep)
+         end if
+
+!=======================================================================
+!     tendencies
+!=======================================================================
+
+!     index of the most abundant species at each level
+
+!         major(:) = maxloc(zycol, dim = 2)
+
+!     tendency for the most abundant species = - sum of others
+
+         do l = 1,nlayer
+            iloc=maxloc(zycol(l,:))
+            iqmax=iloc(1)
+            do i = 1,nbq
+               iq = niq(i) ! get tracer index
+               if (iq /= iqmax) then
+                  dqchim(ig,l,iq) = (zycol(l,iq)*mmol(iq)/mmean(ig,l) - zq(ig,l,iq))/ptimestep
+                  dqchim(ig,l,iq) = max(dqchim(ig,l,iq),-zq(ig,l,iq)/ptimestep)
+                  dqchim(ig,l,iqmax) = dqchim(ig,l,iqmax) - dqchim(ig,l,iq) 
+               end if
+            end do
+
+         end do ! of do l = 1,nlayer
+
+
+
+
+
+
+!=======================================================================
+!     end of loop over grid
+!=======================================================================
+
+      end do ! of do ig=1,ngrid
+
+!=======================================================================
+!     write outputs
+!=======================================================================
+
+! value of parameter 'output' to trigger writting of outputs
+! is set above at the declaration of the variable.
+      if (photochem .and. output) then
+
+            call writediagfi(ngrid,'jo3','j o3->o1d',    &
+                             's-1',3,jo3_3d(1,1))
+            call writediagfi(ngrid,'jch4','j ch4->ch3',    &
+                             's-1',3,jch4_3d(1,1))
+            call writediagfi(ngrid,'iter','iterations',  &
+                             ' ',3,iter_3d(1,1))
+            if (callstats) then
+               call wstats(ngrid,'jo3','j o3->o1d',       &
+                           's-1',3,jo3_3d(1,1))
+               call wstats(ngrid,'jch4','j ch4->ch3',       &
+                           's-1',3,jch4_3d(1,1))
+               call wstats(ngrid,'mmean','mean molecular mass',       &
+                           'g.mole-1',3,mmean(1,1))
+            endif
+      end if ! of if (output)
+
+      return
+      end
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/chimiedata_early_earth.h
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/chimiedata_early_earth.h	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/chimiedata_early_earth.h	(revision 1796)
@@ -0,0 +1,66 @@
+!--------------------------------------------
+!     data for photochemistry
+!--------------------------------------------
+
+!--------------------------------------------
+!     dimensions of photolysis lookup table
+!--------------------------------------------
+
+      integer, parameter :: nd    = 29  ! species
+      integer, parameter :: nz    = 143 ! altitude
+      integer, parameter :: nozo  = 4   ! ozone
+      integer, parameter :: nsza  = 21  ! solar zenith angle
+      integer, parameter :: ntemp = 1   ! temperature
+      integer, parameter :: ntau  = 1   ! dust
+      integer, parameter :: nch4  = 9   ! ch4
+
+!--------------------------------------------
+
+      real, parameter :: kb = 1.3806e-23
+
+      common/chimiedata/jphot,colairtab,table_ozo
+
+      real jphot(ntemp,nsza,nz,nozo,ntau,nch4,nd)
+      real colairtab(nz)
+      real szatab(nsza)
+      real table_ozo(nozo)
+      real tautab(ntau)
+      real table_ch4(nch4)
+
+
+!      data szatab/0.,  5., 10., 15., 20., 25.,                          &
+!     &            30., 35., 40., 45., 50., 55.,                         &
+!     &            60., 65., 70., 75., 80., 82.,                         &
+!     &            84., 86., 88., 90., 91., 92.,                         &
+!     &            93., 94., 95./
+
+      data szatab/0., 10., 20., 30., 40., 50.,                          &
+     &            60., 65., 70., 75., 80., 82.,                         &
+     &            84., 86., 88., 90., 91., 92.,                         &
+     &            93., 94., 95./                                        
+
+!      data szatab/40./
+
+!      data tautab/0., 0.2, 0.4, 0.6, 0.8, 1., 2., 4./
+      data tautab/0./
+
+!      data table_ch4/0.e-3, 1.e-3/
+      data table_ch4/0., 1.e-6, 3.e-6, 1.e-5, 3.e-5, 1.e-4, 3.e-4,      &
+     &            1.e-3, 3.e-3/
+!--------------------------------------------
+!     number of reactions in ASIS solver
+!--------------------------------------------
+
+!      integer, parameter :: nb_phot_max       = 36/full
+      integer, parameter :: nb_phot_max       = 29
+
+!      integer, parameter :: nb_reaction_3_max = 6
+!     integer, parameter :: nb_reaction_3_max = 10/full
+      integer, parameter :: nb_reaction_3_max = 10
+
+!      integer, parameter :: nb_reaction_4_max = 30
+!      integer, parameter :: nb_reaction_4_max = 110/full
+!      integer, parameter :: nb_reaction_4_max = 101/no nitrogen
+      integer, parameter :: nb_reaction_4_max = 101
+
+
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/deposition_source_early_earth.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/deposition_source_early_earth.F90	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/deposition_source_early_earth.F90	(revision 1796)
@@ -0,0 +1,116 @@
+      subroutine deposition_source_early_earth(ngrid, nlayer, nq,   &
+                           ig, zzlay, zzlev,zdens,      &
+                           zycol, ptimestep)
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!
+!     dry deposition of chemical species
+!
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!
+      use gases_h
+      use tracer_h, only:   igcm_co2, igcm_co, igcm_o, igcm_o1d, igcm_o2, &
+                            igcm_o3, igcm_h, igcm_h2, igcm_oh, igcm_ho2,  &
+                            igcm_h2o2, igcm_ch4, igcm_n2, igcm_h2o_vap,   &
+                            igcm_no, igcm_n, igcm_no2, igcm_n2d,          &
+                            igcm_ch3, igcm_ch, igcm_3ch2, igcm_1ch2,      &
+                            igcm_cho, igcm_ch2o, igcm_ch3o,               &
+                            igcm_c, igcm_c2, igcm_c2h, igcm_c2h2,         &
+                            igcm_c2h3, igcm_c2h4, igcm_c2h6, igcm_ch2co,  &
+                            igcm_ch3co, igcm_hcaer
+
+      implicit none
+!
+!
+!     input
+! 
+      integer,intent(in) :: ngrid ! number of atmospheric columns
+      integer,intent(in) :: nlayer ! number of atmospheric layers
+      integer,intent(in) :: nq ! number of tracers
+      integer ig                     ! grid point index
+      real    zzlay(ngrid,nlayer)    ! altitude at the middle of the layers (m)
+      real    zzlev(ngrid,nlayer+1)  ! altitude at layer boundaries (m)
+      real    zdens(nlayer)  ! density (cm^-3)
+      real    zycol(nlayer,nq)       ! composition (volume mixing ratio)
+      real    ptimestep              ! physical timestep (s)
+!
+!     local
+!
+      real    vd                         ! dry deposition velocity (cm.s-1)
+      real    deltaz                     ! thickness of first layer (m)
+      real    loss                       ! loss rate (s-1)                       
+      real    prod                       ! production rate (s-1) 
+      integer iq
+      logical, save :: firstcall = .true.
+
+      integer, allocatable, save ::  SF_mode(:)
+      real, allocatable, save ::  SF_value(:)
+      real, allocatable, save ::  prod_rate(:)
+
+      if (.not.allocated(SF_mode)) allocate(SF_mode(nq))
+      if (.not.allocated(SF_value)) allocate(SF_value(nq))
+      if (.not.allocated(prod_rate)) allocate(prod_rate(nq))
+
+if (firstcall) then
+   print*,'photochemistry: initialize deposition/source'
+!   print*,'SF_mode=1 (fixed mixing ratio) / 2 (fixed sedimentation velocity in cm/s and/or flux in molecules/m^3)'
+   do iq=1,nq
+     SF_mode(iq)=2
+     SF_value(iq)=0.
+     prod_rate(iq)=0.
+   enddo 
+
+! Cases SF_mode=1 (fixed mixing ratio)
+
+   SF_mode(igcm_co2)=1
+   SF_value(igcm_co2)=gfrac(igas_CO2)
+   SF_mode(igcm_ch4)=1
+   SF_value(igcm_ch4)=gfrac(igas_CH4)
+!   SF_mode(igcm_o2)=1
+!   SF_value(igcm_o2)=1.e-8
+   SF_mode(igcm_h2)=1
+   SF_value(igcm_h2)=1.e-3
+
+! Cases SF_mode=2 with vsed /=0
+   SF_value(igcm_o)=1.
+   SF_value(igcm_o2)=1.
+   SF_value(igcm_h)=1.
+   SF_value(igcm_oh)=1.
+   SF_value(igcm_ho2)=1.
+   SF_value(igcm_h2o2)=0.2
+!   SF_value(igcm_h2)=2.4e-4
+   SF_value(igcm_co)=1.2e-4
+   SF_value(igcm_cho)=1.
+   SF_value(igcm_ch2o)=0.2
+   SF_value(igcm_ch3)=1
+   SF_value(igcm_o3)=0.07
+   SF_value(igcm_hcaer)=0.01
+
+! Cases SF_mode=2 (production flux in mol/m2/s)
+!   prod_rate(igcm_h2)=3.5e13
+
+firstcall=.false.
+endif !first call
+
+
+!        thickness of first layer (m)
+deltaz = zzlev(ig,2) - zzlev(ig,1)
+
+
+do iq=1,nq
+
+  if(SF_mode(iq).eq.1) then
+!    zycol(1,iq) = SF_value(iq) +(zycol(1,iq)-SF_value(iq))*exp(-ptimestep/8.64e4)
+    zycol(1,iq) = SF_value(iq)
+
+  elseif(SF_mode(iq).eq.2) then
+!        loss/prod rate (s-1)
+    loss = 0.01*SF_value(iq)/deltaz
+    prod=prod_rate(iq)/(zdens(1)*1e6*deltaz)
+    zycol(1,iq) = zycol(1,iq)*exp(-loss*ptimestep)+prod*ptimestep
+
+  endif
+
+enddo
+
+      return
+      end
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/photochemistry_asis_early_earth.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/photochemistry_asis_early_earth.F90	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/photochemistry_asis_early_earth.F90	(revision 1796)
@@ -0,0 +1,3639 @@
+!*****************************************************************
+!
+!     Photochemical routine 
+!
+!     Author: Franck Lefevre
+!             Benjamin Charnay
+!     ------
+!
+!     Version: 27/05/2016
+!
+!*****************************************************************
+
+subroutine photochemistry_asis_early_earth(nlayer, nq, ngrid,                   &
+                          ig, lswitch, zycol, sza, fractcol, ptimestep, press,  &
+                          temp, dens, zmmean, dist_sol, surfdust1d,          &
+                          surfice1d, jo3, jch4, tau, iter)
+
+      use callkeys_mod
+implicit none
+
+#include "chimiedata.h" 
+
+!===================================================================
+!     inputs:
+!===================================================================
+
+integer, intent(in) :: nlayer ! number of atmospheric layers
+integer, intent(in) :: nq     ! number of tracers
+integer,intent(in) :: ngrid   ! number of atmospheric columns
+
+integer :: ig                 ! grid point index
+      
+real :: sza                   ! solar zenith angle (deg)
+real :: fractcol              ! day fraction
+real :: ptimestep             ! physics timestep (s)
+real :: press(nlayer)         ! pressure (hpa)
+real :: temp(nlayer)          ! temperature (k)
+real :: dens(nlayer)          ! density (cm-3)
+real :: zmmean(nlayer)        ! mean molar mass (g/mole)
+real :: dist_sol              ! sun distance (au) 
+real :: surfdust1d(nlayer)    ! dust surface area (cm2/cm3)
+real :: surfice1d(nlayer)     ! ice surface area (cm2/cm3)
+real :: tau                   ! optical depth at 7 hpa
+
+!===================================================================
+!     input/output:
+!===================================================================
+      
+real :: zycol(nlayer,nq)       ! chemical species volume mixing ratio
+
+!===================================================================
+!     output:
+!===================================================================
+      
+integer :: iter(nlayer)        ! iteration counter
+real    :: jo3(nlayer)         ! photodissociation rate o3 -> o1d
+real    :: jch4(nlayer)        ! photodissociation rate ch4 -> ch3 + h
+
+!===================================================================
+!     local:
+!===================================================================
+
+integer :: phychemrat         ! (physical timestep)/(nominal chemical timestep)
+integer :: j_o3_o1d, j_ch4_ch3_h, ilev
+integer :: j_ch4_1ch2_h2, j_ch4_3ch2_h_h, j_ch4_ch_h2_h
+integer :: iesp, nesp
+integer :: lswitch
+
+logical, save :: firstcall = .true.
+
+parameter (nesp = 35)         ! number of species in the chemistry
+
+! tracer indexes in the chemistry:
+
+integer,parameter :: i_co2  =  1
+integer,parameter :: i_co   =  2
+integer,parameter :: i_o    =  3
+integer,parameter :: i_o1d  =  4
+integer,parameter :: i_o2   =  5
+integer,parameter :: i_o3   =  6
+integer,parameter :: i_h    =  7
+integer,parameter :: i_h2   =  8
+integer,parameter :: i_oh   =  9
+integer,parameter :: i_ho2  = 10
+integer,parameter :: i_h2o2 = 11
+integer,parameter :: i_h2o  = 12
+integer,parameter :: i_n    = 13
+integer,parameter :: i_n2d  = 14
+integer,parameter :: i_no   = 15
+integer,parameter :: i_no2  = 16
+integer,parameter :: i_n2   = 17
+
+integer,parameter :: i_ch4  = 18
+integer,parameter :: i_ch3  = 19
+integer,parameter :: i_ch   = 20
+integer,parameter :: i_3ch2 = 21
+integer,parameter :: i_1ch2 = 22
+integer,parameter :: i_cho  = 23
+integer,parameter :: i_ch2o = 24
+integer,parameter :: i_ch3o = 25
+integer,parameter :: i_c    = 26
+integer,parameter :: i_c2   = 27
+integer,parameter :: i_c2h  = 28
+integer,parameter :: i_c2h2 = 29
+integer,parameter :: i_c2h3 = 30
+integer,parameter :: i_c2h4 = 31
+integer,parameter :: i_c2h6 = 32
+integer,parameter :: i_ch2co = 33
+integer,parameter :: i_ch3co = 34
+integer,parameter :: i_hcaer = 35
+
+
+
+real :: stimestep           ! standard timestep for the chemistry (s) 
+real :: ctimestep           ! real timestep for the chemistry (s) 
+real :: dt_guess            ! first-guess timestep (s) 
+real :: dt_corrected        ! corrected timestep (s) 
+real :: dt_min = 1.         ! minimum allowed timestep (s) 
+real :: dtg                 ! correction factor for the timestep (s) 
+real :: j(nlayer,nd)        ! interpolated photolysis rates (s-1)
+real :: time                ! internal time (between 0 and ptimestep, in s)
+
+real, dimension(nlayer,nesp)            :: rm   ! mixing ratios 
+real (kind = 8), dimension(nesp)        :: cold ! number densities at previous timestep (molecule.cm-3) 
+real (kind = 8), dimension(nlayer,nesp) :: c    ! number densities at current timestep (molecule.cm-3) 
+real (kind = 8), dimension(nesp)        :: cnew ! number densities at next timestep (molecule.cm-3) 
+ 
+! reaction rates
+ 
+real (kind = 8), dimension(nlayer,      nb_phot_max) :: v_phot
+real (kind = 8), dimension(nlayer,nb_reaction_3_max) :: v_3
+real (kind = 8), dimension(nlayer,nb_reaction_4_max) :: v_4
+logical :: hetero_dust, hetero_ice
+
+! matrix
+
+real (kind = 8), dimension(nesp,nesp) :: mat, mat1
+integer, dimension(nesp)              :: indx
+integer                               :: code
+
+! production and loss terms (for first-guess solution only)
+
+real (kind = 8), dimension(nesp) :: prod, loss
+
+! curvatures
+
+real :: ratio, curv, e, e1, e2, e3
+
+!===================================================================
+!     initialisation of the reaction indexes
+!===================================================================
+
+if (firstcall) then
+   print*,'photochemistry: initialize indexes'
+   call indice(i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,       &
+               i_h2, i_oh, i_ho2, i_h2o2, i_h2o,               &
+               i_n, i_n2d, i_no, i_no2, i_n2,                  &
+               i_ch4, i_ch3, i_3ch2, i_1ch2, i_cho, i_ch2o,    &
+               i_ch3o, i_c, i_c2, i_c2h, i_c2h2, i_c2h3,       &
+               i_c2h4, i_c2h6, i_ch2co, i_ch3co, i_hcaer)
+   firstcall = .false.
+end if
+
+!===================================================================
+!     initialisation of mixing ratios and densities       
+!===================================================================
+
+call gcmtochim(nlayer, nq, zycol, lswitch, nesp,               &
+               i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,       &
+               i_h2, i_oh, i_ho2, i_h2o2, i_h2o,               &
+               i_n, i_n2d, i_no, i_no2, i_n2,                  &
+               i_ch4, i_ch3, i_3ch2, i_1ch2, i_cho, i_ch2o,    &
+               i_ch3o, i_c, i_c2, i_c2h, i_c2h2, i_c2h3,       &
+               i_c2h4, i_c2h6, i_ch2co, i_ch3co, i_hcaer, dens, rm, c) 
+
+!===================================================================
+!     interpolation of photolysis rates in the lookup table      
+!===================================================================
+
+call photolysis_asis(nlayer, ngrid, lswitch, press, temp, sza, fractcol,tau, zmmean, dist_sol, & 
+                     rm(:,i_co2), rm(:,i_o3), rm(:,i_ch4), v_phot)
+
+! save o3 photolysis for output
+
+j_o3_o1d = 5
+jo3(:) = v_phot(:,j_o3_o1d)
+
+j_ch4_ch3_h = 10
+j_ch4_1ch2_h2=11
+j_ch4_3ch2_h_h=12
+j_ch4_ch_h2_h=13
+jch4(:) = v_phot(:,j_ch4_ch3_h)+v_phot(:,j_ch4_1ch2_h2)+v_phot(:,j_ch4_3ch2_h_h)+v_phot(:,j_ch4_ch_h2_h)
+
+!===================================================================
+!     reaction rates                                     
+!===================================================================
+!     switches for heterogeneous chemistry
+!     hetero_ice  : reactions on ice clouds
+!     hetero_dust : reactions on dust    
+!===================================================================
+
+hetero_dust = .false.
+hetero_ice  = .false.
+
+call reactionrates(nlayer, lswitch, dens, c(:,i_co2), c(:,i_o2), &
+                   press, temp, hetero_dust, hetero_ice,         &
+                   surfdust1d, surfice1d, v_phot, v_3, v_4)
+
+!===================================================================
+!     stimestep : standard chemical timestep (s)                           
+!     ctimestep : real chemical timestep (s),
+!                 taking into account the physical timestep                           
+!===================================================================
+
+stimestep = 600. ! standard value : 10 mn
+
+phychemrat = nint(ptimestep/stimestep)
+phychemrat = 1
+
+ctimestep = ptimestep/real(phychemrat)
+
+!print*, "stimestep  = ", stimestep
+!print*, "ptimestep  = ", ptimestep
+!print*, "phychemrat = ", phychemrat
+!print*, "ctimestep  = ", ctimestep
+!stop
+
+!===================================================================
+!     loop over levels         
+!===================================================================
+
+do ilev = 1,lswitch - 1
+
+!  initializations
+
+   time = 0.
+   iter(ilev) = 0
+   dt_guess = ctimestep
+   cold(:) = c(ilev,:)
+
+!  internal loop for the chemistry
+
+   do while (time < ptimestep)
+
+   iter(ilev) = iter(ilev) + 1    ! iteration counter
+  
+!  first-guess: fill matrix
+
+   call fill_matrix(ilev, mat1, prod, loss, c, nesp, nlayer, v_phot, v_3, v_4)
+
+! first guess : form the matrix identity + mat*dt_guess
+
+   mat(:,:) = mat1(:,:)*dt_guess
+   do iesp = 1,nesp
+      mat(iesp,iesp) = 1. + mat(iesp,iesp)
+   end do
+
+!  first-guess: solve linear system
+     
+   cnew(:) = c(ilev,:)
+
+!#ifdef LAPACK
+   call dgesv(nesp,1,mat,nesp,indx,cnew,nesp,code)
+!#else
+!   write(*,*) "photochemistry_asis error, missing LAPACK routine dgesv"
+!   stop
+!#endif
+!  eliminate small values
+
+   where (cnew(:)/dens(ilev) < 1.e-30)
+      cnew(:) = 0.
+   end where
+
+!  curvature of the solution and weighted error norm for O
+!
+!  cold : concentrations at time t - dt 
+!  c    : concentrations at time t
+!  cnew : concentrations guessed at time t + dt
+
+!  ratio = dtold/dtnew
+!  here ratio = 1 since the timestep for the guess is equal to the previous timestep
+
+   ratio = 1.
+
+   curv = 2.*(ratio*cnew(i_o) - (1. + ratio)*c(ilev,i_o) + cold(i_o)) &
+          /(ratio*(1. + ratio))
+   e1 = (curv/(cnew(i_o) + cnew(i_o3)))*100.
+   e1 = abs(e1)
+
+!  curvature of the solution and weighted error norm for HO2
+
+   curv = 2.*(ratio*cnew(i_ho2) - (1. + ratio)*c(ilev,i_ho2) + cold(i_ho2)) &
+          /(ratio*(1. + ratio))
+   e2 = (curv/(cnew(i_h) + cnew(i_oh) + cnew(i_ho2) + 2.*cnew(i_h2o2)))*100.
+   e2 = abs(e2)
+
+!  curvature of the solution and weighted error norm for NO2
+
+!  curv = 2.*(ratio*cnew(i_no2) - (1. + ratio)*c(ilev,i_no2) + cold(i_no2)) &
+!         /(ratio*(1. + ratio))
+!  e3 = (curv/(cnew(i_no) + cnew(i_no2)))*100.
+!  e3 = abs(e3)
+   e3 = 0.
+
+!  timestep correction
+
+   e = max(e1, e2)
+   e = max(e,  e3)
+   e = max(e, 0.1)
+   dtg = max(0.001, min(2.5,0.8/sqrt(e)))
+!  dtg = 1.                                     ! uncomment this line to turn off the variable timestep scheme
+   dt_corrected = max(dt_min,dtg*dt_guess)      ! minimal timestep: dt_min
+   dt_corrected = min(dt_corrected,ctimestep)   ! maximal timestep: ctimestep
+
+   if (time + dt_corrected > ptimestep) then
+      dt_corrected = ptimestep - time
+   end if
+
+   if (dt_corrected /= dt_guess) then  ! the timestep has been modified
+
+!  form the matrix identity + mat*dt_corrected
+
+      mat(:,:) = mat1(:,:)*dt_corrected
+      do iesp = 1,nesp
+         mat(iesp,iesp) = 1. + mat(iesp,iesp)
+      end do
+
+!  solve linear system
+     
+      cnew(:) = c(ilev,:)
+
+!#ifdef LAPACK
+      call dgesv(nesp,1,mat,nesp,indx,cnew,nesp,code)
+!#else
+!   write(*,*) "photochemistry_asis error, missing LAPACK routine dgesv"
+!   stop
+!#endif
+   end if
+
+!  eliminate small values
+
+   where (cnew(:)/dens(ilev) < 1.e-30)
+      cnew(:) = 0.
+   end where
+
+   cold(:)   = c(ilev,:)
+   c(ilev,:) = cnew(:)
+   cnew(:)   = 0.
+
+!  increment internal time
+
+   time = time + dt_corrected
+   dt_guess = dt_corrected     ! first-guess timestep for next iteration
+
+   end do ! while (time < ptimestep)
+
+end do ! ilev
+
+!===================================================================
+!     save chemical species for the gcm       
+!===================================================================
+
+call chimtogcm(nlayer, nq, zycol, lswitch, nesp,              &
+               i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,      &
+               i_h2, i_oh, i_ho2, i_h2o2, i_h2o,              &
+               i_n, i_n2d, i_no, i_no2, i_n2,                 &
+               i_ch4, i_ch3, i_3ch2, i_1ch2, i_cho, i_ch2o,   &
+               i_ch3o, i_c, i_c2, i_c2h, i_c2h2, i_c2h3,      &
+               i_c2h4, i_c2h6, i_ch2co, i_ch3co, i_hcaer, dens, c) 
+
+contains
+
+!======================================================================
+
+ subroutine reactionrates(nlayer,                               &
+                          lswitch, dens, co2, o2, press, t,     &
+                          hetero_dust, hetero_ice,              &
+                          surfdust1d, surfice1d,                &
+                          v_phot, v_3, v_4)
+ 
+!================================================================
+! compute reaction rates                                        !
+!----------------------------------------------------------------
+! reaction               type                array              !
+!----------------------------------------------------------------
+! A + B    --> C + D     bimolecular         v_4                !
+! A + A    --> B + C     quadratic           v_3                !
+! A + C    --> B + C     quenching           v_phot             !
+! A + ice  --> B + C     heterogeneous       v_phot             !
+!================================================================
+
+use comcstfi_mod
+
+implicit none
+
+#include "chimiedata.h"
+
+!----------------------------------------------------------------------
+!     input
+!----------------------------------------------------------------------
+
+integer, intent(in)     :: nlayer            ! number of atmospheric layers
+integer                 :: lswitch           ! interface level between lower
+                                             ! atmosphere and thermosphere chemistries
+real, dimension(nlayer) :: dens              ! total number density (molecule.cm-3)
+real, dimension(nlayer) :: press             ! pressure (hPa)
+real, dimension(nlayer) :: t                 ! temperature (K)
+real, dimension(nlayer) :: surfdust1d        ! dust surface area (cm2.cm-3)
+real, dimension(nlayer) :: surfice1d         ! ice surface area (cm2.cm-3)
+real (kind = 8), dimension(nlayer) :: co2    ! co2 number density (molecule.cm-3)
+real (kind = 8), dimension(nlayer) :: o2     ! o2 number density (molecule.cm-3)
+logical :: hetero_dust, hetero_ice           ! switches for heterogeneous chemistry
+
+!----------------------------------------------------------------------
+!     output
+!----------------------------------------------------------------------
+
+real (kind = 8), dimension(nlayer,      nb_phot_max) :: v_phot
+real (kind = 8), dimension(nlayer,nb_reaction_3_max) :: v_3
+real (kind = 8), dimension(nlayer,nb_reaction_4_max) :: v_4
+
+!----------------------------------------------------------------------
+!     local
+!----------------------------------------------------------------------
+
+integer          :: ilev
+integer          :: nb_phot, nb_reaction_3, nb_reaction_4
+real :: ak0, ak1, xpo, rate
+real :: k1a0, k1b0, k1ainf, k1a, k1b, fc, fx, x, y, gam
+real, dimension(nlayer) :: deq
+real, dimension(nlayer) :: a001, a002, a003,                           &
+                             b001, b002, b003, b004, b005, b006, b007,   &
+                             b008, b009,                                 &
+                             c001, c002, c003, c004, c005, c006, c007,   &
+                             c008, c009, c010, c011, c012, c013, c014,   &
+                             c015, c016, c017, c018,                     &
+                             d001, d002, d003, d004, d005, d006, d007,   &
+                             d008, d009,                                 &
+                             e001, e002,                                 &
+                             h001, h002, h003, h004, h005,               &       
+                             f001, f002, f003, f004, f005, f006, f007,   &
+                             f008, f009, f010, f011, f012, f013, f014,   &
+                             f015, f016, f017, f018, f019, f020, f021,   &
+                             f022, f023, f024, f025, f026, f027, f028,   &
+                             f029, f030, f031, f032, f033, f034, f035,   &
+                             f036, f037, f038, f039, f040, f041, f042,   &
+                             f043, f044, f045, f046, f047, f048, f049,   &
+                             f050, f051, f052, f053, f054, f055, f056,   &
+                             f057, f058, f059, f060, f061, f062, f063,   &
+                             f064, f065, f066, f067, f068, f069, f070,   &
+                             f071, f072, f073, f074, f075, f076, f077,   &
+                             f078, f079, f080, f081, f082
+
+
+!----------------------------------------------------------------------
+!     initialisation
+!----------------------------------------------------------------------
+
+      nb_phot       = 26       ! jearly_earth à 28 ou 26 (sans n/no/no2)
+      nb_reaction_3 = 0
+      nb_reaction_4 = 0
+
+!----------------------------------------------------------------------
+!     oxygen reactions 
+!----------------------------------------------------------------------
+
+!---  a001: o + o2 + co2 -> o3 + co2
+
+!     jpl 2003
+!
+!     co2 efficiency as a third body (2.075)
+!     from sehested et al., j. geophys. res., 100, 1995.
+
+      a001(:) = 2.075*6.0e-34*(t(:)/300.)**(-2.4)*dens(:)
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = a001(:)
+
+!---  a002: o + o + co2 -> o2 + co2
+
+!     Tsang and Hampson, J. Chem. Phys. Ref. Data, 15, 1087, 1986
+
+!     a002(:) = 2.5*5.2e-35*exp(900./t(:))*dens(:)
+
+!     Campbell and Gray, Chem. Phys. Lett., 18, 607, 1973
+
+!     a002(:) = 1.2e-32*(300./t(:))**(2.0)*dens(:)  ! yung expression
+      a002(:) = 2.5*9.46e-34*exp(485./t(:))*dens(:) ! nist expression
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = a002(:)
+
+!---  a003: o + o3 -> o2 + o2
+
+!     jpl 2003
+
+      a003(:) = 8.0e-12*exp(-2060./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = a003(:)
+
+!----------------------------------------------------------------------
+!     o(1d) reactions
+!----------------------------------------------------------------------
+
+!---  b001: o(1d) + co2  -> o + co2
+
+!     jpl 2006
+
+      b001(:) = 7.5e-11*exp(115./t(:))
+   
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = b001(:)*co2(:)
+
+!---  b002: o(1d) + h2o  -> oh + oh
+
+!     jpl 2006
+ 
+      b002(:) = 1.63e-10*exp(60./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = b002(:)
+
+!---  b003: o(1d) + h2  -> oh + h
+
+!     jpl 2011
+
+      b003(:) = 1.2e-10
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = b003(:)
+
+!---  b004: o(1d) + o2  -> o + o2
+
+!     jpl 2006
+
+      b004(:) = 3.3e-11*exp(55./t(:))
+
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = b004(:)*o2(:)
+    
+!---  b005: o(1d) + o3  -> o2 + o2
+
+!     jpl 2003
+
+      b005(:) = 1.2e-10
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = b005(:)
+    
+!---  b006: o(1d) + o3  -> o2 + o + o
+
+!     jpl 2003
+
+      b006(:) = 1.2e-10
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = b006(:)
+    
+!---  b007: o(1d) + ch4 -> ch3 + oh
+
+!     jpl 2003
+
+      b007(:) = 1.5e-10*0.75
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = b007(:)
+!---  b008: o(1d) + ch4 -> ch3o + h
+
+!     jpl 2003
+
+      b008(:) = 1.5e-10*0.20
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = b008(:)
+!
+!---  b009: o(1d) + ch4 -> ch2o + h2
+
+!     jpl 2003
+
+      b009(:) = 1.5e-10*0.05
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = b009(:)
+!----------------------------------------------------------------------
+!     hydrogen reactions
+!----------------------------------------------------------------------
+
+!---  c001: o + ho2 -> oh + o2
+
+!     jpl 2003
+
+      c001(:) = 3.0e-11*exp(200./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c001(:)
+
+!---  c002: o + oh -> o2 + h
+
+!     jpl 2011
+
+      c002(:) = 1.8e-11*exp(180./t(:))
+
+!     robertson and smith, j. chem. phys. a 110, 6673, 2006
+
+!     c002(:) = 11.2e-11*t(:)**(-0.32)*exp(177./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c002(:)
+
+!---  c003: h + o3 -> oh + o2
+
+!     jpl 2003
+
+      c003(:) = 1.4e-10*exp(-470./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c003(:)
+
+!---  c004: h + ho2 -> oh + oh
+
+!     jpl 2006
+
+      c004(:) = 7.2e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c004(:)
+
+!---  c005: h + ho2 -> h2 + o2
+
+!     jpl 2006
+
+      c005(:) = 6.9e-12
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c005(:)
+
+!---  c006: h + ho2 -> h2o + o
+
+!     jpl 2006
+
+      c006(:) = 1.6e-12
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c006(:)
+
+!---  c007: oh + ho2 -> h2o + o2
+
+!     jpl 2003
+
+!     canty et al., grl, 2006 suggest to increase this rate
+!     by 20%. not done here.
+
+      c007(:) = 4.8e-11*exp(250./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c007(:)
+
+!---  c008: ho2 + ho2 -> h2o2 + o2
+
+!     jpl 2006
+
+!     c008(:) = 3.5e-13*exp(430./t(:))
+
+!     christensen et al., grl, 13, 2002
+
+      c008(:) = 1.5e-12*exp(19./t(:))
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = c008(:)
+
+!---  c009: oh + h2o2 -> h2o + ho2
+
+!     jpl 2006
+
+      c009(:) = 1.8e-12
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c009(:)
+
+!---  c010: oh + h2 -> h2o + h
+
+!     jpl 2006
+
+      c010(:) = 2.8e-12*exp(-1800./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c010(:)
+
+!---  c011: h + o2 + co2 -> ho2 + co2
+
+!     jpl 2011
+
+      do ilev = 1,lswitch-1
+         ak0 = 2.5*4.4e-32*(t(ilev)/300.)**(-1.3)
+         ak1 = 7.5e-11*(t(ilev)/300.)**(0.2)
+
+         rate = (ak0*dens(ilev))/(1. + ak0*dens(ilev)/ak1)
+         xpo = 1./(1. + alog10((ak0*dens(ilev))/ak1)**2)
+         c011(ilev) = rate*0.6**xpo
+      end do
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c011(:)
+
+!---  c012: o + h2o2 -> oh + ho2
+
+!     jpl 2003
+
+      c012(:) = 1.4e-12*exp(-2000./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c012(:)
+
+!---  c013: oh + oh -> h2o + o
+
+!     jpl 2006
+
+      c013(:) = 1.8e-12
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = c013(:)
+
+!---  c014: oh + o3 -> ho2 + o2
+
+!     jpl 2003
+
+      c014(:) = 1.7e-12*exp(-940./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c014(:)
+
+!---  c015: ho2 + o3 -> oh + o2 + o2
+
+!     jpl 2003
+
+      c015(:) = 1.0e-14*exp(-490./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c015(:)
+
+!---  c016: ho2 + ho2 + co2 -> h2o2 + o2 + co2
+
+!     jpl 2011
+
+      c016(:) = 2.5*2.1e-33*exp(920./t(:))*dens(:)
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = c016(:)
+
+!---  c017: oh + oh + co2 -> h2o2 + co2
+
+!     jpl 2003
+
+      do ilev = 1,lswitch-1
+         ak0 = 2.5*6.9e-31*(t(ilev)/300.)**(-1.0)
+         ak1 = 2.6e-11*(t(ilev)/300.)**(0.0)
+
+         rate = (ak0*dens(ilev))/(1. + ak0*dens(ilev)/ak1)
+         xpo = 1./(1. + alog10((ak0*dens(ilev))/ak1)**2)
+         c017(ilev) = rate*0.6**xpo
+      end do
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = c017(:)
+
+!---  c018: h + h + co2 -> h2 + co2
+
+!     baulch et al., 2005
+
+      c018(:) = 2.5*1.8e-30*(t(:)**(-1.0))*dens(:)
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = c018(:)
+
+!----------------------------------------------------------------------
+!     nitrogen reactions
+!----------------------------------------------------------------------
+
+if(1.eq.0) then
+
+!---  d001: no2 + o -> no + o2
+
+!     jpl 2006
+
+      d001(:) = 5.1e-12*exp(210./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d001(:)
+
+!---  d002: no + o3 -> no2 + o2
+
+!     jpl 2006
+
+      d002(:) = 3.0e-12*exp(-1500./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d002(:)
+
+!---  d003: no + ho2 -> no2 + oh
+
+!     jpl 2011
+
+      d003(:) = 3.3e-12*exp(270./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d003(:)
+
+!---  d004: n + no -> n2 + o
+
+!     jpl 2011
+
+      d004(:) = 2.1e-11*exp(100./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d004(:)
+
+!---  d005: n + o2 -> no + o
+
+!     jpl 2011
+
+      d005(:) = 1.5e-11*exp(-3600./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d005(:)
+
+!---  d006: no2 + h -> no + oh
+
+!     jpl 2011
+
+      d006(:) = 4.0e-10*exp(-340./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d006(:)
+
+!---  d007: n + o -> no
+ 
+      d007(:) = 2.8e-17*(300./t(:))**0.5
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d007(:)
+
+!---  d008: n + ho2 -> no + oh
+
+!     brune et al., j. chem. phys., 87, 1983 
+
+      d008(:) = 2.19e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d008(:)
+
+!---  d009: n + oh -> no + h
+
+!     atkinson et al., j. phys. chem. ref. data, 18, 881, 1989 
+
+      d009(:) = 3.8e-11*exp(85./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d009(:)
+
+endif
+
+!----------------------------------------------------------------------
+!     carbon reactions
+!----------------------------------------------------------------------
+
+!---  e001: oh + co -> co2 + h
+
+!     jpl 2003
+
+!     e001(:) = 1.5e-13*(1 + 0.6*press(:)/1013.)
+
+!     mccabe et al., grl, 28, 3135, 2001
+
+!     e001(:) = 1.57e-13 + 3.54e-33*dens(:)
+
+!     jpl 2006
+
+!     ak0 = 1.5e-13*(t(:)/300.)**(0.6)
+!     ak1 = 2.1e-9*(t(:)/300.)**(6.1)
+!     rate1 = ak0/(1. + ak0/(ak1/dens(:)))
+!     xpo1 = 1./(1. + alog10(ak0/(ak1/dens(:)))**2)
+
+!     ak0 = 5.9e-33*(t(:)/300.)**(-1.4)
+!     ak1 = 1.1e-12*(t(:)/300.)**(1.3)
+!     rate2 = (ak0*dens(:))/(1. + ak0*dens(:)/ak1)
+!     xpo2 = 1./(1. + alog10((ak0*dens(:))/ak1)**2)
+
+!     e001(:) = rate1*0.6**xpo1 + rate2*0.6**xpo2
+
+!     joshi et al., 2006
+
+      do ilev = 1,lswitch-1
+         k1a0 = 1.34*2.5*dens(ilev)                                  &
+               *1/(1/(3.62e-26*t(ilev)**(-2.739)*exp(-20./t(ilev)))  &
+               + 1/(6.48e-33*t(ilev)**(0.14)*exp(-57./t(ilev))))     ! typo in paper corrected
+         k1b0 = 1.17e-19*t(ilev)**(2.053)*exp(139./t(ilev))          &
+              + 9.56e-12*t(ilev)**(-0.664)*exp(-167./t(ilev))
+         k1ainf = 1.52e-17*t(ilev)**(1.858)*exp(28.8/t(ilev))        &
+                + 4.78e-8*t(ilev)**(-1.851)*exp(-318./t(ilev))
+         x = k1a0/(k1ainf - k1b0)
+         y = k1b0/(k1ainf - k1b0)
+         fc = 0.628*exp(-1223./t(ilev)) + (1. - 0.628)*exp(-39./t(ilev))  &
+            + exp(-t(ilev)/255.)
+         fx = fc**(1./(1. + (alog(x))**2))                           ! typo in paper corrected
+         k1a = k1a0*((1. + y)/(1. + x))*fx
+         k1b = k1b0*(1./(1.+x))*fx
+
+         e001(ilev) = k1a + k1b
+      end do
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = e001(:)
+
+!---  e002: o + co + m -> co2 + m
+
+!     tsang and hampson, 1986.
+
+      e002(:) = 2.5*6.5e-33*exp(-2184./t(:))*dens(:)
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = e002(:)
+
+
+if(1.eq.1) then
+
+!----------------------------------------------------------------------
+!     methane/ethane reactions
+!----------------------------------------------------------------------
+!---  f001: 3ch2 + 3ch2 -> c2h2 + h2
+
+!     Braun 1970
+      
+      f001(:) = 5.3e-11
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = f001(:)
+
+!---  f002: c + h2 + m -> 3ch2 
+
+!     Zahnle 1986
+
+      f002(:) = 8.3e-11*8.75e-31*exp(524./t(:))*dens(:)/(dens(:)*8.75e-31*exp(524./t(:))+8.3e-11)
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f002(:)
+
+!---  f003: c + o2 -> co + o
+
+!     Donovan and Husain 1970
+
+      f003(:) =3.3e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f003(:)
+
+!---  f004: c + oh -> co + h
+
+!     Giguere and Huebner 1978
+
+      f004(:) =4.0e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f004(:)
+
+!---  f005: c2 + ch4 -> c2h + ch3
+
+!     Pitts 1982
+
+      f005(:) =5.05e-11*exp(-297./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f005(:)
+
+!---  f006: c2 + h2 -> c2h + h
+
+!     Pitts 1982
+
+      f006(:) =1.77e-10*exp(-1469./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f006(:)
+
+!---  f007: c2 + o -> c + co
+
+!     Prasad and Huntress 1980
+
+      f007(:) =5.0e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f007(:)
+
+
+!---  f008: c2 + o2 -> co + co
+
+!     Baughcum and Oldenborg 1984
+
+      f008(:) =1.5e-11*exp(-550./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f008(:)
+
+!---  f009: c2h + c2h2 -> hcaer + h
+
+!     Stephens 1987
+
+      f009(:) =1.5e-10
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f009(:)
+
+!---  f010: c2h + ch4 -> c2h2 + ch3
+
+!     Allen 1992 Lander 1990
+
+      f010(:) =6.94e-12*exp(-250./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f010(:)
+
+
+!---  f011: c2h + h + m -> c2h2 + m
+
+!     Tsang 1986
+
+      f011(:) =1.26e-18*exp(-721./t(:))*t(:)**-3.1*3.0e-10*dens(:)/(3.0e-10+dens(:)*1.26e-18*exp(-721./t(:))*t(:)**-3.1)
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f011(:)
+
+!---  f012: c2h + h2 -> c2h2 + h
+
+!     Allen 1992 Stephens 1987
+
+      f012(:) =5.58e-11*exp(-1443./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f012(:)
+
+!---  f013: c2h + o -> co + ch
+
+!     Zahnle 1986
+
+      f013(:) =1.0e-10*exp(-250./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f013(:)
+
+!---  f014: c2h + o2 -> co + cho
+
+!     Brown 1981
+
+      f014(:) =2.0e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f014(:)
+
+!---  f015: c2h2 + h + m -> c2h3 + m
+
+!     Romani 1993
+
+      f015(:) =2.6e-31*8.3e-11*exp(-1374./t(:))*dens(:)/(2.6e-31*dens(:) + 8.3e-11*exp(-1374./t(:)) )
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f015(:)
+
+!---  f016: c2h2 + o -> 3ch2 + co
+
+!     Zahnle 1986
+
+      f016(:) =2.9e-11*exp(-1600./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f016(:)
+
+!---  f017: c2h2 + oh + m -> ch2co + h +  m
+
+!     Perry and Williamson 1982
+
+      f017(:) =5.8e-31*exp(1258./t(:))*1.4e-12*exp(388./t(:))*dens(:)/(dens(:)*5.8e-31*exp(1258./t(:)) + 1.4e-12*exp(388./t(:)))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f017(:)
+
+!---  f018: c2h2 + oh -> co + ch3
+
+!     Hampson and Garvin 1977
+
+      f018(:) = 2.0e-12*exp(-250./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f018(:)
+
+!---  f019: c2h3 + c2h3 -> c2h4 + c2h2
+
+!     Fahr 1991
+
+      f019(:) = 2.4e-11
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = f019(:)
+
+!---  f020: c2h3 + ch3 -> c2h2 + ch4
+
+!     Fahr 1991
+
+      f020(:) = 3.4e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f020(:)
+
+!---  f021: c2h3 + ch4 -> c2h4 + ch3
+
+!     Tsang 1986
+
+      f021(:) = 2.4e-24*exp(-2754./t(:))*t(:)**4.02
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f021(:)
+
+!---  f022: c2h3 + h -> c2h2 + h2
+
+!     Warnatz 1984
+
+      f022(:) = 3.3e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f022(:)
+
+!---  f023: c2h3 + h2 -> c2h4 + h
+
+!     Allen 1992
+
+      f023(:) = 2.6e-13*exp(-2646./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f023(:)
+
+!---  f024: c2h3 + o -> ch2co + h
+
+!     Hoyermann 1981
+
+      f024(:) = 5.5e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f024(:)
+
+!---  f025: c2h3 + oh -> c2h2 + h2o
+
+!     Benson 1967
+
+      f025(:) = 8.3e-12
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f025(:)
+
+!---  f026: c2h4 + o -> cho + ch3
+
+!     Hampson and Garvin 1977
+
+      f026(:) = 5.5e-12*exp(-565./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f026(:)
+
+!---  f027: c2h4 + oh -> ch2o + ch3
+
+!     Hampson and Garvin 1977
+
+      f027(:) = 2.2e-12*exp(385./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f027(:)
+
+!---  f028: ch + ch4 + m -> c2h4 + h + m
+
+!     Romani 1993
+
+      f028(:) = min(2.5e-11*exp(200./t(:)),1.7e-10)
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f028(:)
+
+!---  f029: ch + co2 -> cho + co
+
+!     Berman 1982
+
+      f029(:) = 5.9e-12*exp(-350./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f029(:)
+
+!---  f030: ch + h -> c + h2
+
+!     Becker 1989
+
+      f030(:) = 1.4e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f030(:)
+
+!---  f031: ch + h2 -> 3ch2 + h
+
+!     Zabarnick 1986
+
+      f031(:) = 2.38e-10*exp(-1760./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f031(:)
+
+!---  f032: ch + h2 + m -> ch3 + m
+
+!     Romani 1993
+
+      f032(:) = 8.75e-31*exp(524./t(:))*8.3e-11*dens(:)/(dens(:)*8.75e-31*exp(524./t(:)) + 8.3e-11)
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f032(:)
+
+!---  f033: ch + o -> co + h
+
+!     Messing 1981
+
+      f033(:) = 9.5e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f033(:)
+
+!---  f034: ch + o2 -> co + oh
+
+!     Butler 1981
+
+      f034(:) = 5.9e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f034(:)
+
+!---  f035: 1ch2 + ch4 -> ch3 + ch3
+
+!     Bohland 1985
+
+      f035(:) = 7.14e-12*exp(-5050./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f035(:)
+
+!---  f036: 1ch2 + co2 -> ch2o + co
+
+!     Zahnle 86
+
+      f036(:) = 1e-12
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f036(:)
+
+!---  f037: 1ch2 + h2 -> 3ch2 + h2
+
+!     Romani 1993
+
+      f037(:) = 1.26e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f037(:)
+
+!---  f038: 1ch2 + h2 -> ch3 + h
+
+!     Tsang 1986
+
+      f038(:) = 5.0e-15
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f038(:)
+
+!---  f039: 1ch2 + m -> 3ch2 + m
+
+!     Ashfold 1981
+
+      f039(:) = 8.8e-12
+
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = f039(:)
+
+!---  f040: 1ch2 + o2 -> cho + oh
+
+!     Ashfold 1981
+
+      f040(:) = 3.0e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f040(:)
+
+!---  f041: 3ch2 + c2h3 -> ch3 + c2h2
+
+!     Tsang 1986
+
+      f041(:) = 3.0e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f041(:)
+
+!---  f042: 3ch2 + ch3 -> c2h4 + h
+
+!     Tsang 1986
+
+      f042(:) = 7.0e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f042(:)
+
+!---  f043: 3ch2 + co + m -> ch2co + m
+
+!     Yung 1984
+
+      f043(:) = 1.0e-28*1e-15*dens(:)/(dens(:)*1.0e-28 + 1e-15)
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f043(:)
+
+
+!---  f044: 3ch2 + co2 -> ch2o + co
+
+!     Laufer 1981
+
+      f044(:) = 1.0e-14
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f044(:)
+
+!---  f045: 3ch2 + h  -> ch + h2
+
+!     Zabarnick  1986
+
+      f045(:) = 4.7e-10*exp(-370./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f045(:)
+
+!---  f046: 3ch2 + h + m -> ch3 +  m
+
+!     Gladstone  1996
+
+      f046(:) = 1.5e-10*3.1e-30*exp(475./t(:))/(1.5e-10 + dens(:)*3.1e-30*exp(475./t(:)))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f046(:)
+
+!---  f047: 3ch2 + o -> ch + oh
+
+!     Huebner  1980
+
+      f047(:) = 8.0e-12
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f047(:)
+
+!---  f048: 3ch2 + o -> co + h+h
+
+!     Homann  1983
+
+      f048(:) = 8.3e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f048(:)
+
+!---  f049: 3ch2 + o -> cho + h
+
+!     Homann  1983
+
+      f049(:) = 1.0e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f049(:)
+
+!---  f050: 3ch2 + o2 -> hco + oh
+
+!     Baulch  1994
+
+      f050(:) = 4.1e-11*exp(-750./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f050(:)
+
+!---  f051: ch2co + h -> ch3 + co
+
+!     Michael  1979
+
+      f051(:) = 1.9e-11*exp(-1725./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f051(:)
+
+!---  f052: ch2co + o -> h2co + co
+
+!     Lee  1980
+
+      f052(:) = 3.3e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f052(:)
+
+!---  f053: ch3 + ch3 + m -> c2h6 + m
+
+!     Wagner  1988
+
+      do ilev = 1,lswitch-1
+         ak0 = 1.17e-25*exp(-500./t(ilev))*(t(ilev)/300.)**(-3.75)
+         ak1 = 3.0e-11*(t(ilev)/300.)**(-1.0)
+
+         rate = (ak0*dens(ilev))/(1. + ak0*dens(ilev)/ak1)
+         xpo = 1./(1. + alog10((ak0*dens(ilev))/ak1)**2.)
+         f053(ilev) = rate*0.6**xpo
+      end do
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = f053(:)
+
+!---  f054: ch3 + co + m -> ch3co + m
+
+!     Watkins  1974
+
+      f054(:) = 1.4e-32*exp(-3000./t(:))*dens(:)
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f054(:)
+
+!---  f055: ch3 + h + m -> ch4 + m
+
+!     Baulch  1994
+
+
+      do ilev = 1,lswitch-1
+         ak0 = 1.0e-28*(t(ilev)/300.)**(-1.8)
+         ak1 = 2.e-10*(t(ilev)/300.)**(-0.4)
+
+         rate = (ak0*dens(ilev))/(1. + ak0*dens(ilev)/ak1)
+         xpo = 1./(1. + alog10((ak0*dens(ilev))/ak1)**2.)
+         f055(ilev) = rate*0.6**xpo
+      end do
+
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f055(:)
+
+!---  f056: ch3 + ch2o -> ch4 + cho
+
+!     Baulch  1994
+
+      f056(:) = 1.6e-16*exp(899./t(:))*(t(:)/298.)**6.1
+!      f056(:) = 4.9e-15*(t(:)/298.)**4.4 *exp(-2450./t(:)) 
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f056(:)
+
+!---  f057: ch3 + cho -> ch4 + co
+
+!     Tsang  1986
+
+      f057(:) = 5.0e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f057(:)
+
+!---  f058: ch3 + o -> ch2o + h
+
+!     Sander  2006
+
+      f058(:) = 1.1e-10
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f058(:)
+
+!---  f059: ch3 + o2 -> ch2o + oh
+
+!     Sander  2006
+
+
+      do ilev = 1,lswitch-1
+         ak0 = 4.5e-31*(t(ilev)/300.)**(-3.)
+         ak1 = 1.8e-12*(t(ilev)/300.)**(-1.7)
+
+         rate = (ak0*dens(ilev))/(1. + ak0*dens(ilev)/ak1)
+         xpo = 1./(1. + alog10((ak0*dens(ilev))/ak1)**2.)
+         f059(ilev) = rate*0.6**xpo
+      end do
+
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f059(:)
+
+!---  f060: ch3 + o3 -> ch2o + ho2
+
+!     Sander  2006
+
+      f060(:) = 5.4e-12*exp(-220./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f060(:)
+
+!---  f061: ch3 + o3 -> ch3o + o2
+
+!     Sander  2006
+
+      f061(:) = 5.4e-12*exp(-220.0/t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f061(:)
+
+!---  f062: 3ch2 + c2h3 -> ch3 + c2h2
+
+!     Tsang  1986
+
+      f062(:) = 3.0e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f062(:)
+
+!---  f063: ch3 + oh -> ch3o + h
+
+!     Jasper  2007
+
+      f063(:) = 9.3e-11*exp(-1606/t(:))*(t(:)/298.)
+!      f063(:) = 1.3e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f063(:)
+
+!---  f064: ch3 + oh -> co + h2 + h2
+
+!     Fenimore [1969]
+
+      f064(:) = 6.7e-12
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f064(:)
+
+!---  f065: ch3co + ch3 -> c2h6 + co
+
+!     Adachi  1981
+
+      f065(:) = 5.4e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f065(:)
+
+!---  f066: ch3co + ch3 -> ch4 + ch2co
+
+!     Adachi  1981
+
+      f066(:) = 8.6e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f066(:)
+
+!---  f067: ch3co + h -> ch4 + co
+
+!     Zahnle  1986
+
+      f067(:) = 1.0e-10
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f067(:)
+
+!---  f068: ch3co + o -> ch2o + cho
+
+!     Zahnle  1986
+
+      f068(:) = 5.0e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f068(:)
+
+!---  f069: ch3o + co -> ch3 + co2
+
+!     Wen  1989
+
+      f069(:) = 2.6e-11*exp(-5940.0/t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f069(:)
+
+!---  f070: ch4 + o -> ch3 + oh
+
+!     Tsang  1986
+
+      f070(:) = 8.75E-12*exp(-4330.0/t(:))*(t(:)/298.0)**1.5
+!      f070(:) = 5.8E-11*exp(-4450.0/t(:))     
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f070(:)
+
+!---  f071: ch4 + oh -> ch3 + h2o
+
+!     Sander  2006
+
+      f071(:) = 2.45e-12*exp(-1775.0/t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f071(:)
+
+!---  f072: h + co + m -> cho + m
+
+!     Baulch  1994
+
+      f072(:) = 1.4e-34*exp(-100.0/t(:))*dens(:)
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f072(:)
+
+!---  f073: h + cho -> h2 + co
+
+!     Baulch  1992
+
+      f073(:) = 1.8e-10
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f073(:)
+
+!---  f074: ch2o + h -> h2 + cho
+
+!     Baulch  1994
+
+      f074(:) = 2.14e-12*exp(-1090/t(:))*(t(:)/298)**1.62
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f074(:)
+
+!---  f075: ch2o + o -> cho + oh
+
+!     Sander  2006
+
+      f075(:) = 3.4e-11*exp(-1600/t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f075(:)
+
+!---  f076: ch2o + oh -> h2o + cho
+
+!     Sander  2006
+
+      f076(:) = 5.5e-12*exp(125/t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f076(:)
+
+!---  f077: cho + ch2o -> ch3o + co
+
+!     Wen  1989
+
+      f077(:) = 3.8e-17
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f077(:)
+
+!---  f078: cho + cho -> ch2o + co
+
+!     Tsang  1986
+
+      f078(:) = 4.5e-11
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = f078(:)
+
+!---  f079: cho + o2 -> ho2 + co
+
+!     Sander 2006
+
+      f079(:) = 5.2e-12
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f079(:)
+
+!---  f080: o + cho -> h + co2
+
+!     Tsang 1986
+
+      f080(:) = 5.0e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f080(:)
+
+!---  f081: o + cho -> oh + co
+
+!     Hampson 1977
+
+      f081(:) = 1.0e-10
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f081(:)
+
+!---  f082: oh + cho -> h2o + co
+
+!     Tsang 1986
+
+      f082(:) = 1.0e-10
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = f082(:)
+
+
+endif 
+
+
+
+
+!----------------------------------------------------------------------
+!     heterogeneous chemistry 
+!----------------------------------------------------------------------
+
+      if (1.eq.0) then
+      if (hetero_ice) then
+
+!        k = (surface*v*gamma)/4 (s-1)
+!        v = 100*sqrt(8rt/(pi*m))  (cm s-1)
+ 
+!---     h001: ho2 + ice -> products
+ 
+!        cooper and abbatt, 1996: gamma = 0.025
+      
+         gam = 0.025
+         h001(:) = surfice1d(:)       &
+                   *100.*sqrt(8.*8.31*t(:)/(33.e-3*pi))*gam/4.
+ 
+!        h002: oh + ice -> products
+ 
+!        cooper and abbatt, 1996: gamma = 0.03
+ 
+         gam = 0.03
+         h002(:) = surfice1d(:)       &
+                   *100.*sqrt(8.*8.31*t(:)/(17.e-3*pi))*gam/4.
+
+!---     h003: h2o2 + ice -> products
+ 
+!        gamma = 0.    test value
+ 
+         gam = 0.
+         h003(:) = surfice1d(:)       &
+                   *100.*sqrt(8.*8.31*t(:)/(34.e-3*pi))*gam/4.
+      else
+         h001(:) = 0.
+         h002(:) = 0.
+         h003(:) = 0.
+      end if
+
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = h001(:)
+
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = h002(:)
+
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = h003(:)
+
+      if (hetero_dust) then
+ 
+!---     h004: ho2 + dust -> products
+ 
+!        jacob, 2000: gamma = 0.2
+!        see dereus et al., atm. chem. phys., 2005
+ 
+         gam = 0.2
+         h004(:) = surfdust1d(:)  &
+                   *100.*sqrt(8.*8.31*t(:)/(33.e-3*pi))*gam/4.
+ 
+!---     h005: h2o2 + dust -> products
+ 
+!        gamma = 5.e-4
+!        see dereus et al., atm. chem. phys., 2005
+ 
+         gam = 5.e-4
+         h005(:) = surfdust1d(:)  &
+                   *100.*sqrt(8.*8.31*t(:)/(34.e-3*pi))*gam/4.
+      else
+         h004(:) = 0.
+         h005(:) = 0.
+      end if
+ 
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = h004(:)
+
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = h005(:)
+
+      endif
+end subroutine reactionrates
+
+!======================================================================
+
+ subroutine fill_matrix(ilev, mat, prod, loss, c, nesp, nlayer, v_phot, v_3, v_4)
+
+!======================================================================
+! filling of the jacobian matrix
+!======================================================================
+
+use types_asis
+
+implicit none
+
+#include "chimiedata.h"
+
+! input
+
+integer             :: ilev    ! level index
+integer             :: nesp    ! number of species in the chemistry
+integer, intent(in) :: nlayer  ! number of atmospheric layers
+
+real (kind = 8), dimension(nlayer,nesp)              :: c    ! number densities
+real (kind = 8), dimension(nlayer,      nb_phot_max) :: v_phot
+real (kind = 8), dimension(nlayer,nb_reaction_3_max) :: v_3
+real (kind = 8), dimension(nlayer,nb_reaction_4_max) :: v_4
+
+! output
+
+real (kind = 8), dimension(nesp,nesp), intent(out) :: mat  ! matrix
+real (kind = 8), dimension(nesp), intent(out)      :: prod, loss
+
+! local
+
+integer :: iesp
+integer :: ind_phot_2,ind_phot_4,ind_phot_6
+integer :: ind_3_2,ind_3_4,ind_3_6
+integer :: ind_4_2,ind_4_4,ind_4_6,ind_4_8
+integer :: iphot,i3,i4
+
+real(kind = jprb) :: eps, eps_4  ! implicit/explicit coefficient
+
+! initialisations 
+
+mat(:,:) = 0.
+prod(:)  = 0.
+loss(:)  = 0.
+
+! photodissociations
+! or reactions a + c -> b + c
+! or reactions a + ice -> b + c
+
+do iphot = 1,nb_phot_max
+
+  ind_phot_2 = indice_phot(iphot)%z2
+  ind_phot_4 = indice_phot(iphot)%z4
+  ind_phot_6 = indice_phot(iphot)%z6
+
+  mat(ind_phot_2,ind_phot_2) = mat(ind_phot_2,ind_phot_2) + indice_phot(iphot)%z1*v_phot(ilev,iphot)
+  mat(ind_phot_4,ind_phot_2) = mat(ind_phot_4,ind_phot_2) - indice_phot(iphot)%z3*v_phot(ilev,iphot)
+  mat(ind_phot_6,ind_phot_2) = mat(ind_phot_6,ind_phot_2) - indice_phot(iphot)%z5*v_phot(ilev,iphot)
+
+  loss(ind_phot_2) = loss(ind_phot_2) + indice_phot(iphot)%z1*v_phot(ilev,iphot)
+  prod(ind_phot_4) = prod(ind_phot_4) + indice_phot(iphot)%z3*v_phot(ilev,iphot)*c(ilev,ind_phot_2)
+  prod(ind_phot_6) = prod(ind_phot_6) + indice_phot(iphot)%z5*v_phot(ilev,iphot)*c(ilev,ind_phot_2)
+
+end do
+
+! reactions a + a -> b + c 
+
+do i3 = 1,nb_reaction_3_max
+
+  ind_3_2 = indice_3(i3)%z2
+  ind_3_4 = indice_3(i3)%z4
+  ind_3_6 = indice_3(i3)%z6
+
+  mat(ind_3_2,ind_3_2) = mat(ind_3_2,ind_3_2) + indice_3(i3)%z1*v_3(ilev,i3)*c(ilev,ind_3_2)
+  mat(ind_3_4,ind_3_2) = mat(ind_3_4,ind_3_2) - indice_3(i3)%z3*v_3(ilev,i3)*c(ilev,ind_3_2)
+  mat(ind_3_6,ind_3_2) = mat(ind_3_6,ind_3_2) - indice_3(i3)%z5*v_3(ilev,i3)*c(ilev,ind_3_2)
+
+  loss(ind_3_2) = loss(ind_3_2) + indice_3(i3)%z1*v_3(ilev,i3)*c(ilev,ind_3_2)
+  prod(ind_3_4) = prod(ind_3_4) + indice_3(i3)%z3*v_3(ilev,i3)*c(ilev,ind_3_2)*c(ilev,ind_3_2)
+  prod(ind_3_6) = prod(ind_3_6) + indice_3(i3)%z5*v_3(ilev,i3)*c(ilev,ind_3_2)*c(ilev,ind_3_2)
+
+end do
+
+! reactions a + b -> c + d 
+
+eps = 1.d-10
+
+do i4 = 1,nb_reaction_4_max
+
+  ind_4_2 = indice_4(i4)%z2
+  ind_4_4 = indice_4(i4)%z4
+  ind_4_6 = indice_4(i4)%z6
+  ind_4_8 = indice_4(i4)%z8
+
+  eps_4 = abs(c(ilev,ind_4_2))/(abs(c(ilev,ind_4_2)) + abs(c(ilev,ind_4_4)) + eps)
+  eps_4 = min(eps_4,1.0_jprb)
+
+  mat(ind_4_2,ind_4_2) = mat(ind_4_2,ind_4_2) + indice_4(i4)%z1*v_4(ilev,i4)*(1. - eps_4)*c(ilev,ind_4_4) 
+  mat(ind_4_2,ind_4_4) = mat(ind_4_2,ind_4_4) + indice_4(i4)%z1*v_4(ilev,i4)*eps_4*c(ilev,ind_4_2)
+  mat(ind_4_4,ind_4_2) = mat(ind_4_4,ind_4_2) + indice_4(i4)%z3*v_4(ilev,i4)*(1. - eps_4)*c(ilev,ind_4_4)
+  mat(ind_4_4,ind_4_4) = mat(ind_4_4,ind_4_4) + indice_4(i4)%z3*v_4(ilev,i4)*eps_4*c(ilev,ind_4_2)   
+  mat(ind_4_6,ind_4_2) = mat(ind_4_6,ind_4_2) - indice_4(i4)%z5*v_4(ilev,i4)*(1. - eps_4)*c(ilev,ind_4_4)
+  mat(ind_4_6,ind_4_4) = mat(ind_4_6,ind_4_4) - indice_4(i4)%z5*v_4(ilev,i4)*eps_4*c(ilev,ind_4_2)
+  mat(ind_4_8,ind_4_2) = mat(ind_4_8,ind_4_2) - indice_4(i4)%z7*v_4(ilev,i4)*(1. - eps_4)*c(ilev,ind_4_4)
+  mat(ind_4_8,ind_4_4) = mat(ind_4_8,ind_4_4) - indice_4(i4)%z7*v_4(ilev,i4)*eps_4*c(ilev,ind_4_2)
+
+  loss(ind_4_2) = loss(ind_4_2) + indice_4(i4)%z1*v_4(ilev,i4)*c(ilev,ind_4_4)
+  loss(ind_4_4) = loss(ind_4_4) + indice_4(i4)%z3*v_4(ilev,i4)*c(ilev,ind_4_2)
+  prod(ind_4_6) = prod(ind_4_6) + indice_4(i4)%z5*v_4(ilev,i4)*c(ilev,ind_4_2)*c(ilev,ind_4_4)
+  prod(ind_4_8) = prod(ind_4_8) + indice_4(i4)%z7*v_4(ilev,i4)*c(ilev,ind_4_2)*c(ilev,ind_4_4)
+
+end do
+
+end subroutine fill_matrix
+
+!================================================================
+
+ subroutine indice(i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,       &
+                   i_h2, i_oh, i_ho2, i_h2o2, i_h2o,               &
+                   i_n, i_n2d, i_no, i_no2, i_n2,                  &
+                   i_ch4, i_ch3, i_3ch2, i_1ch2, i_cho, i_ch2o,    &
+                   i_ch3o, i_c, i_c2, i_c2h, i_c2h2, i_c2h3,       &
+                   i_c2h4, i_c2h6, i_ch2co, i_ch3co, i_hcaer)
+
+!================================================================
+! set the "indice" arrays used to fill the jacobian matrix      !
+!----------------------------------------------------------------
+! reaction                                   type               !
+!----------------------------------------------------------------
+! A + hv   --> B + C     photolysis          indice_phot        ! 
+! A + B    --> C + D     bimolecular         indice_4           !
+! A + A    --> B + C     quadratic           indice_3           !
+! A + C    --> B + C     quenching           indice_phot        !
+! A + ice  --> B + C     heterogeneous       indice_phot        !
+!================================================================
+
+use types_asis
+
+implicit none
+
+#include "chimiedata.h"
+
+! input
+
+integer :: i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,       &
+           i_h2, i_oh, i_ho2, i_h2o2, i_h2o,               &
+           i_n, i_n2d, i_no, i_no2, i_n2,                  &
+           i_ch4, i_ch3, i_3ch2, i_1ch2, i_cho, i_ch2o,    &
+           i_ch3o, i_c, i_c2, i_c2h, i_c2h2, i_c2h3,       &
+           i_c2h4, i_c2h6, i_ch2co, i_ch3co, i_hcaer
+
+! local
+
+integer :: nb_phot, nb_reaction_3, nb_reaction_4
+integer :: i_dummy
+
+allocate (indice_phot(nb_phot_max))
+allocate (indice_3(nb_reaction_3_max))
+allocate (indice_4(nb_reaction_4_max))
+
+i_dummy = 1
+
+nb_phot       = 0
+nb_reaction_3 = 0
+nb_reaction_4 = 0
+
+!===========================================================
+!      O2 + hv -> O + O
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_o2, 2.0, i_o, 0.0, i_dummy) 
+
+!===========================================================
+!      O2 + hv -> O + O(1D)
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_o2, 1.0, i_o, 1.0, i_o1d) 
+
+!===========================================================
+!      CO2 + hv -> CO + O
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_co2, 1.0, i_co, 1.0, i_o) 
+
+!===========================================================
+!      CO2 + hv -> CO + O(1D)
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_co2, 1.0, i_co, 1.0, i_o1d) 
+
+!===========================================================
+!      O3 + hv -> O2 + O(1D)
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_o3, 1.0, i_o2, 1.0, i_o1d) 
+
+!===========================================================
+!      O3 + hv -> O2 + O
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_o3, 1.0, i_o2, 1.0, i_o) 
+
+!===========================================================
+!      H2O + hv -> H + OH
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_h2o, 1.0, i_h, 1.0, i_oh) 
+
+!===========================================================
+!      H2O2 + hv -> OH + OH
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_h2o2, 2.0, i_oh, 0.0, i_dummy) 
+
+!===========================================================
+!      HO2 + hv -> OH + O
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_ho2, 1.0, i_oh, 1.0, i_o) 
+
+!===========================================================
+!      NO + hv -> N + O
+!===========================================================
+
+!nb_phot = nb_phot + 1
+
+!indice_phot(nb_phot) = z3spec(1.0, i_no, 1.0, i_n, 1.0, i_o) 
+
+!===========================================================
+!      NO2 + hv -> NO + O
+!===========================================================
+
+!nb_phot = nb_phot + 1
+
+!indice_phot(nb_phot) = z3spec(1.0, i_no2, 1.0, i_no, 1.0, i_o) 
+
+!===========================================================
+!      HNO3 + hv -> NO2 + OH
+!===========================================================
+
+!nb_phot = nb_phot + 1
+
+!indice_phot(nb_phot) = z3spec(1.0, i_hno3, 1.0, i_no2, 1.0, i_oh)
+
+!===========================================================
+!      HNO4 + hv -> NO2 + HO2
+!===========================================================
+
+!nb_phot = nb_phot + 1
+
+!indice_phot(nb_phot) = z3spec(1.0, i_hno4, 1.0, i_no2, 1.0, i_ho2)
+
+if(1.eq.1) then
+!===========================================================
+!      CH4 + hv -> CH3 + H
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_ch4, 1.0, i_ch3, 1.0, i_h)
+
+!===========================================================
+!      CH4 + hv -> 1CH2 + H2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_ch4, 1.0, i_1ch2, 1.0, i_h2)
+
+!===========================================================
+!      CH4 + hv -> 1CH2 + H + H
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_ch4, 1.0, i_3ch2, 2.0, i_h)
+
+!===========================================================
+!      CH4 + hv -> CH + H2 + H
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(0.5, i_ch4, 1.0, i_ch, 0.0, i_dummy)
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(0.5, i_ch4, 1.0, i_h2, 1.0, i_h)
+
+!if(1.eq.0) then
+!===========================================================
+!      CH2O + hv -> CHO + H
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_ch2o, 1.0, i_cho, 1.0, i_h)
+
+!===========================================================
+!      CH2O + hv -> CO + H2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_ch2o, 1.0, i_co, 1.0, i_h2)
+
+!===========================================================
+!      C2H6 + hv -> CH4 + 1CH2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_c2h6, 1.0, i_ch4, 1.0, i_1ch2)
+
+!===========================================================
+!      C2H6 + hv -> C2H2 + H2 + H2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_c2h6, 1.0, i_c2h2, 2.0, i_h2)
+
+!===========================================================
+!      C2H6 + hv -> C2H4 + H + H
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_c2h6, 1.0, i_c2h4, 2.0, i_h)
+
+!===========================================================
+!      C2H6 + hv -> C2H4 + H2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_c2h6, 1.0, i_c2h4, 1.0, i_h2)
+
+!===========================================================
+!      C2H6 + hv -> CH3 + CH3
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_c2h6, 2.0, i_ch3, 0.0, i_dummy)
+
+!===========================================================
+!      C2H2 + hv -> C2H + H
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_c2h2, 1.0, i_c2h, 1.0, i_h)
+
+!===========================================================
+!      C2H2 + hv -> C2 + H2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_c2h2, 1.0, i_c2, 1.0, i_h2)
+
+!===========================================================
+!      C2H4 + hv -> C2H2 + H2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_c2h4, 1.0, i_c2h2, 1.0, i_h2)
+
+!===========================================================
+!      C2H4 + hv -> C2H2 + H + H
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_c2h4, 1.0, i_c2h2, 2.0, i_h)
+
+!===========================================================
+!      CH2CO + hv -> 3CH2 + CO
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_ch2co, 1.0, i_3ch2, 1.0, i_co)
+
+endif
+
+!===========================================================
+!      a001 : O + O2 + CO2 -> O3 + CO2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o, 1.0, i_o2, 1.0, i_o3, 0.0, i_dummy) 
+
+!===========================================================
+!      a002 : O + O + CO2 -> O2 + CO2
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_o, 1.0, i_o2, 0.0, i_dummy) 
+
+!===========================================================
+!      a003 : O + O3 -> O2 + O2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o, 1.0, i_o3, 2.0, i_o2, 0.0, i_dummy) 
+
+!===========================================================
+!      b001 : O(1D) + CO2 -> O + CO2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_o1d, 1.0, i_o, 0.0, i_dummy) 
+
+!===========================================================
+!      b002 : O(1D) + H2O -> OH + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o1d, 1.0, i_h2o, 2.0, i_oh, 0.0, i_dummy) 
+
+!===========================================================
+!      b003 : O(1D) + H2 -> OH + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o1d, 1.0, i_h2, 1.0, i_oh, 1.0, i_h) 
+
+!===========================================================
+!      b004 : O(1D) + O2 -> O + O2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_o1d, 1.0, i_o, 0.0, i_dummy) 
+
+!===========================================================
+!      b005 : O(1D) + O3 -> O2 + O2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o1d, 1.0, i_o3, 2.0, i_o2, 0.0, i_dummy) 
+
+!===========================================================
+!      b006 : O(1D) + O3 -> O2 + O + O
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o1d, 1.0, i_o3, 1.0, i_o2, 2.0, i_o) 
+
+!===========================================================
+!      b007 : O(1D) + CH4 -> CH3 + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o1d, 1.0, i_ch4, 1.0, i_ch3, 1.0, i_oh)
+
+!===========================================================
+!      b008 : O(1D) + CH4 -> CH3O + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o1d, 1.0, i_ch4, 1.0, i_ch3o, 1.0, i_h)
+
+!===========================================================
+!      b009 : O(1D) + CH4 -> CH2O + H2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o1d, 1.0, i_ch4, 1.0, i_ch2o, 1.0, i_h2)
+
+
+!===========================================================
+!      c001 : O + HO2 -> OH + O2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o, 1.0, i_ho2, 1.0, i_oh, 1.0, i_o2) 
+
+!===========================================================
+!      c002 : O + OH -> O2 + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o, 1.0, i_oh, 1.0, i_o2, 1.0, i_h) 
+
+!===========================================================
+!      c003 : H + O3 -> OH + O2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_h, 1.0, i_o3, 1.0, i_oh, 1.0, i_o2) 
+
+!===========================================================
+!      c004 : H + HO2 -> OH + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_h, 1.0, i_ho2, 2.0, i_oh, 0.0, i_dummy) 
+
+!===========================================================
+!      c005 : H + HO2 -> H2 + O2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_h, 1.0, i_ho2, 1.0, i_h2, 1.0, i_o2) 
+
+!===========================================================
+!      c006 : H + HO2 -> H2O + O
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_h, 1.0, i_ho2, 1.0, i_h2o, 1.0, i_o) 
+
+!===========================================================
+!      c007 : OH + HO2 -> H2O + O2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_oh, 1.0, i_ho2, 1.0, i_h2o, 1.0, i_o2) 
+
+!===========================================================
+!      c008 : HO2 + HO2 -> H2O2 + O2
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_ho2, 1.0, i_h2o2, 1.0, i_o2) 
+
+!===========================================================
+!      c009 : OH + H2O2 -> H2O + HO2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_oh, 1.0, i_h2o2, 1.0, i_h2o, 1.0, i_ho2) 
+
+!===========================================================
+!      c010 : OH + H2 -> H2O + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_oh, 1.0, i_h2, 1.0, i_h2o, 1.0, i_h) 
+
+!===========================================================
+!      c011 : H + O2 + CO2 -> HO2 + CO2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_h, 1.0, i_o2, 1.0, i_ho2, 0.0, i_dummy) 
+
+!===========================================================
+!      c012 : O + H2O2 -> OH + HO2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o, 1.0, i_h2o2, 1.0, i_oh, 1.0, i_ho2) 
+
+!===========================================================
+!      c013 : OH + OH -> H2O + O
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_oh, 1.0, i_h2o, 1.0, i_o) 
+
+!===========================================================
+!      c014 : OH + O3 -> HO2 + O2 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_oh, 1.0, i_o3, 1.0, i_ho2, 1.0, i_o2) 
+
+!===========================================================
+!      c015 : HO2 + O3 -> OH + O2 + O2 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ho2, 1.0, i_o3, 1.0, i_oh, 2.0, i_o2) 
+
+!===========================================================
+!      c016 : HO2 + HO2 + CO2 -> H2O2 + O2 + CO2 
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_ho2, 1.0, i_h2o2, 1.0, i_o2) 
+
+!===========================================================
+!      c017 : OH + OH + CO2 -> H2O2 + CO2 
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_oh, 1.0, i_h2o2, 0.0, i_dummy) 
+
+!===========================================================
+!      c018 : H + H + CO2 -> H2 + CO2 
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_h, 1.0, i_h2, 0.0, i_dummy) 
+
+if(1.eq.0) then
+
+!===========================================================
+!      d001 : NO2 + O -> NO + O2 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_no2, 1.0, i_o, 1.0, i_no, 1.0, i_o2) 
+
+!===========================================================
+!      d002 : NO + O3 -> NO2 + O2 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_no, 1.0, i_o3, 1.0, i_no2, 1.0, i_o2) 
+
+!===========================================================
+!      d003 : NO + HO2 -> NO2 + OH 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_no, 1.0, i_ho2, 1.0, i_no2, 1.0, i_oh) 
+
+!===========================================================
+!      d004 : N + NO -> N2 + O 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_n, 1.0, i_no, 1.0, i_n2, 1.0, i_o) 
+
+!===========================================================
+!      d005 : N + O2 -> NO + O 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_n, 1.0, i_o2, 1.0, i_no, 1.0, i_o) 
+
+!===========================================================
+!      d006 : NO2 + H -> NO + OH 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_no2, 1.0, i_h, 1.0, i_no, 1.0, i_oh) 
+
+!===========================================================
+!      d007 : N + O -> NO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_n, 1.0, i_o, 1.0, i_no, 0.0, i_dummy) 
+
+!===========================================================
+!      d008 : N + HO2 -> NO + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_n, 1.0, i_ho2, 1.0, i_no, 1.0, i_oh) 
+
+!===========================================================
+!      d009 : N + OH -> NO + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_n, 1.0, i_oh, 1.0, i_no, 1.0, i_h) 
+
+endif
+
+!===========================================================
+!      e001 : CO + OH -> CO2 + H 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_co, 1.0, i_oh, 1.0, i_co2, 1.0, i_h) 
+
+!===========================================================
+!      e002 : CO + O + M -> CO2 + M 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_co, 1.0, i_o, 1.0, i_co2, 0.0, i_dummy) 
+
+
+if(1.eq.1) then
+!===========================================================
+!      f001 : 3CH2 + 3CH2 -> C2H2 + H2 
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_3ch2, 1.0, i_c2h2, 1.0, i_h2)
+
+!===========================================================
+!      f002 : C + H2 + m -> 3CH2 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c, 1.0, i_h2, 1.0, i_3ch2, 0.0, i_dummy)
+
+!===========================================================
+!      f003 : C + O2  -> CO + O
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c, 1.0, i_o2, 1.0, i_co, 1.0, i_o)
+
+!===========================================================
+!      f004 : C + OH -> CO + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c, 1.0, i_oh, 1.0, i_co, 1.0, i_h)
+
+!===========================================================
+!      f005 : C2 + CH4 -> C2H + CH3
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2, 1.0, i_ch4, 1.0, i_c2h, 1.0, i_ch3)
+
+!===========================================================
+!      f006 : C2 + H2 -> C2H + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2, 1.0, i_h2, 1.0, i_c2h, 1.0, i_h)
+
+!===========================================================
+!      f007 : C2 + O -> C + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2, 1.0, i_o, 1.0, i_c, 1.0, i_co)
+
+!===========================================================
+!      f008 : C2 + O2 -> CO + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2, 1.0, i_o2, 2.0, i_co, 0.0, i_dummy)
+
+!===========================================================
+!      f009 : C2H + C2H2 -> HCAER + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h, 1.0, i_c2h2, 1.0, i_hcaer, 1.0, i_h)
+
+!===========================================================
+!      f010 : C2H + CH4 -> C2H2 + CH3
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h, 1.0, i_ch4, 1.0, i_c2h2, 1.0, i_ch3)
+
+!===========================================================
+!      f011 : C2H + H + m -> C2H2 + m
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h, 1.0, i_h, 1.0, i_c2h2, 0.0, i_dummy)
+
+!===========================================================
+!      f012 : C2H + H2 -> C2H2 + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h, 1.0, i_h2, 1.0, i_c2h2, 1.0, i_h)
+
+!===========================================================
+!      f013 : C2H + O -> CO + CH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h, 1.0, i_o, 1.0, i_co, 1.0, i_ch)
+
+!===========================================================
+!      f014 : C2H + O2 -> CO + CHO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h, 1.0, i_o2, 1.0, i_co, 1.0, i_cho)
+
+!===========================================================
+!      f015 : C2H2 + H + m -> C2H3 + m
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h2, 1.0, i_h, 1.0, i_c2h3, 0.0, i_dummy)
+
+!===========================================================
+!      f016 : C2H2 + O -> 3CH2 + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h2, 1.0, i_o, 1.0, i_3ch2, 1.0, i_co)
+
+!===========================================================
+!      f017 : C2H2 + OH + m -> CH2CO + H + m
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h2, 1.0, i_oh, 1.0, i_ch2co, 1.0, i_h)
+
+!===========================================================
+!      f018 : C2H2 + OH -> CO + CH3 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h2, 1.0, i_oh, 1.0, i_co, 1.0, i_ch3)
+
+!===========================================================
+!      f019 : C2H3 + C2H3 -> C2H4 + C2H2
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_c2h3, 1.0, i_c2h4, 1.0, i_c2h2)
+
+!===========================================================
+!      f020 : C2H3 + CH3 -> C2H2 + CH4
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h3, 1.0, i_ch3, 1.0, i_c2h2, 1.0, i_ch4)
+
+!===========================================================
+!      f021 : C2H3 + CH4 -> C2H4 + CH3
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h3, 1.0, i_ch4, 1.0, i_c2h4, 1.0, i_ch3)
+
+!===========================================================
+!      f022 : C2H3 + H -> C2H2 + H2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h3, 1.0, i_h, 1.0, i_c2h2, 1.0, i_h2)
+
+!===========================================================
+!      f023 : C2H3 + H2 -> C2H4 + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h3, 1.0, i_h2, 1.0, i_c2h4, 1.0, i_h)
+
+!===========================================================
+!      f024 : C2H3 + O -> CH2CO + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h3, 1.0, i_o, 1.0, i_ch2co, 1.0, i_h)
+
+!===========================================================
+!      f025 : C2H3 + OH -> C2H2 + H2O
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h3, 1.0, i_oh, 1.0, i_c2h2, 1.0, i_h2o)
+
+!===========================================================
+!      f026 : C2H4 + O -> CHO + CH3
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h4, 1.0, i_o, 1.0, i_cho, 1.0, i_ch3)
+
+!===========================================================
+!      f027 : C2H4 + OH -> CH2O + CH3
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_c2h4, 1.0, i_oh, 1.0, i_ch2O, 1.0, i_ch3)
+
+!===========================================================
+!      f028 : CH + CH4 -> C2H4 + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch, 1.0, i_ch4, 1.0, i_c2h4, 1.0, i_h)
+
+!===========================================================
+!      f029 : CH + CO2 -> CHO + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch, 1.0, i_co2, 1.0, i_cho, 1.0, i_co)
+
+!===========================================================
+!      f030 : CH + H -> C + H2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch, 1.0, i_h, 1.0, i_c, 1.0, i_h2)
+
+!===========================================================
+!      f031 : CH + H2 -> 3CH2 + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch, 1.0, i_h2, 1.0, i_3ch2, 1.0, i_h)
+
+!===========================================================
+!      f032 : CH + H2 + m -> CH3 +m
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch, 1.0, i_h2, 1.0, i_ch3, 0.0, i_dummy)
+
+!===========================================================
+!      f033 : CH + O -> CO + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch, 1.0, i_o, 1.0, i_co, 1.0, i_h)
+
+!===========================================================
+!      f034 : CH + O2 -> CO + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch, 1.0, i_o2, 1.0, i_co, 1.0, i_oh)
+
+!===========================================================
+!      f035 : 1CH2 + CH4 -> CH3 + CH3
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_1ch2, 1.0, i_ch4, 2.0, i_ch3, 0.0, i_dummy)
+
+!===========================================================
+!      f036 : 1CH2 + CO2 -> CH2O + CO 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_1ch2, 1.0, i_co2, 1.0, i_ch2o, 1.0, i_co)
+
+!===========================================================
+!      f037 : 1CH2 + H2 -> 3CH2 + H2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_1ch2, 1.0, i_h2, 1.0, i_3ch2, 1.0,i_h2)
+
+!===========================================================
+!      f038 : 1CH2 + H2 -> CH3 + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_1ch2, 1.0, i_h2, 1.0, i_ch3, 1.0, i_h)
+
+!===========================================================
+!      f039 : 1CH2 + m -> 3CH2 + m
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_1ch2, 1.0, i_3ch2, 0.0, i_dummy)
+
+
+!===========================================================
+!      f040 : 1CH2 + O2 -> CHO + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_1ch2, 1.0, i_o2, 1.0, i_cho, 1.0, i_oh)
+
+!===========================================================
+!      f041 : 3CH2 + C2H3 -> CH3 + C2H2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_3ch2, 1.0, i_c2h3, 1.0, i_ch3, 1.0, i_c2h2)
+
+!===========================================================
+!      f042 : 3CH2 + CH3 -> C2H4 + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_3ch2, 1.0, i_ch3, 1.0, i_c2h4, 1.0, i_h)
+
+!===========================================================
+!      f043 : 3CH2 + CO + m -> CH2CO + m
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_3ch2, 1.0, i_co, 1.0, i_ch2co, 0.0, i_dummy)
+
+!===========================================================
+!      f044 : 3CH2 + CO2 -> CH2O + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_3ch2, 1.0, i_co2, 1.0, i_ch2o, 1.0, i_co)
+
+!===========================================================
+!      f045 : 3CH2 + H -> CH + H2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_3ch2, 1.0, i_h, 1.0, i_ch, 1.0, i_h2)
+
+!===========================================================
+!      f046 : 3CH2 + H + m -> CH3 + m
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_3ch2, 1.0, i_h, 1.0, i_ch3, 0.0, i_dummy)
+
+!===========================================================
+!      f047 : 3CH2 + O -> CH + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_3ch2, 1.0, i_o, 1.0, i_ch, 1.0, i_oh)
+
+!===========================================================
+!      f048 : 3CH2 + O -> CO + H + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_3ch2, 1.0, i_o, 1.0, i_co, 2.0, i_h)
+
+!===========================================================
+!      f049 : 3CH2 + O -> CHO + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_3ch2, 1.0, i_o, 1.0, i_cho, 1.0, i_h)
+
+!===========================================================
+!      f050 : 3CH2 + O2 -> CHO + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_3ch2, 1.0, i_o2, 1.0, i_cho, 1.0, i_oh)
+
+!===========================================================
+!      f051 : CH2CO + H -> CH3 + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch2co, 1.0, i_h, 1.0, i_ch3, 1.0, i_co)
+
+!===========================================================
+!      f052 : CH2CO + O -> CH2O + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch2co, 1.0, i_o, 1.0, i_ch2o, 1.0, i_co)
+
+!===========================================================
+!      f053 : CH3 + CH3 + m -> C2H6 + m
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_ch3, 1.0, i_c2h6, 0.0, i_dummy)
+
+!===========================================================
+!      f054 : CH3 + CO + m -> CH3CO + m
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3, 1.0, i_co, 1.0, i_ch3co, 0.0, i_dummy)
+
+!===========================================================
+!      f055 : CH3 + H + m -> CH4 + m
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3, 1.0, i_h, 1.0, i_ch4, 0.0, i_dummy)
+
+!===========================================================
+!      f056 : CH3 + CH2O -> CH4 + CHO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3, 1.0, i_ch2o, 1.0, i_ch4, 1.0, i_cho)
+
+!===========================================================
+!      f057 : CH3 + CHO -> CH4 + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3, 1.0, i_cho, 1.0, i_ch4, 1.0, i_co)
+
+!===========================================================
+!      f058 : CH3 + O -> CH2O + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3, 1.0, i_o, 1.0, i_ch2o, 1.0, i_h)
+
+!===========================================================
+!      f059 : CH3 + O2 -> CH2O + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3, 1.0, i_o2, 1.0, i_ch2o, 1.0, i_oh)
+
+!===========================================================
+!      f060 : CH3 + O3 -> CH2O + HO2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3, 1.0, i_o3, 1.0, i_ch2o, 1.0, i_ho2)
+
+!===========================================================
+!      f061 : CH3 + O3 -> CH3O + O2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3, 1.0, i_o3, 1.0, i_ch3o, 1.0, i_o2)
+
+!===========================================================
+!      f062 : 3CH2 + C2H3 -> CH3 + CH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_3ch2, 1.0, i_c2h3, 1.0, i_ch3, 1.0, i_ch)
+
+!===========================================================
+!      f063 : CH3 + OH -> CH3O + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3, 1.0, i_oh, 1.0, i_ch3o, 1.0, i_h)
+
+!===========================================================
+!      f064 : CH3 + OH -> CO + H2 + H2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3, 1.0, i_oh, 1.0, i_co, 2.0, i_h2)
+
+!===========================================================
+!      f065 : CH3CO + CH3 -> C2H6 + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3co, 1.0, i_ch3, 1.0, i_c2h6, 1.0, i_co)
+
+!===========================================================
+!      f066 : CH3CO + CH3 -> CH4 + CH2CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3co, 1.0, i_ch3, 1.0, i_ch4, 1.0, i_ch2co)
+
+!===========================================================
+!      f067 : CH3CO + H -> CH4 + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3co, 1.0, i_h, 1.0, i_ch4, 1.0, i_co)
+
+!===========================================================
+!      f068 : CH3CO + O -> CH2O + CHO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3co, 1.0, i_o, 1.0, i_ch2o, 1.0, i_cho)
+
+!===========================================================
+!      f069 : CH3O + CO -> CH3 + CO2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch3o, 1.0, i_co, 1.0, i_ch3, 1.0, i_co2)
+
+!===========================================================
+!      f070 : CH4 + O -> CH3 + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch4, 1.0, i_o, 1.0, i_ch3, 1.0, i_oh)
+
+!===========================================================
+!      f071 : CH4 + OH -> CH3 + H2O
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch4, 1.0, i_oh, 1.0, i_ch3, 1.0, i_h2o)
+
+!===========================================================
+!      f072 : H + CO + m -> CHO + m
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_h, 1.0, i_co, 1.0, i_cho, 0.0, i_dummy)
+
+!===========================================================
+!      f073 : H + CHO -> H2 + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_h, 1.0, i_cho, 1.0, i_h2, 1.0, i_co)
+
+!===========================================================
+!      f074 : CH2O + H -> H2 + CHO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch2o, 1.0, i_h, 1.0, i_h2, 1.0, i_cho)
+
+!===========================================================
+!      f075 : CH2O + O -> CHO + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch2o, 1.0, i_o, 1.0, i_cho, 1.0, i_oh)
+
+!===========================================================
+!      f076 : CH2O + OH -> H2O + CHO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ch2o, 1.0, i_oh, 1.0, i_h2o, 1.0, i_cho)
+
+!===========================================================
+!      f077 : CHO + CH2O -> CH3O + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_cho, 1.0, i_ch2o, 1.0, i_ch3o, 1.0, i_co)
+
+!===========================================================
+!      f078 : CHO + CHO -> CH2O + CO
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_cho, 1.0, i_ch2o, 1.0, i_co)
+
+!===========================================================
+!      f079 : CHO + O2 -> HO2 + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_cho, 1.0, i_o2, 1.0, i_ho2, 1.0, i_co)
+
+!===========================================================
+!      f080 : O + CHO -> H + CO2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o, 1.0, i_cho, 1.0, i_h, 1.0, i_co2)
+
+!===========================================================
+!      f081 : CHO + O2 -> OH + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_cho, 1.0, i_o2, 1.0, i_oh, 1.0, i_co)
+
+!===========================================================
+!      f082 : OH + CHO -> H2O + CO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_oh, 1.0, i_cho, 1.0, i_h2o, 1.0, i_co)
+
+endif
+
+if(1.eq.0) then
+!===========================================================
+!      h001: HO2 + ice -> products
+!            treated as
+!            HO2 -> 0.5 H2O + 0.75 O2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_ho2, 0.5, i_h2o, 0.75, i_o2) 
+
+!===========================================================
+!      h002: OH + ice -> products
+!            treated as
+!            OH -> 0.5 H2O + 0.25 O2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_oh, 0.5, i_h2o, 0.25, i_o2) 
+
+!===========================================================
+!      h003: H2O2 + ice -> products
+!            treated as
+!            H2O2 -> H2O + 0.5 O2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_h2o2, 1.0, i_h2o, 0.5, i_o2) 
+
+!===========================================================
+!      h004: HO2 + dust -> products
+!            treated as
+!            HO2 -> 0.5 H2O + 0.75 O2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_ho2, 0.5, i_h2o, 0.75, i_o2) 
+
+!===========================================================
+!      h005: H2O2 + dust -> products
+!            treated as
+!            H2O2 -> H2O + 0.5 O2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_h2o2, 1.0, i_h2o, 0.5, i_o2) 
+
+endif
+!===========================================================
+!  check dimensions 
+!===========================================================
+
+print*, 'nb_phot       = ', nb_phot
+print*, 'nb_reaction_4 = ', nb_reaction_4
+print*, 'nb_reaction_3 = ', nb_reaction_3
+
+if ((nb_phot /= nb_phot_max)             .or.  &
+    (nb_reaction_3 /= nb_reaction_3_max) .or.  &
+    (nb_reaction_4 /= nb_reaction_4_max)) then
+   print*, 'wrong dimensions in indice' 
+   stop
+end if  
+
+end subroutine indice
+
+!*****************************************************************
+
+      subroutine gcmtochim(nlayer, nq, zycol, lswitch, nesp,         &
+                           i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h, &
+                           i_h2, i_oh, i_ho2, i_h2o2, i_h2o,         &
+                           i_n, i_n2d, i_no, i_no2, i_n2,            &
+                           i_ch4, i_ch3, i_3ch2, i_1ch2, i_cho,      &
+                           i_ch2o,i_ch3o, i_c, i_c2, i_c2h, i_c2h2,  &
+                           i_c2h3, i_c2h4, i_c2h6, i_ch2co, i_ch3co, &
+                           i_hcaer, dens, rm, c) 
+
+!*****************************************************************
+
+      use tracer_h, only:  igcm_co2, igcm_co, igcm_o, igcm_o1d,         &
+                           igcm_o2, igcm_o3, igcm_h, igcm_h2, igcm_oh,  &
+                           igcm_ho2, igcm_h2o2, igcm_h2o_vap,           &
+                           igcm_n, igcm_n2d, igcm_no, igcm_no2, igcm_n2, &
+                           igcm_ch4, igcm_ch3, igcm_ch, igcm_3ch2,       &
+                           igcm_1ch2, igcm_cho, igcm_ch2o, igcm_ch3o,    &
+                           igcm_c, igcm_c2, igcm_c2h, igcm_c2h2,         &
+                           igcm_c2h3, igcm_c2h4, igcm_c2h6, igcm_ch2co,  &
+                           igcm_ch3co, igcm_hcaer
+
+
+      use callkeys_mod
+
+      implicit none
+
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     input:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+      
+      integer, intent(in) :: nlayer ! number of atmospheric layers
+      integer, intent(in) :: nq     ! number of tracers in the gcm
+      integer :: nesp               ! number of species in the chemistry
+      integer :: lswitch            ! interface level between chemistries
+
+      integer :: i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,           &
+                 i_h2, i_oh, i_ho2, i_h2o2, i_h2o,                   &
+                 i_n, i_n2d, i_no, i_no2, i_n2, i_ch4,               &
+                 i_ch3, i_3ch2, i_1ch2, i_cho, i_ch2o,               &
+                 i_ch3o, i_c, i_c2, i_c2h, i_c2h2, i_c2h3,           &
+                 i_c2h4, i_c2h6, i_ch2co, i_ch3co, i_hcaer
+
+      real :: zycol(nlayer,nq)      ! volume mixing ratios in the gcm
+      real :: dens(nlayer)          ! total number density (molecule.cm-3) 
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     output:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      real, dimension(nlayer,nesp)            :: rm ! volume mixing ratios 
+      real (kind = 8), dimension(nlayer,nesp) :: c  ! number densities (molecule.cm-3) 
+      
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     local:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      integer      :: l, iesp
+      logical,save :: firstcall = .true.
+      
+      
+!     first call initializations
+
+      if (firstcall) then
+
+!       identify the indexes of the tracers we need
+
+         if (igcm_co2 == 0) then
+            write(*,*) "gcmtochim: Error; no CO2 tracer !!!"
+            stop
+         endif
+         if (igcm_co == 0) then
+            write(*,*) "gcmtochim: Error; no CO tracer !!!"
+            stop
+         end if
+         if (igcm_o == 0) then
+            write(*,*) "gcmtochim: Error; no O tracer !!!"
+            stop
+         end if
+         if (igcm_o1d == 0) then
+            write(*,*) "gcmtochim: Error; no O1D tracer !!!"
+            stop
+         end if
+         if (igcm_o2 == 0) then
+            write(*,*) "gcmtochim: Error; no O2 tracer !!!"
+            stop
+         end if
+         if (igcm_o3 == 0) then
+            write(*,*) "gcmtochim: Error; no O3 tracer !!!"
+            stop
+         end if
+         if (igcm_h == 0) then
+            write(*,*) "gcmtochim: Error; no H tracer !!!"
+            stop
+         end if
+         if (igcm_h2 == 0) then
+            write(*,*) "gcmtochim: Error; no H2 tracer !!!"
+            stop
+         end if
+         if (igcm_oh == 0) then
+            write(*,*) "gcmtochim: Error; no OH tracer !!!"
+            stop
+         end if
+         if (igcm_ho2 == 0) then
+            write(*,*) "gcmtochim: Error; no HO2 tracer !!!"
+            stop
+         end if
+         if (igcm_h2o2 == 0) then
+            write(*,*) "gcmtochim: Error; no H2O2 tracer !!!"
+            stop
+         end if
+         if (igcm_n == 0) then
+            write(*,*) "gcmtochim: Error; no N tracer !!!"
+            stop
+         end if
+         if (igcm_n2d == 0) then
+            write(*,*) "gcmtochim: Error; no N2D tracer !!!"
+            stop
+         end if
+         if (igcm_no == 0) then
+            write(*,*) "gcmtochim: Error; no NO tracer !!!"
+            stop
+         end if
+         if (igcm_no2 == 0) then
+            write(*,*) "gcmtochim: Error; no NO2 tracer !!!"
+            stop
+         end if
+         if (igcm_n2 == 0) then
+            write(*,*) "gcmtochim: Error; no N2 tracer !!!"
+            stop
+         end if
+         if (igcm_h2o_vap == 0) then
+            write(*,*) "gcmtochim: Error; no water vapor tracer !!!"
+            stop
+         end if
+
+         if (igcm_ch4 == 0) then
+            write(*,*) "gcmtochim: Error; no CH4 tracer !!!"
+            stop
+         end if
+         if (igcm_ch3 == 0) then
+            write(*,*) "gcmtochim: Error; no CH3 tracer !!!"
+            stop
+         end if
+         if (igcm_ch == 0) then
+            write(*,*) "gcmtochim: Error; no CH tracer !!!"
+            stop
+         end if
+         if (igcm_3ch2 == 0) then
+            write(*,*) "gcmtochim: Error; no 3CH2 tracer !!!"
+            stop
+         end if
+         if (igcm_1ch2 == 0) then
+            write(*,*) "gcmtochim: Error; no 1CH2 tracer !!!"
+            stop
+         end if
+         if (igcm_cho == 0) then
+            write(*,*) "gcmtochim: Error; no CHO tracer !!!"
+            stop
+         end if
+         if (igcm_ch2o == 0) then
+            write(*,*) "gcmtochim: Error; no CH2O tracer !!!"
+            stop
+         end if
+         if (igcm_ch3o == 0) then
+            write(*,*) "gcmtochim: Error; no CH3O tracer !!!"
+            stop
+         end if
+         if (igcm_c == 0) then
+            write(*,*) "gcmtochim: Error; no C tracer !!!"
+            stop
+         end if
+         if (igcm_c2 == 0) then
+            write(*,*) "gcmtochim: Error; no C2 tracer !!!"
+            stop
+         end if
+         if (igcm_c2h == 0) then
+            write(*,*) "gcmtochim: Error; no C2H tracer !!!"
+            stop
+         end if
+         if (igcm_c2h2 == 0) then
+            write(*,*) "gcmtochim: Error; no C2H2 tracer !!!"
+            stop
+         end if
+         if (igcm_c2h3 == 0) then
+            write(*,*) "gcmtochim: Error; no C2H3 tracer !!!"
+            stop
+         end if
+         if (igcm_c2h4 == 0) then
+            write(*,*) "gcmtochim: Error; no C2H4 tracer !!!"
+            stop
+         end if
+         if (igcm_c2h6 == 0) then
+            write(*,*) "gcmtochim: Error; no C2H6 tracer !!!"
+            stop
+         end if
+         if (igcm_ch2co == 0) then
+            write(*,*) "gcmtochim: Error; no CH2CO tracer !!!"
+            stop
+         end if
+         if (igcm_ch3co == 0) then
+            write(*,*) "gcmtochim: Error; no CH3CO tracer !!!"
+            stop
+         end if
+         if (igcm_hcaer == 0) then
+            write(*,*) "gcmtochim: Error; no HCAER tracer !!!"
+            stop
+         end if
+
+
+
+
+
+         firstcall = .false.
+      end if ! of if (firstcall)
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     initialise mixing ratios
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      do l = 1,lswitch-1
+         rm(l,i_co2)  = zycol(l, igcm_co2)
+         rm(l,i_co)   = zycol(l, igcm_co)
+         rm(l,i_o)    = zycol(l, igcm_o)
+         rm(l,i_o1d)  = zycol(l, igcm_o1d)
+         rm(l,i_o2)   = zycol(l, igcm_o2)
+         rm(l,i_o3)   = zycol(l, igcm_o3)
+         rm(l,i_h)    = zycol(l, igcm_h)
+         rm(l,i_h2)   = zycol(l, igcm_h2)
+         rm(l,i_oh)   = zycol(l, igcm_oh)
+         rm(l,i_ho2)  = zycol(l, igcm_ho2)
+         rm(l,i_h2o2) = zycol(l, igcm_h2o2)
+         rm(l,i_h2o)  = zycol(l, igcm_h2o_vap)
+         rm(l,i_n)    = zycol(l, igcm_n)
+         rm(l,i_n2d)  = zycol(l, igcm_n2d)
+         rm(l,i_no)   = zycol(l, igcm_no)
+         rm(l,i_no2)  = zycol(l, igcm_no2)
+         rm(l,i_n2)   = zycol(l, igcm_n2)
+         rm(l,i_ch4)   = zycol(l, igcm_ch4)
+         rm(l,i_ch3)   = zycol(l, igcm_ch3)
+         rm(l,i_ch)   = zycol(l, igcm_ch)
+         rm(l,i_3ch2)   = zycol(l, igcm_3ch2)
+         rm(l,i_1ch2)   = zycol(l, igcm_1ch2)
+         rm(l,i_cho)   = zycol(l, igcm_cho)
+         rm(l,i_ch2o)   = zycol(l, igcm_ch2o)
+         rm(l,i_ch3o)   = zycol(l, igcm_ch3o)
+         rm(l,i_c)   = zycol(l, igcm_c)
+         rm(l,i_c2)   = zycol(l, igcm_c2)
+         rm(l,i_c2h)   = zycol(l, igcm_c2h)
+         rm(l,i_c2h2)   = zycol(l, igcm_c2h2)
+         rm(l,i_c2h3)   = zycol(l, igcm_c2h3)
+         rm(l,i_c2h4)   = zycol(l, igcm_c2h4)
+         rm(l,i_c2h6)   = zycol(l, igcm_c2h6)
+         rm(l,i_ch2co)   = zycol(l, igcm_ch2co)
+         rm(l,i_ch3co)   = zycol(l, igcm_ch3co)
+         rm(l,i_hcaer)   = zycol(l, igcm_hcaer)
+      end do 
+
+      where (rm(:,:) < 1.e-30)
+         rm(:,:) = 0.
+      end where
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     initialise number densities
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      do iesp = 1,nesp
+         do l = 1,lswitch-1
+            c(l,iesp) = rm(l,iesp)*dens(l)
+         end do
+      end do
+
+      end subroutine gcmtochim
+
+!*****************************************************************
+ 
+      subroutine chimtogcm(nlayer, nq, zycol, lswitch, nesp,         &
+                           i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h, &
+                           i_h2, i_oh, i_ho2, i_h2o2, i_h2o,         &
+                           i_n, i_n2d, i_no, i_no2, i_n2, i_ch4,     &
+                           i_ch3, i_3ch2, i_1ch2, i_cho, i_ch2o,     &
+                           i_ch3o, i_c, i_c2, i_c2h, i_c2h2, i_c2h3, &
+                           i_c2h4, i_c2h6, i_ch2co, i_ch3co, i_hcaer, dens, c) 
+ 
+!*****************************************************************
+ 
+      use tracer_h, only: igcm_co2, igcm_co, igcm_o, igcm_o1d,            &
+                            igcm_o2, igcm_o3, igcm_h, igcm_h2, igcm_oh,   &
+                            igcm_ho2, igcm_h2o2, igcm_h2o_vap,            &
+                            igcm_n, igcm_n2d, igcm_no, igcm_no2, igcm_n2, &
+                            igcm_ch4, igcm_ch3, igcm_ch, igcm_3ch2,       &
+                            igcm_1ch2, igcm_cho, igcm_ch2o, igcm_ch3o,    &
+                            igcm_c, igcm_c2, igcm_c2h, igcm_c2h2,         &
+                            igcm_c2h3, igcm_c2h4, igcm_c2h6, igcm_ch2co,  &
+                            igcm_ch3co, igcm_hcaer
+
+      use callkeys_mod
+
+      implicit none
+
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     inputs:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+ 
+      integer, intent(in) :: nlayer  ! number of atmospheric layers
+      integer, intent(in) :: nq      ! number of tracers in the gcm
+      integer :: nesp                ! number of species in the chemistry
+      integer :: lswitch             ! interface level between chemistries
+      integer :: i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,       &
+                 i_h2, i_oh, i_ho2, i_h2o2, i_h2o,               &
+                 i_n, i_n2d, i_no, i_no2, i_n2, i_ch4,           &
+                 i_ch3, i_3ch2, i_1ch2, i_cho, i_ch2o,           &
+                 i_ch3o, i_c, i_c2, i_c2h, i_c2h2, i_c2h3,       &
+                 i_c2h4, i_c2h6, i_ch2co, i_ch3co, i_hcaer
+
+
+
+      real :: dens(nlayer)     ! total number density (molecule.cm-3) 
+      real (kind = 8), dimension(nlayer,nesp) :: c  ! number densities (molecule.cm-3) 
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     output:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+       
+      real zycol(nlayer,nq)  ! volume mixing ratios in the gcm
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     local:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      integer l
+      
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     save mixing ratios for the gcm
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      do l = 1,lswitch-1
+         zycol(l, igcm_co2)     = c(l,i_co2)/dens(l) 
+         zycol(l, igcm_co)      = c(l,i_co)/dens(l) 
+         zycol(l, igcm_o)       = c(l,i_o)/dens(l) 
+         zycol(l, igcm_o1d)     = c(l,i_o1d)/dens(l)
+         zycol(l, igcm_o2)      = c(l,i_o2)/dens(l) 
+         zycol(l, igcm_o3)      = c(l,i_o3)/dens(l) 
+         zycol(l, igcm_h)       = c(l,i_h)/dens(l)  
+         zycol(l, igcm_h2)      = c(l,i_h2)/dens(l) 
+         zycol(l, igcm_oh)      = c(l,i_oh)/dens(l) 
+         zycol(l, igcm_ho2)     = c(l,i_ho2)/dens(l) 
+         zycol(l, igcm_h2o2)    = c(l,i_h2o2)/dens(l)
+         zycol(l, igcm_h2o_vap) = c(l,i_h2o)/dens(l)
+         zycol(l, igcm_n)       = c(l,i_n)/dens(l)
+         zycol(l, igcm_n2d)     = c(l,i_n2d)/dens(l)
+         zycol(l, igcm_no)      = c(l,i_no)/dens(l)
+         zycol(l, igcm_no2)     = c(l,i_no2)/dens(l)
+         zycol(l, igcm_n2)      = c(l,i_n2)/dens(l)
+
+         zycol(l, igcm_ch4)     = c(l,i_ch4)/dens(l)
+         zycol(l, igcm_ch3)     = c(l,i_ch3)/dens(l)
+         zycol(l, igcm_ch)     = c(l,i_ch)/dens(l)
+         zycol(l, igcm_3ch2)     = c(l,i_3ch2)/dens(l)
+         zycol(l, igcm_1ch2)     = c(l,i_1ch2)/dens(l)
+         zycol(l, igcm_cho)     = c(l,i_cho)/dens(l)
+         zycol(l, igcm_ch2o)     = c(l,i_ch2o)/dens(l)
+         zycol(l, igcm_ch3o)     = c(l,i_ch3o)/dens(l)
+         zycol(l, igcm_c)     = c(l,i_c)/dens(l)
+         zycol(l, igcm_c2)     = c(l,i_c2)/dens(l)
+         zycol(l, igcm_c2h)     = c(l,i_c2h)/dens(l)
+         zycol(l, igcm_c2h2)     = c(l,i_c2h2)/dens(l)
+         zycol(l, igcm_c2h3)     = c(l,i_c2h3)/dens(l)
+         zycol(l, igcm_c2h4)     = c(l,i_c2h4)/dens(l)
+         zycol(l, igcm_c2h6)     = c(l,i_c2h6)/dens(l)
+         zycol(l, igcm_ch2co)     = c(l,i_ch2co)/dens(l)
+         zycol(l, igcm_ch3co)     = c(l,i_ch3co)/dens(l)
+         zycol(l, igcm_hcaer)     = c(l,i_hcaer)/dens(l)
+
+
+      end do 
+
+      end subroutine chimtogcm
+
+end subroutine photochemistry_asis
+
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/photolysis_asis_early_earth.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/photolysis_asis_early_earth.F90	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/photolysis_asis_early_earth.F90	(revision 1796)
@@ -0,0 +1,652 @@
+!==========================================================================
+
+      subroutine photolysis_asis_early_earth(nlayer, ngrid,                    &
+                                 lswitch, press, temp, sza,fractcol, tauref,   &
+                                 zmmean, dist_sol, rmco2, rmo3, rmch4, v_phot)
+
+!==========================================================================
+
+      use comcstfi_mod
+      use callkeys_mod
+
+      implicit none
+
+#include "chimiedata_early_earth.h" 
+
+!==========================================================================
+!     input:
+!==========================================================================
+       
+      integer, intent(in) :: nlayer ! number of atmospheric layers
+      integer,intent(in) :: ngrid   ! number of atmospheric columns
+      integer :: lswitch            ! interface level between chemistries
+      real :: press(nlayer)         ! pressure (hPa)
+      real :: temp(nlayer)          ! temperature (K)
+      real :: sza                   ! solar zenith angle (deg)
+      real :: fractcol              ! day fraction
+      real :: tauref                ! optical depth at 7 hpa
+      real :: zmmean(nlayer)        ! mean molecular mass (g)
+      real :: dist_sol              ! sun distance (AU) 
+      real :: rmco2(nlayer)         ! co2 mixing ratio
+      real :: rmo3(nlayer)          ! ozone mixing ratio
+      real :: rmch4(nlayer)          ! ch4 mixing ratio
+
+!==========================================================================
+!     output: interpolated photodissociation rates (s-1)
+!==========================================================================
+
+      real (kind = 8), dimension(nlayer,nb_phot_max) :: v_phot
+
+!==========================================================================
+!     local:
+!==========================================================================
+
+      integer :: icol, ij, indsza, indtau, indcol, indozo, indtemp,     &
+                 iozo, isza, itau, it, ich4, indch4, l
+
+      integer :: j_o2_o, j_o2_o1d, j_co2_o, j_co2_o1d, j_o3_o1d,        &
+                 j_o3_o, j_h2o, j_hdo, j_h2o2, j_ho2, j_no, j_no2,      &
+                 j_hno3, j_hno4,                                        &
+                 j_ch4_ch3_h, j_ch4_1ch2_h2, j_ch4_3ch2_h_h,            &
+                 j_ch4_ch_h2_h, j_ch3o2h, j_ch2o_hco, j_ch2o_co,        &
+                 j_ch3oh, j_c2h6, j_hcl, j_hocl, j_clo, j_so2, j_so,    &
+                 j_h2s, j_so3,                                          &
+                 j_c2h6_ch4_1ch2, j_c2h6_c2h2_2h2, j_c2h6_c2h4_2h,      &
+                 j_c2h6_c2h4_h2, j_c2h6_ch3_ch3, j_c2h2_c2h_h,          &
+                 j_c2h2_c2_h2, j_c2h4_c2h2_h2, j_c2h4_c2h2_h_h,         &
+                 j_ch2co_3ch2_co 
+
+
+
+      real :: col(nlayer)                 ! overhead air column   (molecule cm-2)
+      real :: colo3(nlayer)               ! overhead ozone column (molecule cm-2)
+      real :: colch4(nlayer)               ! overhead CH4 column (molecule cm-2)
+      real :: tauch4(nlayer)               ! estimation of optical depth by CH4
+      real :: ch4_equ(nlayer)               ! equivalent constant mixing ratio for the same column of CH4
+      real :: poids(2,2,2,2,2,2)          ! 6D interpolation weights 
+      real :: tref                        ! temperature  at 1.9 hPa in the gcm (K)
+      real :: table_temp(ntemp)           ! temperatures at 1.9 hPa in jmars   (K)
+      real :: ch4ref                      ! ch4 mixing ratio at top of the atmosphere
+      real :: cinf, csup, cicol, ciozo, cisza, citemp, citau, cich4
+      real :: colo3min, dp, coef
+      real :: ratio_o3(nlayer)
+      real :: tau
+      real :: j(nlayer,nd)
+
+!==========================================================================
+!     day/night criterion
+!==========================================================================
+
+      if (sza <= 95.) then 
+
+!==========================================================================
+!     temperatures at 1.9 hPa in lookup table
+!==========================================================================
+      
+!      table_temp(1) = 226.2
+!      table_temp(2) = 206.2
+!      table_temp(3) = 186.2
+!      table_temp(4) = 169.8
+
+!      table_temp(2) = 186.2
+      table_temp(1) = 176.2
+
+!==========================================================================
+!     interpolation in solar zenith angle
+!==========================================================================
+ 
+      indsza = nsza - 1
+      do isza = 1,nsza
+         if (szatab(isza) >= sza) then
+            indsza = isza - 1
+            indsza = max(indsza, 1)
+            exit
+         end if
+      end do
+
+      if(nsza.eq.1) then
+        cisza = 0.
+        indsza=1
+      else
+        cisza = (sza - szatab(indsza))  &
+             /(szatab(indsza + 1) - szatab(indsza))
+      endif
+!==========================================================================
+!     interpolation in dust (tau)
+!==========================================================================
+
+      tau = min(tauref, tautab(ntau))
+      tau = max(tau, tautab(1))
+
+      indtau = ntau - 1
+      do itau = 1,ntau
+         if (tautab(itau) >= tau) then
+            indtau = itau - 1
+            indtau = max(indtau, 1)
+            exit
+         end if
+      end do
+
+      if(ntau.eq.1) then
+        citau=0.
+        indtau=1
+      else
+        citau = (tau - tautab(indtau))     &
+             /(tautab(indtau + 1) - tautab(indtau))
+      endif
+
+
+
+!==========================================================================
+!     air and ozone columns
+!==========================================================================
+
+!     co2 column at model top (molecule.cm-2)
+
+!      col(lswitch-1) = 6.022e22*rmco2(lswitch-1)*press(lswitch-1)*100.  &
+!                       /(zmmean(lswitch-1)*g)
+      col(lswitch-1) = 6.022e22*press(lswitch-1)*100./(zmmean(lswitch-1)*g)
+
+
+!     ozone column at model top
+
+      colo3(lswitch-1) = 0.
+!     co2 and ozone columns for other levels (molecule.cm-2)
+
+      do l = lswitch-2,1,-1
+         dp = (press(l) - press(l+1))*100.
+!         col(l) = col(l+1) + (rmco2(l+1) + rmco2(l))*0.5   &
+!                             *6.022e22*dp/(zmmean(l)*g)
+         col(l) = col(l+1) +  6.022e22*dp/(zmmean(l)*g)
+         col(l) = min(col(l), colairtab(1))
+         colo3(l) = colo3(l+1) + (rmo3(l+1) + rmo3(l))*0.5 &
+                                 *6.022e22*dp/(zmmean(l)*g)
+
+      end do
+
+!     ratio ozone column/minimal theoretical column (0.1 micron-atm) 
+
+!     ro3 = 7.171e-10 is the o3 mixing ratio for a uniform
+!     profile giving a column 10 micron-atmosphere at
+!     a surface pressure of 1 bar.
+
+      do l = 1,lswitch-1
+         colo3min    = col(l)*7.171e-10
+         ratio_o3(l) = colo3(l)/colo3min
+         ratio_o3(l) = min(ratio_o3(l), table_ozo(nozo)*10.)
+         ratio_o3(l) = max(ratio_o3(l), 0.)
+      end do
+
+
+!==========================================================================
+!     ch4 dependence
+!==========================================================================
+
+!     1) search for temperature at 1.9 hPa (tref): vertical
+!     interpolation
+
+      ch4ref = rmch4(lswitch-2)
+      colch4(lswitch-1) = 0.
+      do l = lswitch-2,1,-1
+         dp = (press(l) - press(l+1))*100.
+         colch4(l) = colch4(l+1) + (rmch4(l+1) + rmch4(l))*0.5 &
+                                 *6.022e22*dp/(zmmean(l)*g)
+         ch4_equ(l)=colch4(l)/col(l)
+!         tauch4(l)=1.8e-21*colch4(l)
+!         if(tauch4(l).ge.1.0) exit
+      end do
+!      ch4ref = (rmch4(l+1)*(tauch4(l)-1)+rmch4(l)*(1-tauch4(l+1))) &
+!                                 /(tauch4(l)-tauch4(l+1))
+
+!     2) interpolation in CH4
+
+!      ch4ref = min(ch4ref,table_ch4(nch4))
+!      ch4ref = max(ch4ref,table_ch4(1))
+
+!      indch4 = nch4 - 1
+!      do ich4 = 1,nch4
+!         if (table_ch4(ich4) >= ch4ref) then
+!            indch4 = ich4 - 1
+!            indch4 = max(indch4, 1)
+!            exit
+!         end if
+!      end do
+!      cich4 = (ch4ref - table_ch4(indch4))     &
+!             /(table_ch4(indch4 + 1) - table_ch4(indch4))
+
+
+
+!==========================================================================
+!     temperature dependence
+!==========================================================================
+
+!     1) search for temperature at 1.9 hPa (tref): vertical interpolation
+
+      tref = temp(1)
+      do l = (lswitch-1)-1,1,-1
+         if (press(l) > 1.9) then
+            cinf = (press(l) - 1.9)/(press(l) - press(l+1))
+            csup = 1. - cinf
+            tref = cinf*temp(l+1) + csup*temp(l)
+            exit
+         end if
+      end do 
+
+!     2) interpolation in temperature
+
+      tref = min(tref,table_temp(1))
+      tref = max(tref,table_temp(ntemp))
+
+      if(ntemp.eq.1) then
+        citemp = 1.
+        indtemp = 1
+      else
+        do it = 2, ntemp
+           if (table_temp(it) <= tref) then
+              citemp = (log(tref) - log(table_temp(it)))              &
+                      /(log(table_temp(it-1)) - log(table_temp(it)))
+              indtemp = it - 1
+              exit
+           end if
+        end do
+      endif
+
+
+
+!==========================================================================
+!     loop over vertical levels
+!==========================================================================
+
+      do l = 1,lswitch-1
+
+!     interpolation in air column
+
+         indcol = nz - 1
+         do icol = 1,nz
+            if (colairtab(icol) < col(l)) then
+               indcol = icol - 1
+               exit
+            end if
+         end do
+         cicol = (log(col(l)) - log(colairtab(indcol + 1)))              &
+                /(log(colairtab(indcol)) - log(colairtab(indcol + 1)))
+
+!     interpolation in ozone column
+
+         indozo = nozo - 1
+         do iozo = 1,nozo
+            if (table_ozo(iozo)*10. >= ratio_o3(l)) then
+               indozo = iozo - 1
+               indozo = max(indozo, 1)
+               exit
+            end if
+         end do
+
+      if(nozo.eq.1) then
+         ciozo = 0.
+      else
+         ciozo = (ratio_o3(l) - table_ozo(indozo)*10.)             &
+                /(table_ozo(indozo + 1)*10. - table_ozo(indozo)*10.)
+      endif
+
+!     2) interpolation in CH4
+
+      ch4ref = min(ch4_equ(l),table_ch4(nch4))
+      ch4ref = max(ch4ref,table_ch4(1))
+
+      indch4 = nch4 - 1
+      do ich4 = 1,nch4
+         if (table_ch4(ich4) >= ch4ref) then
+            indch4 = ich4 - 1
+            indch4 = max(indch4, 1)
+            exit
+         end if
+      end do
+      cich4 = (ch4ref - table_ch4(indch4))     &
+             /(table_ch4(indch4 + 1) - table_ch4(indch4))
+
+!print*,'l',l
+!print*,'col(l)',col(l)
+!print*,'ch4ref=',ch4ref
+!print*,'cich4=',cich4
+!print*,'ratio_o3(l)',ratio_o3(l)/10
+!print*,'ciozo=',ciozo
+
+!     5-dimensional interpolation weights
+
+!     poids(temp,sza,co2,o3,tau,ch4)
+
+         poids(1,1,1,1,1,1) = citemp*(1.-cisza)*cicol*(1.-ciozo)*(1.-citau)*(1.-cich4)
+         poids(1,1,1,2,1,1) = citemp*(1.-cisza)*cicol*ciozo*(1.-citau)*(1.-cich4)       
+         poids(1,1,2,1,1,1) = citemp*(1.-cisza)*(1.-cicol)*(1.-ciozo)*(1.-citau)*(1.-cich4)
+         poids(1,1,2,2,1,1) = citemp*(1.-cisza)*(1.-cicol)*ciozo*(1.-citau)*(1.-cich4) 
+         poids(1,2,1,1,1,1) = citemp*cisza*cicol*(1.-ciozo)*(1.-citau)*(1.-cich4)               
+         poids(1,2,1,2,1,1) = citemp*cisza*cicol*ciozo*(1.-citau)*(1.-cich4)                    
+         poids(1,2,2,1,1,1) = citemp*cisza*(1.-cicol)*(1.-ciozo)*(1.-citau)*(1.-cich4)          
+         poids(1,2,2,2,1,1) = citemp*cisza*(1.-cicol)*ciozo*(1.-citau)*(1.-cich4)               
+!         poids(2,1,1,1,1,1) = (1.-citemp)*(1.-cisza)*cicol*(1.-ciozo)*(1.-citau)*(1.-cich4)     
+!         poids(2,1,1,2,1,1) = (1.-citemp)*(1.-cisza)*cicol*ciozo*(1.-citau)*(1.-cich4)          
+!         poids(2,1,2,1,1,1) = (1.-citemp)*(1.-cisza)*(1.-cicol)*(1.-ciozo)*(1.-citau)*(1.-cich4)
+!         poids(2,1,2,2,1,1) = (1.-citemp)*(1.-cisza)*(1.-cicol)*ciozo*(1.-citau)*(1.-cich4)     
+!         poids(2,2,1,1,1,1) = (1.-citemp)*cisza*cicol*(1.-ciozo)*(1.-citau)*(1.-cich4)          
+!         poids(2,2,1,2,1,1) = (1.-citemp)*cisza*cicol*ciozo*(1.-citau)*(1.-cich4)               
+!         poids(2,2,2,1,1,1) = (1.-citemp)*cisza*(1.-cicol)*(1.-ciozo)*(1.-citau)*(1.-cich4)     
+!         poids(2,2,2,2,1,1) = (1.-citemp)*cisza*(1.-cicol)*ciozo*(1.-citau)*(1.-cich4)          
+!!
+!         poids(1,1,1,1,2,1) = citemp*(1.-cisza)*cicol*(1.-ciozo)*citau*(1.-cich4)               
+!         poids(1,1,1,2,2,1) = citemp*(1.-cisza)*cicol*ciozo*citau*(1.-cich4)                    
+!         poids(1,1,2,1,2,1) = citemp*(1.-cisza)*(1.-cicol)*(1.-ciozo)*citau*(1.-cich4)          
+!         poids(1,1,2,2,2,1) = citemp*(1.-cisza)*(1.-cicol)*ciozo*citau*(1.-cich4)               
+!         poids(1,2,1,1,2,1) = citemp*cisza*cicol*(1.-ciozo)*citau*(1.-cich4)                    
+!         poids(1,2,1,2,2,1) = citemp*cisza*cicol*ciozo*citau*(1.-cich4)                         
+!         poids(1,2,2,1,2,1) = citemp*cisza*(1.-cicol)*(1.-ciozo)*citau*(1.-cich4)               
+!         poids(1,2,2,2,2,1) = citemp*cisza*(1.-cicol)*ciozo*citau*(1.-cich4)                    
+!         poids(2,1,1,1,2,1) = (1.-citemp)*(1.-cisza)*cicol*(1.-ciozo)*citau*(1.-cich4)          
+!         poids(2,1,1,2,2,1) = (1.-citemp)*(1.-cisza)*cicol*ciozo*citau*(1.-cich4)               
+!         poids(2,1,2,1,2,1) = (1.-citemp)*(1.-cisza)*(1.-cicol)*(1.-ciozo)*citau*(1.-cich4)     
+!         poids(2,1,2,2,2,1) = (1.-citemp)*(1.-cisza)*(1.-cicol)*ciozo*citau*(1.-cich4)          
+!         poids(2,2,1,1,2,1) = (1.-citemp)*cisza*cicol*(1.-ciozo)*citau*(1.-cich4)               
+!         poids(2,2,1,2,2,1) = (1.-citemp)*cisza*cicol*ciozo*citau*(1.-cich4)                    
+!         poids(2,2,2,1,2,1) = (1.-citemp)*cisza*(1.-cicol)*(1.-ciozo)*citau*(1.-cich4)          
+!         poids(2,2,2,2,2,1) = (1.-citemp)*cisza*(1.-cicol)*ciozo*citau*(1.-cich4)               
+!      
+         poids(1,1,1,1,1,2) = citemp*(1.-cisza)*cicol*(1.-ciozo)*(1.-citau)*cich4               
+         poids(1,1,1,2,1,2) = citemp*(1.-cisza)*cicol*ciozo*(1.-citau)*cich4                    
+         poids(1,1,2,1,1,2) = citemp*(1.-cisza)*(1.-cicol)*(1.-ciozo)*(1.-citau)*cich4          
+         poids(1,1,2,2,1,2) = citemp*(1.-cisza)*(1.-cicol)*ciozo*(1.-citau)*cich4               
+         poids(1,2,1,1,1,2) = citemp*cisza*cicol*(1.-ciozo)*(1.-citau)*cich4                    
+         poids(1,2,1,2,1,2) = citemp*cisza*cicol*ciozo*(1.-citau)*cich4                         
+         poids(1,2,2,1,1,2) = citemp*cisza*(1.-cicol)*(1.-ciozo)*(1.-citau)*cich4               
+         poids(1,2,2,2,1,2) = citemp*cisza*(1.-cicol)*ciozo*(1.-citau)*cich4                    
+!         poids(2,1,1,1,1,2) = (1.-citemp)*(1.-cisza)*cicol*(1.-ciozo)*(1.-citau)*cich4          
+!         poids(2,1,1,2,1,2) = (1.-citemp)*(1.-cisza)*cicol*ciozo*(1.-citau)*cich4               
+!         poids(2,1,2,1,1,2) = (1.-citemp)*(1.-cisza)*(1.-cicol)*(1.-ciozo)*(1.-citau)*cich4     
+!         poids(2,1,2,2,1,2) = (1.-citemp)*(1.-cisza)*(1.-cicol)*ciozo*(1.-citau)*cich4          
+!         poids(2,2,1,1,1,2) = (1.-citemp)*cisza*cicol*(1.-ciozo)*(1.-citau)*cich4               
+!         poids(2,2,1,2,1,2) = (1.-citemp)*cisza*cicol*ciozo*(1.-citau)*cich4                    
+!         poids(2,2,2,1,1,2) = (1.-citemp)*cisza*(1.-cicol)*(1.-ciozo)*(1.-citau)*cich4          
+!         poids(2,2,2,2,1,2) = (1.-citemp)*cisza*(1.-cicol)*ciozo*(1.-citau)*cich4               
+!!
+!         poids(1,1,1,1,2,2) = citemp*(1.-cisza)*cicol*(1.-ciozo)*citau*cich4                    
+!         poids(1,1,1,2,2,2) = citemp*(1.-cisza)*cicol*ciozo*citau*cich4                         
+!         poids(1,1,2,1,2,2) = citemp*(1.-cisza)*(1.-cicol)*(1.-ciozo)*citau*cich4               
+!         poids(1,1,2,2,2,2) = citemp*(1.-cisza)*(1.-cicol)*ciozo*citau*cich4                    
+!         poids(1,2,1,1,2,2) = citemp*cisza*cicol*(1.-ciozo)*citau*cich4                         
+!         poids(1,2,1,2,2,2) = citemp*cisza*cicol*ciozo*citau*cich4                              
+!         poids(1,2,2,1,2,2) = citemp*cisza*(1.-cicol)*(1.-ciozo)*citau*cich4                    
+!         poids(1,2,2,2,2,2) = citemp*cisza*(1.-cicol)*ciozo*citau*cich4                         
+!         poids(2,1,1,1,2,2) = (1.-citemp)*(1.-cisza)*cicol*(1.-ciozo)*citau*cich4               
+!         poids(2,1,1,2,2,2) = (1.-citemp)*(1.-cisza)*cicol*ciozo*citau*cich4                    
+!         poids(2,1,2,1,2,2) = (1.-citemp)*(1.-cisza)*(1.-cicol)*(1.-ciozo)*citau*cich4          
+!         poids(2,1,2,2,2,2) = (1.-citemp)*(1.-cisza)*(1.-cicol)*ciozo*citau*cich4               
+!         poids(2,2,1,1,2,2) = (1.-citemp)*cisza*cicol*(1.-ciozo)*citau*cich4                    
+!         poids(2,2,1,2,2,2) = (1.-citemp)*cisza*cicol*ciozo*citau*cich4                         
+!         poids(2,2,2,1,2,2) = (1.-citemp)*cisza*(1.-cicol)*(1.-ciozo)*citau*cich4               
+!         poids(2,2,2,2,2,2) = (1.-citemp)*cisza*(1.-cicol)*ciozo*citau*cich4                    
+
+
+
+
+
+
+
+
+!     4-dimensional interpolation in the lookup table
+
+         do ij = 1,nd
+            j(l,ij) =                                                                & 
+            poids(1,1,1,1,1,1)*jphot(indtemp,indsza,indcol,indozo,indtau,indch4,ij)           &
+          + poids(1,1,1,2,1,1)*jphot(indtemp,indsza,indcol,indozo+1,indtau,indch4,ij)         &
+          + poids(1,1,2,1,1,1)*jphot(indtemp,indsza,indcol+1,indozo,indtau,indch4,ij)         &
+          + poids(1,1,2,2,1,1)*jphot(indtemp,indsza,indcol+1,indozo+1,indtau,indch4,ij)       &
+          + poids(1,2,1,1,1,1)*jphot(indtemp,indsza+1,indcol,indozo,indtau,indch4,ij)         &
+          + poids(1,2,1,2,1,1)*jphot(indtemp,indsza+1,indcol,indozo+1,indtau,indch4,ij)       &
+          + poids(1,2,2,1,1,1)*jphot(indtemp,indsza+1,indcol+1,indozo,indtau,indch4,ij)       &
+          + poids(1,2,2,2,1,1)*jphot(indtemp,indsza+1,indcol+1,indozo+1,indtau,indch4,ij)     &
+!          + poids(2,1,1,1,1,1)*jphot(indtemp+1,indsza,indcol,indozo,indtau,indch4,ij)         &
+!          + poids(2,1,1,2,1,1)*jphot(indtemp+1,indsza,indcol,indozo+1,indtau,indch4,ij)       &
+!          + poids(2,1,2,1,1,1)*jphot(indtemp+1,indsza,indcol+1,indozo,indtau,indch4,ij)       &
+!          + poids(2,1,2,2,1,1)*jphot(indtemp+1,indsza,indcol+1,indozo+1,indtau,indch4,ij)     &
+!          + poids(2,2,1,1,1,1)*jphot(indtemp+1,indsza+1,indcol,indozo,indtau,indch4,ij)       &
+!          + poids(2,2,1,2,1,1)*jphot(indtemp+1,indsza+1,indcol,indozo+1,indtau,indch4,ij)     &
+!          + poids(2,2,2,1,1,1)*jphot(indtemp+1,indsza+1,indcol+1,indozo,indtau,indch4,ij)     &
+!          + poids(2,2,2,2,1,1)*jphot(indtemp+1,indsza+1,indcol+1,indozo+1,indtau,indch4,ij)   &
+!!
+!          + poids(1,1,1,1,2,1)*jphot(indtemp,indsza,indcol,indozo,indtau+1,indch4,ij)         &
+!          + poids(1,1,1,2,2,1)*jphot(indtemp,indsza,indcol,indozo+1,indtau+1,indch4,ij)       &
+!          + poids(1,1,2,1,2,1)*jphot(indtemp,indsza,indcol+1,indozo,indtau+1,indch4,ij)       &
+!          + poids(1,1,2,2,2,1)*jphot(indtemp,indsza,indcol+1,indozo+1,indtau+1,indch4,ij)     &
+!          + poids(1,2,1,1,2,1)*jphot(indtemp,indsza+1,indcol,indozo,indtau+1,indch4,ij)       &
+!          + poids(1,2,1,2,2,1)*jphot(indtemp,indsza+1,indcol,indozo+1,indtau+1,indch4,ij)     &
+!          + poids(1,2,2,1,2,1)*jphot(indtemp,indsza+1,indcol+1,indozo,indtau+1,indch4,ij)     &
+!          + poids(1,2,2,2,2,1)*jphot(indtemp,indsza+1,indcol+1,indozo+1,indtau+1,indch4,ij)   &
+!          + poids(2,1,1,1,2,1)*jphot(indtemp+1,indsza,indcol,indozo,indtau+1,indch4,ij)       &
+!          + poids(2,1,1,2,2,1)*jphot(indtemp+1,indsza,indcol,indozo+1,indtau+1,indch4,ij)     &
+!          + poids(2,1,2,1,2,1)*jphot(indtemp+1,indsza,indcol+1,indozo,indtau+1,indch4,ij)     &
+!          + poids(2,1,2,2,2,1)*jphot(indtemp+1,indsza,indcol+1,indozo+1,indtau+1,indch4,ij)   &
+!          + poids(2,2,1,1,2,1)*jphot(indtemp+1,indsza+1,indcol,indozo,indtau+1,indch4,ij)     &
+!          + poids(2,2,1,2,2,1)*jphot(indtemp+1,indsza+1,indcol,indozo+1,indtau+1,indch4,ij)   &
+!          + poids(2,2,2,1,2,1)*jphot(indtemp+1,indsza+1,indcol+1,indozo,indtau+1,indch4,ij)   &
+!          + poids(2,2,2,2,2,1)*jphot(indtemp+1,indsza+1,indcol+1,indozo+1,indtau+1,indch4,ij)
+! CH4
+          + poids(1,1,1,1,1,2)*jphot(indtemp,indsza,indcol,indozo,indtau,indch4+1,ij)           &
+          + poids(1,1,1,2,1,2)*jphot(indtemp,indsza,indcol,indozo+1,indtau,indch4+1,ij)         &
+          + poids(1,1,2,1,1,2)*jphot(indtemp,indsza,indcol+1,indozo,indtau,indch4+1,ij)         &
+          + poids(1,1,2,2,1,2)*jphot(indtemp,indsza,indcol+1,indozo+1,indtau,indch4+1,ij) &
+          + poids(1,2,1,1,1,2)*jphot(indtemp,indsza+1,indcol,indozo,indtau,indch4+1,ij) &
+          + poids(1,2,1,2,1,2)*jphot(indtemp,indsza+1,indcol,indozo+1,indtau,indch4+1,ij) &
+          + poids(1,2,2,1,1,2)*jphot(indtemp,indsza+1,indcol+1,indozo,indtau,indch4+1,ij) &
+          + poids(1,2,2,2,1,2)*jphot(indtemp,indsza+1,indcol+1,indozo+1,indtau,indch4+1,ij) 
+!          + poids(2,1,1,1,1,2)*jphot(indtemp+1,indsza,indcol,indozo,indtau,indch4+1,ij) &
+!          + poids(2,1,1,2,1,2)*jphot(indtemp+1,indsza,indcol,indozo+1,indtau,indch4+1,ij) &
+!          + poids(2,1,2,1,1,2)*jphot(indtemp+1,indsza,indcol+1,indozo,indtau,indch4+1,ij) &
+!          + poids(2,1,2,2,1,2)*jphot(indtemp+1,indsza,indcol+1,indozo+1,indtau,indch4+1,ij) &
+!          + poids(2,2,1,1,1,2)*jphot(indtemp+1,indsza+1,indcol,indozo,indtau,indch4+1,ij) &
+!          + poids(2,2,1,2,1,2)*jphot(indtemp+1,indsza+1,indcol,indozo+1,indtau,indch4+1,ij) &
+!          + poids(2,2,2,1,1,2)*jphot(indtemp+1,indsza+1,indcol+1,indozo,indtau,indch4+1,ij) &
+!          + poids(2,2,2,2,1,2)*jphot(indtemp+1,indsza+1,indcol+1,indozo+1,indtau,indch4+1,ij) &
+!!
+!          + poids(1,1,1,1,2,2)*jphot(indtemp,indsza,indcol,indozo,indtau+1,indch4+1,ij) &
+!          + poids(1,1,1,2,2,2)*jphot(indtemp,indsza,indcol,indozo+1,indtau+1,indch4+1,ij) &
+!          + poids(1,1,2,1,2,2)*jphot(indtemp,indsza,indcol+1,indozo,indtau+1,indch4+1,ij) &
+!          + poids(1,1,2,2,2,2)*jphot(indtemp,indsza,indcol+1,indozo+1,indtau+1,indch4+1,ij) &
+!          + poids(1,2,1,1,2,2)*jphot(indtemp,indsza+1,indcol,indozo,indtau+1,indch4+1,ij) &
+!          + poids(1,2,1,2,2,2)*jphot(indtemp,indsza+1,indcol,indozo+1,indtau+1,indch4+1,ij) &
+!          + poids(1,2,2,1,2,2)*jphot(indtemp,indsza+1,indcol+1,indozo,indtau+1,indch4+1,ij) &
+!          + poids(1,2,2,2,2,2)*jphot(indtemp,indsza+1,indcol+1,indozo+1,indtau+1,indch4+1,ij) &
+!          + poids(2,1,1,1,2,2)*jphot(indtemp+1,indsza,indcol,indozo,indtau+1,indch4+1,ij) &
+!          + poids(2,1,1,2,2,2)*jphot(indtemp+1,indsza,indcol,indozo+1,indtau+1,indch4+1,ij) &
+!          + poids(2,1,2,1,2,2)*jphot(indtemp+1,indsza,indcol+1,indozo,indtau+1,indch4+1,ij) &
+!          + poids(2,1,2,2,2,2)*jphot(indtemp+1,indsza,indcol+1,indozo+1,indtau+1,indch4+1,ij) &
+!          + poids(2,2,1,1,2,2)*jphot(indtemp+1,indsza+1,indcol,indozo,indtau+1,indch4+1,ij) &
+!          + poids(2,2,1,2,2,2)*jphot(indtemp+1,indsza+1,indcol,indozo+1,indtau+1,indch4+1,ij) &
+!          + poids(2,2,2,1,2,2)*jphot(indtemp+1,indsza+1,indcol+1,indozo,indtau+1,indch4+1,ij) &
+!          + poids(2,2,2,2,2,2)*jphot(indtemp+1,indsza+1,indcol+1,indozo+1,indtau+1,indch4+1,ij)
+
+         end do
+
+!     correction for sun distance
+
+         do ij = 1,nd
+!            j(l,ij) = j(l,ij)*(1.52/dist_sol)**2.
+            j(l,ij) = j(l,ij)*(1.0/dist_sol)**2.
+  
+            ! Only during daylight.
+            if((ngrid.eq.1))then
+                  j(l,ij)= j(l,ij)* 0.25 ! globally averaged = divide by 4
+            elseif(diurnal .eqv. .false.) then
+                  j(l,ij)= j(l,ij) * fractcol
+            endif
+
+
+         end do 
+
+
+
+!==========================================================================
+!     end of loop over vertical levels
+!==========================================================================
+
+      end do
+
+      else
+
+!==========================================================================
+!     night
+!==========================================================================
+
+         j(:,:) = 0.
+
+      end if
+
+! photodissociation rates numbering in the lookup table
+
+! jmars.20140930
+
+
+!      j_o2_o         =  1      ! o2 + hv     -> o + o
+!      j_o2_o1d       =  2      ! o2 + hv     -> o + o(1d)
+!      j_co2_o        =  3      ! co2 + hv    -> co + o
+!      j_co2_o1d      =  4      ! co2 + hv    -> co + o(1d)
+!      j_o3_o1d       =  5      ! o3 + hv     -> o2 + o(1d)
+!      j_o3_o         =  6      ! o3 + hv     -> o2 + o
+!      j_h2o          =  7      ! h2o + hv    -> h + oh
+!      j_h2o2         =  8      ! h2o2 + hv   -> oh + oh
+!      j_ho2          =  9      ! ho2 + hv    -> oh + o
+!      j_no           =  10     ! no + hv     -> n + o
+!      j_no2          =  11     ! no2 + hv    -> no + o
+!      j_hno3         =  12     ! hno3 + hv   -> no2 + oh
+!      j_hno4         =  13     ! hno4 + hv   -> no2 + ho2
+
+! jmars.20111014
+
+!     j_o2_o         =  1      ! o2 + hv     -> o + o
+!     j_o2_o1d       =  2      ! o2 + hv     -> o + o(1d)
+!     j_co2_o        =  3      ! co2 + hv    -> co + o
+!     j_co2_o1d      =  4      ! co2 + hv    -> co + o(1d)
+!     j_o3_o1d       =  5      ! o3 + hv     -> o2 + o(1d)
+!     j_o3_o         =  6      ! o3 + hv     -> o2 + o
+!     j_h2o          =  7      ! h2o + hv    -> h + oh
+!     j_hdo          =  8      ! hdo + hv    -> d + oh
+!     j_h2o2         =  9      ! h2o2 + hv   -> oh + oh
+!     j_ho2          =  10     ! ho2 + hv    -> oh + o
+!     j_no2          =  11     ! no2 + hv    -> no + o
+!     j_ch4_ch3_h    =  12     ! ch4 + hv    -> ch3 + h
+!     j_ch4_1ch2_h2  =  13     ! ch4 + hv    -> 1ch2 + h2
+!     j_ch4_3ch2_h_h =  14     ! ch4 + hv    -> 3ch2 + h + h
+!     j_ch4_ch_h2_h  =  15     ! ch4 + hv    -> ch + h2 + h
+!     j_ch3o2h       =  16     ! ch3o2h + hv -> ch3o + oh
+!     j_ch2o_hco     =  17     ! ch2o + hv   -> h + hco
+!     j_ch2o_co      =  18     ! ch2o + hv   -> h2 + co
+!     j_ch3oh        =  19     ! ch3oh + hv  -> ch3o + h
+!     j_c2h6         =  20     ! c2h6 + hv   -> products
+!     j_hcl          =  21     ! hcl + hv    -> h + cl
+!     j_hocl         =  22     ! hocl + hv   -> oh + cl
+!     j_clo          =  23     ! clo + hv    -> o + cl
+!     j_so2          =  24     ! so2 + hv    -> so + o
+!     j_so           =  25     ! so + hv     -> s + o
+!     j_h2s          =  26     ! h2s + hv    -> hs + s
+!     j_so3          =  27     ! so2 + hv    -> so2 + o
+!     j_hno3         =  28     ! hno3 + hv   -> oh + no2
+!     j_hno4         =  29     ! hno4 + hv   -> ho2 + no2
+
+
+! jearly_earth
+
+     j_o2_o         =  1      ! o2 + hv     -> o + o
+     j_o2_o1d       =  2      ! o2 + hv     -> o + o(1d)
+     j_co2_o        =  3      ! co2 + hv    -> co + o
+     j_co2_o1d      =  4      ! co2 + hv    -> co + o(1d)
+     j_o3_o1d       =  5      ! o3 + hv     -> o2 + o(1d)
+     j_o3_o         =  6      ! o3 + hv     -> o2 + o
+     j_h2o          =  7      ! h2o + hv    -> h + oh
+     j_h2o2         =  8      ! h2o2 + hv   -> oh + oh
+     j_ho2          =  9     ! ho2 + hv    -> oh + o
+     j_no           =  10     ! no + hv     -> n + o
+     j_no2          =  11     ! no2 + hv    -> no + o
+     j_hno3         =  12     ! hno3 + hv   -> oh + no2
+     j_hno4         =  13     ! hno4 + hv   -> ho2 + no2
+     j_ch4_ch3_h    =  14     ! ch4 + hv    -> ch3 + h
+     j_ch4_1ch2_h2  =  15     ! ch4 + hv    -> 1ch2 + h2
+     j_ch4_3ch2_h_h =  16     ! ch4 + hv    -> 3ch2 + h + h
+     j_ch4_ch_h2_h  =  17     ! ch4 + hv    -> ch + h2 + h
+     j_ch2o_hco     =  18     ! ch2co + hv  -> choo + h
+     j_ch2o_co      =  19     ! ch2co + hv  -> co + h2
+     j_c2h6_ch4_1ch2 =  20    ! c2h6 + hv   -> ch4 + 1ch2
+     j_c2h6_c2h2_2h2 =  21    ! c2h6 + hv   -> c2h2 + 2h2
+     j_c2h6_c2h4_2h =  22    ! c2h6 + hv   -> c2h4 + 2h
+     j_c2h6_c2h4_h2 =  23    ! c2h6 + hv   -> c2h4 + h2
+     j_c2h6_ch3_ch3 =  24    ! c2h6 + hv   -> ch3 + ch3
+     j_c2h2_c2h_h =  25    ! c2h2 + hv   -> c2h + h
+     j_c2h2_c2_h2 =  26    ! c2h2 + hv   -> c2 + h2
+     j_c2h4_c2h2_h2 =  27    ! c2h4 + hv   -> c2h2 + h2
+     j_c2h4_c2h2_h_h =  28    ! c2h4 + hv   -> c2h2 + h + h
+     j_ch2co_3ch2_co =  29    ! ch2co + hv   -> 3ch2 + co
+
+
+
+! fill v_phot array
+
+      v_phot(:,:) = 0.
+
+      do l = 1,lswitch-1
+         v_phot(l, 1) = j(l,j_o2_o)
+         v_phot(l, 2) = j(l,j_o2_o1d)
+         v_phot(l, 3) = j(l,j_co2_o)
+         v_phot(l, 4) = j(l,j_co2_o1d)
+         v_phot(l, 5) = j(l,j_o3_o1d)
+         v_phot(l, 6) = j(l,j_o3_o)
+         v_phot(l, 7) = j(l,j_h2o)
+         v_phot(l, 8) = j(l,j_h2o2)
+         v_phot(l, 9) = j(l,j_ho2)
+!         v_phot(l,10) = j(l,j_no)
+!         v_phot(l,11) = j(l,j_no2)
+!         v_phot(l,12) = j(l,j_ch4_ch3_h)
+!         v_phot(l,13) = j(l,j_ch4_1ch2_h2)
+!         v_phot(l,14) = j(l,j_ch4_3ch2_h_h)
+!         v_phot(l,15) = j(l,j_ch4_ch_h2_h)
+!         v_phot(l,16) = j(l,j_ch4_ch_h2_h)
+!         v_phot(l,17) = j(l,j_ch2o_hco)
+!         v_phot(l,18) = j(l,j_ch2o_co)
+!         v_phot(l,19) = j(l,j_c2h6_ch4_1ch2)
+!         v_phot(l,20) = j(l,j_c2h6_c2h2_2h2)
+!         v_phot(l,21) = j(l,j_c2h6_c2h4_2h)
+!         v_phot(l,22) = j(l,j_c2h6_c2h4_h2)
+!         v_phot(l,23) = j(l,j_c2h6_ch3_ch3)
+!         v_phot(l,24) = j(l,j_c2h2_c2h_h)
+!         v_phot(l,25) = j(l,j_c2h2_c2_h2)
+!         v_phot(l,26) = j(l,j_c2h4_c2h2_h2)
+!         v_phot(l,27) = j(l,j_c2h4_c2h2_h_h)
+!         v_phot(l,28) = j(l,j_ch2co_3ch2_co)
+
+         v_phot(l,10) = j(l,j_ch4_ch3_h)
+         v_phot(l,11) = j(l,j_ch4_1ch2_h2)
+         v_phot(l,12) = j(l,j_ch4_3ch2_h_h)
+         v_phot(l,13) = j(l,j_ch4_ch_h2_h)
+         v_phot(l,14) = j(l,j_ch4_ch_h2_h)
+         v_phot(l,15) = j(l,j_ch2o_hco)
+         v_phot(l,16) = j(l,j_ch2o_co)
+         v_phot(l,17) = j(l,j_c2h6_ch4_1ch2)
+         v_phot(l,18) = j(l,j_c2h6_c2h2_2h2)
+         v_phot(l,19) = j(l,j_c2h6_c2h4_2h)
+         v_phot(l,20) = j(l,j_c2h6_c2h4_h2)
+         v_phot(l,21) = j(l,j_c2h6_ch3_ch3)
+         v_phot(l,22) = j(l,j_c2h2_c2h_h)
+         v_phot(l,23) = j(l,j_c2h2_c2_h2)
+         v_phot(l,24) = j(l,j_c2h4_c2h2_h2)
+         v_phot(l,25) = j(l,j_c2h4_c2h2_h_h)
+         v_phot(l,26) = j(l,j_ch2co_3ch2_co)
+
+
+
+
+
+
+      end do
+
+!      v_phot(:,:) = 0.
+
+      return
+      end
+
+!*****************************************************************
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/read_phototable_early_earth.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/read_phototable_early_earth.F90	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/chemistry_early_earth/read_phototable_early_earth.F90	(revision 1796)
@@ -0,0 +1,100 @@
+!***********************************************************************
+
+      subroutine read_phototable_early_earth
+
+!***********************************************************************
+!
+!   subject:
+!   --------
+!
+!   read photolysis lookup table
+!
+!   VERSION: 8/10/2014
+!
+!   Author:   Franck Lefevre
+!
+!   Arguments:
+!   ----------
+!
+!   The output variable is jphot and is put in common chimiedata.
+!
+!***********************************************************************
+
+      use ioipsl_getincom 
+      use ioipsl_getin_p_mod, only: getin_p
+      use datafile_mod
+      implicit none
+
+#include "chimiedata_early_earth.h"
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     local:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      integer :: fic, ij, iozo, isza, itemp, iz, itau, ich4, ierr
+      real    :: xsza, dummy
+
+      character(len = 128) :: phototable ! photolysis table file name
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+! set photolysis table input file name
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+
+
+! look for a " phototable= ..." option in def files
+     write(*,*) "Directory where external input files are:"
+      phototable = "jmars.20140930" ! default
+     call getin_p("phototable",phototable) ! default path
+     write(*,*) " phototable = ",trim(phototable)
+
+
+      fic = 81
+
+      open(fic, form = 'formatted', status = 'old',                &
+           file =trim(datadir)//"/"//trim(phototable),iostat=ierr)
+
+      if (ierr /= 0) THEN
+        write(*,*)'Error : cannot open photolysis lookup table ', trim(phototable)
+        write(*,*)'It should be in :',trim(datadir),'/'
+        write(*,*)'1) You can change this directory in callphys.def'
+        write(*,*)'   with:'
+        write(*,*)'   datadir=/path/to/the/directory'
+        write(*,*)'2) You can change the input phototable file name in'
+        write(*,*)'   callphys.def with:'
+        write(*,*)'   phototable=filename'
+        stop
+      end if
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+! read photolys table
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      print*, 'read photolysis lookup table ',trim(phototable)
+
+      do itau = 1,ntau
+         do itemp = 1,ntemp
+            do iozo = 1,nozo
+               do ich4 =1,nch4
+                  do isza = 1,nsza
+                     do iz = nz,1,-1
+                        read(fic,*) colairtab(iz), xsza,table_ozo(iozo), dummy, dummy, dummy, table_ch4(ich4)
+                        read(fic,'(7e11.4)') (jphot(itemp,isza,iz,iozo,itau,ich4,ij), ij= 1,nd)
+                        do ij = 1,nd
+                           if (jphot(itemp,isza,iz,iozo,itau,ich4,ij) == 1.e-30) then
+                              jphot(itemp,isza,iz,iozo,itau,ich4,ij) = 0.
+                           end if
+                        end do
+                     end do
+                  end do
+               end do
+            end do
+         end do
+      end do
+
+      print*, 'lookup table...ok'
+      close(fic)
+
+
+      return
+      end
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/chimiedata.h
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/chimiedata.h	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/chimiedata.h	(revision 1796)
@@ -0,0 +1,42 @@
+!--------------------------------------------
+!     data for photochemistry
+!--------------------------------------------
+
+!--------------------------------------------
+!     dimensions of photolysis lookup table
+!--------------------------------------------
+
+      integer, parameter :: nd    = 13  ! species
+      integer, parameter :: nz    = 143 ! altitude
+      integer, parameter :: nozo  = 7   ! ozone
+      integer, parameter :: nsza  = 27  ! solar zenith angle
+      integer, parameter :: ntemp = 4   ! temperature
+      integer, parameter :: ntau  = 8   ! dust
+
+!--------------------------------------------
+
+      real, parameter :: kb = 1.3806e-23
+
+      common/chimiedata/jphot,colairtab,table_ozo
+
+      real jphot(ntemp,nsza,nz,nozo,ntau,nd)
+      real colairtab(nz)
+      real szatab(nsza)
+      real table_ozo(nozo)
+      real tautab(ntau)
+
+      data szatab/0.,  5., 10., 15., 20., 25.,                          &
+     &            30., 35., 40., 45., 50., 55.,                         &
+     &            60., 65., 70., 75., 80., 82.,                         &
+     &            84., 86., 88., 90., 91., 92.,                         &
+     &            93., 94., 95./
+
+      data tautab/0., 0.2, 0.4, 0.6, 0.8, 1., 2., 4./
+
+!--------------------------------------------
+!     number of reactions in ASIS solver
+!--------------------------------------------
+
+      integer, parameter :: nb_phot_max       = 18
+      integer, parameter :: nb_reaction_3_max = 6
+      integer, parameter :: nb_reaction_4_max = 30
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/concentrations.F
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/concentrations.F	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/concentrations.F	(revision 1796)
@@ -0,0 +1,357 @@
+      SUBROUTINE concentrations(ngrid,nlayer,nq,
+     &                          pplay,pt,pdt,pq,pdq,ptimestep)
+                                             
+      use tracer_h, only: igcm_co2, igcm_co, igcm_o, igcm_o1d,
+     &                      igcm_o2, igcm_o3, igcm_h, igcm_h2,
+     &                      igcm_oh, igcm_ho2, igcm_n2, igcm_ar,
+     &                      igcm_h2o_vap, igcm_n, igcm_no, igcm_no2,
+     &                      igcm_n2d, igcm_ch4, 
+     &                      igcm_ch3, igcm_ch, igcm_3ch2, igcm_1ch2,      
+     &                      igcm_cho, igcm_ch2o, igcm_ch3o,               
+     &                      igcm_c, igcm_c2, igcm_c2h, igcm_c2h2,         
+     &                      igcm_c2h3, igcm_c2h4, igcm_c2h6, igcm_ch2co,  
+     &                      igcm_ch3co, igcm_hcaer,
+     &                      igcm_h2o2, mmol
+
+      use conc_mod, only: mmean, Akknew, rnew, cpnew
+      USE comcstfi_mod                   
+      use callkeys_mod
+      implicit none
+
+!=======================================================================
+! CALCULATION OF MEAN MOLECULAR MASS, Cp, Akk and R
+!
+! mmean(ngrid,nlayer)	amu
+! cpnew(ngrid,nlayer)	J/kg/K
+! rnew(ngrid,nlayer)	J/kg/K
+! akknew(ngrid,nlayer)	coefficient of thermal concduction
+!
+! version: April 2012 - Franck Lefevre
+!=======================================================================
+
+!     declarations
+ 
+#include "chimiedata.h"
+!     input/output
+
+      integer,intent(in) :: ngrid ! number of atmospheric columns
+      integer,intent(in) :: nlayer ! number of atmospheric layers
+      integer,intent(in) :: nq ! number of tracers
+      real,intent(in) :: pplay(ngrid,nlayer)
+      real,intent(in) :: pt(ngrid,nlayer)
+      real,intent(in) :: pdt(ngrid,nlayer)
+      real,intent(in) :: pq(ngrid,nlayer,nq)
+      real,intent(in) :: pdq(ngrid,nlayer,nq)
+      real,intent(in) :: ptimestep
+
+!     local variables
+
+      integer       :: i, l, ig, iq
+      integer, save :: nbq
+      integer,allocatable,save :: niq(:)
+      real          :: ni(nq), ntot
+      real          :: zq(ngrid, nlayer, nq)
+      real          :: zt(ngrid, nlayer)
+      real,allocatable,save    :: aki(:)
+      real,allocatable,save    :: cpi(:)
+
+      logical, save :: firstcall = .true.
+
+
+      if (firstcall) then
+
+         ! allocate local saved arrays:
+         allocate(aki(nq))
+         allocate(cpi(nq))
+         allocate(niq(nq))
+!        find index of chemical tracers to use
+!        initialize thermal conductivity and specific heat coefficients
+!        !? values are estimated
+
+         nbq = 0 ! to count number of tracers used in this subroutine
+
+         if (igcm_co2 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_co2
+            aki(nbq) = 3.072e-4
+            cpi(nbq) = 0.834e3
+         end if
+         if (igcm_co /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_co
+            aki(nbq) = 4.87e-4
+            cpi(nbq) = 1.034e3
+         end if
+         if (igcm_o /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_o
+            aki(nbq) = 7.59e-4
+            cpi(nbq) = 1.3e3
+         end if
+         if (igcm_o1d /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_o1d
+            aki(nbq) = 7.59e-4  !?
+            cpi(nbq) = 1.3e3    !?
+         end if
+         if (igcm_o2 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_o2
+            aki(nbq) = 5.68e-4
+            cpi(nbq) = 0.9194e3
+         end if
+         if (igcm_o3 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_o3
+            aki(nbq) = 3.00e-4  !?
+            cpi(nbq) = 0.800e3  !?
+         end if
+         if (igcm_h /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_h
+            aki(nbq) = 0.0
+            cpi(nbq) = 20.780e3
+         end if
+         if (igcm_h2 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_h2
+            aki(nbq) = 36.314e-4
+            cpi(nbq) = 14.266e3
+         end if
+         if (igcm_oh /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_oh
+            aki(nbq)  = 7.00e-4 !?
+            cpi(nbq)  = 1.045e3
+         end if
+         if (igcm_ho2 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_ho2
+            aki(nbq) = 0.0
+            cpi(nbq) = 1.065e3  !?
+         end if
+         if (igcm_h2o2 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_h2o2
+            aki(nbq) = 0.0
+            cpi(nbq) = 1.065e3  !?
+         end if
+         if (igcm_h2o_vap /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_h2o_vap
+            aki(nbq) = 0.0
+            cpi(nbq) = 1.870e3
+         end if
+         if (igcm_n /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_n
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_n2d /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_n2d
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_no /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_no
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_no2 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_no2
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if (igcm_n2 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_n2
+            aki(nbq) = 5.6e-4
+            cpi(nbq) = 1.034e3
+         end if
+         if(igcm_ch4 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_ch4
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_ch3 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_ch3
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_ch /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_ch
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_1ch2 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_1ch2
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_3ch2 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_3ch2
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_cho /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_cho
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_ch2o /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_ch2o
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_ch3o /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_ch3o
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_c /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_c
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_c2 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_c2
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_c2h /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_c2h
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_c2h2 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_c2h2
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_c2h3 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_c2h3
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_c2h4 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_c2h4
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_c2h6 /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_c2h6
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_ch2co /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_ch2co
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_ch3co /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_ch3co
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if(igcm_hcaer /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_hcaer
+            aki(nbq) = 0.0
+            cpi(nbq) = 0.0
+         endif
+         if (igcm_ar /= 0) then
+            nbq = nbq + 1
+            niq(nbq) = igcm_ar
+            aki(nbq) = 0.0      !?
+            cpi(nbq) = 1.000e3  !?
+         end if
+
+
+         ! tell the world about it:
+         write(*,*) "concentrations: firstcall, nbq=",nbq
+         write(*,*) "  niq(1:nbq)=",niq(1:nbq)
+         write(*,*) "  aki(1:nbq)=",aki(1:nbq)
+         write(*,*) "  cpi(1:nbq)=",cpi(1:nbq)
+
+         firstcall = .false.
+
+      end if ! if (firstcall)
+
+!     update temperature
+
+      do l = 1,nlayer
+         do ig = 1,ngrid
+            zt(ig,l) = pt(ig,l) + pdt(ig,l)*ptimestep
+         end do
+      end do
+
+!     update tracers
+
+      do l = 1,nlayer
+         do ig = 1,ngrid
+            do i = 1,nbq
+               iq = niq(i) 
+               zq(ig,l,iq) = max(1.e-30, pq(ig,l,iq)
+     $                                 + pdq(ig,l,iq)*ptimestep)
+            end do
+         end do
+      end do
+
+!     mmean : mean molecular mass
+!     rnew  : specific gas constant
+
+      mmean(:,:)  = 0.
+      do l = 1,nlayer
+         do ig = 1,ngrid
+            do i = 1,nbq
+               iq = niq(i)
+               mmean(ig,l) = mmean(ig,l) + zq(ig,l,iq)/mmol(iq)
+            end do
+            mmean(ig,l) = 1./mmean(ig,l)
+            rnew(ig,l) = 8.314/mmean(ig,l)*1.e3     ! J/kg/K		
+         end do
+      end do
+
+
+!     cpnew  : specicic heat
+!     akknew : thermal conductivity cofficient
+      cpnew(:,:)  = 0.
+      akknew(:,:) = 0.
+
+      do l = 1,nlayer
+         do ig = 1,ngrid
+            ntot = pplay(ig,l)/(1.381e-23*zt(ig,l))*1.e-6  ! in #/cm3
+            do i = 1,nbq
+               iq = niq(i) 
+               ni(iq) = ntot*zq(ig,l,iq)*mmean(ig,l)/mmol(iq)
+               cpnew(ig,l) = cpnew(ig,l) + ni(iq)*cpi(i)
+               akknew(ig,l) = akknew(ig,l) + ni(iq)*aki(i)
+            end do 
+            cpnew(ig,l) = cpnew(ig,l)/ntot
+            akknew(ig,l) = akknew(ig,l)/ntot
+         end do
+      end do
+
+      return
+      end 
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/dtridgl.F
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/dtridgl.F	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/dtridgl.F	(revision 1796)
@@ -0,0 +1,36 @@
+      SUBROUTINE DTRIDGL(L,AF,BF,CF,DF,XK)
+
+C  GCM2.0  Feb 2003
+
+C     DOUBLE PRECISION VERSION OF TRIDGL
+
+      PARAMETER (NMAX=201)
+      IMPLICIT REAL*8  (A-H,O-Z)
+      DIMENSION AF(L),BF(L),CF(L),DF(L),XK(L)
+      DIMENSION AS(NMAX),DS(NMAX)
+
+C*    THIS SUBROUTINE SOLVES A SYSTEM OF TRIDIAGIONAL MATRIX
+C*    EQUATIONS. THE FORM OF THE EQUATIONS ARE:
+C*    A(I)*X(I-1) + B(I)*X(I) + C(I)*X(I+1) = D(I)
+C*    WHERE I=1,L  LESS THAN 103.
+C* ..............REVIEWED -CP........
+
+C======================================================================C
+
+      AS(L) = AF(L)/BF(L)
+      DS(L) = DF(L)/BF(L)
+
+      DO I=2,L
+        X         = 1./(BF(L+1-I) - CF(L+1-I)*AS(L+2-I))
+        AS(L+1-I) = AF(L+1-I)*X
+        DS(L+1-I) = (DF(L+1-I)-CF(L+1-I)*DS(L+2-I))*X
+      END DO
+ 
+      XK(1)=DS(1)
+      DO I=2,L
+        XKB   = XK(I-1)
+        XK(I) = DS(I)-AS(I)*XKB
+      END DO
+
+      RETURN
+      END
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/inichim_1D.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/inichim_1D.F90	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/inichim_1D.F90	(revision 1796)
@@ -0,0 +1,717 @@
+      subroutine inichim_1D(nq, pq, qsurf, ps, &
+                                  flagh2o,flagthermo)
+
+      use tracer_h
+      USE comvert_mod, ONLY: aps,bps
+      USE mod_grid_phy_lmdz, ONLY: nbp_lev
+      use callkeys_mod
+      use datafile_mod
+
+      implicit none
+
+!=======================================================================
+!
+!  Purpose:
+!  --------
+!
+!  Initialization of the chemistry for use in the building of a new start file
+!  used by program newstart.F
+!  also used by program testphys1d.F
+!
+!  Authors: 
+!  -------
+!  Initial version 11/2002 by Sebastien Lebonnois
+!  Revised 07/2003 by Monica Angelats-i-Coll to use input files
+!  Modified 10/2008 Identify tracers by their names Ehouarn Millour
+!  Modified 11/2011 Addition of methane Franck Lefevre
+!  Rewritten 04/2012 Franck Lefevre
+!
+!  Arguments:
+!  ----------
+!
+!  pq(nbp_lon+1,nbp_lat,nbp_lev,nq)  Advected fields, ie chemical species here
+!  qsurf(ngrid,nq)     Amount of tracer on the surface (kg/m2)
+!  ps(nbp_lon+1,nbp_lat)           Surface pressure (Pa)
+!  flagh2o                 flag for initialisation of h2o (1: yes / 0: no)
+!  flagthermo              flag for initialisation of thermosphere only (1: yes / 0: no)
+!
+!=======================================================================
+
+
+! inputs :
+
+      integer,intent(in) :: nq                    ! number of tracers
+      real,intent(in) :: ps            ! surface pressure in the gcm (Pa)   
+      integer,intent(in) :: flagh2o               ! flag for h2o initialisation
+      integer,intent(in) :: flagthermo            ! flag for thermosphere initialisation only
+
+! outputs :
+
+      real,intent(out) :: pq(nbp_lev,nq)  ! advected fields, ie chemical species
+      real,intent(out) :: qsurf(nq)     ! surface values (kg/m2) of tracers
+
+! local :
+
+      integer :: iq, l, n, nbqchem
+      integer :: count, ierr, dummy
+      real    :: mmean(nbp_lev)             ! mean molecular mass (g)
+      real    :: pgcm                             ! pressure at each layer in the gcm (Pa)
+
+      integer, parameter         :: nalt = 252    ! number of altitudes in the initialization files
+      integer                    :: nspe          ! number of species in the initialization files
+      integer, allocatable       :: niq(:)        ! local index of species in initialization files
+      real, dimension(nalt)      :: tinit, zzfile ! temperature in initialization files
+      real, dimension(nalt)      :: pinit         ! pressure in initialization files
+      real, dimension(nalt)      :: densinit      ! total number density in initialization files
+      real, allocatable          :: vmrinit(:,:)  ! mixing ratios in initialization files
+      real, allocatable          :: vmrint(:)     ! mixing ratio interpolated onto the gcm vertical grid
+      real                       :: vmr
+
+      character(len=20)          :: txt           ! to store some text
+      logical                    :: flagnitro     ! checks if N species present
+
+! 1. identify tracers by their names: (and set corresponding values of mmol)
+
+! 1.1 initialize tracer indexes to zero:
+!      nqmx=nq ! initialize value of nqmx
+
+!      do iq = 1,nq
+!        igcm_dustbin(iq) = 0
+!      end do
+
+!      igcm_dust_mass   = 0
+!      igcm_dust_number = 0
+!      igcm_ccn_mass    = 0
+!      igcm_ccn_number  = 0
+      igcm_h2o_vap     = 0
+      igcm_h2o_ice     = 0
+      igcm_co2         = 0
+      igcm_co          = 0
+      igcm_o           = 0
+      igcm_o1d         = 0
+      igcm_o2          = 0
+      igcm_o3          = 0
+      igcm_h           = 0
+      igcm_h2          = 0
+      igcm_oh          = 0
+      igcm_ho2         = 0
+      igcm_h2o2        = 0
+      igcm_ch4         = 0
+      igcm_n2          = 0
+      igcm_n           = 0
+      igcm_n2d         = 0
+      igcm_no          = 0
+      igcm_no2         = 0
+      igcm_ar          = 0
+      igcm_ar_n2       = 0
+      igcm_ch3         = 0
+      igcm_ch          = 0
+      igcm_3ch2        = 0
+      igcm_1ch2        = 0
+      igcm_cho         = 0
+      igcm_ch2o        = 0 
+      igcm_c           = 0
+      igcm_c2          = 0
+      igcm_c2h         = 0
+      igcm_c2h2        = 0
+      igcm_c2h3        = 0
+      igcm_c2h4        = 0
+      igcm_c2h6        = 0
+      igcm_ch2co       = 0
+      igcm_ch3co       = 0
+      igcm_hcaer       = 0
+
+! 1.2 find dust tracers
+      count = 0
+!
+!      if (dustbin > 0) then
+!         do iq = 1,nq
+!            txt = " "
+!            write(txt,'(a4,i2.2)') 'dust', count + 1
+!            if (noms(iq) == txt) then
+!               count = count + 1
+!               igcm_dustbin(count) = iq
+!               mmol(iq) = 100.
+!            end if
+!         end do !do iq=1,nq
+!      end if ! of if (dustbin.gt.0)
+!
+!      if (doubleq) then
+!         do iq = 1,nq
+!            if (noms(iq) == "dust_mass") then
+!               igcm_dust_mass = iq
+!               count = count + 1
+!            end if
+!            if (noms(iq) == "dust_number") then
+!               igcm_dust_number = iq
+!               count = count + 1
+!            end if
+!         end do
+!      end if ! of if (doubleq)
+!
+!      if (scavenging) then
+!         do iq = 1,nq
+!            if (noms(iq) == "ccn_mass") then
+!               igcm_ccn_mass = iq
+!               count = count + 1
+!            end if
+!            if (noms(iq) == "ccn_number") then
+!               igcm_ccn_number = iq
+!               count = count + 1
+!            end if
+!         end do
+!      end if ! of if (scavenging)
+!
+!      if (submicron) then
+!         do iq=1,nq
+!            if (noms(iq) == "dust_submicron") then
+!               igcm_dust_submicron = iq
+!               mmol(iq) = 100.
+!               count = count + 1
+!            end if
+!         end do
+!      end if ! of if (submicron)
+
+! 1.3 find chemistry and water tracers
+
+      nbqchem = 0
+
+      do iq = 1,nq
+         if (noms(iq) == "co2") then
+            igcm_co2 = iq
+            mmol(igcm_co2) = 44.
+            count = count + 1
+            nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "co") then
+           igcm_co = iq
+           mmol(igcm_co) = 28.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "o") then
+           igcm_o = iq
+           mmol(igcm_o) = 16.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "o1d") then
+           igcm_o1d = iq
+           mmol(igcm_o1d) = 16.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "o2") then
+           igcm_o2 = iq
+           mmol(igcm_o2) = 32.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "o3") then
+           igcm_o3 = iq
+           mmol(igcm_o3) = 48.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "h") then
+           igcm_h = iq
+           mmol(igcm_h) = 1.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "h2") then
+           igcm_h2 = iq
+           mmol(igcm_h2) = 2.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "oh") then
+           igcm_oh = iq
+           mmol(igcm_oh) = 17.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "ho2") then
+           igcm_ho2 = iq
+           mmol(igcm_ho2) = 33.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "h2o2") then
+           igcm_h2o2 = iq
+           mmol(igcm_h2o2) = 34.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "n2") then
+           igcm_n2 = iq
+           mmol(igcm_n2) = 28.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "ch4") then
+           igcm_ch4 = iq
+           mmol(igcm_ch4) = 16.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "ar") then
+           igcm_ar = iq
+           mmol(igcm_ar) = 40.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "n") then
+           igcm_n = iq
+           mmol(igcm_n) = 14.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "n2d") then
+           igcm_n2d = iq
+           mmol(igcm_n2d) = 14.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "no") then
+           igcm_no = iq
+           mmol(igcm_no) = 30.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "no2") then
+           igcm_no2 = iq
+           mmol(igcm_no2) = 46.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+
+        if (noms(iq) == "h2o_vap") then
+           igcm_h2o_vap = iq
+           mmol(igcm_h2o_vap) = 18.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "h2o_ice") then
+           igcm_h2o_ice = iq
+           mmol(igcm_h2o_ice) = 18.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+
+
+        if (noms(iq).eq."ch3") then
+          igcm_ch3=iq
+          mmol(igcm_ch3)=15.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."ch") then
+          igcm_ch=iq
+          mmol(igcm_ch)=13.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."3ch2") then
+          igcm_3ch2=iq
+          mmol(igcm_3ch2)=14.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."1ch2") then
+          igcm_1ch2=iq
+          mmol(igcm_1ch2)=14.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."cho") then
+          igcm_cho=iq
+          mmol(igcm_cho)=29.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."ch2o") then
+          igcm_ch2o=iq
+          mmol(igcm_ch2o)=30.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."ch3o") then
+          igcm_ch3o=iq
+          mmol(igcm_ch3o)=31.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c") then
+          igcm_c=iq
+          mmol(igcm_c)=12.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c2") then
+          igcm_c2=iq
+          mmol(igcm_c2)=24.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c2h") then
+          igcm_c2h=iq
+          mmol(igcm_c2h)=25.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c2h2") then
+          igcm_c2h2=iq
+          mmol(igcm_c2h2)=26.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c2h3") then
+          igcm_c2h3=iq
+          mmol(igcm_c2h3)=27.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c2h4") then
+          igcm_c2h4=iq
+          mmol(igcm_c2h4)=28.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c2h6") then
+          igcm_c2h6=iq
+          mmol(igcm_c2h6)=30.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."ch2co") then
+          igcm_ch2co=iq
+          mmol(igcm_ch2co)=42.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."ch3co") then
+          igcm_ch3co=iq
+          mmol(igcm_ch3co)=43.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."hcaer") then
+          igcm_hcaer=iq
+          mmol(igcm_hcaer)=50.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+
+
+
+
+! 1.5 find idealized non-condensible tracer
+
+        if (noms(iq) == "Ar_N2") then
+           igcm_ar_n2 = iq
+           mmol(igcm_ar_n2) = 30.
+           count = count + 1
+        end if
+
+      end do ! of do iq=1,nq
+     
+ 
+! 1.6 check that we identified all tracers:
+
+      if (count /= nq) then
+         write(*,*) "inichim_1D: found only ",count," tracers"
+         write(*,*) "                  expected ",nq
+         do iq = 1,count
+            write(*,*) '      ', iq, ' ', trim(noms(iq))
+         end do
+         stop
+      else
+         write(*,*) "inichim_1D: found all expected tracers"
+         do iq = 1,nq
+            write(*,*) '      ', iq, ' ', trim(noms(iq))
+         end do
+      end if
+
+! 1.7 check if nitrogen species are present:
+
+      if(igcm_no == 0) then
+         !check that no N species is in traceur.def
+         if(igcm_n /= 0 .or. igcm_no2 /= 0 .or. igcm_n2d /= 0) then
+            write(*,*)'inichim_1D error:'
+            write(*,*)'N, NO2 and/or N2D are in traceur.def, but not NO'
+            write(*,*)'stop'
+            stop
+         endif
+         flagnitro = .false.
+         nspe = 15
+      else
+         !check that all N species are in traceur.def
+         if(igcm_n == 0 .or. igcm_no2 == 0 .or. igcm_n2d == 0) then
+            write(*,*)'inichim_1D error:'
+            write(*,*)'if NO is in traceur.def, N, NO2 and N2D must also be'
+            write(*,*)'stop'
+            stop
+         endif
+         flagnitro = .true.
+         nspe = 18
+      endif
+
+! 1.8 allocate arrays
+
+      allocate(niq(nspe))
+      allocate(vmrinit(nalt,nspe))
+      allocate(vmrint(nspe))
+
+! 2. load in chemistry data for initialization:
+
+! order of major species in initialization file:
+!
+!    1: co2 
+!    2: ar
+!    3: n2  
+!    4: o2  
+!    5: co  
+!    6: o   
+!    7: h2
+!
+! order of minor species in initialization file:
+!
+!    1: h  
+!    2: oh 
+!    3: ho2 
+!    4: h2o 
+!    5: h2o2 
+!    6: o1d
+!    7: o3
+!
+! order of nitrogen species in initialization file:
+!
+!    1: n
+!    2: no
+!    3: no2
+!    4: n2d
+
+! major species:
+
+      niq(1) = igcm_co2
+      niq(2) = igcm_ar
+      niq(3) = igcm_n2
+      niq(4) = igcm_o2
+      niq(5) = igcm_co
+      niq(6) = igcm_o
+      niq(7) = igcm_h2
+
+! minor species:
+
+      niq(8)  = igcm_h
+      niq(9)  = igcm_oh
+      niq(10) = igcm_ho2
+      niq(11) = igcm_h2o_vap
+      niq(12) = igcm_h2o2
+      niq(13) = igcm_o1d 
+      niq(14) = igcm_o3
+
+! nitrogen species:
+
+      if (flagnitro) then
+         niq(15) = igcm_n
+         niq(16) = igcm_no
+         niq(17) = igcm_no2
+         niq(18) = igcm_n2d         
+      end if
+
+! carbon species:
+!      niq(18) = igcm_ch4
+!      niq(19) = igcm_ch3
+!      niq(20) = igcm_ch
+!      niq(21) = igcm_1ch2
+!      niq(22) = igcm_3ch2
+!      niq(23) = igcm_cho
+!      niq(24) = igcm_ch2o
+!      niq(25) = igcm_ch3o
+!      niq(26) = igcm_c
+!      niq(27) = igcm_c2
+!      niq(28) = igcm_c2h
+!      niq(29) = igcm_c2h2
+!      niq(30) = igcm_c2h3
+!      niq(31) = igcm_c2h4
+!      niq(32) = igcm_c2h6
+!      niq(33) = igcm_ch2co
+!      niq(34) = igcm_ch3co
+!      niq(35) = igcm_hcaer
+
+
+
+! 2.1 open initialization files
+      if(1.eq.1) then
+      open(210, iostat=ierr,file=trim(datadir)//'/atmosfera_LMD_may.dat')
+      if (ierr /= 0) then
+         write(*,*)'Error : cannot open file atmosfera_LMD_may.dat '
+         write(*,*)'(in aeronomars/inichim_1D.F)'
+         write(*,*)'It should be in :', trim(datadir),'/'
+         write(*,*)'1) You can change this path in callphys.def with'
+         write(*,*)'   datadir=/path/to/datafiles/'
+         write(*,*)'2) If necessary atmosfera_LMD_may.dat (and others)'
+         write(*,*)'   can be obtained online on:'
+         write(*,*)' http://www.lmd.jussieu.fr/~lmdz/planets/mars/datadir'
+         stop
+      end if
+      open(220, iostat=ierr,file=trim(datadir)//'/atmosfera_LMD_min.dat')
+      if (ierr /= 0) then
+         write(*,*)'Error : cannot open file atmosfera_LMD_min.dat '
+         write(*,*)'(in aeronomars/inichim_1D.F)'
+         write(*,*)'It should be in :', trim(datadir),'/'
+         write(*,*)'1) You can change this path in callphys.def with'
+         write(*,*)'   datadir=/path/to/datafiles/'
+         write(*,*)'2) If necessary atmosfera_LMD_min.dat (and others)'
+         write(*,*)'   can be obtained online on:'
+         write(*,*)' http://www.lmd.jussieu.fr/~lmdz/planets/mars/datadir'
+         stop
+      end if
+
+      print*,'flagnitro=',flagnitro
+      if(flagnitro) then
+         open(230, iostat=ierr,file=trim(datadir)//'/atmosfera_LMD_nitr.dat')
+         if (ierr /= 0) then
+            write(*,*)'Error : cannot open file atmosfera_LMD_nitr.dat '
+            write(*,*)'(in aeronomars/inichim_1D.F)'
+            write(*,*)'It should be in :', datadir
+            write(*,*)'1) You can change this directory address in '
+            write(*,*)'   file phymars/datafile.h'
+            write(*,*)'2) If necessary atmosfera_LMD_nitr.dat (and others)'
+            write(*,*)'   can be obtained online on:'
+            write(*,*)' http://www.lmd.jussieu.fr/~lmdz/planets/mars/datadir'
+            STOP
+         endif
+      endif   ! Of if(flagnitro)
+
+
+! 2.2 read initialization files'
+
+! major species
+
+      read(210,*)
+      do l = 1,nalt
+         read(210,*) dummy, tinit(l), pinit(l), densinit(l), &
+                     (vmrinit(l,n), n = 1,7)
+         pinit(l) = pinit(l)*100.              ! conversion in Pa
+         pinit(l) = log(pinit(l))              ! for the vertical interpolation
+      end do
+      close(210)
+
+! minor species
+
+      read(220,*)
+      do l = 1,nalt
+         read(220,*) dummy, (vmrinit(l,n), n = 8,14)
+      end do 
+      close(220)
+
+! nitrogen species
+
+      if(flagnitro) then
+         read(230,*)
+         do l = 1,nalt
+            read(230,*) dummy, (vmrinit(l,n), n = 15,18)
+         end do
+         close(230)
+      endif
+      endif !if(1.eq.0)
+
+
+! initialization for the early eath
+      if (1.eq.0) then
+        do l = 1,nalt
+         vmrinit(l,:)=0e-7
+         vmrinit(l,1)=0.1 !co2
+         vmrinit(l,2)=0.9 !n2
+         vmrinit(l,3)=0.0 !o2
+         vmrinit(l,6)=4e-3 !h2
+         vmrinit(l,10)=1e-9 !h2o
+         vmrinit(l,18)=0.0e-5 !ch4
+         vmrinit(l,10:13)=0.0e-7 !n
+         vmrinit(l,14)=0.0 !n
+         vmrinit(l,15)=0.0 !no
+         vmrinit(l,16)=0.0 !no2  
+!         pinit(l)=aps(l) + bps(l)*ps
+!        vmrinit(l,18)=2e-3*min(pinit(l)/100.,1.) ! decrease with scale height above 1 hpa
+         vmrinit(l,2)=0.0
+         vmrinit(l,2)=1-sum(vmrinit(l,:)) !n2
+!         vmrinit(l,4)=0.1
+!         vmrinit(l,7)=0.001
+        end do
+      endif
+
+
+      
+! 3. initialization of tracers
+
+            do l = 1,nbp_lev
+
+               pgcm = aps(l) + bps(l)*ps  ! gcm pressure               
+               pgcm = log(pgcm)                ! for the vertical interpolation
+               mmean(l) = 0.
+               
+! 3.1 vertical interpolation
+               do n = 1,nspe
+                  call intrplf(pgcm,vmr,pinit,vmrinit(:,n),nalt)
+                  vmrint(n) = vmr
+                  iq = niq(n)
+                  mmean(l) = mmean(l) + vmrint(n)*mmol(iq)
+!                  mmean(l) = mmean(l) + vmrinit(1,n)*mmol(iq)
+               end do
+
+! 3.2 attribute mixing ratio: - all layers or only thermosphere
+!                             - with our without h2o 
+
+               if (flagthermo == 0 .or. (flagthermo == 1 .and. exp(pgcm) < 0.1)) then
+                  do n = 1,nq
+                    pq(l,iq) = 0.
+                    qsurf(iq) = 0.
+                  enddo
+
+                  do n = 1,nspe
+                     iq = niq(n)
+!                     if (iq /= igcm_h2o_vap .or. flagh2o == 1) then
+                        pq(l,iq) = vmrint(n)*mmol(iq)/mmean(l)
+!                        pq(l,iq) = vmrinit(1,n)*mmol(iq)/mmean(1)
+!                     end if
+                  end do
+!                     pq(l,igcm_ch4) = 2.e-3*min((aps(l) + bps(l)*ps)/100.,1.)*mmol(igcm_ch4)/mmean(l)
+               end if
+ 
+            end do
+
+
+! set surface values of chemistry tracers to zero
+
+      if (flagthermo == 0) then
+         ! NB: no problem for "surface water vapour" tracer which is always 0
+         do n = 1,nspe
+            iq = niq(n)
+            qsurf(iq) = 0.
+         end do
+      end if
+
+! 3.3 initialization of tracers not contained in the initialization files
+
+! methane : 10 ppbv
+
+!      if (igcm_ch4 /= 0) then
+!         vmr = 10.e-9       
+!               do l = 1,nbp_lev
+!                  pq(l,igcm_ch4) = vmr*mmol(igcm_ch4)/mmean(l)
+!               end do
+!         ! set surface value to zero
+!         qsurf(igcm_ch4) = 0.
+!      end if
+
+      
+      ! deallocations
+
+      deallocate(niq)
+      deallocate(vmrinit)
+      deallocate(vmrint)
+
+      end
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/inichim_newstart.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/inichim_newstart.F90	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/inichim_newstart.F90	(revision 1796)
@@ -0,0 +1,729 @@
+      subroutine inichim_newstart(ngrid, nq, pq, qsurf, ps, &
+                                  flagh2o, flagthermo)
+
+      use tracer_h
+      USE comvert_mod, ONLY: aps,bps
+      USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev
+      use callkeys_mod
+      use datafile_mod
+
+      implicit none
+
+!=======================================================================
+!
+!  Purpose:
+!  --------
+!
+!  Initialization of the chemistry for use in the building of a new start file
+!  used by program newstart.F
+!  also used by program testphys1d.F
+!
+!  Authors: 
+!  -------
+!  Initial version 11/2002 by Sebastien Lebonnois
+!  Revised 07/2003 by Monica Angelats-i-Coll to use input files
+!  Modified 10/2008 Identify tracers by their names Ehouarn Millour
+!  Modified 11/2011 Addition of methane Franck Lefevre
+!  Rewritten 04/2012 Franck Lefevre
+!
+!  Arguments:
+!  ----------
+!
+!  pq(nbp_lon+1,nbp_lat,nbp_lev,nq)  Advected fields, ie chemical species here
+!  qsurf(ngrid,nq)     Amount of tracer on the surface (kg/m2)
+!  ps(nbp_lon+1,nbp_lat)           Surface pressure (Pa)
+!  flagh2o                 flag for initialisation of h2o (1: yes / 0: no)
+!  flagthermo              flag for initialisation of thermosphere only (1: yes / 0: no)
+!
+!=======================================================================
+
+
+! inputs :
+
+      integer,intent(in) :: ngrid         ! number of atmospheric columns in the physics
+      integer,intent(in) :: nq                    ! number of tracers
+      real,intent(in) :: ps(nbp_lon+1,nbp_lat)            ! surface pressure in the gcm (Pa)   
+      integer,intent(in) :: flagh2o               ! flag for h2o initialisation
+      integer,intent(in) :: flagthermo            ! flag for thermosphere initialisation only
+
+! outputs :
+
+      real,intent(out) :: pq(nbp_lon+1,nbp_lat,nbp_lev,nq)  ! advected fields, ie chemical species
+      real,intent(out) :: qsurf(ngrid,nq)     ! surface values (kg/m2) of tracers
+
+! local :
+
+      integer :: iq, i, j, l, n, nbqchem
+      integer :: count, ierr, dummy
+      real    :: mmean(nbp_lon+1,nbp_lat,nbp_lev)             ! mean molecular mass (g)
+      real    :: pgcm                             ! pressure at each layer in the gcm (Pa)
+
+      integer, parameter         :: nalt = 252    ! number of altitudes in the initialization files
+      integer                    :: nspe          ! number of species in the initialization files
+      integer, allocatable       :: niq(:)        ! local index of species in initialization files
+      real, dimension(nalt)      :: tinit, zzfile ! temperature in initialization files
+      real, dimension(nalt)      :: pinit         ! pressure in initialization files
+      real, dimension(nalt)      :: densinit      ! total number density in initialization files
+      real, allocatable          :: vmrinit(:,:)  ! mixing ratios in initialization files
+      real, allocatable          :: vmrint(:)     ! mixing ratio interpolated onto the gcm vertical grid
+      real                       :: vmr
+
+      character(len=20)          :: txt           ! to store some text
+      logical                    :: flagnitro     ! checks if N species present
+
+! 1. identify tracers by their names: (and set corresponding values of mmol)
+
+! 1.1 initialize tracer indexes to zero:
+!      nqmx=nq ! initialize value of nqmx
+
+      do iq = 1,nq
+        igcm_dustbin(iq) = 0
+      end do
+
+!      igcm_dust_mass   = 0
+!      igcm_dust_number = 0
+!      igcm_ccn_mass    = 0
+!      igcm_ccn_number  = 0
+      igcm_h2o_vap     = 0
+      igcm_h2o_ice     = 0
+      igcm_co2         = 0
+      igcm_co          = 0
+      igcm_o           = 0
+      igcm_o1d         = 0
+      igcm_o2          = 0
+      igcm_o3          = 0
+      igcm_h           = 0
+      igcm_h2          = 0
+      igcm_oh          = 0
+      igcm_ho2         = 0
+      igcm_h2o2        = 0
+      igcm_ch4         = 0
+      igcm_n2          = 0
+      igcm_ar          = 0
+      igcm_ar_n2       = 0
+      igcm_ch3         = 0
+      igcm_ch          = 0
+      igcm_3ch2        = 0
+      igcm_1ch2        = 0
+      igcm_cho         = 0
+      igcm_ch2o        = 0
+      igcm_c           = 0
+      igcm_c2          = 0
+      igcm_c2h         = 0
+      igcm_c2h2        = 0
+      igcm_c2h3        = 0
+      igcm_c2h4        = 0
+      igcm_c2h6        = 0
+      igcm_ch2co       = 0
+      igcm_ch3co       = 0
+      igcm_hcaer       = 0
+
+! 1.2 find dust tracers
+      count = 0
+!
+!      if (dustbin > 0) then
+!         do iq = 1,nq
+!            txt = " "
+!            write(txt,'(a4,i2.2)') 'dust', count + 1
+!            if (noms(iq) == txt) then
+!               count = count + 1
+!               igcm_dustbin(count) = iq
+!               mmol(iq) = 100.
+!            end if
+!         end do !do iq=1,nq
+!      end if ! of if (dustbin.gt.0)
+!
+!      if (doubleq) then
+!         do iq = 1,nq
+!            if (noms(iq) == "dust_mass") then
+!               igcm_dust_mass = iq
+!               count = count + 1
+!            end if
+!            if (noms(iq) == "dust_number") then
+!               igcm_dust_number = iq
+!               count = count + 1
+!            end if
+!         end do
+!      end if ! of if (doubleq)
+!
+!      if (scavenging) then
+!         do iq = 1,nq
+!            if (noms(iq) == "ccn_mass") then
+!               igcm_ccn_mass = iq
+!               count = count + 1
+!            end if
+!            if (noms(iq) == "ccn_number") then
+!               igcm_ccn_number = iq
+!               count = count + 1
+!            end if
+!         end do
+!      end if ! of if (scavenging)
+!
+!      if (submicron) then
+!         do iq=1,nq
+!            if (noms(iq) == "dust_submicron") then
+!               igcm_dust_submicron = iq
+!               mmol(iq) = 100.
+!               count = count + 1
+!            end if
+!         end do
+!      end if ! of if (submicron)
+
+! 1.3 find chemistry and water tracers
+
+      nbqchem = 0
+
+      do iq = 1,nq
+         if (noms(iq) == "co2") then
+            igcm_co2 = iq
+            mmol(igcm_co2) = 44.
+            count = count + 1
+            nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "co") then
+           igcm_co = iq
+           mmol(igcm_co) = 28.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "o") then
+           igcm_o = iq
+           mmol(igcm_o) = 16.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "o1d") then
+           igcm_o1d = iq
+           mmol(igcm_o1d) = 16.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "o2") then
+           igcm_o2 = iq
+           mmol(igcm_o2) = 32.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "o3") then
+           igcm_o3 = iq
+           mmol(igcm_o3) = 48.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "h") then
+           igcm_h = iq
+           mmol(igcm_h) = 1.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "h2") then
+           igcm_h2 = iq
+           mmol(igcm_h2) = 2.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "oh") then
+           igcm_oh = iq
+           mmol(igcm_oh) = 17.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "ho2") then
+           igcm_ho2 = iq
+           mmol(igcm_ho2) = 33.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "h2o2") then
+           igcm_h2o2 = iq
+           mmol(igcm_h2o2) = 34.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "ch4") then
+           igcm_ch4 = iq
+           mmol(igcm_ch4) = 16.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "n2") then
+           igcm_n2 = iq
+           mmol(igcm_n2) = 28.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "n") then
+           igcm_n = iq
+           mmol(igcm_n) = 14.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "n2d") then
+           igcm_n2d = iq
+           mmol(igcm_n2d) = 14.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "no") then
+           igcm_no = iq
+           mmol(igcm_no) = 30.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "no2") then
+           igcm_no2 = iq
+           mmol(igcm_no2) = 46.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "h2o_vap") then
+           igcm_h2o_vap = iq
+           mmol(igcm_h2o_vap) = 18.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+        if (noms(iq) == "h2o_ice") then
+           igcm_h2o_ice = iq
+           mmol(igcm_h2o_ice) = 18.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+
+        if (noms(iq).eq."ch3") then
+          igcm_ch3=iq
+          mmol(igcm_ch3)=15.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."ch") then
+          igcm_ch=iq
+          mmol(igcm_ch)=13.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."3ch2") then
+          igcm_3ch2=iq
+          mmol(igcm_3ch2)=14.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."1ch2") then
+          igcm_1ch2=iq
+          mmol(igcm_1ch2)=14.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."cho") then
+          igcm_cho=iq
+          mmol(igcm_cho)=29.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."ch2o") then
+          igcm_ch2o=iq
+          mmol(igcm_ch2o)=30.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."ch3o") then
+          igcm_ch3o=iq
+          mmol(igcm_ch3o)=31.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c") then
+          igcm_c=iq
+          mmol(igcm_c)=12.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c2") then
+          igcm_c2=iq
+          mmol(igcm_c2)=24.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c2h") then
+          igcm_c2h=iq
+          mmol(igcm_c2h)=25.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c2h2") then
+          igcm_c2h2=iq
+          mmol(igcm_c2h2)=26.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c2h3") then
+          igcm_c2h3=iq
+          mmol(igcm_c2h3)=27.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c2h4") then
+          igcm_c2h4=iq
+          mmol(igcm_c2h4)=28.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."c2h6") then
+          igcm_c2h6=iq
+          mmol(igcm_c2h6)=30.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."ch2co") then
+          igcm_ch2co=iq
+          mmol(igcm_ch2co)=42.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."ch3co") then
+          igcm_ch3co=iq
+          mmol(igcm_ch3co)=43.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq).eq."hcaer") then
+          igcm_hcaer=iq
+          mmol(igcm_hcaer)=50.
+          count=count+1
+           nbqchem = nbqchem + 1
+        endif
+        if (noms(iq) == "ar") then
+           igcm_ar = iq
+           mmol(igcm_ar) = 40.
+           count = count + 1
+           nbqchem = nbqchem + 1
+        end if
+
+
+
+! 1.5 find idealized non-condensible tracer
+
+        if (noms(iq) == "Ar_N2") then
+           igcm_ar_n2 = iq
+           mmol(igcm_ar_n2) = 30.
+           count = count + 1
+        end if
+
+      end do ! of do iq=1,nq
+      
+! 1.6 check that we identified all tracers:
+
+      if (count /= nq) then
+         write(*,*) "inichim_newstart: found only ",count," tracers"
+         write(*,*) "                  expected ",nq
+         do iq = 1,count
+            write(*,*) '      ', iq, ' ', trim(noms(iq))
+         end do
+         stop
+      else
+         write(*,*) "inichim_newstart: found all expected tracers"
+         do iq = 1,nq
+            write(*,*) '      ', iq, ' ', trim(noms(iq))
+         end do
+      end if
+
+! 1.7 check if nitrogen species are present:
+
+      if(igcm_no == 0) then
+         !check that no N species is in traceur.def
+         if(igcm_n /= 0 .or. igcm_no2 /= 0 .or. igcm_n2d /= 0) then
+            write(*,*)'inichim_newstart error:'
+            write(*,*)'N, NO2 and/or N2D are in traceur.def, but not NO'
+            write(*,*)'stop'
+            stop
+         endif
+         flagnitro = .false.
+         nspe = 14
+      else
+         !check that all N species are in traceur.def
+         if(igcm_n == 0 .or. igcm_no2 == 0 .or. igcm_n2d == 0) then
+            write(*,*)'inichim_newstart error:'
+            write(*,*)'if NO is in traceur.def, N, NO2 and N2D must also be'
+            write(*,*)'stop'
+            stop
+         endif
+         flagnitro = .true.
+         nspe = 35
+      endif
+
+! 1.8 allocate arrays
+
+      allocate(niq(nspe))
+      allocate(vmrinit(nalt,nspe))
+      allocate(vmrint(nspe))
+
+! 2. load in chemistry data for initialization:
+
+! order of major species in initialization file:
+!
+!    1: co2 
+!    2: ar
+!    3: n2  
+!    4: o2  
+!    5: co  
+!    6: o   
+!    7: h2
+!
+! order of minor species in initialization file:
+!
+!    1: h  
+!    2: oh 
+!    3: ho2 
+!    4: h2o 
+!    5: h2o2 
+!    6: o1d
+!    7: o3
+!
+! order of nitrogen species in initialization file:
+!
+!    1: n
+!    2: no
+!    3: no2
+!    4: n2d
+
+! major species:
+
+      niq(1) = igcm_co2
+!      niq(2) = igcm_ar
+      niq(2) = igcm_n2
+      niq(3) = igcm_o2
+      niq(4) = igcm_co
+      niq(5) = igcm_o
+      niq(6) = igcm_h2
+
+! minor species:
+
+      niq(7)  = igcm_h
+      niq(8)  = igcm_oh
+      niq(9) = igcm_ho2
+      niq(10) = igcm_h2o_vap
+      niq(11) = igcm_h2o2
+      niq(12) = igcm_o1d 
+      niq(13) = igcm_o3
+
+! nitrogen species:
+
+      if (flagnitro) then
+         niq(14) = igcm_n
+         niq(15) = igcm_no
+         niq(16) = igcm_no2
+         niq(17) = igcm_n2d         
+      end if
+
+
+
+
+! carbon species:
+      niq(18) = igcm_ch4
+      niq(19) = igcm_ch3
+      niq(20) = igcm_ch
+      niq(21) = igcm_1ch2
+      niq(22) = igcm_3ch2
+      niq(23) = igcm_cho
+      niq(24) = igcm_ch2o
+      niq(25) = igcm_ch3o
+      niq(26) = igcm_c
+      niq(27) = igcm_c2
+      niq(28) = igcm_c2h
+      niq(29) = igcm_c2h2
+      niq(30) = igcm_c2h3
+      niq(31) = igcm_c2h4
+      niq(32) = igcm_c2h6
+      niq(33) = igcm_ch2co
+      niq(34) = igcm_ch3co
+      niq(35) = igcm_hcaer
+
+
+! 2.1 open initialization files
+      open(210, iostat=ierr,file=trim(datadir)//'/atmosfera_LMD_may.dat')
+      if (ierr /= 0) then
+         write(*,*)'Error : cannot open file atmosfera_LMD_may.dat '
+         write(*,*)'(in aeronomars/inichim_newstart.F)'
+         write(*,*)'It should be in :', trim(datadir),'/'
+         write(*,*)'1) You can change this path in callphys.def with'
+         write(*,*)'   datadir=/path/to/datafiles/'
+         write(*,*)'2) If necessary atmosfera_LMD_may.dat (and others)'
+         write(*,*)'   can be obtained online on:'
+         write(*,*)' http://www.lmd.jussieu.fr/~lmdz/planets/mars/datadir'
+         stop
+      end if
+      open(220, iostat=ierr,file=trim(datadir)//'/atmosfera_LMD_min.dat')
+      if (ierr /= 0) then
+         write(*,*)'Error : cannot open file atmosfera_LMD_min.dat '
+         write(*,*)'(in aeronomars/inichim_newstart.F)'
+         write(*,*)'It should be in :', trim(datadir),'/'
+         write(*,*)'1) You can change this path in callphys.def with'
+         write(*,*)'   datadir=/path/to/datafiles/'
+         write(*,*)'2) If necessary atmosfera_LMD_min.dat (and others)'
+         write(*,*)'   can be obtained online on:'
+         write(*,*)' http://www.lmd.jussieu.fr/~lmdz/planets/mars/datadir'
+         stop
+      end if
+      if(flagnitro) then
+         open(230, iostat=ierr,file=trim(datadir)//'/atmosfera_LMD_nitr.dat')
+         if (ierr.ne.0) then
+            write(*,*)'Error : cannot open file atmosfera_LMD_nitr.dat '
+            write(*,*)'(in aeronomars/inichim_newstart.F)'
+            write(*,*)'It should be in :', datadir
+            write(*,*)'1) You can change this directory address in '
+            write(*,*)'   file phymars/datafile.h'
+            write(*,*)'2) If necessary atmosfera_LMD_nitr.dat (and others)'
+            write(*,*)'   can be obtained online on:'
+            write(*,*)' http://www.lmd.jussieu.fr/~lmdz/planets/mars/datadir'
+            STOP
+         endif
+      endif   ! Of if(flagnitro)
+
+! 2.2 read initialization files
+
+! major species
+
+      read(210,*)
+      do l = 1,nalt
+         read(210,*) dummy, tinit(l), pinit(l), densinit(l), &
+                     (vmrinit(l,n), n = 1,7)
+         pinit(l) = pinit(l)*100.              ! conversion in Pa
+         pinit(l) = log(pinit(l))              ! for the vertical interpolation
+      end do
+      close(210)
+
+! minor species
+
+      read(220,*)
+      do l = 1,nalt
+         read(220,*) dummy, (vmrinit(l,n), n = 8,14)
+      end do 
+      close(220)
+
+! nitrogen species
+
+      if (flagnitro) then
+         read(230,*)
+         do l = 1,nalt
+            read(230,*) dummy, (vmrinit(l,n), n = 15,18)
+         end do
+         close(230)
+      end if
+
+
+      if (1.eq.1) then
+        do l = 1,nalt
+         vmrinit(l,:)=0.0
+         vmrinit(l,1)=0.01 !co2
+         vmrinit(l,2)=0.989 !n2
+!         vmrinit(l,3)=2.e-17/mmol(niq(3))*28 !o2
+!         vmrinit(l,4)=3.8e-6/mmol(niq(4))*28  !co
+!         vmrinit(l,5)=4.e-14/mmol(niq(5))*28  !o
+!         vmrinit(l,6)=1.3e-7/mmol(niq(6))*28  !h2
+         vmrinit(l,6)=1e-3
+!         vmrinit(l,7)=5.e-16/mmol(niq(7))*28 !h
+!         vmrinit(l,8)=2.e-17/mmol(niq(8))*28 !oh
+!         vmrinit(l,9)=1.e-17/mmol(niq(9))*28 !ho2
+         vmrinit(l,10)=1e-6 !h2o
+!         vmrinit(l,11)=2.e-20/mmol(niq(11))*28 !h2o2
+!         vmrinit(l,12)=0. !o1d
+!         vmrinit(l,13)=3.e-22/mmol(niq(13))*28 !o3
+
+
+         vmrinit(l,18)=1.0e-3 !ch4
+!         vmrinit(l,19)=1.3e-12/mmol(niq(19))*28 !ch3
+!         vmrinit(l,23)=1.e-12/mmol(niq(23))*28 !cho
+!         vmrinit(l,24)=2.7e-11/mmol(niq(24))*28 !ch2o
+!         vmrinit(l,25)=2.e-9/mmol(niq(25))*28 !ch3o
+!         vmrinit(l,32)=2.e-7/mmol(niq(32))*28 !c2h6
+!         vmrinit(l,33)=5.e-12/mmol(niq(33))*28 !ch2co
+!         vmrinit(l,34)=1.e-13/mmol(niq(34))*28 !ch3co
+
+
+
+!         pinit(l)=aps(l) + bps(l)*ps
+!         vmrinit(l,18)=2e-3*min(pinit(l)/100.,1.) ! decrease with scale
+!         height above 1 hpa
+         vmrinit(l,2)=0.0
+         vmrinit(l,2)=1-sum(vmrinit(l,:)) !n2
+!         vmrinit(l,4)=0.1
+!         vmrinit(l,7)=0.001
+        end do
+      endif
+
+      
+! 3. initialization of tracers
+
+      do i = 1,nbp_lon+1
+         do j = 1,nbp_lat
+            do l = 1,nbp_lev
+
+               pgcm = aps(l) + bps(l)*ps(i,j)  ! gcm pressure
+               pgcm = log(pgcm)                ! for the vertical interpolation
+               mmean(i,j,l) = 0.
+
+! 3.1 vertical interpolation
+
+               do n = 1,nspe
+                  call intrplf(pgcm,vmr,pinit,vmrinit(:,n),nalt)
+                  vmrint(n) = vmr
+!                  vmrint(n) = vmrinit(l,n)
+                  iq = niq(n)
+                  mmean(i,j,l) = mmean(i,j,l) + vmrint(n)*mmol(iq)
+               end do
+
+! 3.2 attribute mixing ratio: - all layers or only thermosphere
+!                             - with our without h2o 
+
+
+
+               if (flagthermo == 0 .or. (flagthermo == 1 .and. exp(pgcm) < 0.1)) then
+                  do n = 1,nspe
+                     iq = niq(n)
+                     if (iq /= igcm_h2o_vap .or. flagh2o == 1) then
+                        pq(i,j,l,iq) = vmrint(n)*mmol(iq)/mmean(i,j,l)
+                     end if
+                  end do
+               end if
+
+            end do
+         end do
+      end do
+
+! set surface values of chemistry tracers to zero
+
+
+      if (flagthermo == 0) then
+         ! NB: no problem for "surface water vapour" tracer which is always 0
+         do n = 1,nspe
+            iq = niq(n)
+            qsurf(1:ngrid,iq) = 0.
+         end do
+      end if
+
+! 3.3 initialization of tracers not contained in the initialization files
+
+! methane : 10 ppbv
+
+!      if (igcm_ch4 /= 0) then
+!         vmr = 10.e-9       
+!         do i = 1,nbp_lon+1
+!            do j = 1,nbp_lat
+!               do l = 1,nbp_lev
+!                  pq(i,j,l,igcm_ch4) = vmr*mmol(igcm_ch4)/mmean(i,j,l)
+!               end do
+!            end do
+!         end do
+!         ! set surface value to zero
+!         qsurf(1:ngrid,igcm_ch4) = 0.
+!      end if
+
+! ions: 0
+
+      
+      ! deallocations
+
+      deallocate(niq)
+      deallocate(vmrinit)
+      deallocate(vmrint)
+
+      end
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/intrplf.F
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/intrplf.F	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/intrplf.F	(revision 1796)
@@ -0,0 +1,42 @@
+c******************************************************
+      SUBROUTINE intrplf(x,y,xd,yd,nd)
+c interpolation, give y = f(x) with array xd,yd known, size nd
+ 
+c  Version with CONSTANT values outside limits
+c**********************************************************
+ 
+c Variable declaration
+c --------------------
+c  Arguments :
+      real x,y
+      real xd(nd),yd(nd)
+      integer nd
+c  internal
+      integer i,j
+      real y_undefined
+ 
+c run
+c ---
+      y_undefined=1.e20
+ 
+      y=0.
+      if ((x.le.xd(1)).and.(x.le.xd(nd))) then
+        if (xd(1).lt.xd(nd)) y = yd(1) ! yd(1)
+        if (xd(1).ge.xd(nd)) y = yd(nd) ! yd(1)
+      else if ((x.ge.xd(1)).and.(x.ge.xd(nd))) then
+        if (xd(1).lt.xd(nd)) y = yd(nd) ! yd(1)
+        if (xd(1).ge.xd(nd)) y = yd(1) ! yd(1)
+c        y = yd (nd)
+      else
+        do i=1,nd-1
+         if ( ( (x.ge.xd(i)).and.(x.lt.xd(i+1)) )
+     &     .or. ( (x.le.xd(i)).and.(x.gt.xd(i+1)) ) ) then
+           y=yd(i)+(x-xd(i))*(yd(i+1)-yd(i))/(xd(i+1)-xd(i))
+           goto 99
+         end if
+        end do
+      end if
+ 
+ 99   continue
+      return
+      end                    
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/inv.F
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/inv.F	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/inv.F	(revision 1796)
@@ -0,0 +1,121 @@
+      SUBROUTINE inv(A,N)
+
+      implicit none
+
+c=======================================================================
+c   Scheme A
+c
+c   subject:
+c   --------
+c
+c   Inversion of a matrix:
+c   Combinaison des routines ludcmp.f et lubksb.f du Numerical Recipes
+c=======================================================================
+
+      real       TINY
+      PARAMETER (TINY=1.0E-20)
+      real       AAMAX,DUM,SUM
+      integer    IMAX,I,II,J,K,L,LL,N
+      real       A(N,N),INDX(N),VV(N,N)
+
+      IMAX = 0
+      do I=1,N
+          AAMAX=0.
+          do J=1,N
+            IF (ABS(A(I,J)).GT.AAMAX) AAMAX=ABS(A(I,J))
+          enddo
+          if (AAMAX.EQ.0.) then
+              write(*,*) 'Singular matrix.'
+              stop
+          endif
+          VV(I,1)=1./AAMAX
+      enddo
+      do J=1,N
+        IF (J.GT.1) THEN
+          do I=1,J-1
+            SUM=A(I,J)
+            IF (I.GT.1)THEN
+              do K=1,I-1
+                SUM=SUM-A(I,K)*A(K,J)
+              enddo
+              A(I,J)=SUM
+            ENDIF
+          enddo
+        ENDIF
+        AAMAX=0.
+        do I=J,N
+          SUM=A(I,J)
+          IF (J.GT.1)THEN
+            do K=1,J-1
+              SUM=SUM-A(I,K)*A(K,J)
+            enddo
+            A(I,J)=SUM
+          ENDIF
+          DUM=VV(I,1)*ABS(SUM)
+          IF (DUM.GE.AAMAX) THEN
+            IMAX=I
+            AAMAX=DUM
+          ENDIF
+        enddo
+        IF (J.NE.IMAX)THEN
+          do K=1,N
+            DUM=A(IMAX,K)
+            A(IMAX,K)=A(J,K)
+            A(J,K)=DUM
+          enddo
+          VV(IMAX,1)=VV(J,1)
+        ENDIF
+        INDX(J)=IMAX
+        if(abs(A(J,J)).LT.TINY) then
+              write(*,*) 'Pivot too small.'
+              stop
+        endif
+        IF(J.NE.N)THEN
+          DUM=1./A(J,J)
+          do I=J+1,N
+            A(I,J)=A(I,J)*DUM
+          enddo
+        ENDIF
+      enddo
+
+      do I=1,N
+         do J=1,N
+            VV(I,J) = 0.
+         enddo
+         VV(I,I) = 1.
+      enddo
+
+      do L=1,N
+        II=0
+        do I=1,N
+          LL=INDX(I)
+          SUM=VV(LL,L)
+          VV(LL,L)=VV(I,L)
+          IF (II.NE.0)THEN
+            do J=II,I-1
+              SUM=SUM-A(I,J)*VV(J,L)
+            enddo
+          ELSE IF (SUM.NE.0.) THEN
+            II=I
+          ENDIF
+          VV(I,L)=SUM
+        enddo
+        do I=N,1,-1
+          SUM=VV(I,L)
+          IF(I.LT.N)THEN
+            do J=I+1,N
+              SUM=SUM-A(I,J)*VV(J,L)
+            enddo
+          ENDIF
+          VV(I,L)=SUM/A(I,I)
+        enddo
+      enddo
+
+      do I=1,N
+        do L=1,N
+          A(I,L)=VV(I,L)
+        enddo
+      enddo
+
+      return
+      END
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/photochemistry_asis.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/photochemistry_asis.F90	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/photochemistry_asis.F90	(revision 1796)
@@ -0,0 +1,1867 @@
+!*****************************************************************
+!
+!     Photochemical routine 
+!
+!     Author: Franck Lefevre
+!     ------
+!
+!     Version: 10/11/2015
+!
+!*****************************************************************
+
+subroutine photochemistry_asis(nlayer, nq, ngrid,                               &
+                          ig, lswitch, zycol, sza, fractcol, ptimestep, press,  &
+                          temp, dens, zmmean, dist_sol, surfdust1d,             &
+                          surfice1d, jo3, tau, iter)
+
+      use callkeys_mod
+implicit none
+
+#include "chimiedata.h" 
+
+!===================================================================
+!     inputs:
+!===================================================================
+
+integer, intent(in) :: nlayer ! number of atmospheric layers
+integer, intent(in) :: nq     ! number of tracers
+integer,intent(in) :: ngrid   ! number of atmospheric columns
+integer :: ig                 ! grid point index
+      
+real :: sza                   ! solar zenith angle (deg)
+real :: fractcol              ! day fraction
+real :: ptimestep             ! physics timestep (s)
+real :: press(nlayer)         ! pressure (hpa)
+real :: temp(nlayer)          ! temperature (k)
+real :: dens(nlayer)          ! density (cm-3)
+real :: zmmean(nlayer)        ! mean molar mass (g/mole)
+real :: dist_sol              ! sun distance (au) 
+real :: surfdust1d(nlayer)    ! dust surface area (cm2/cm3)
+real :: surfice1d(nlayer)     ! ice surface area (cm2/cm3)
+real :: tau                   ! optical depth at 7 hpa
+
+!===================================================================
+!     input/output:
+!===================================================================
+      
+real :: zycol(nlayer,nq)       ! chemical species volume mixing ratio
+
+!===================================================================
+!     output:
+!===================================================================
+      
+integer :: iter(nlayer)        ! iteration counter
+real    :: jo3(nlayer)         ! photodissociation rate o3 -> o1d
+
+!===================================================================
+!     local:
+!===================================================================
+
+integer :: phychemrat         ! (physical timestep)/(nominal chemical timestep)
+integer :: j_o3_o1d, ilev
+integer :: iesp, nesp
+integer :: lswitch
+
+logical, save :: firstcall = .true.
+
+parameter (nesp = 17)         ! number of species in the chemistry
+
+! tracer indexes in the chemistry:
+
+integer,parameter :: i_co2  =  1
+integer,parameter :: i_co   =  2
+integer,parameter :: i_o    =  3
+integer,parameter :: i_o1d  =  4
+integer,parameter :: i_o2   =  5
+integer,parameter :: i_o3   =  6
+integer,parameter :: i_h    =  7
+integer,parameter :: i_h2   =  8
+integer,parameter :: i_oh   =  9
+integer,parameter :: i_ho2  = 10
+integer,parameter :: i_h2o2 = 11
+integer,parameter :: i_h2o  = 12
+integer,parameter :: i_n    = 13
+integer,parameter :: i_n2d  = 14
+integer,parameter :: i_no   = 15
+integer,parameter :: i_no2  = 16
+integer,parameter :: i_n2   = 17
+
+real :: stimestep           ! standard timestep for the chemistry (s) 
+real :: ctimestep           ! real timestep for the chemistry (s) 
+real :: dt_guess            ! first-guess timestep (s) 
+real :: dt_corrected        ! corrected timestep (s) 
+real :: dt_min = 1.         ! minimum allowed timestep (s) 
+real :: dtg                 ! correction factor for the timestep (s) 
+real :: j(nlayer,nd)        ! interpolated photolysis rates (s-1)
+real :: time                ! internal time (between 0 and ptimestep, in s)
+
+real, dimension(nlayer,nesp)            :: rm   ! mixing ratios 
+real (kind = 8), dimension(nesp)        :: cold ! number densities at previous timestep (molecule.cm-3) 
+real (kind = 8), dimension(nlayer,nesp) :: c    ! number densities at current timestep (molecule.cm-3) 
+real (kind = 8), dimension(nesp)        :: cnew ! number densities at next timestep (molecule.cm-3) 
+ 
+! reaction rates
+ 
+real (kind = 8), dimension(nlayer,      nb_phot_max) :: v_phot
+real (kind = 8), dimension(nlayer,nb_reaction_3_max) :: v_3
+real (kind = 8), dimension(nlayer,nb_reaction_4_max) :: v_4
+logical :: hetero_dust, hetero_ice
+
+! matrix
+
+real (kind = 8), dimension(nesp,nesp) :: mat, mat1
+integer, dimension(nesp)              :: indx
+integer                               :: code
+
+! production and loss terms (for first-guess solution only)
+
+real (kind = 8), dimension(nesp) :: prod, loss
+
+! curvatures
+
+real :: ratio, curv, e, e1, e2, e3
+
+!===================================================================
+!     initialisation of the reaction indexes
+!===================================================================
+
+if (firstcall) then
+   print*,'photochemistry: initialize indexes'
+   call indice(i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,       &
+               i_h2, i_oh, i_ho2, i_h2o2, i_h2o,               &
+               i_n, i_n2d, i_no, i_no2, i_n2)
+   firstcall = .false.
+end if
+
+!===================================================================
+!     initialisation of mixing ratios and densities       
+!===================================================================
+
+call gcmtochim(nlayer, nq, zycol, lswitch, nesp,               &
+               i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,       &
+               i_h2, i_oh, i_ho2, i_h2o2, i_h2o,               &
+               i_n, i_n2d, i_no, i_no2, i_n2, dens, rm, c) 
+
+!===================================================================
+!     interpolation of photolysis rates in the lookup table      
+!===================================================================
+
+call photolysis_asis(nlayer, ngrid, lswitch, press, temp, sza, fractcol, tau, zmmean, dist_sol, & 
+                     rm(:,i_co2), rm(:,i_o3), v_phot)
+
+! save o3 photolysis for output
+
+j_o3_o1d = 5
+jo3(:) = v_phot(:,j_o3_o1d)
+
+!===================================================================
+!     reaction rates                                     
+!===================================================================
+!     switches for heterogeneous chemistry
+!     hetero_ice  : reactions on ice clouds
+!     hetero_dust : reactions on dust    
+!===================================================================
+
+hetero_dust = .false.
+hetero_ice  = .false.
+
+call reactionrates(nlayer, lswitch, dens, c(:,i_co2), c(:,i_o2), &
+                   press, temp, hetero_dust, hetero_ice,         &
+                   surfdust1d, surfice1d, v_phot, v_3, v_4)
+
+!===================================================================
+!     stimestep : standard chemical timestep (s)                           
+!     ctimestep : real chemical timestep (s),
+!                 taking into account the physical timestep                           
+!===================================================================
+
+stimestep = 600. ! standard value : 10 mn
+
+phychemrat = nint(ptimestep/stimestep)
+phychemrat = 1
+
+ctimestep = ptimestep/real(phychemrat)
+
+!print*, "stimestep  = ", stimestep
+!print*, "ptimestep  = ", ptimestep
+!print*, "phychemrat = ", phychemrat
+!print*, "ctimestep  = ", ctimestep
+!stop
+
+!===================================================================
+!     loop over levels         
+!===================================================================
+
+do ilev = 1,lswitch - 1
+
+!  initializations
+
+   time = 0.
+   iter(ilev) = 0
+   dt_guess = ctimestep
+   cold(:) = c(ilev,:)
+
+!  internal loop for the chemistry
+
+   do while (time < ptimestep)
+
+   iter(ilev) = iter(ilev) + 1    ! iteration counter
+
+!  first-guess: fill matrix
+
+   call fill_matrix(ilev, mat1, prod, loss, c, nesp, nlayer, v_phot, v_3, v_4)
+
+!  adaptative evaluation of the sub time step
+
+   call define_dt(nesp, dt_corrected, dt_guess, ctimestep, cold(:), c(ilev,:),  &
+                  mat1, prod, loss, dens(ilev))
+
+   if (time + dt_corrected > ptimestep) then
+      dt_corrected = ptimestep - time
+   end if
+
+!  if (dt_corrected /= dt_guess) then  ! the timestep has been modified
+
+!  form the matrix identity + mat*dt_corrected
+
+   mat(:,:) = mat1(:,:)*dt_corrected
+   do iesp = 1,nesp
+      mat(iesp,iesp) = 1. + mat(iesp,iesp)
+   end do
+
+!  solve the linear system  M*Cn+1 = Cn (RHS in cnew, then replaced by solution)
+
+   cnew(:) = c(ilev,:)
+
+#ifdef LAPACK
+   call dgesv(nesp,1,mat,nesp,indx,cnew,nesp,code)
+#else
+#   write(*,*) "photochemistry_asis error, missing LAPACK routine dgesv"
+#   stop
+#endif
+
+!  end if
+
+!  eliminate small values
+
+   where (cnew(:)/dens(ilev) < 1.e-30)
+      cnew(:) = 0.
+   end where
+
+!  update concentrations
+
+   cold(:)   = c(ilev,:)
+   c(ilev,:) = cnew(:)
+   cnew(:)   = 0.
+
+!  increment internal time
+
+   time = time + dt_corrected
+   dt_guess = dt_corrected     ! first-guess timestep for next iteration
+
+   end do ! while (time < ptimestep)
+
+end do ! ilev
+
+!===================================================================
+!     save chemical species for the gcm       
+!===================================================================
+
+call chimtogcm(nlayer, nq, zycol, lswitch, nesp,              &
+               i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,      &
+               i_h2, i_oh, i_ho2, i_h2o2, i_h2o,              &
+               i_n, i_n2d, i_no, i_no2, i_n2, dens, c) 
+
+contains
+
+!================================================================
+
+ subroutine define_dt(nesp, dtnew, dtold, ctimestep, cold, ccur, mat1, &
+                      prod, loss, dens)
+
+!================================================================
+! iterative evaluation of the appropriate time step dtnew
+! according to curvature criterion based on
+! e = 2 Rtol [r Cn+1 -(1-r) Cn + Cn-1 ]/[(1+r) Cn]
+! with r = (tn - tn-1)/(tn+1 - tn)
+!================================================================
+
+implicit none
+
+! input
+
+integer :: nesp  ! number of species in the chemistry
+
+real :: dtold, ctimestep
+real (kind = 8), dimension(nesp)      :: cold, ccur
+real (kind = 8), dimension(nesp,nesp) :: mat1
+real (kind = 8), dimension(nesp)      :: prod, loss
+real                                  :: dens
+
+! output
+
+real :: dtnew
+
+! local
+
+real (kind = 8), dimension(nesp)      :: cnew
+real (kind = 8), dimension(nesp,nesp) :: mat
+real (kind = 8) :: atol, ratio, e, es, coef
+
+integer                  :: code, iesp, iter
+integer, dimension(nesp) :: indx
+
+real :: dttest
+
+! parameters
+
+real (kind = 8), parameter :: dtmin   = 10.      ! minimum time step (s)
+real (kind = 8), parameter :: vmrtol  = 1.e-11   ! absolute tolerance on vmr
+real (kind = 8), parameter :: rtol    = 1./0.05   ! 1/rtol recommended value : 0.1-0.02
+integer,         parameter :: niter   = 3        ! number of iterations
+real (kind = 8), parameter :: coefmax = 2.
+real (kind = 8), parameter :: coefmin = 0.1
+logical                    :: fast_guess = .true.
+
+dttest = dtold   ! dttest = dtold = dt_guess
+
+atol = vmrtol*dens ! absolute tolerance in molecule.cm-3
+
+do iter = 1,niter
+
+if (fast_guess) then
+
+! first guess : fast semi-implicit method
+
+   do iesp = 1, nesp
+      cnew(iesp) = (ccur(iesp) + prod(iesp)*dttest)/(1. + loss(iesp)*dttest)
+   end do
+
+else
+
+! first guess : form the matrix identity + mat*dt_guess
+
+   mat(:,:) = mat1(:,:)*dttest
+   do iesp = 1,nesp
+      mat(iesp,iesp) = 1. + mat(iesp,iesp)
+   end do
+
+! form right-hand side (RHS) of the system
+
+   cnew(:) = ccur(:)
+
+! solve the linear system  M*Cn+1 = Cn (RHS in cnew, then replaced by solution)
+
+#ifdef LAPACK
+      call dgesv(nesp,1,mat,nesp,indx,cnew,nesp,code)
+#else
+   write(*,*) "photochemistry_asis error, missing LAPACK routine dgesv"
+   stop
+#endif
+
+end if
+
+! ratio old/new subtimestep
+
+ratio = dtold/dttest
+
+! e : local error indicatocitr
+
+e = 0.
+
+do iesp = 1,nesp
+   es = 2.*abs((ratio*cnew(iesp) - (1. + ratio)*ccur(iesp) + cold(iesp))   &
+         /(1. + ratio)/max(ccur(iesp),atol))
+
+   if (es > e) then
+      e = es
+   end if
+end do
+e = rtol*e
+
+! timestep correction
+
+coef = max(coefmin, min(coefmax,0.8/sqrt(e)))
+
+dttest = max(dtmin,dttest*coef)
+dttest = min(ctimestep,dttest)
+
+end do ! iter
+
+! new timestep
+
+dtnew = dttest
+
+end subroutine define_dt
+
+
+
+
+!======================================================================
+
+ subroutine reactionrates(nlayer,                               &
+                          lswitch, dens, co2, o2, press, t,     &
+                          hetero_dust, hetero_ice,              &
+                          surfdust1d, surfice1d,                &
+                          v_phot, v_3, v_4)
+ 
+!================================================================
+! compute reaction rates                                        !
+!----------------------------------------------------------------
+! reaction               type                array              !
+!----------------------------------------------------------------
+! A + B    --> C + D     bimolecular         v_4                !
+! A + A    --> B + C     quadratic           v_3                !
+! A + C    --> B + C     quenching           v_phot             !
+! A + ice  --> B + C     heterogeneous       v_phot             !
+!================================================================
+
+use comcstfi_mod
+
+implicit none
+
+#include "chimiedata.h"
+
+!----------------------------------------------------------------------
+!     input
+!----------------------------------------------------------------------
+
+integer, intent(in)     :: nlayer            ! number of atmospheric layers
+integer                 :: lswitch           ! interface level between lower
+                                             ! atmosphere and thermosphere chemistries
+real, dimension(nlayer) :: dens              ! total number density (molecule.cm-3)
+real, dimension(nlayer) :: press             ! pressure (hPa)
+real, dimension(nlayer) :: t                 ! temperature (K)
+real, dimension(nlayer) :: surfdust1d        ! dust surface area (cm2.cm-3)
+real, dimension(nlayer) :: surfice1d         ! ice surface area (cm2.cm-3)
+real (kind = 8), dimension(nlayer) :: co2    ! co2 number density (molecule.cm-3)
+real (kind = 8), dimension(nlayer) :: o2     ! o2 number density (molecule.cm-3)
+logical :: hetero_dust, hetero_ice           ! switches for heterogeneous chemistry
+
+!----------------------------------------------------------------------
+!     output
+!----------------------------------------------------------------------
+
+real (kind = 8), dimension(nlayer,      nb_phot_max) :: v_phot
+real (kind = 8), dimension(nlayer,nb_reaction_3_max) :: v_3
+real (kind = 8), dimension(nlayer,nb_reaction_4_max) :: v_4
+
+!----------------------------------------------------------------------
+!     local
+!----------------------------------------------------------------------
+
+integer          :: ilev
+integer          :: nb_phot, nb_reaction_3, nb_reaction_4
+real :: ak0, ak1, xpo, rate
+real :: k1a0, k1b0, k1ainf, k1a, k1b, fc, fx, x, y, gam
+real, dimension(nlayer) :: deq
+real, dimension(nlayer) :: a001, a002, a003,                           &
+                             b001, b002, b003, b004, b005, b006, b007,   &
+                             b008, b009,                                 &
+                             c001, c002, c003, c004, c005, c006, c007,   &
+                             c008, c009, c010, c011, c012, c013, c014,   &
+                             c015, c016, c017, c018,                     &
+                             d001, d002, d003, d004, d005, d006, d007,   &
+                             d008, d009,                                 &
+                             e001, e002,                                 &
+                             h001, h002, h003, h004, h005
+
+!----------------------------------------------------------------------
+!     initialisation
+!----------------------------------------------------------------------
+
+      nb_phot       = 11       ! jmars.20140930 reduit de 13 a 11
+      nb_reaction_3 = 0
+      nb_reaction_4 = 0
+
+!----------------------------------------------------------------------
+!     oxygen reactions 
+!----------------------------------------------------------------------
+
+!---  a001: o + o2 + co2 -> o3 + co2
+
+!     jpl 2003
+!
+!     co2 efficiency as a third body (2.075)
+!     from sehested et al., j. geophys. res., 100, 1995.
+
+      a001(:) = 2.075*6.0e-34*(t(:)/300.)**(-2.4)*dens(:)
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = a001(:)
+
+!---  a002: o + o + co2 -> o2 + co2
+
+!     Tsang and Hampson, J. Chem. Phys. Ref. Data, 15, 1087, 1986
+
+!     a002(:) = 2.5*5.2e-35*exp(900./t(:))*dens(:)
+
+!     Campbell and Gray, Chem. Phys. Lett., 18, 607, 1973
+
+!     a002(:) = 1.2e-32*(300./t(:))**(2.0)*dens(:)  ! yung expression
+      a002(:) = 2.5*9.46e-34*exp(485./t(:))*dens(:) ! nist expression
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = a002(:)
+
+!---  a003: o + o3 -> o2 + o2
+
+!     jpl 2003
+
+      a003(:) = 8.0e-12*exp(-2060./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = a003(:)
+
+!----------------------------------------------------------------------
+!     o(1d) reactions
+!----------------------------------------------------------------------
+
+!---  b001: o(1d) + co2  -> o + co2
+
+!     jpl 2006
+
+      b001(:) = 7.5e-11*exp(115./t(:))
+   
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = b001(:)*co2(:)
+
+!---  b002: o(1d) + h2o  -> oh + oh
+
+!     jpl 2006
+ 
+      b002(:) = 1.63e-10*exp(60./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = b002(:)
+
+!---  b003: o(1d) + h2  -> oh + h
+
+!     jpl 2011
+
+      b003(:) = 1.2e-10
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = b003(:)
+
+!---  b004: o(1d) + o2  -> o + o2
+
+!     jpl 2006
+
+      b004(:) = 3.3e-11*exp(55./t(:))
+
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = b004(:)*o2(:)
+    
+!---  b005: o(1d) + o3  -> o2 + o2
+
+!     jpl 2003
+
+      b005(:) = 1.2e-10
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = b005(:)
+    
+!---  b006: o(1d) + o3  -> o2 + o + o
+
+!     jpl 2003
+
+      b006(:) = 1.2e-10
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = b006(:)
+    
+!---  b007: o(1d) + ch4 -> ch3 + oh
+
+!     jpl 2003
+
+      b007(:) = 1.5e-10*0.75
+
+!---  b008: o(1d) + ch4 -> ch3o + h
+
+!     jpl 2003
+
+      b008(:) = 1.5e-10*0.20
+!
+!---  b009: o(1d) + ch4 -> ch2o + h2
+
+!     jpl 2003
+
+      b009(:) = 1.5e-10*0.05
+
+!----------------------------------------------------------------------
+!     hydrogen reactions
+!----------------------------------------------------------------------
+
+!---  c001: o + ho2 -> oh + o2
+
+!     jpl 2003
+
+      c001(:) = 3.0e-11*exp(200./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c001(:)
+
+!---  c002: o + oh -> o2 + h
+
+!     jpl 2011
+
+      c002(:) = 1.8e-11*exp(180./t(:))
+
+!     robertson and smith, j. chem. phys. a 110, 6673, 2006
+
+!     c002(:) = 11.2e-11*t(:)**(-0.32)*exp(177./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c002(:)
+
+!---  c003: h + o3 -> oh + o2
+
+!     jpl 2003
+
+      c003(:) = 1.4e-10*exp(-470./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c003(:)
+
+!---  c004: h + ho2 -> oh + oh
+
+!     jpl 2006
+
+      c004(:) = 7.2e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c004(:)
+
+!---  c005: h + ho2 -> h2 + o2
+
+!     jpl 2006
+
+      c005(:) = 6.9e-12
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c005(:)
+
+!---  c006: h + ho2 -> h2o + o
+
+!     jpl 2006
+
+      c006(:) = 1.6e-12
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c006(:)
+
+!---  c007: oh + ho2 -> h2o + o2
+
+!     jpl 2003
+
+!     canty et al., grl, 2006 suggest to increase this rate
+!     by 20%. not done here.
+
+      c007(:) = 4.8e-11*exp(250./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c007(:)
+
+!---  c008: ho2 + ho2 -> h2o2 + o2
+
+!     jpl 2006
+
+!     c008(:) = 3.5e-13*exp(430./t(:))
+
+!     christensen et al., grl, 13, 2002
+
+      c008(:) = 1.5e-12*exp(19./t(:))
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = c008(:)
+
+!---  c009: oh + h2o2 -> h2o + ho2
+
+!     jpl 2006
+
+      c009(:) = 1.8e-12
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c009(:)
+
+!---  c010: oh + h2 -> h2o + h
+
+!     jpl 2006
+
+      c010(:) = 2.8e-12*exp(-1800./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c010(:)
+
+!---  c011: h + o2 + co2 -> ho2 + co2
+
+!     jpl 2011
+
+      do ilev = 1,lswitch-1
+         ak0 = 2.5*4.4e-32*(t(ilev)/300.)**(-1.3)
+         ak1 = 7.5e-11*(t(ilev)/300.)**(0.2)
+
+         rate = (ak0*dens(ilev))/(1. + ak0*dens(ilev)/ak1)
+         xpo = 1./(1. + alog10((ak0*dens(ilev))/ak1)**2)
+         c011(ilev) = rate*0.6**xpo
+      end do
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c011(:)
+
+!---  c012: o + h2o2 -> oh + ho2
+
+!     jpl 2003
+
+      c012(:) = 1.4e-12*exp(-2000./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c012(:)
+
+!---  c013: oh + oh -> h2o + o
+
+!     jpl 2006
+
+      c013(:) = 1.8e-12
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = c013(:)
+
+!---  c014: oh + o3 -> ho2 + o2
+
+!     jpl 2003
+
+      c014(:) = 1.7e-12*exp(-940./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c014(:)
+
+!---  c015: ho2 + o3 -> oh + o2 + o2
+
+!     jpl 2003
+
+      c015(:) = 1.0e-14*exp(-490./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = c015(:)
+
+!---  c016: ho2 + ho2 + co2 -> h2o2 + o2 + co2
+
+!     jpl 2011
+
+      c016(:) = 2.5*2.1e-33*exp(920./t(:))*dens(:)
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = c016(:)
+
+!---  c017: oh + oh + co2 -> h2o2 + co2
+
+!     jpl 2003
+
+      do ilev = 1,lswitch-1
+         ak0 = 2.5*6.9e-31*(t(ilev)/300.)**(-1.0)
+         ak1 = 2.6e-11*(t(ilev)/300.)**(0.0)
+
+         rate = (ak0*dens(ilev))/(1. + ak0*dens(ilev)/ak1)
+         xpo = 1./(1. + alog10((ak0*dens(ilev))/ak1)**2)
+         c017(ilev) = rate*0.6**xpo
+      end do
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = c017(:)
+
+!---  c018: h + h + co2 -> h2 + co2
+
+!     baulch et al., 2005
+
+      c018(:) = 2.5*1.8e-30*(t(:)**(-1.0))*dens(:)
+
+      nb_reaction_3 = nb_reaction_3 + 1
+      v_3(:,nb_reaction_3) = c018(:)
+
+!----------------------------------------------------------------------
+!     nitrogen reactions
+!----------------------------------------------------------------------
+
+!---  d001: no2 + o -> no + o2
+
+!     jpl 2006
+
+      d001(:) = 5.1e-12*exp(210./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d001(:)
+
+!---  d002: no + o3 -> no2 + o2
+
+!     jpl 2006
+
+      d002(:) = 3.0e-12*exp(-1500./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d002(:)
+
+!---  d003: no + ho2 -> no2 + oh
+
+!     jpl 2011
+
+      d003(:) = 3.3e-12*exp(270./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d003(:)
+
+!---  d004: n + no -> n2 + o
+
+!     jpl 2011
+
+      d004(:) = 2.1e-11*exp(100./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d004(:)
+
+!---  d005: n + o2 -> no + o
+
+!     jpl 2011
+
+      d005(:) = 1.5e-11*exp(-3600./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d005(:)
+
+!---  d006: no2 + h -> no + oh
+
+!     jpl 2011
+
+      d006(:) = 4.0e-10*exp(-340./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d006(:)
+
+!---  d007: n + o -> no
+ 
+      d007(:) = 2.8e-17*(300./t(:))**0.5
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d007(:)
+
+!---  d008: n + ho2 -> no + oh
+
+!     brune et al., j. chem. phys., 87, 1983 
+
+      d008(:) = 2.19e-11
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d008(:)
+
+!---  d009: n + oh -> no + h
+
+!     atkinson et al., j. phys. chem. ref. data, 18, 881, 1989 
+
+      d009(:) = 3.8e-11*exp(85./t(:))
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = d009(:)
+
+!----------------------------------------------------------------------
+!     carbon reactions
+!----------------------------------------------------------------------
+
+!---  e001: oh + co -> co2 + h
+
+!     jpl 2003
+
+!     e001(:) = 1.5e-13*(1 + 0.6*press(:)/1013.)
+
+!     mccabe et al., grl, 28, 3135, 2001
+
+!     e001(:) = 1.57e-13 + 3.54e-33*dens(:)
+
+!     jpl 2006
+
+!     ak0 = 1.5e-13*(t(:)/300.)**(0.6)
+!     ak1 = 2.1e-9*(t(:)/300.)**(6.1)
+!     rate1 = ak0/(1. + ak0/(ak1/dens(:)))
+!     xpo1 = 1./(1. + alog10(ak0/(ak1/dens(:)))**2)
+
+!     ak0 = 5.9e-33*(t(:)/300.)**(-1.4)
+!     ak1 = 1.1e-12*(t(:)/300.)**(1.3)
+!     rate2 = (ak0*dens(:))/(1. + ak0*dens(:)/ak1)
+!     xpo2 = 1./(1. + alog10((ak0*dens(:))/ak1)**2)
+
+!     e001(:) = rate1*0.6**xpo1 + rate2*0.6**xpo2
+
+!     joshi et al., 2006
+
+      do ilev = 1,lswitch-1
+         k1a0 = 1.34*2.5*dens(ilev)                                  &
+               *1/(1/(3.62e-26*t(ilev)**(-2.739)*exp(-20./t(ilev)))  &
+               + 1/(6.48e-33*t(ilev)**(0.14)*exp(-57./t(ilev))))     ! typo in paper corrected
+         k1b0 = 1.17e-19*t(ilev)**(2.053)*exp(139./t(ilev))          &
+              + 9.56e-12*t(ilev)**(-0.664)*exp(-167./t(ilev))
+         k1ainf = 1.52e-17*t(ilev)**(1.858)*exp(28.8/t(ilev))        &
+                + 4.78e-8*t(ilev)**(-1.851)*exp(-318./t(ilev))
+         x = k1a0/(k1ainf - k1b0)
+         y = k1b0/(k1ainf - k1b0)
+         fc = 0.628*exp(-1223./t(ilev)) + (1. - 0.628)*exp(-39./t(ilev))  &
+            + exp(-t(ilev)/255.)
+         fx = fc**(1./(1. + (alog(x))**2))                           ! typo in paper corrected
+         k1a = k1a0*((1. + y)/(1. + x))*fx
+         k1b = k1b0*(1./(1.+x))*fx
+
+         e001(ilev) = k1a + k1b
+      end do
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = e001(:)
+
+!---  e002: o + co + m -> co2 + m
+
+!     tsang and hampson, 1986.
+
+      e002(:) = 2.5*6.5e-33*exp(-2184./t(:))*dens(:)
+
+      nb_reaction_4 = nb_reaction_4 + 1
+      v_4(:,nb_reaction_4) = e002(:)
+
+!----------------------------------------------------------------------
+!     heterogeneous chemistry 
+!----------------------------------------------------------------------
+
+      if (hetero_ice) then
+
+!        k = (surface*v*gamma)/4 (s-1)
+!        v = 100*sqrt(8rt/(pi*m))  (cm s-1)
+ 
+!---     h001: ho2 + ice -> products
+ 
+!        cooper and abbatt, 1996: gamma = 0.025
+      
+         gam = 0.025
+         h001(:) = surfice1d(:)       &
+                   *100.*sqrt(8.*8.31*t(:)/(33.e-3*pi))*gam/4.
+ 
+!        h002: oh + ice -> products
+ 
+!        cooper and abbatt, 1996: gamma = 0.03
+ 
+         gam = 0.03
+         h002(:) = surfice1d(:)       &
+                   *100.*sqrt(8.*8.31*t(:)/(17.e-3*pi))*gam/4.
+
+!---     h003: h2o2 + ice -> products
+ 
+!        gamma = 0.    test value
+ 
+         gam = 0.
+         h003(:) = surfice1d(:)       &
+                   *100.*sqrt(8.*8.31*t(:)/(34.e-3*pi))*gam/4.
+      else
+         h001(:) = 0.
+         h002(:) = 0.
+         h003(:) = 0.
+      end if
+
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = h001(:)
+
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = h002(:)
+
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = h003(:)
+
+      if (hetero_dust) then
+ 
+!---     h004: ho2 + dust -> products
+ 
+!        jacob, 2000: gamma = 0.2
+!        see dereus et al., atm. chem. phys., 2005
+ 
+         gam = 0.2
+         h004(:) = surfdust1d(:)  &
+                   *100.*sqrt(8.*8.31*t(:)/(33.e-3*pi))*gam/4.
+ 
+!---     h005: h2o2 + dust -> products
+ 
+!        gamma = 5.e-4
+!        see dereus et al., atm. chem. phys., 2005
+ 
+         gam = 5.e-4
+         h005(:) = surfdust1d(:)  &
+                   *100.*sqrt(8.*8.31*t(:)/(34.e-3*pi))*gam/4.
+      else
+         h004(:) = 0.
+         h005(:) = 0.
+      end if
+ 
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = h004(:)
+
+      nb_phot = nb_phot + 1
+      v_phot(:,nb_phot) = h005(:)
+
+end subroutine reactionrates
+
+!======================================================================
+
+ subroutine fill_matrix(ilev, mat, prod, loss, c, nesp, nlayer, v_phot, v_3, v_4)
+
+!======================================================================
+! filling of the jacobian matrix
+!======================================================================
+
+use types_asis
+
+implicit none
+
+#include "chimiedata.h"
+
+! input
+
+integer             :: ilev    ! level index
+integer             :: nesp    ! number of species in the chemistry
+integer, intent(in) :: nlayer  ! number of atmospheric layers
+
+real (kind = 8), dimension(nlayer,nesp)              :: c    ! number densities
+real (kind = 8), dimension(nlayer,      nb_phot_max) :: v_phot
+real (kind = 8), dimension(nlayer,nb_reaction_3_max) :: v_3
+real (kind = 8), dimension(nlayer,nb_reaction_4_max) :: v_4
+
+! output
+
+real (kind = 8), dimension(nesp,nesp), intent(out) :: mat  ! matrix
+real (kind = 8), dimension(nesp), intent(out)      :: prod, loss
+
+! local
+
+integer :: iesp
+integer :: ind_phot_2,ind_phot_4,ind_phot_6
+integer :: ind_3_2,ind_3_4,ind_3_6
+integer :: ind_4_2,ind_4_4,ind_4_6,ind_4_8
+integer :: iphot,i3,i4
+
+real(kind = jprb) :: eps, eps_4  ! implicit/explicit coefficient
+
+! initialisations 
+
+mat(:,:) = 0.
+prod(:)  = 0.
+loss(:)  = 0.
+
+! photodissociations
+! or reactions a + c -> b + c
+! or reactions a + ice -> b + c
+
+do iphot = 1,nb_phot_max
+
+  ind_phot_2 = indice_phot(iphot)%z2
+  ind_phot_4 = indice_phot(iphot)%z4
+  ind_phot_6 = indice_phot(iphot)%z6
+
+  mat(ind_phot_2,ind_phot_2) = mat(ind_phot_2,ind_phot_2) + indice_phot(iphot)%z1*v_phot(ilev,iphot)
+  mat(ind_phot_4,ind_phot_2) = mat(ind_phot_4,ind_phot_2) - indice_phot(iphot)%z3*v_phot(ilev,iphot)
+  mat(ind_phot_6,ind_phot_2) = mat(ind_phot_6,ind_phot_2) - indice_phot(iphot)%z5*v_phot(ilev,iphot)
+
+  loss(ind_phot_2) = loss(ind_phot_2) + indice_phot(iphot)%z1*v_phot(ilev,iphot)
+  prod(ind_phot_4) = prod(ind_phot_4) + indice_phot(iphot)%z3*v_phot(ilev,iphot)*c(ilev,ind_phot_2)
+  prod(ind_phot_6) = prod(ind_phot_6) + indice_phot(iphot)%z5*v_phot(ilev,iphot)*c(ilev,ind_phot_2)
+
+end do
+
+! reactions a + a -> b + c 
+
+do i3 = 1,nb_reaction_3_max
+
+  ind_3_2 = indice_3(i3)%z2
+  ind_3_4 = indice_3(i3)%z4
+  ind_3_6 = indice_3(i3)%z6
+
+  mat(ind_3_2,ind_3_2) = mat(ind_3_2,ind_3_2) + indice_3(i3)%z1*v_3(ilev,i3)*c(ilev,ind_3_2)
+  mat(ind_3_4,ind_3_2) = mat(ind_3_4,ind_3_2) - indice_3(i3)%z3*v_3(ilev,i3)*c(ilev,ind_3_2)
+  mat(ind_3_6,ind_3_2) = mat(ind_3_6,ind_3_2) - indice_3(i3)%z5*v_3(ilev,i3)*c(ilev,ind_3_2)
+
+  loss(ind_3_2) = loss(ind_3_2) + indice_3(i3)%z1*v_3(ilev,i3)*c(ilev,ind_3_2)
+  prod(ind_3_4) = prod(ind_3_4) + indice_3(i3)%z3*v_3(ilev,i3)*c(ilev,ind_3_2)*c(ilev,ind_3_2)
+  prod(ind_3_6) = prod(ind_3_6) + indice_3(i3)%z5*v_3(ilev,i3)*c(ilev,ind_3_2)*c(ilev,ind_3_2)
+
+end do
+
+! reactions a + b -> c + d 
+
+eps = 1.d-10
+
+do i4 = 1,nb_reaction_4_max
+
+  ind_4_2 = indice_4(i4)%z2
+  ind_4_4 = indice_4(i4)%z4
+  ind_4_6 = indice_4(i4)%z6
+  ind_4_8 = indice_4(i4)%z8
+
+  eps_4 = abs(c(ilev,ind_4_2))/(abs(c(ilev,ind_4_2)) + abs(c(ilev,ind_4_4)) + eps)
+  eps_4 = min(eps_4,1.0_jprb)
+
+  mat(ind_4_2,ind_4_2) = mat(ind_4_2,ind_4_2) + indice_4(i4)%z1*v_4(ilev,i4)*(1. - eps_4)*c(ilev,ind_4_4) 
+  mat(ind_4_2,ind_4_4) = mat(ind_4_2,ind_4_4) + indice_4(i4)%z1*v_4(ilev,i4)*eps_4*c(ilev,ind_4_2)
+  mat(ind_4_4,ind_4_2) = mat(ind_4_4,ind_4_2) + indice_4(i4)%z3*v_4(ilev,i4)*(1. - eps_4)*c(ilev,ind_4_4)
+  mat(ind_4_4,ind_4_4) = mat(ind_4_4,ind_4_4) + indice_4(i4)%z3*v_4(ilev,i4)*eps_4*c(ilev,ind_4_2)   
+  mat(ind_4_6,ind_4_2) = mat(ind_4_6,ind_4_2) - indice_4(i4)%z5*v_4(ilev,i4)*(1. - eps_4)*c(ilev,ind_4_4)
+  mat(ind_4_6,ind_4_4) = mat(ind_4_6,ind_4_4) - indice_4(i4)%z5*v_4(ilev,i4)*eps_4*c(ilev,ind_4_2)
+  mat(ind_4_8,ind_4_2) = mat(ind_4_8,ind_4_2) - indice_4(i4)%z7*v_4(ilev,i4)*(1. - eps_4)*c(ilev,ind_4_4)
+  mat(ind_4_8,ind_4_4) = mat(ind_4_8,ind_4_4) - indice_4(i4)%z7*v_4(ilev,i4)*eps_4*c(ilev,ind_4_2)
+
+  loss(ind_4_2) = loss(ind_4_2) + indice_4(i4)%z1*v_4(ilev,i4)*c(ilev,ind_4_4)
+  loss(ind_4_4) = loss(ind_4_4) + indice_4(i4)%z3*v_4(ilev,i4)*c(ilev,ind_4_2)
+  prod(ind_4_6) = prod(ind_4_6) + indice_4(i4)%z5*v_4(ilev,i4)*c(ilev,ind_4_2)*c(ilev,ind_4_4)
+  prod(ind_4_8) = prod(ind_4_8) + indice_4(i4)%z7*v_4(ilev,i4)*c(ilev,ind_4_2)*c(ilev,ind_4_4)
+
+end do
+
+end subroutine fill_matrix
+
+!================================================================
+
+ subroutine indice(i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,       &
+                   i_h2, i_oh, i_ho2, i_h2o2, i_h2o,               &
+                   i_n, i_n2d, i_no, i_no2, i_n2)
+
+!================================================================
+! set the "indice" arrays used to fill the jacobian matrix      !
+!----------------------------------------------------------------
+! reaction                                   type               !
+!----------------------------------------------------------------
+! A + hv   --> B + C     photolysis          indice_phot        ! 
+! A + B    --> C + D     bimolecular         indice_4           !
+! A + A    --> B + C     quadratic           indice_3           !
+! A + C    --> B + C     quenching           indice_phot        !
+! A + ice  --> B + C     heterogeneous       indice_phot        !
+!================================================================
+
+use types_asis
+
+implicit none
+
+#include "chimiedata.h"
+
+! input
+
+integer :: i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,       &
+           i_h2, i_oh, i_ho2, i_h2o2, i_h2o,               &
+           i_n, i_n2d, i_no, i_no2, i_n2
+
+! local
+
+integer :: nb_phot, nb_reaction_3, nb_reaction_4
+integer :: i_dummy
+
+allocate (indice_phot(nb_phot_max))
+allocate (indice_3(nb_reaction_3_max))
+allocate (indice_4(nb_reaction_4_max))
+
+i_dummy = 1
+
+nb_phot       = 0
+nb_reaction_3 = 0
+nb_reaction_4 = 0
+
+!===========================================================
+!      O2 + hv -> O + O
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_o2, 2.0, i_o, 0.0, i_dummy) 
+
+!===========================================================
+!      O2 + hv -> O + O(1D)
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_o2, 1.0, i_o, 1.0, i_o1d) 
+
+!===========================================================
+!      CO2 + hv -> CO + O
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_co2, 1.0, i_co, 1.0, i_o) 
+
+!===========================================================
+!      CO2 + hv -> CO + O(1D)
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_co2, 1.0, i_co, 1.0, i_o1d) 
+
+!===========================================================
+!      O3 + hv -> O2 + O(1D)
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_o3, 1.0, i_o2, 1.0, i_o1d) 
+
+!===========================================================
+!      O3 + hv -> O2 + O
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_o3, 1.0, i_o2, 1.0, i_o) 
+
+!===========================================================
+!      H2O + hv -> H + OH
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_h2o, 1.0, i_h, 1.0, i_oh) 
+
+!===========================================================
+!      H2O2 + hv -> OH + OH
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_h2o2, 2.0, i_oh, 0.0, i_dummy) 
+
+!===========================================================
+!      HO2 + hv -> OH + O
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_ho2, 1.0, i_oh, 1.0, i_o) 
+
+!===========================================================
+!      NO + hv -> N + O
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_no, 1.0, i_n, 1.0, i_o) 
+
+!===========================================================
+!      NO2 + hv -> NO + O
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_no2, 1.0, i_no, 1.0, i_o) 
+
+!===========================================================
+!      a001 : O + O2 + CO2 -> O3 + CO2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o, 1.0, i_o2, 1.0, i_o3, 0.0, i_dummy) 
+
+!===========================================================
+!      a002 : O + O + CO2 -> O2 + CO2
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_o, 1.0, i_o2, 0.0, i_dummy) 
+
+!===========================================================
+!      a003 : O + O3 -> O2 + O2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o, 1.0, i_o3, 2.0, i_o2, 0.0, i_dummy) 
+
+!===========================================================
+!      b001 : O(1D) + CO2 -> O + CO2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_o1d, 1.0, i_o, 0.0, i_dummy) 
+
+!===========================================================
+!      b002 : O(1D) + H2O -> OH + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o1d, 1.0, i_h2o, 2.0, i_oh, 0.0, i_dummy) 
+
+!===========================================================
+!      b003 : O(1D) + H2 -> OH + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o1d, 1.0, i_h2, 1.0, i_oh, 1.0, i_h) 
+
+!===========================================================
+!      b004 : O(1D) + O2 -> O + O2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_o1d, 1.0, i_o, 0.0, i_dummy) 
+
+!===========================================================
+!      b005 : O(1D) + O3 -> O2 + O2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o1d, 1.0, i_o3, 2.0, i_o2, 0.0, i_dummy) 
+
+!===========================================================
+!      b006 : O(1D) + O3 -> O2 + O + O
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o1d, 1.0, i_o3, 1.0, i_o2, 2.0, i_o) 
+
+!===========================================================
+!      c001 : O + HO2 -> OH + O2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o, 1.0, i_ho2, 1.0, i_oh, 1.0, i_o2) 
+
+!===========================================================
+!      c002 : O + OH -> O2 + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o, 1.0, i_oh, 1.0, i_o2, 1.0, i_h) 
+
+!===========================================================
+!      c003 : H + O3 -> OH + O2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_h, 1.0, i_o3, 1.0, i_oh, 1.0, i_o2) 
+
+!===========================================================
+!      c004 : H + HO2 -> OH + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_h, 1.0, i_ho2, 2.0, i_oh, 0.0, i_dummy) 
+
+!===========================================================
+!      c005 : H + HO2 -> H2 + O2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_h, 1.0, i_ho2, 1.0, i_h2, 1.0, i_o2) 
+
+!===========================================================
+!      c006 : H + HO2 -> H2O + O
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_h, 1.0, i_ho2, 1.0, i_h2o, 1.0, i_o) 
+
+!===========================================================
+!      c007 : OH + HO2 -> H2O + O2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_oh, 1.0, i_ho2, 1.0, i_h2o, 1.0, i_o2) 
+
+!===========================================================
+!      c008 : HO2 + HO2 -> H2O2 + O2
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_ho2, 1.0, i_h2o2, 1.0, i_o2) 
+
+!===========================================================
+!      c009 : OH + H2O2 -> H2O + HO2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_oh, 1.0, i_h2o2, 1.0, i_h2o, 1.0, i_ho2) 
+
+!===========================================================
+!      c010 : OH + H2 -> H2O + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_oh, 1.0, i_h2, 1.0, i_h2o, 1.0, i_h) 
+
+!===========================================================
+!      c011 : H + O2 + CO2 -> HO2 + CO2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_h, 1.0, i_o2, 1.0, i_ho2, 0.0, i_dummy) 
+
+!===========================================================
+!      c012 : O + H2O2 -> OH + HO2
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_o, 1.0, i_h2o2, 1.0, i_oh, 1.0, i_ho2) 
+
+!===========================================================
+!      c013 : OH + OH -> H2O + O
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_oh, 1.0, i_h2o, 1.0, i_o) 
+
+!===========================================================
+!      c014 : OH + O3 -> HO2 + O2 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_oh, 1.0, i_o3, 1.0, i_ho2, 1.0, i_o2) 
+
+!===========================================================
+!      c015 : HO2 + O3 -> OH + O2 + O2 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_ho2, 1.0, i_o3, 1.0, i_oh, 2.0, i_o2) 
+
+!===========================================================
+!      c016 : HO2 + HO2 + CO2 -> H2O2 + O2 + CO2 
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_ho2, 1.0, i_h2o2, 1.0, i_o2) 
+
+!===========================================================
+!      c017 : OH + OH + CO2 -> H2O2 + CO2 
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_oh, 1.0, i_h2o2, 0.0, i_dummy) 
+
+!===========================================================
+!      c018 : H + H + CO2 -> H2 + CO2 
+!===========================================================
+
+nb_reaction_3 = nb_reaction_3 + 1
+
+indice_3(nb_reaction_3) = z3spec(2.0, i_h, 1.0, i_h2, 0.0, i_dummy) 
+
+!===========================================================
+!      d001 : NO2 + O -> NO + O2 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_no2, 1.0, i_o, 1.0, i_no, 1.0, i_o2) 
+
+!===========================================================
+!      d002 : NO + O3 -> NO2 + O2 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_no, 1.0, i_o3, 1.0, i_no2, 1.0, i_o2) 
+
+!===========================================================
+!      d003 : NO + HO2 -> NO2 + OH 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_no, 1.0, i_ho2, 1.0, i_no2, 1.0, i_oh) 
+
+!===========================================================
+!      d004 : N + NO -> N2 + O 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_n, 1.0, i_no, 1.0, i_n2, 1.0, i_o) 
+
+!===========================================================
+!      d005 : N + O2 -> NO + O 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_n, 1.0, i_o2, 1.0, i_no, 1.0, i_o) 
+
+!===========================================================
+!      d006 : NO2 + H -> NO + OH 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_no2, 1.0, i_h, 1.0, i_no, 1.0, i_oh) 
+
+!===========================================================
+!      d007 : N + O -> NO
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_n, 1.0, i_o, 1.0, i_no, 0.0, i_dummy) 
+
+!===========================================================
+!      d008 : N + HO2 -> NO + OH
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_n, 1.0, i_ho2, 1.0, i_no, 1.0, i_oh) 
+
+!===========================================================
+!      d009 : N + OH -> NO + H
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_n, 1.0, i_oh, 1.0, i_no, 1.0, i_h) 
+
+!===========================================================
+!      e001 : CO + OH -> CO2 + H 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_co, 1.0, i_oh, 1.0, i_co2, 1.0, i_h) 
+
+!===========================================================
+!      e002 : CO + O + M -> CO2 + M 
+!===========================================================
+
+nb_reaction_4 = nb_reaction_4 + 1
+
+indice_4(nb_reaction_4) = z4spec(1.0, i_co, 1.0, i_o, 1.0, i_co2, 0.0, i_dummy) 
+
+!===========================================================
+!      h001: HO2 + ice -> products
+!            treated as
+!            HO2 -> 0.5 H2O + 0.75 O2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_ho2, 0.5, i_h2o, 0.75, i_o2) 
+
+!===========================================================
+!      h002: OH + ice -> products
+!            treated as
+!            OH -> 0.5 H2O + 0.25 O2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_oh, 0.5, i_h2o, 0.25, i_o2) 
+
+!===========================================================
+!      h003: H2O2 + ice -> products
+!            treated as
+!            H2O2 -> H2O + 0.5 O2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_h2o2, 1.0, i_h2o, 0.5, i_o2) 
+
+!===========================================================
+!      h004: HO2 + dust -> products
+!            treated as
+!            HO2 -> 0.5 H2O + 0.75 O2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_ho2, 0.5, i_h2o, 0.75, i_o2) 
+
+!===========================================================
+!      h005: H2O2 + dust -> products
+!            treated as
+!            H2O2 -> H2O + 0.5 O2
+!===========================================================
+
+nb_phot = nb_phot + 1
+
+indice_phot(nb_phot) = z3spec(1.0, i_h2o2, 1.0, i_h2o, 0.5, i_o2) 
+
+!===========================================================
+!  check dimensions 
+!===========================================================
+
+print*, 'nb_phot       = ', nb_phot
+print*, 'nb_reaction_4 = ', nb_reaction_4
+print*, 'nb_reaction_3 = ', nb_reaction_3
+
+if ((nb_phot /= nb_phot_max)             .or.  &
+    (nb_reaction_3 /= nb_reaction_3_max) .or.  &
+    (nb_reaction_4 /= nb_reaction_4_max)) then
+   print*, 'wrong dimensions in indice' 
+   stop
+end if  
+
+end subroutine indice
+
+!*****************************************************************
+
+      subroutine gcmtochim(nlayer, nq, zycol, lswitch, nesp,         &
+                           i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h, &
+                           i_h2, i_oh, i_ho2, i_h2o2, i_h2o,         &
+                           i_n, i_n2d, i_no, i_no2, i_n2,            &
+                           dens, rm, c) 
+
+!*****************************************************************
+
+      use tracer_h, only: igcm_co2, igcm_co, igcm_o, igcm_o1d,         &
+     &                      igcm_o2, igcm_o3, igcm_h, igcm_h2, igcm_oh,  &
+     &                      igcm_ho2, igcm_h2o2, igcm_h2o_vap,           &
+     &                      igcm_n, igcm_n2d, igcm_no, igcm_no2, igcm_n2
+
+      use callkeys_mod
+
+      implicit none
+
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     input:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+      
+      integer, intent(in) :: nlayer ! number of atmospheric layers
+      integer, intent(in) :: nq     ! number of tracers in the gcm
+      integer :: nesp               ! number of species in the chemistry
+      integer :: lswitch            ! interface level between chemistries
+
+      integer :: i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,           &
+                 i_h2, i_oh, i_ho2, i_h2o2, i_h2o,                   &
+                 i_n, i_n2d, i_no, i_no2, i_n2
+
+      real :: zycol(nlayer,nq)      ! volume mixing ratios in the gcm
+      real :: dens(nlayer)          ! total number density (molecule.cm-3) 
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     output:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      real, dimension(nlayer,nesp)            :: rm ! volume mixing ratios 
+      real (kind = 8), dimension(nlayer,nesp) :: c  ! number densities (molecule.cm-3) 
+      
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     local:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      integer      :: l, iesp
+      logical,save :: firstcall = .true.
+      
+      
+!     first call initializations
+
+      if (firstcall) then
+
+!       identify the indexes of the tracers we need
+
+         if (igcm_co2 == 0) then
+            write(*,*) "gcmtochim: Error; no CO2 tracer !!!"
+            stop
+         endif
+         if (igcm_co == 0) then
+            write(*,*) "gcmtochim: Error; no CO tracer !!!"
+            stop
+         end if
+         if (igcm_o == 0) then
+            write(*,*) "gcmtochim: Error; no O tracer !!!"
+            stop
+         end if
+         if (igcm_o1d == 0) then
+            write(*,*) "gcmtochim: Error; no O1D tracer !!!"
+            stop
+         end if
+         if (igcm_o2 == 0) then
+            write(*,*) "gcmtochim: Error; no O2 tracer !!!"
+            stop
+         end if
+         if (igcm_o3 == 0) then
+            write(*,*) "gcmtochim: Error; no O3 tracer !!!"
+            stop
+         end if
+         if (igcm_h == 0) then
+            write(*,*) "gcmtochim: Error; no H tracer !!!"
+            stop
+         end if
+         if (igcm_h2 == 0) then
+            write(*,*) "gcmtochim: Error; no H2 tracer !!!"
+            stop
+         end if
+         if (igcm_oh == 0) then
+            write(*,*) "gcmtochim: Error; no OH tracer !!!"
+            stop
+         end if
+         if (igcm_ho2 == 0) then
+            write(*,*) "gcmtochim: Error; no HO2 tracer !!!"
+            stop
+         end if
+         if (igcm_h2o2 == 0) then
+            write(*,*) "gcmtochim: Error; no H2O2 tracer !!!"
+            stop
+         end if
+         if (igcm_n == 0) then
+            write(*,*) "gcmtochim: Error; no N tracer !!!"
+!            stop
+         end if
+         if (igcm_n2d == 0) then
+            write(*,*) "gcmtochim: Error; no N2D tracer !!!"
+!            stop
+         end if
+         if (igcm_no == 0) then
+            write(*,*) "gcmtochim: Error; no NO tracer !!!"
+!            stop
+         end if
+         if (igcm_no2 == 0) then
+            write(*,*) "gcmtochim: Error; no NO2 tracer !!!"
+!            stop
+         end if
+         if (igcm_n2 == 0) then
+            write(*,*) "gcmtochim: Error; no N2 tracer !!!"
+            stop
+         end if
+         if (igcm_h2o_vap == 0) then
+            write(*,*) "gcmtochim: Error; no water vapor tracer !!!"
+            stop
+         end if
+         firstcall = .false.
+      end if ! of if (firstcall)
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     initialise mixing ratios
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      do l = 1,lswitch-1
+         rm(l,i_co2)  = zycol(l, igcm_co2)
+         rm(l,i_co)   = zycol(l, igcm_co)
+         rm(l,i_o)    = zycol(l, igcm_o)
+         rm(l,i_o1d)  = zycol(l, igcm_o1d)
+         rm(l,i_o2)   = zycol(l, igcm_o2)
+         rm(l,i_o3)   = zycol(l, igcm_o3)
+         rm(l,i_h)    = zycol(l, igcm_h)
+         rm(l,i_h2)   = zycol(l, igcm_h2)
+         rm(l,i_oh)   = zycol(l, igcm_oh)
+         rm(l,i_ho2)  = zycol(l, igcm_ho2)
+         rm(l,i_h2o2) = zycol(l, igcm_h2o2)
+         rm(l,i_h2o)  = zycol(l, igcm_h2o_vap)
+         rm(l,i_n)    = zycol(l, igcm_n)
+         rm(l,i_n2d)  = zycol(l, igcm_n2d)
+         rm(l,i_no)   = zycol(l, igcm_no)
+         rm(l,i_no2)  = zycol(l, igcm_no2)
+         rm(l,i_n2)   = zycol(l, igcm_n2)
+      end do 
+
+      where (rm(:,:) < 1.e-30)
+         rm(:,:) = 0.
+      end where
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     initialise number densities
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      do iesp = 1,nesp
+         do l = 1,lswitch-1
+            c(l,iesp) = rm(l,iesp)*dens(l)
+         end do
+      end do
+
+      end subroutine gcmtochim
+
+!*****************************************************************
+ 
+      subroutine chimtogcm(nlayer, nq, zycol, lswitch, nesp,         &
+                           i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h, &
+                           i_h2, i_oh, i_ho2, i_h2o2, i_h2o,         &
+                           i_n, i_n2d, i_no, i_no2, i_n2, dens, c) 
+ 
+!*****************************************************************
+ 
+      use tracer_h, only: igcm_co2, igcm_co, igcm_o, igcm_o1d,          &
+                            igcm_o2, igcm_o3, igcm_h, igcm_h2, igcm_oh,   &
+                            igcm_ho2, igcm_h2o2, igcm_h2o_vap,            &
+                            igcm_n, igcm_n2d, igcm_no, igcm_no2, igcm_n2
+
+      use callkeys_mod
+
+      implicit none
+
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     inputs:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+ 
+      integer, intent(in) :: nlayer  ! number of atmospheric layers
+      integer, intent(in) :: nq      ! number of tracers in the gcm
+      integer :: nesp                ! number of species in the chemistry
+      integer :: lswitch             ! interface level between chemistries
+      integer :: i_co2, i_co, i_o, i_o1d, i_o2, i_o3, i_h,       &
+                 i_h2, i_oh, i_ho2, i_h2o2, i_h2o,               &
+                 i_n, i_n2d, i_no, i_no2, i_n2
+
+      real :: dens(nlayer)     ! total number density (molecule.cm-3) 
+      real (kind = 8), dimension(nlayer,nesp) :: c  ! number densities (molecule.cm-3) 
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     output:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+       
+      real zycol(nlayer,nq)  ! volume mixing ratios in the gcm
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     local:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      integer l
+      
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     save mixing ratios for the gcm
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      do l = 1,lswitch-1
+         zycol(l, igcm_co2)     = c(l,i_co2)/dens(l) 
+         zycol(l, igcm_co)      = c(l,i_co)/dens(l) 
+         zycol(l, igcm_o)       = c(l,i_o)/dens(l) 
+         zycol(l, igcm_o1d)     = c(l,i_o1d)/dens(l)
+         zycol(l, igcm_o2)      = c(l,i_o2)/dens(l) 
+         zycol(l, igcm_o3)      = c(l,i_o3)/dens(l) 
+         zycol(l, igcm_h)       = c(l,i_h)/dens(l)  
+         zycol(l, igcm_h2)      = c(l,i_h2)/dens(l) 
+         zycol(l, igcm_oh)      = c(l,i_oh)/dens(l) 
+         zycol(l, igcm_ho2)     = c(l,i_ho2)/dens(l) 
+         zycol(l, igcm_h2o2)    = c(l,i_h2o2)/dens(l)
+         zycol(l, igcm_h2o_vap) = c(l,i_h2o)/dens(l)
+         zycol(l, igcm_n)       = c(l,i_n)/dens(l)
+         zycol(l, igcm_n2d)     = c(l,i_n2d)/dens(l)
+         zycol(l, igcm_no)      = c(l,i_no)/dens(l)
+         zycol(l, igcm_no2)     = c(l,i_no2)/dens(l)
+         zycol(l, igcm_n2)      = c(l,i_n2)/dens(l)
+      end do 
+
+      end subroutine chimtogcm
+
+end subroutine photochemistry_asis
+
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/photolysis_asis.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/photolysis_asis.F90	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/photolysis_asis.F90	(revision 1796)
@@ -0,0 +1,390 @@
+!==========================================================================
+
+      subroutine photolysis_asis(nlayer, ngrid,                                 &
+                                 lswitch, press, temp, sza, fractcol, tauref,   &
+                                 zmmean, dist_sol, rmco2, rmo3, v_phot)
+
+!==========================================================================
+
+      use comcstfi_mod
+      use callkeys_mod
+
+      implicit none
+
+#include "chimiedata.h" 
+
+!==========================================================================
+!     input:
+!==========================================================================
+       
+      integer, intent(in) :: nlayer ! number of atmospheric layers
+      integer,intent(in) :: ngrid   ! number of atmospheric columns
+      integer :: lswitch            ! interface level between chemistries
+      real :: press(nlayer)         ! pressure (hPa)
+      real :: temp(nlayer)          ! temperature (K)
+      real :: sza                   ! solar zenith angle (deg)
+      real :: fractcol              ! day fraction
+      real :: tauref                ! optical depth at 7 hpa
+      real :: zmmean(nlayer)        ! mean molecular mass (g)
+      real :: dist_sol              ! sun distance (AU) 
+      real :: rmco2(nlayer)         ! co2 mixing ratio
+      real :: rmo3(nlayer)          ! ozone mixing ratio
+
+!==========================================================================
+!     output: interpolated photodissociation rates (s-1)
+!==========================================================================
+
+      real (kind = 8), dimension(nlayer,nb_phot_max) :: v_phot
+
+!==========================================================================
+!     local:
+!==========================================================================
+
+      integer :: icol, ij, indsza, indtau, indcol, indozo, indtemp,     &
+                 iozo, isza, itau, it, l
+
+      integer :: j_o2_o, j_o2_o1d, j_co2_o, j_co2_o1d, j_o3_o1d,        &
+                 j_o3_o, j_h2o, j_hdo, j_h2o2, j_ho2, j_no, j_no2,      &
+                 j_hno3, j_hno4,                                        &
+                 j_ch4_ch3_h, j_ch4_1ch2_h2, j_ch4_3ch2_h_h,            &
+                 j_ch4_ch_h2_h, j_ch3o2h, j_ch2o_hco, j_ch2o_co,        &
+                 j_ch3oh, j_c2h6, j_hcl, j_hocl, j_clo, j_so2, j_so,    &
+                 j_h2s, j_so3
+
+      real :: col(nlayer)                 ! overhead air column   (molecule cm-2)
+      real :: colo3(nlayer)               ! overhead ozone column (molecule cm-2)
+      real :: poids(2,2,2,2,2)            ! 5D interpolation weights 
+      real :: tref                        ! temperature  at 1.9 hPa in the gcm (K)
+      real :: table_temp(ntemp)           ! temperatures at 1.9 hPa in jmars   (K)
+      real :: cinf, csup, cicol, ciozo, cisza, citemp, citau
+      real :: colo3min, dp, coef
+      real :: ratio_o3(nlayer)
+      real :: tau
+      real :: j(nlayer,nd)
+
+!==========================================================================
+!     day/night criterion
+!==========================================================================
+
+      if (sza <= 95.) then 
+
+!==========================================================================
+!     temperatures at 1.9 hPa in lookup table
+!==========================================================================
+      
+      table_temp(1) = 226.2
+      table_temp(2) = 206.2
+      table_temp(3) = 186.2
+      table_temp(4) = 169.8
+
+!==========================================================================
+!     interpolation in solar zenith angle
+!==========================================================================
+ 
+      indsza = nsza - 1
+      do isza = 1,nsza
+         if (szatab(isza) >= sza) then
+            indsza = isza - 1
+            indsza = max(indsza, 1)
+            exit
+         end if
+      end do
+      cisza = (sza - szatab(indsza))  &
+             /(szatab(indsza + 1) - szatab(indsza))
+
+!==========================================================================
+!     interpolation in dust (tau)
+!==========================================================================
+
+      tau = min(tauref, tautab(ntau))
+      tau = max(tau, tautab(1))
+
+      indtau = ntau - 1
+      do itau = 1,ntau
+         if (tautab(itau) >= tau) then
+            indtau = itau - 1
+            indtau = max(indtau, 1)
+            exit
+         end if
+      end do
+      citau = (tau - tautab(indtau))     &
+             /(tautab(indtau + 1) - tautab(indtau))
+
+!==========================================================================
+!     co2 and ozone columns
+!==========================================================================
+
+!     co2 column at model top (molecule.cm-2)
+
+      col(lswitch-1) = 6.022e22*rmco2(lswitch-1)*press(lswitch-1)*100.  &
+                       /(zmmean(lswitch-1)*g)
+
+!     ozone column at model top
+
+      colo3(lswitch-1) = 0.
+
+!     co2 and ozone columns for other levels (molecule.cm-2)
+
+      do l = lswitch-2,1,-1
+         dp = (press(l) - press(l+1))*100.
+         col(l) = col(l+1) + (rmco2(l+1) + rmco2(l))*0.5   &
+                             *6.022e22*dp/(zmmean(l)*g)
+         col(l) = min(col(l), colairtab(1))
+         colo3(l) = colo3(l+1) + (rmo3(l+1) + rmo3(l))*0.5 &
+                                 *6.022e22*dp/(zmmean(l)*g)
+      end do
+
+!     ratio ozone column/minimal theoretical column (0.1 micron-atm) 
+
+!     ro3 = 7.171e-10 is the o3 mixing ratio for a uniform
+!     profile giving a column 0.1 micron-atmosphere at
+!     a surface pressure of 10 hpa.
+
+      do l = 1,lswitch-1
+         colo3min    = col(l)*7.171e-10
+         ratio_o3(l) = colo3(l)/colo3min
+         ratio_o3(l) = min(ratio_o3(l), table_ozo(nozo)*10.)
+         ratio_o3(l) = max(ratio_o3(l), 1.)
+      end do
+
+!==========================================================================
+!     temperature dependence
+!==========================================================================
+
+!     1) search for temperature at 1.9 hPa (tref): vertical interpolation
+
+      tref = temp(1)
+      do l = (lswitch-1)-1,1,-1
+         if (press(l) > 1.9) then
+            cinf = (press(l) - 1.9)/(press(l) - press(l+1))
+            csup = 1. - cinf
+            tref = cinf*temp(l+1) + csup*temp(l)
+            exit
+         end if
+      end do 
+
+!     2) interpolation in temperature
+
+      tref = min(tref,table_temp(1))
+      tref = max(tref,table_temp(ntemp))
+
+      do it = 2, ntemp
+         if (table_temp(it) <= tref) then
+            citemp = (log(tref) - log(table_temp(it)))              &
+                    /(log(table_temp(it-1)) - log(table_temp(it)))
+            indtemp = it - 1
+            exit
+         end if
+      end do
+
+!==========================================================================
+!     loop over vertical levels
+!==========================================================================
+
+      do l = 1,lswitch-1
+
+!     interpolation in air column
+
+         indcol = nz - 1
+         do icol = 1,nz
+            if (colairtab(icol) < col(l)) then
+               indcol = icol - 1
+               exit
+            end if
+         end do
+         cicol = (log(col(l)) - log(colairtab(indcol + 1)))              &
+                /(log(colairtab(indcol)) - log(colairtab(indcol + 1)))
+
+!     interpolation in ozone column
+
+         indozo = nozo - 1
+         do iozo = 1,nozo
+            if (table_ozo(iozo)*10. >= ratio_o3(l)) then
+               indozo = iozo - 1
+               indozo = max(indozo, 1)
+               exit
+            end if
+         end do
+         ciozo = (ratio_o3(l) - table_ozo(indozo)*10.)             &
+                /(table_ozo(indozo + 1)*10. - table_ozo(indozo)*10.)
+
+!     4-dimensional interpolation weights
+
+!     poids(temp,sza,co2,o3,tau)
+
+         poids(1,1,1,1,1) = citemp*(1.-cisza)*cicol*(1.-ciozo)*(1.-citau)
+         poids(1,1,1,2,1) = citemp*(1.-cisza)*cicol*ciozo*(1.-citau)
+         poids(1,1,2,1,1) = citemp*(1.-cisza)*(1.-cicol)*(1.-ciozo)*(1.-citau)
+         poids(1,1,2,2,1) = citemp*(1.-cisza)*(1.-cicol)*ciozo*(1.-citau)
+         poids(1,2,1,1,1) = citemp*cisza*cicol*(1.-ciozo)*(1.-citau)
+         poids(1,2,1,2,1) = citemp*cisza*cicol*ciozo*(1.-citau)
+         poids(1,2,2,1,1) = citemp*cisza*(1.-cicol)*(1.-ciozo)*(1.-citau)
+         poids(1,2,2,2,1) = citemp*cisza*(1.-cicol)*ciozo*(1.-citau)
+         poids(2,1,1,1,1) = (1.-citemp)*(1.-cisza)*cicol*(1.-ciozo)*(1.-citau)
+         poids(2,1,1,2,1) = (1.-citemp)*(1.-cisza)*cicol*ciozo*(1.-citau)
+         poids(2,1,2,1,1) = (1.-citemp)*(1.-cisza)*(1.-cicol)*(1.-ciozo)*(1.-citau)
+         poids(2,1,2,2,1) = (1.-citemp)*(1.-cisza)*(1.-cicol)*ciozo*(1.-citau)
+         poids(2,2,1,1,1) = (1.-citemp)*cisza*cicol*(1.-ciozo)*(1.-citau)
+         poids(2,2,1,2,1) = (1.-citemp)*cisza*cicol*ciozo*(1.-citau)
+         poids(2,2,2,1,1) = (1.-citemp)*cisza*(1.-cicol)*(1.-ciozo)*(1.-citau)
+         poids(2,2,2,2,1) = (1.-citemp)*cisza*(1.-cicol)*ciozo*(1.-citau)
+!
+         poids(1,1,1,1,2) = citemp*(1.-cisza)*cicol*(1.-ciozo)*citau
+         poids(1,1,1,2,2) = citemp*(1.-cisza)*cicol*ciozo*citau
+         poids(1,1,2,1,2) = citemp*(1.-cisza)*(1.-cicol)*(1.-ciozo)*citau
+         poids(1,1,2,2,2) = citemp*(1.-cisza)*(1.-cicol)*ciozo*citau
+         poids(1,2,1,1,2) = citemp*cisza*cicol*(1.-ciozo)*citau
+         poids(1,2,1,2,2) = citemp*cisza*cicol*ciozo*citau
+         poids(1,2,2,1,2) = citemp*cisza*(1.-cicol)*(1.-ciozo)*citau
+         poids(1,2,2,2,2) = citemp*cisza*(1.-cicol)*ciozo*citau
+         poids(2,1,1,1,2) = (1.-citemp)*(1.-cisza)*cicol*(1.-ciozo)*citau
+         poids(2,1,1,2,2) = (1.-citemp)*(1.-cisza)*cicol*ciozo*citau
+         poids(2,1,2,1,2) = (1.-citemp)*(1.-cisza)*(1.-cicol)*(1.-ciozo)*citau
+         poids(2,1,2,2,2) = (1.-citemp)*(1.-cisza)*(1.-cicol)*ciozo*citau
+         poids(2,2,1,1,2) = (1.-citemp)*cisza*cicol*(1.-ciozo)*citau
+         poids(2,2,1,2,2) = (1.-citemp)*cisza*cicol*ciozo*citau
+         poids(2,2,2,1,2) = (1.-citemp)*cisza*(1.-cicol)*(1.-ciozo)*citau
+         poids(2,2,2,2,2) = (1.-citemp)*cisza*(1.-cicol)*ciozo*citau
+
+!     4-dimensional interpolation in the lookup table
+
+         do ij = 1,nd
+            j(l,ij) =                                                                & 
+            poids(1,1,1,1,1)*jphot(indtemp,indsza,indcol,indozo,indtau,ij)           &
+          + poids(1,1,1,2,1)*jphot(indtemp,indsza,indcol,indozo+1,indtau,ij)         &
+          + poids(1,1,2,1,1)*jphot(indtemp,indsza,indcol+1,indozo,indtau,ij)         &
+          + poids(1,1,2,2,1)*jphot(indtemp,indsza,indcol+1,indozo+1,indtau,ij)       &
+          + poids(1,2,1,1,1)*jphot(indtemp,indsza+1,indcol,indozo,indtau,ij)         &
+          + poids(1,2,1,2,1)*jphot(indtemp,indsza+1,indcol,indozo+1,indtau,ij)       &
+          + poids(1,2,2,1,1)*jphot(indtemp,indsza+1,indcol+1,indozo,indtau,ij)       &
+          + poids(1,2,2,2,1)*jphot(indtemp,indsza+1,indcol+1,indozo+1,indtau,ij)     &
+          + poids(2,1,1,1,1)*jphot(indtemp+1,indsza,indcol,indozo,indtau,ij)         &
+          + poids(2,1,1,2,1)*jphot(indtemp+1,indsza,indcol,indozo+1,indtau,ij)       &
+          + poids(2,1,2,1,1)*jphot(indtemp+1,indsza,indcol+1,indozo,indtau,ij)       &
+          + poids(2,1,2,2,1)*jphot(indtemp+1,indsza,indcol+1,indozo+1,indtau,ij)     &
+          + poids(2,2,1,1,1)*jphot(indtemp+1,indsza+1,indcol,indozo,indtau,ij)       &
+          + poids(2,2,1,2,1)*jphot(indtemp+1,indsza+1,indcol,indozo+1,indtau,ij)     &
+          + poids(2,2,2,1,1)*jphot(indtemp+1,indsza+1,indcol+1,indozo,indtau,ij)     &
+          + poids(2,2,2,2,1)*jphot(indtemp+1,indsza+1,indcol+1,indozo+1,indtau,ij)   &
+!
+          + poids(1,1,1,1,2)*jphot(indtemp,indsza,indcol,indozo,indtau+1,ij)         &
+          + poids(1,1,1,2,2)*jphot(indtemp,indsza,indcol,indozo+1,indtau+1,ij)       &
+          + poids(1,1,2,1,2)*jphot(indtemp,indsza,indcol+1,indozo,indtau+1,ij)       &
+          + poids(1,1,2,2,2)*jphot(indtemp,indsza,indcol+1,indozo+1,indtau+1,ij)     &
+          + poids(1,2,1,1,2)*jphot(indtemp,indsza+1,indcol,indozo,indtau+1,ij)       &
+          + poids(1,2,1,2,2)*jphot(indtemp,indsza+1,indcol,indozo+1,indtau+1,ij)     &
+          + poids(1,2,2,1,2)*jphot(indtemp,indsza+1,indcol+1,indozo,indtau+1,ij)     &
+          + poids(1,2,2,2,2)*jphot(indtemp,indsza+1,indcol+1,indozo+1,indtau+1,ij)   &
+          + poids(2,1,1,1,2)*jphot(indtemp+1,indsza,indcol,indozo,indtau+1,ij)       &
+          + poids(2,1,1,2,2)*jphot(indtemp+1,indsza,indcol,indozo+1,indtau+1,ij)     &
+          + poids(2,1,2,1,2)*jphot(indtemp+1,indsza,indcol+1,indozo,indtau+1,ij)     &
+          + poids(2,1,2,2,2)*jphot(indtemp+1,indsza,indcol+1,indozo+1,indtau+1,ij)   &
+          + poids(2,2,1,1,2)*jphot(indtemp+1,indsza+1,indcol,indozo,indtau+1,ij)     &
+          + poids(2,2,1,2,2)*jphot(indtemp+1,indsza+1,indcol,indozo+1,indtau+1,ij)   &
+          + poids(2,2,2,1,2)*jphot(indtemp+1,indsza+1,indcol+1,indozo,indtau+1,ij)   &
+          + poids(2,2,2,2,2)*jphot(indtemp+1,indsza+1,indcol+1,indozo+1,indtau+1,ij)
+         end do
+
+!     correction for sun distance
+
+         do ij = 1,nd
+!            j(l,ij) = j(l,ij)*(1.52/dist_sol)**2.
+            j(l,ij) = j(l,ij)*(1.0/dist_sol)**2.
+
+            ! Only during daylight.
+            if((ngrid.eq.1))then
+                  j(l,ij)= j(l,ij)* 0.25 ! globally averaged = divide by 4
+            elseif(diurnal .eqv. .false.) then
+                  j(l,ij)= j(l,ij) * fractcol
+            endif
+         end do 
+
+!==========================================================================
+!     end of loop over vertical levels
+!==========================================================================
+
+      end do
+
+      else
+
+!==========================================================================
+!     night
+!==========================================================================
+
+         j(:,:) = 0.
+
+      end if
+
+! photodissociation rates numbering in the lookup table
+
+! jmars.20140930
+
+
+      j_o2_o         =  1      ! o2 + hv     -> o + o
+      j_o2_o1d       =  2      ! o2 + hv     -> o + o(1d)
+      j_co2_o        =  3      ! co2 + hv    -> co + o
+      j_co2_o1d      =  4      ! co2 + hv    -> co + o(1d)
+      j_o3_o1d       =  5      ! o3 + hv     -> o2 + o(1d)
+      j_o3_o         =  6      ! o3 + hv     -> o2 + o
+      j_h2o          =  7      ! h2o + hv    -> h + oh
+      j_h2o2         =  8      ! h2o2 + hv   -> oh + oh
+      j_ho2          =  9      ! ho2 + hv    -> oh + o
+      j_no           =  10     ! no + hv     -> n + o
+      j_no2          =  11     ! no2 + hv    -> no + o
+      j_hno3         =  12     ! hno3 + hv   -> no2 + oh
+      j_hno4         =  13     ! hno4 + hv   -> no2 + ho2
+
+! jmars.20111014
+
+!     j_o2_o         =  1      ! o2 + hv     -> o + o
+!     j_o2_o1d       =  2      ! o2 + hv     -> o + o(1d)
+!     j_co2_o        =  3      ! co2 + hv    -> co + o
+!     j_co2_o1d      =  4      ! co2 + hv    -> co + o(1d)
+!     j_o3_o1d       =  5      ! o3 + hv     -> o2 + o(1d)
+!     j_o3_o         =  6      ! o3 + hv     -> o2 + o
+!     j_h2o          =  7      ! h2o + hv    -> h + oh
+!     j_hdo          =  8      ! hdo + hv    -> d + oh
+!     j_h2o2         =  9      ! h2o2 + hv   -> oh + oh
+!     j_ho2          =  10     ! ho2 + hv    -> oh + o
+!     j_no2          =  11     ! no2 + hv    -> no + o
+!     j_ch4_ch3_h    =  12     ! ch4 + hv    -> ch3 + h
+!     j_ch4_1ch2_h2  =  13     ! ch4 + hv    -> 1ch2 + h2
+!     j_ch4_3ch2_h_h =  14     ! ch4 + hv    -> 3ch2 + h + h
+!     j_ch4_ch_h2_h  =  15     ! ch4 + hv    -> ch + h2 + h
+!     j_ch3o2h       =  16     ! ch3o2h + hv -> ch3o + oh
+!     j_ch2o_hco     =  17     ! ch2o + hv   -> h + hco
+!     j_ch2o_co      =  18     ! ch2o + hv   -> h2 + co
+!     j_ch3oh        =  19     ! ch3oh + hv  -> ch3o + h
+!     j_c2h6         =  20     ! c2h6 + hv   -> products
+!     j_hcl          =  21     ! hcl + hv    -> h + cl
+!     j_hocl         =  22     ! hocl + hv   -> oh + cl
+!     j_clo          =  23     ! clo + hv    -> o + cl
+!     j_so2          =  24     ! so2 + hv    -> so + o
+!     j_so           =  25     ! so + hv     -> s + o
+!     j_h2s          =  26     ! h2s + hv    -> hs + s
+!     j_so3          =  27     ! so2 + hv    -> so2 + o
+!     j_hno3         =  28     ! hno3 + hv   -> oh + no2
+!     j_hno4         =  29     ! hno4 + hv   -> ho2 + no2
+
+! fill v_phot array
+
+      v_phot(:,:) = 0.
+
+      do l = 1,lswitch-1
+         v_phot(l, 1) = j(l,j_o2_o)
+         v_phot(l, 2) = j(l,j_o2_o1d)
+         v_phot(l, 3) = j(l,j_co2_o)
+         v_phot(l, 4) = j(l,j_co2_o1d)
+         v_phot(l, 5) = j(l,j_o3_o1d)
+         v_phot(l, 6) = j(l,j_o3_o)
+         v_phot(l, 7) = j(l,j_h2o)
+         v_phot(l, 8) = j(l,j_h2o2)
+         v_phot(l, 9) = j(l,j_ho2)
+         v_phot(l,10) = j(l,j_no)
+         v_phot(l,11) = j(l,j_no2)
+      end do
+
+      return
+      end
+
+!*****************************************************************
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/read_phototable.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/read_phototable.F90	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/read_phototable.F90	(revision 1796)
@@ -0,0 +1,97 @@
+!***********************************************************************
+
+      subroutine read_phototable
+
+!***********************************************************************
+!
+!   subject:
+!   --------
+!
+!   read photolysis lookup table
+!
+!   VERSION: 8/10/2014
+!
+!   Author:   Franck Lefevre
+!
+!   Arguments:
+!   ----------
+!
+!   The output variable is jphot and is put in common chimiedata.
+!
+!***********************************************************************
+
+      use ioipsl_getincom 
+      use ioipsl_getin_p_mod, only: getin_p
+      use datafile_mod
+      implicit none
+
+#include "chimiedata.h"
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!     local:
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      integer :: fic, ij, iozo, isza, itemp, iz, itau, ierr
+      real    :: xsza
+
+      character(len = 128) :: phototable ! photolysis table file name
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+! set photolysis table input file name
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+
+
+! look for a " phototable= ..." option in def files
+     write(*,*) "Directory where external input files are:"
+      phototable = "jmars.20140930" ! default
+     call getin_p("phototable",phototable) ! default path
+     write(*,*) " phototable = ",trim(phototable)
+
+
+      fic = 81
+
+      open(fic, form = 'formatted', status = 'old',                &
+           file =trim(datadir)//"/"//trim(phototable),iostat=ierr)
+
+      if (ierr /= 0) THEN
+        write(*,*)'Error : cannot open photolysis lookup table ', trim(phototable)
+        write(*,*)'It should be in :',trim(datadir),'/'
+        write(*,*)'1) You can change this directory in callphys.def'
+        write(*,*)'   with:'
+        write(*,*)'   datadir=/path/to/the/directory'
+        write(*,*)'2) You can change the input phototable file name in'
+        write(*,*)'   callphys.def with:'
+        write(*,*)'   phototable=filename'
+        stop
+      end if
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+! read photolys table
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+
+      print*, 'read photolysis lookup table ',trim(phototable)
+
+      do itau = 1,ntau
+         do itemp = 1,ntemp
+            do iozo = 1,nozo
+               do isza = 1,nsza
+                  do iz = nz,1,-1
+                     read(fic,*) colairtab(iz), xsza, table_ozo(iozo)
+                     read(fic,'(7e11.4)') (jphot(itemp,isza,iz,iozo,itau,ij), ij= 1,nd)
+                     do ij = 1,nd
+                        if (jphot(itemp,isza,iz,iozo,itau,ij) == 1.e-30) then
+                           jphot(itemp,isza,iz,iozo,itau,ij) = 0.
+                        end if
+                     end do
+                  end do
+               end do
+            end do
+         end do
+      end do
+
+      print*, 'lookup table...ok'
+      close(fic)
+
+      return
+      end
Index: /trunk/LMDZ.GENERIC/libf/aeronostd/types_asis.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/aeronostd/types_asis.F90	(revision 1796)
+++ /trunk/LMDZ.GENERIC/libf/aeronostd/types_asis.F90	(revision 1796)
@@ -0,0 +1,33 @@
+module types_asis
+
+implicit none
+
+integer, parameter :: jpim = 4
+integer, parameter :: jprb = 8
+
+type z3spec
+	real(kind=jprb)    :: z1
+        integer(kind=jpim) :: z2
+	real(kind=jprb)    :: z3
+        integer(kind=jpim) :: z4
+	real(kind=jprb)    :: z5
+        integer(kind=jpim) :: z6
+end type z3spec
+type z4spec
+	real(kind=jprb)    :: z1
+        integer(kind=jpim) :: z2
+	real(kind=jprb)    :: z3
+        integer(kind=jpim) :: z4
+	real(kind=jprb)    :: z5
+        integer(kind=jpim) :: z6
+	real(kind=jprb)    :: z7
+        integer(kind=jpim) :: z8
+end type z4spec
+
+! indexes for the jacobian matrix
+
+type(z3spec), allocatable, save :: indice_phot(:)
+type(z3spec), allocatable, save :: indice_3(:)
+type(z4spec), allocatable, save :: indice_4(:)
+
+end module types_asis
