Index: /trunk/LMDZ.GENERIC/README
===================================================================
--- /trunk/LMDZ.GENERIC/README	(revision 470)
+++ /trunk/LMDZ.GENERIC/README	(revision 471)
@@ -565,2 +565,8 @@
 M              469   libf/phystd/radinc_h.F90
 M              469   libf/phystd/radcommon_h.F90
+
+== 13/12/2011 == AS
+- Same spirit as previous commit, but for ngasmx which is now read in gases.def -- before arrays w/ dim ngasmx are allocated dynamically
+- Allocation is done in su_gases.F90 which is called in inifis
+- Outside su_gases.F90, very few modifications to the code : the new module "gases_h.F90" simply replaces the old common "gases.h" !
+- Compiles fine. Tested with debugging options through pgdbg. Runs fine. Exact same results in Early Mars test case.
Index: /trunk/LMDZ.GENERIC/libf/phystd/calc_cpp_mugaz.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/calc_cpp_mugaz.F90	(revision 470)
+++ /trunk/LMDZ.GENERIC/libf/phystd/calc_cpp_mugaz.F90	(revision 471)
@@ -13,9 +13,9 @@
 !==================================================================
 
+      use gases_h
       implicit none
 
 #include "comcstfi.h"
 !#include "callkeys.h"
-#include "gases.h"
 
       integer igas
Index: /trunk/LMDZ.GENERIC/libf/phystd/calc_rayleigh.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/calc_rayleigh.F90	(revision 470)
+++ /trunk/LMDZ.GENERIC/libf/phystd/calc_rayleigh.F90	(revision 471)
@@ -26,4 +26,5 @@
       use radinc_h, only: L_NSPECTV
       use radcommon_h, only: WAVEV, BWNV, DWNV, tstellar, tauray, scalep
+      use gases_h
 
       implicit none
@@ -31,5 +32,4 @@
 #include "comcstfi.h"
 #include "callkeys.h"
-#include "gases.h"
 
       real*8 wl
Index: /trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90	(revision 470)
+++ /trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90	(revision 471)
@@ -13,4 +13,5 @@
       use datafile_mod, only: datadir
       use ioipsl_getincom 
+      use gases_h
 
       implicit none
@@ -35,5 +36,4 @@
 #include "callkeys.h"
 #include "tracer.h"
-#include "gases.h"
 
 !-----------------------------------------------------------------------
Index: /trunk/LMDZ.GENERIC/libf/phystd/condens_co2cloud.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/condens_co2cloud.F90	(revision 470)
+++ /trunk/LMDZ.GENERIC/libf/phystd/condens_co2cloud.F90	(revision 471)
@@ -7,4 +7,5 @@
 
       use radinc_h, only : naerkind
+      use gases_h
 
       implicit none
@@ -56,5 +57,4 @@
 #include "callkeys.h"
 #include "tracer.h"
-#include "gases.h"
 
 !-----------------------------------------------------------------------
Index: /trunk/LMDZ.GENERIC/libf/phystd/condense_cloud.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/condense_cloud.F90	(revision 470)
+++ /trunk/LMDZ.GENERIC/libf/phystd/condense_cloud.F90	(revision 471)
@@ -7,4 +7,5 @@
 
       use radinc_h, only : naerkind
+      use gases_h
 
       implicit none
@@ -56,5 +57,4 @@
 #include "callkeys.h"
 #include "tracer.h"
-#include "gases.h"
 
 !-----------------------------------------------------------------------
Index: /trunk/LMDZ.GENERIC/libf/phystd/cp_neutral.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/cp_neutral.F90	(revision 470)
+++ /trunk/LMDZ.GENERIC/libf/phystd/cp_neutral.F90	(revision 471)
@@ -1,7 +1,7 @@
 double precision function cp_neutral(T)
 
+  use gases_h
+
   implicit none
-
-#include "gases.h"
 
   ! inputs
Index: unk/LMDZ.GENERIC/libf/phystd/gases.h
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/gases.h	(revision 470)
+++ 	(revision )
@@ -1,12 +1,0 @@
-!-----------------------------------------------------------------------
-! INCLUDE 'gases.h'
-
-      integer, parameter :: ngasmx = 2 
-      integer vgas
-      character*3 :: gnom(ngasmx) ! name of the gas
-!      character(len=3) :: gnom(ngasmx) ! name of the gas
-      real gfrac(ngasmx)
-
-      COMMON/gases/gnom,vgas,gfrac
-
-!-----------------------------------------------------------------------
Index: /trunk/LMDZ.GENERIC/libf/phystd/gases_h.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/gases_h.F90	(revision 471)
+++ /trunk/LMDZ.GENERIC/libf/phystd/gases_h.F90	(revision 471)
@@ -0,0 +1,19 @@
+      module gases_h
+
+      implicit none
+
+!======================================================================C
+!
+!     GASES_H    
+!
+!     THIS A F90-ALLOCATABLE VERSION FOR gases.h -- AS 12/2011
+!
+!======================================================================C
+
+      !!! THOSE ARE SET AND ALLOCATED IN su_gases.F90
+      integer :: ngasmx
+      integer :: vgas
+      character*3,allocatable,DIMENSION(:) :: gnom ! name of the gas
+      real,allocatable,DIMENSION(:) :: gfrac
+
+      end module gases_h
Index: /trunk/LMDZ.GENERIC/libf/phystd/gradients_kcm.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/gradients_kcm.F90	(revision 470)
+++ /trunk/LMDZ.GENERIC/libf/phystd/gradients_kcm.F90	(revision 471)
@@ -2,7 +2,6 @@
 
   use params_h
+  use gases_h
   implicit none
-
-#include "gases.h"
 
   ! inputs
Index: /trunk/LMDZ.GENERIC/libf/phystd/kcmprof_fn.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/kcmprof_fn.F90	(revision 470)
+++ /trunk/LMDZ.GENERIC/libf/phystd/kcmprof_fn.F90	(revision 471)
@@ -3,4 +3,5 @@
 use params_h
 use watercommon_h, only : mH2O
+use gases_h
 implicit none
 
@@ -15,5 +16,4 @@
 #include "comcstfi.h"
 #include "callkeys.h"
-#include "gases.h"
 
   integer ilay, nlay
Index: /trunk/LMDZ.GENERIC/libf/phystd/optci.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/optci.F90	(revision 470)
+++ /trunk/LMDZ.GENERIC/libf/phystd/optci.F90	(revision 471)
@@ -5,4 +5,5 @@
       use radinc_h
       use radcommon_h, only: gasi, tlimit, wrefVAR, Cmk,tgasref,pfgasref,wnoi,scalep
+      use gases_h
       implicit none
 
@@ -30,5 +31,4 @@
 #include "comcstfi.h"
 #include "callkeys.h"
-#include "gases.h"
 
 
Index: /trunk/LMDZ.GENERIC/libf/phystd/optcv.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/optcv.F90	(revision 470)
+++ /trunk/LMDZ.GENERIC/libf/phystd/optcv.F90	(revision 471)
@@ -5,4 +5,5 @@
       use radinc_h
       use radcommon_h, only: gasv, tlimit, wrefVAR, Cmk, tgasref, pfgasref,wnov,scalep
+      use gases_h
 
       implicit none
@@ -36,5 +37,4 @@
 #include "callkeys.h"
 #include "comcstfi.h"
-#include "gases.h"
 
       real*8 DTAUV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
Index: /trunk/LMDZ.GENERIC/libf/phystd/physiq.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/physiq.F90	(revision 470)
+++ /trunk/LMDZ.GENERIC/libf/phystd/physiq.F90	(revision 471)
@@ -9,5 +9,5 @@
       use radinc_h, only : naerkind
       use watercommon_h, only : mx_eau_sol, To, RLVTT, mH2O
-     
+      use gases_h
       implicit none
 
@@ -2147,4 +2147,11 @@
       icount=icount+1
 
+      !!! DEALLOCATE STUFF
+      if (lastcall) then
+        IF ( ALLOCATED( gnom ) ) DEALLOCATE( gnom )    !! this was allocated in su_gases.F90
+        IF ( ALLOCATED( gfrac ) ) DEALLOCATE( gfrac )  !! this was allocated in su_gases.F90
+      endif
+
+
       return
     end subroutine physiq
Index: /trunk/LMDZ.GENERIC/libf/phystd/su_gases.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/su_gases.F90	(revision 470)
+++ /trunk/LMDZ.GENERIC/libf/phystd/su_gases.F90	(revision 471)
@@ -1,9 +1,9 @@
 subroutine su_gases
+
+  use gases_h
 
   implicit none
 
-#include "gases.h"
-
-       integer ngas, igas, ierr
+       integer igas, ierr
 
 !==================================================================
@@ -24,5 +24,5 @@
           write(*,*) "sugases.F90: reading file gases.def"
           read(90,*)
-          read(90,*,iostat=ierr) ngas
+          read(90,*,iostat=ierr) ngasmx
           if (ierr.ne.0) then
              write(*,*) "sugases.F90: error reading number of gases"
@@ -30,13 +30,9 @@
              call abort
           endif
-          ! check that the number of gases is indeed ngasmx
-          if (ngas.ne.ngasmx) then
-             write(*,*) "sugases.F90: error, wrong number of gases:"
-             write(*,*) "ngas=",ngas," whereas ngasmx=",ngasmx
-             write(*,*) "Check that the values in gases.def and gases.h match..."
-             call abort
-          endif
 
-          do igas=1,ngas
+          PRINT *, "OK I HAVE ",ngasmx, " GASES. NOW I ALLOCATE ARRAYS AND READ NAMES AND FRAC."
+
+          IF ( .NOT. ALLOCATED( gnom ) ) ALLOCATE( gnom( ngasmx ) )
+          do igas=1,ngasmx
              read(90,*,iostat=ierr) gnom(igas)
              if (ierr.ne.0) then
@@ -44,8 +40,9 @@
                 call abort
              endif
-          enddo                  !of do igas=1,ngas
+          enddo                  !of do igas=1,ngasmx
           
           vgas=0
-          do igas=1,ngas
+          IF ( .NOT. ALLOCATED( gfrac ) ) ALLOCATE( gfrac( ngasmx ) )
+          do igas=1,ngasmx
              read(90,*,iostat=ierr) gfrac(igas)
              if (ierr.ne.0) then
@@ -65,5 +62,5 @@
              endif
              
-          enddo                  !of do igas=1,ngas
+          enddo                  !of do igas=1,ngasmx
 
        else
Index: /trunk/LMDZ.GENERIC/libf/phystd/sugas_corrk.F90
===================================================================
--- /trunk/LMDZ.GENERIC/libf/phystd/sugas_corrk.F90	(revision 470)
+++ /trunk/LMDZ.GENERIC/libf/phystd/sugas_corrk.F90	(revision 471)
@@ -24,8 +24,8 @@
       use radcommon_h, only : wrefvar,gastype
       use datafile_mod, only: datadir
+      use gases_h
       implicit none
 
 #include "callkeys.h"
-#include "gases.h"
 
 !==================================================================
