Index: trunk/LMDZ.GENERIC/libf/phystd/calc_cpp_mugaz.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/calc_cpp_mugaz.F90	(revision 586)
+++ trunk/LMDZ.GENERIC/libf/phystd/calc_cpp_mugaz.F90	(revision 588)
@@ -80,5 +80,8 @@
          R     = 8.314511E+0 *1000.E+0/mugaz
          rcp   = R/cpp
-      elseif((cpp.ne.cpp_c) .or. (mugaz.ne.mugaz_c))then
+!      elseif((cpp.ne.cpp_c) .or. (mugaz.ne.mugaz_c))then
+         ! Ehouarn: tolerate a small mismatch between computed/stored values
+       elseif((abs(1.-cpp/cpp_c).gt.1.e-6) .or.  &
+              (abs(1.-mugaz/mugaz_c).gt.1.e-6)) then
          if(check_cpp_match)then
             print*,'Values do not match!'
Index: trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90	(revision 586)
+++ trunk/LMDZ.GENERIC/libf/phystd/callcorrk.F90	(revision 588)
@@ -522,6 +522,6 @@
                temp=aerosol(ig,L_NLAYRAD-k,iaer)/QREFvis3d(ig,L_NLAYRAD-k,iaer)
 
-               tauaero(2*k+2,iaer)=max(temp*pweight,0.0)
-               tauaero(2*k+3,iaer)=max(temp-tauaero(2*k+2,iaer),0.0)
+               tauaero(2*k+2,iaer)=max(temp*pweight,0.d0)
+               tauaero(2*k+3,iaer)=max(temp-tauaero(2*k+2,iaer),0.d0)
 !
             end do
Index: trunk/LMDZ.GENERIC/libf/phystd/datareadnc.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/datareadnc.F	(revision 586)
+++ trunk/LMDZ.GENERIC/libf/phystd/datareadnc.F	(revision 588)
@@ -43,4 +43,6 @@
 
       use datafile_mod, only: datadir
+! to use  'getin'
+      USE ioipsl_getincom 
       implicit none
 
@@ -77,6 +79,5 @@
       REAL        zthe(imdp1*jmdp1)
 
-      INTEGER   lnblnk, ierr
-      EXTERNAL    lnblnk
+      INTEGER   ierr
 
       INTEGER   unit,nvarid
@@ -110,5 +111,7 @@
 c    Lecture NetCDF des donnees latitude et longitude
 c-----------------------------------------------------------------------
-
+!    First get the corret value of dtadir, if not already done:
+      ! default 'datadir' is set in "datadir_mod"
+      call getin("datadir",datadir)
       write(*,*) 'Choice of surface data is:'
       filestring='ls '//trim(datadir)//'/*.nc'
Index: trunk/LMDZ.GENERIC/libf/phystd/def_var.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/def_var.F90	(revision 586)
+++ trunk/LMDZ.GENERIC/libf/phystd/def_var.F90	(revision 588)
@@ -27,6 +27,6 @@
 ierr=NF_REDEF(nid)
 
-print*,'in def_var.F90, dimids='
-print*,dimids
+!print*,'in def_var.F90, dimids='
+!print*,dimids
 
 ! 2. Define the variable
Index: trunk/LMDZ.GENERIC/libf/phystd/physdem1.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/physdem1.F	(revision 586)
+++ trunk/LMDZ.GENERIC/libf/phystd/physdem1.F	(revision 588)
@@ -48,5 +48,5 @@
       REAL day_ini
       INTEGER nsoil,nq
-      integer ierr,idim1,idim2,idim3,idim4,idim5,nvarid
+      integer ierr,idim1,idim2,idim3,idim4,idim5,idim6,nvarid
 
       REAL phystep,time
@@ -82,6 +82,4 @@
       real pzsig(ngridmx),pzgam(ngridmx),pzthe(ngridmx)
       integer ig
-      INTEGER lnblnk
-      EXTERNAL lnblnk
 
 ! flag which identifies if we are using old tracer names (qsurf01,...)
@@ -144,5 +142,4 @@
       endif
 c
-!      ierr = NF_DEF_DIM (nid,"nlayer+1",llm+1,idim4)
       ierr = NF_DEF_DIM (nid,"nlayer_plus_1",llm+1,idim4)
       if (ierr.ne.NF_NOERR) then
@@ -157,4 +154,11 @@
         WRITE(6,*)' nq = ',nq,' and ierr = ', ierr
         write(6,*) NF_STRERROR(ierr)
+      endif
+
+      ierr = NF_DEF_DIM (nid,"nlayer",llm,idim6)
+      if (ierr.ne.NF_NOERR) then
+        WRITE(6,*)'physdem1: Problem defining nlayer dimension'
+        write(6,*) NF_STRERROR(ierr)
+	call abort
       endif
 
@@ -448,24 +452,4 @@
 c Write the physical fields
 
-! CO2 Ice Cover
-!
-!      ierr = NF_REDEF (nid)
-!#ifdef NC_DOUBLE
-!      ierr = NF_DEF_VAR (nid, "co2ice", NF_DOUBLE, 1, idim2,nvarid)
-!#else
-!      ierr = NF_DEF_VAR (nid, "co2ice", NF_FLOAT, 1, idim2,nvarid)
-!#endif
-!      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 13,
-!     .                        "CO2 ice cover")
-!      ierr = NF_ENDDEF(nid)
-!#ifdef NC_DOUBLE
-!      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,co2ice)
-!#else
-!      ierr = NF_PUT_VAR_REAL (nid,nvarid,co2ice)
-!#endif
-
-
-
-
 
 ! Soil Thermal inertia
@@ -574,7 +558,9 @@
       ierr = NF_REDEF (nid)
 #ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid, "cloudfrac", NF_DOUBLE, 1, idim2,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid, "cloudfrac", NF_FLOAT, 1, idim2,nvarid)
+      ierr = NF_DEF_VAR (nid, "cloudfrac", NF_DOUBLE, 2,
+     & (/idim2,idim6/),nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "cloudfrac", NF_FLOAT, 2,
+     & (/idim2,idim6/),nvarid)
 #endif
       ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 14,
Index: trunk/LMDZ.GENERIC/libf/phystd/physiq.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/physiq.F90	(revision 586)
+++ trunk/LMDZ.GENERIC/libf/phystd/physiq.F90	(revision 588)
@@ -209,11 +209,10 @@
       real latvl1,lonvl1             ! Viking Lander 1 point (for diagnostic)
 
-      real reffrad(ngridmx,nlayermx,naerkind)                 ! aerosol effective radius (m)
+      real,save :: reffrad(ngridmx,nlayermx,naerkind) ! aerosol effective radius (m)
 
 !     Tendencies due to various processes:
       real dqsurf(ngridmx,nqmx)
-      real zdtlw(ngridmx,nlayermx)                            ! (K/s)
-      real zdtsw(ngridmx,nlayermx)                            ! (K/s)
-      save zdtlw, zdtsw
+      real,save :: zdtlw(ngridmx,nlayermx)                    ! (K/s)
+      real,save :: zdtsw(ngridmx,nlayermx)                    ! (K/s)
 
       real cldtlw(ngridmx,nlayermx)                           ! (K/s) LW heating rate for clear areas
@@ -1724,8 +1723,8 @@
             if((ngridmx.gt.1) .or. (mod(icount-1,nint(ecritphy)).eq.0))then
                ! to record global radiative balance
-               open(92,file="rad_bal.out",form='formatted',access='append')
+               open(92,file="rad_bal.out",form='formatted',position='append')
                write(92,*) zday,ISR/totarea,ASR/totarea,OLR/totarea
                close(92)
-               open(93,file="tem_bal.out",form='formatted',access='append')
+               open(93,file="tem_bal.out",form='formatted',position='append')
                write(93,*) zday,Ts1,Ts2,Ts3,TsS
                close(93)
@@ -1739,5 +1738,5 @@
 !     ------------------------------------------------------------------
       if(testradtimes)then
-         open(38,file="tau_phys.out",form='formatted',access='append')
+         open(38,file="tau_phys.out",form='formatted',position='append')
          ig=1
          do l=1,nlayer
@@ -1813,5 +1812,5 @@
             if((ngridmx.gt.1) .or. (mod(icount-1,nint(ecritphy)).eq.0))then
                ! to record global water balance
-               open(98,file="h2o_bal.out",form='formatted',access='append')
+               open(98,file="h2o_bal.out",form='formatted',position='append')
                write(98,*) zday,icesrf/totarea,liqsrf/totarea,icecol/totarea,vapcol/totarea
                close(98)
Index: trunk/LMDZ.GENERIC/libf/phystd/tabfi.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/tabfi.F	(revision 586)
+++ trunk/LMDZ.GENERIC/libf/phystd/tabfi.F	(revision 588)
@@ -176,4 +176,5 @@
       mugaz = tab_cntrl(tab0+8)
       rcp = tab_cntrl(tab0+9)
+      cpp=(8.314511/(mugaz/1000.0))/rcp
       daysec = tab_cntrl(tab0+10)
       dtphys = tab_cntrl(tab0+11)
@@ -502,5 +503,5 @@
           write(*,*) 
           write(*,*) ' mugaz (new value):',mugaz
-          r=8.314/(mugaz/1000.0)
+          r=8.314511/(mugaz/1000.0)
           write(*,*) ' R (new value):',r
 
@@ -512,4 +513,5 @@
           write(*,*) 
           write(*,*) ' rcp (new value):',rcp
+          r=8.314511/(mugaz/1000.0)
           cpp=r/rcp
           write(*,*) ' cpp (new value):',cpp
