Index: trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90	(revision 374)
+++ trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90	(revision 470)
@@ -892,3 +892,13 @@
       endif
 
+      !!! see physiq.F for explanations about CLFvarying. This is temporary.
+      if (lastcall .and. .not.CLFvarying) then
+        IF( ALLOCATED( gasi ) ) DEALLOCATE( gasi )
+        IF( ALLOCATED( gasv ) ) DEALLOCATE( gasv )
+        IF( ALLOCATED( pgasref ) ) DEALLOCATE( pgasref )
+        IF( ALLOCATED( tgasref ) ) DEALLOCATE( tgasref )
+        IF( ALLOCATED( wrefvar ) ) DEALLOCATE( wrefvar )
+        IF( ALLOCATED( pfgasref ) ) DEALLOCATE( pfgasref )
+      endif
+
     end subroutine callcorrk
Index: trunk/LMDZ.GENERIC/libf/phystd/physiq.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/physiq.F90	(revision 374)
+++ trunk/LMDZ.GENERIC/libf/phystd/physiq.F90	(revision 470)
@@ -724,4 +724,8 @@
               if(CLFvarying)then
 
+               !!! THIS IS NOT A VERY GOOD STRATEGY HERE (everything should be in callcorrk)
+               !!! ---> PROBLEMS WITH ALLOCATED ARRAYS 
+               !!! (temporary solution in callcorrk: do not deallocate if CLFvarying ...)
+
                  clearsky=.true.
                  call callcorrk(ngrid,nlayer,pq,nq,qsurf,           &
Index: trunk/LMDZ.GENERIC/libf/phystd/radcommon_h.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/radcommon_h.F90	(revision 374)
+++ trunk/LMDZ.GENERIC/libf/phystd/radcommon_h.F90	(revision 470)
@@ -72,9 +72,9 @@
       REAL*8 blamv(L_NSPECTV+1) ! these are needed by suaer.F90
 
-      real*8 gasi(L_NTREF,L_PINT,L_REFVAR,L_NSPECTI,L_NGAUSS)
-      real*8 gasv(L_NTREF,L_PINT,L_REFVAR,L_NSPECTV,L_NGAUSS)
+      !!! ALLOCATABLE STUFF SO THAT DIMENSIONS ARE READ in *.dat FILES -- AS 12/2011  
+      REAL*8, DIMENSION(:,:,:,:,:), ALLOCATABLE :: gasi, gasv
+      REAL*8, DIMENSION(:), ALLOCATABLE :: PGASREF, TGASREF, WREFVAR, PFGASREF
       real*8 FZEROI(L_NSPECTI)
       real*8 FZEROV(L_NSPECTV)
-      real*8 PGASREF(L_NPREF), TGASREF(L_NTREF)
       real*8 pgasmin, pgasmax
       real*8 tgasmin, tgasmax
@@ -88,5 +88,4 @@
       real gir(L_NSPECTI,naerkind,nsizemax)
 
-      real*8 WREFVAR(L_REFVAR)
 
 ! Reference wavelengths used to compute reference optical depth (m)
@@ -119,5 +118,4 @@
 
       real*8 PTOP, TAUREF(L_LEVELS+1)
-      real*8 pfgasref(L_PINT) ! finer reference grid for some reason
 
       real*8, parameter :: UBARI = 0.5D0
Index: trunk/LMDZ.GENERIC/libf/phystd/radinc_h.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/radinc_h.F90	(revision 374)
+++ trunk/LMDZ.GENERIC/libf/phystd/radinc_h.F90	(revision 470)
@@ -60,49 +60,14 @@
       integer, parameter :: L_NLEVRAD  = llm+1
 
-!     Below are various parameter combinations that will work for the 
-!     radiative datasets indicated. For the moment, you must change these
-!     values manually before compiling, each time you want to change the
-!     dataset.
- 
+      !!!! THIS IS SET IN sugas_corrk
+      !!!! [use of allocatable arrays] -- AS 12/2011
+      integer :: L_NPREF, L_NTREF, L_REFVAR, L_PINT
+
+!!! THIS ONE DOES NOT CHANGE MUCH... IT CAN BE REGARDED AS A CONSTANT.
       integer, parameter :: L_NGAUSS  = 17
-
-      integer, parameter :: L_NPREF   = 9
-      integer, parameter :: L_NTREF   = 7
-      integer, parameter :: L_REFVAR  = 7   ! earth / earlymars
-!      ! CO2_H2Ovar / N2OCO2rich_H2Ovar / N2OCO2poor_H2Ovar
-!       integer, parameter :: L_REFVAR = 4    ! N2_CH4
-
-!      integer, parameter :: L_NPREF   = 8
-!      integer, parameter :: L_NTREF   = 11
-!      integer, parameter :: L_REFVAR  = 8   ! N2_H2Ovar
-
-!      integer, parameter :: L_NPREF   = 8
-!      integer, parameter :: L_NTREF   = 5
-!      integer, parameter :: L_REFVAR  = 1   ! therm_test2
-
-!      integer, parameter :: L_NPREF   = 12
-!      integer, parameter :: L_NTREF   = 20
-!      integer, parameter :: L_REFVAR  = 1   ! null (for H2 etc.)
-
-!      integer, parameter :: L_NPREF   = 10
-!      integer, parameter :: L_NTREF   = 5
-!      integer, parameter :: L_REFVAR  = 7   ! N2_CO2var
-
-!      integer, parameter :: L_NPREF   = 8
-!      integer, parameter :: L_NTREF   = 6
-!      integer, parameter :: L_REFVAR  = 1   ! pureCO2
-
-!      integer, parameter :: L_NPREF   = 7
-!      integer, parameter :: L_NTREF   = 5
-!      integer, parameter :: L_REFVAR  = 1   ! degraded_pure
-
-!      integer, parameter :: L_NPREF   = 9
-!      integer, parameter :: L_NTREF   = 14
-!      integer, parameter :: L_REFVAR  = 1   ! megaCO2
 
       integer, parameter :: L_NSPECTI = NBinfrared
       integer, parameter :: L_NSPECTV = NBvisible
 
-      integer, parameter :: L_PINT    = (L_NPREF-1)*5+1
       integer, parameter :: NAERKIND  = 2
       real,    parameter :: L_TAUMAX  = 35
Index: trunk/LMDZ.GENERIC/libf/phystd/sugas_corrk.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/sugas_corrk.F90	(revision 374)
+++ trunk/LMDZ.GENERIC/libf/phystd/sugas_corrk.F90	(revision 470)
@@ -34,11 +34,11 @@
 
       integer n, nt, np, nh, ng, nw, m, i
-      integer L_NGAUSScheck, L_NPREFcheck, L_NTREFcheck, L_REFVARcheck
+      integer L_NGAUSScheck
 
       character(len=100) :: file_id
       character(len=300) :: file_path
 
-      real*8 gasi8(L_NTREF,L_NPREF,L_REFVAR,L_NSPECTI,L_NGAUSS)
-      real*8 gasv8(L_NTREF,L_NPREF,L_REFVAR,L_NSPECTV,L_NGAUSS)
+      !! ALLOCATABLE ARRAYS -- AS 12/2011
+      REAL*8, DIMENSION(:,:,:,:,:), ALLOCATABLE :: gasi8, gasv8
 
       real*8 x, xi(4), yi(4), ans, p
@@ -103,15 +103,8 @@
       enddo
 
-      ! check the array size is correct, load the coefficients
-      open(111,file=file_path(1:LEN_TRIM(file_path)),form='formatted')
-      read(111,*) L_REFVARcheck
-      if(.not.(L_REFVARcheck.eq.L_REFVAR)) then   
-         print*,   L_REFVARcheck
-         print*,   L_REFVAR
-         print*,'The size of your radiative transfer mixing ratio array does '
-         print*,'not match the value given in Q.dat, exiting.'
-         print*,'Check the value of L_NREFVAR in radinc_h.F90.'
-         call abort
-      endif
+      ! GET array size, load the coefficients
+      open(111,file=TRIM(file_path),form='formatted')
+      read(111,*) L_REFVAR
+      IF( .NOT. ALLOCATED( wrefvar ) ) ALLOCATE( WREFVAR(L_REFVAR) )
       read(111,*) wrefvar
       close(111)
@@ -165,5 +158,5 @@
       read(111,*) gweight
       close(111)
-
+ 
       ! display the values
       print*,'Correlated-k g-space grid:'
@@ -194,15 +187,14 @@
          call abort
       endif
-      
-      ! check the array size is correct, load the coefficients
+     
+      ! GET array size, load the coefficients
       open(111,file=TRIM(file_path),form='formatted')
-      read(111,*) L_NPREFcheck
-      if(.not.(L_NPREFcheck.eq.L_NPREF)) then
-         print*,'The size of your radiative transfer pressure array does '
-         print*,'not match the value given in p.dat, exiting.'
-         call abort
-      endif
+      read(111,*) L_NPREF
+      IF( .NOT. ALLOCATED( pgasref ) ) ALLOCATE( PGASREF(L_NPREF) )
       read(111,*) pgasref
       close(111)
+      L_PINT = (L_NPREF-1)*5+1
+      IF( .NOT. ALLOCATED( pfgasref ) ) ALLOCATE( PFGASREF(L_PINT) )
+
 
       ! display the values
@@ -244,12 +236,8 @@
       endif
 
-      ! check the array size is correct, load the coefficients
+      ! GET array size, load the coefficients
       open(111,file=TRIM(file_path),form='formatted')
-      read(111,*) L_NTREFcheck
-      if(.not.(L_NTREFcheck.eq.L_NTREF)) then
-         print*,'The size of your radiative transfer temperature array does '
-         print*,'not match the value given in T.dat, exiting.'
-         call abort
-      endif
+      read(111,*) L_NTREF
+      IF( .NOT. ALLOCATED( tgasref ) ) ALLOCATE( TGASREF(L_NTREF) )
       read(111,*) tgasref
       close(111)
@@ -264,4 +252,18 @@
       tgasmin = tgasref(1)
       tgasmax = tgasref(L_NTREF)
+
+
+!-----------------------------------------------------------------------
+!-----------------------------------------------------------------------
+! ALLOCATE THE MULTIDIM ARRAYS IN radcommon_h
+      PRINT *, L_NTREF,L_NPREF,L_REFVAR 
+      IF( .NOT. ALLOCATED( gasi8 ) ) ALLOCATE( gasi8(L_NTREF,L_NPREF,L_REFVAR,L_NSPECTI,L_NGAUSS) )
+      IF( .NOT. ALLOCATED( gasv8 ) ) ALLOCATE( gasv8(L_NTREF,L_NPREF,L_REFVAR,L_NSPECTV,L_NGAUSS) )
+      IF( .NOT. ALLOCATED( gasi ) ) ALLOCATE( gasi(L_NTREF,L_PINT,L_REFVAR,L_NSPECTI,L_NGAUSS) )
+      IF( .NOT. ALLOCATED( gasv ) ) ALLOCATE( gasv(L_NTREF,L_PINT,L_REFVAR,L_NSPECTV,L_NGAUSS) )
+!-----------------------------------------------------------------------
+!-----------------------------------------------------------------------
+
+
 
 !=======================================================================
@@ -308,5 +310,5 @@
          read(111,*) gasi8
          close(111)
-      
+     
          do nw=1,L_NSPECTI
             fzeroi(nw) = 0.
@@ -530,4 +532,10 @@
       enddo
 
+      !!! DEALLOCATE LOCAL ARRAYS
+      IF( ALLOCATED( gasi8 ) ) DEALLOCATE( gasi8 )
+      IF( ALLOCATED( gasv8 ) ) DEALLOCATE( gasv8 )
+      IF( ALLOCATED( pgasref ) ) DEALLOCATE( pgasref )
+
+
       return
     end subroutine sugas_corrk
