Index: trunk/LMDZ.MARS/libf/aeronomars/calchim.F90
===================================================================
--- trunk/LMDZ.MARS/libf/aeronomars/calchim.F90	(revision 1036)
+++ trunk/LMDZ.MARS/libf/aeronomars/calchim.F90	(revision 1047)
@@ -1,3 +1,3 @@
-      subroutine calchim(nq,                                                &
+      subroutine calchim(ngrid,nlayer,nq,                                   &
                          ptimestep,pplay,pplev,pt,pdt,dist_sol,mu0,         &
                          zzlev,zzlay,zday,pq,pdq,dqchim,dqschim,dqcloud,    &
@@ -13,4 +13,6 @@
                             igcm_noplus, igcm_n2plus, igcm_hplus,         &
                             igcm_hco2plus, igcm_elec, mmol
+      use conc_mod, only: mmean ! mean molecular mass of the atmosphere
+
       implicit none
 
@@ -38,66 +40,68 @@
 !
 !    ptimestep                  timestep (s)
-!    pplay(ngridmx,nlayermx)    Pressure at the middle of the layers (Pa)
-!    pplev(ngridmx,nlayermx+1)  Intermediate pressure levels (Pa)
-!    pt(ngridmx,nlayermx)       Temperature (K)
-!    pdt(ngridmx,nlayermx)      Temperature tendency (K)
-!    pu(ngridmx,nlayermx)       u component of the wind (ms-1)
-!    pdu(ngridmx,nlayermx)      u component tendency (K)
-!    pv(ngridmx,nlayermx)       v component of the wind (ms-1)
-!    pdv(ngridmx,nlayermx)      v component tendency (K)
+!    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(ngridmx)               cos of solar zenith angle (=1 when sun at zenith)
-!    pq(ngridmx,nlayermx,nqmx)  Advected fields, ie chemical species here
-!    pdq(ngridmx,nlayermx,nqmx) Previous tendencies on pq
-!    tauref(ngridmx)            Optical depth at 7 hPa
-!    co2ice(ngridmx)            co2 ice surface layer (kg.m-2)
-!    surfdust(ngridmx,nlayermx) dust surface area (m2/m3)
-!    surfice(ngridmx,nlayermx)  ice surface area (m2/m3)
+!    mu0(ngrid)               cos of solar zenith angle (=1 when sun at zenith)
+!    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(ngridmx,nlayermx,nqmx) ! tendencies on pq due to chemistry
-!    dqschim(ngridmx,nqmx)         ! tendencies on qsurf 
-!
-!=======================================================================
-
-#include "dimensions.h"
-#include "dimphys.h"
+!    dqchim(ngrid,nlayer,nq) ! tendencies on pq due to chemistry
+!    dqschim(ngrid,nq)         ! tendencies on qsurf 
+!
+!=======================================================================
+
+!#include "dimensions.h"
+!#include "dimphys.h"
 #include "chimiedata.h"
 !#include "tracer.h"
 #include "comcstfi.h"
 #include "callkeys.h"
-#include "conc.h"
+!#include "conc.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(ngridmx,nlayermx)    ! pressure at the middle of the layers
-      real :: zzlay(ngridmx,nlayermx)    ! pressure at the middle of the layers
-      real :: pplev(ngridmx,nlayermx+1)  ! intermediate pressure levels
-      real :: zzlev(ngridmx,nlayermx+1)  ! altitude at layer boundaries
-      real :: pt(ngridmx,nlayermx)       ! temperature
-      real :: pdt(ngridmx,nlayermx)      ! temperature tendency
-      real :: pu(ngridmx,nlayermx)       ! u component of the wind (m.s-1)
-      real :: pdu(ngridmx,nlayermx)      ! u component tendency
-      real :: pv(ngridmx,nlayermx)       ! v component of the wind (m.s-1)
-      real :: pdv(ngridmx,nlayermx)      ! v component tendency
+      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(ngridmx)               ! cos of solar zenith angle (=1 when sun at zenith)
-      real :: pq(ngridmx,nlayermx,nq)  ! tracers mass mixing ratio
-      real :: pdq(ngridmx,nlayermx,nq) ! previous tendencies
+      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(ngridmx)            ! optical depth at 7 hPa
-      real :: co2ice(ngridmx)            ! co2 ice surface layer (kg.m-2)
-      real :: surfdust(ngridmx,nlayermx) ! dust surface area (m2/m3)
-      real :: surfice(ngridmx,nlayermx)  !  ice surface area (m2/m3)
+      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(ngridmx,nlayermx,nq) ! tendencies on pq due to chemistry
-      real :: dqschim(ngridmx,nq)         ! tendencies on qsurf 
-      real :: dqcloud(ngridmx,nlayermx,nq)! tendencies on pq due to condensation
-      real :: dqscloud(ngridmx,nq)        ! tendencies on qsurf 
+      real :: dqchim(ngrid,nlayer,nq) ! tendencies on pq due to chemistry
+      real :: dqschim(ngrid,nq)         ! tendencies on qsurf 
+      real :: dqcloud(ngrid,nlayer,nq)! tendencies on pq due to condensation
+      real :: dqscloud(ngrid,nq)        ! tendencies on qsurf 
 
 !     local variables:
@@ -143,9 +147,9 @@
 
       real    :: latvl1, lonvl1
-      real    :: zq(ngridmx,nlayermx,nq) ! pq+pdq*ptimestep before chemistry
+      real    :: zq(ngrid,nlayer,nq) ! pq+pdq*ptimestep before chemistry
                                            ! new mole fraction after
-      real    :: zt(ngridmx,nlayermx)      ! temperature
-      real    :: zu(ngridmx,nlayermx)      ! u component of the wind
-      real    :: zv(ngridmx,nlayermx)      ! v component of the wind
+      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
 
@@ -155,13 +159,13 @@
 !     for each column of atmosphere:
 
-      real :: zpress(nlayermx)       !  Pressure (mbar)
-      real :: zdens(nlayermx)        !  Density  (cm-3)
-      real :: ztemp(nlayermx)        !  Temperature (K)
-      real :: zlocal(nlayermx)       !  Altitude (km)
-      real :: zycol(nlayermx,nq)   !  Composition (mole fractions)
+      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 :: szacol                 !  Solar zenith angle
-      real :: surfice1d(nlayermx)    !  Ice surface area (cm2/cm3)
-      real :: surfdust1d(nlayermx)   !  Dust surface area (cm2/cm3)
-      real :: jo3(nlayermx)          !  Photodissociation rate O3->O1D (s-1)
+      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)
 
 !     for output:
@@ -169,5 +173,5 @@
       logical :: output                 ! to issue calls to writediagfi and stats
       parameter (output = .true.)
-      real :: jo3_3d(ngridmx,nlayermx)  ! Photodissociation rate O3->O1D (s-1)
+      real :: jo3_3d(ngrid,nlayer)  ! Photodissociation rate O3->O1D (s-1)
 
 !=======================================================================
@@ -592,8 +596,8 @@
 !=======================================================================
 
-      do ig = 1,ngridmx
+      do ig = 1,ngrid
          
          foundswitch = 0
-         do l = 1,nlayermx
+         do l = 1,nlayer
             do i = 1,nbq
                iq = niq(i) ! get tracer index
@@ -626,8 +630,8 @@
             end if
             if (.not. thermochem) then
-               lswitch = min(50,nlayermx+1)
+               lswitch = min(50,nlayer+1)
             end if
 
-         end do ! of do l=1,nlayermx
+         end do ! of do l=1,nlayer
 
          szacol = acos(mu0(ig))*180./pi
@@ -647,5 +651,5 @@
 !        ozone photolysis, for output
 
-            do l = 1,nlayermx
+            do l = 1,nlayer
                jo3_3d(ig,l) = jo3(l)
             end do
@@ -653,5 +657,6 @@
 !        condensation of h2o2
 
-            call perosat(ig,ptimestep,pplev,pplay,                 &
+            call perosat(ngrid, nlayer, nq,                        &
+                         ig,ptimestep,pplev,pplay,                 &
                          ztemp,zycol,dqcloud,dqscloud)
          end if
@@ -667,5 +672,6 @@
 
          if (depos) then
-            call deposition(ig, ig_vl1, pplay, pplev, zzlay, zzlev,& 
+            call deposition(ngrid, nlayer, nq,                      &
+                            ig, ig_vl1, pplay, pplev, zzlay, zzlev, & 
                             zu, zv, zt, zycol, ptimestep, co2ice)
          end if
@@ -679,5 +685,5 @@
 
 !     tendency for the most abundant species = - sum of others
-         do l = 1,nlayermx
+         do l = 1,nlayer
             iloc=maxloc(zycol(l,:))
             iqmax=iloc(1)
@@ -691,5 +697,5 @@
                end if
             end do
-         end do ! of do l = 1,nlayermx
+         end do ! of do l = 1,nlayer
 
 !=======================================================================
@@ -697,5 +703,5 @@
 !=======================================================================
 
-      end do ! of do ig=1,ngridmx
+      end do ! of do ig=1,ngrid
 
 !=======================================================================
@@ -707,12 +713,12 @@
 
       if (photochem .and. output) then
-         if (ngridmx > 1) then
-            call writediagfi(ngridmx,'jo3','j o3->o1d',    &
+         if (ngrid > 1) then
+            call writediagfi(ngrid,'jo3','j o3->o1d',    &
                              's-1',3,jo3_3d(1,1))
            if (callstats) then
-              call wstats(ngridmx,'jo3','j o3->o1d',       &
+              call wstats(ngrid,'jo3','j o3->o1d',       &
                           's-1',3,jo3_3d(1,1))
            endif
-         end if ! of if (ngridmx.gt.1)
+         end if ! of if (ngrid.gt.1)
       end if ! of if (output)
 
