Index: LMDZ5/branches/testing/libf/dyn3dmem/addfi_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/addfi_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/addfi_loc.F	(revision 2641)
@@ -46,9 +46,7 @@
 c    ------------------
 c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comgeom.h"
-#include "serre.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
 c
 c    Arguments :
Index: LMDZ5/branches/testing/libf/dyn3dmem/advect_new_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/advect_new_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/advect_new_loc.F	(revision 2641)
@@ -7,4 +7,7 @@
       USE write_field_loc
       USE advect_new_mod
+      USE comconst_mod, ONLY: daysec
+      USE logic_mod, ONLY: conser
+      
       IMPLICIT NONE
 c=======================================================================
@@ -27,11 +30,7 @@
 c   -------------
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom.h"
-#include "logic.h"
-#include "ener.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
 
 c   Arguments:
@@ -61,5 +60,5 @@
 c   -------------------------
       
-      IF (conser)  THEN
+      IF (conser.AND.1==0)  THEN
          deuxjour = 2. * daysec
 
@@ -122,5 +121,5 @@
                   
            uav(ij,l)=0.25*(ucov(ij,l)+ucov(ij-iip1,l))
-     .	             +0.25*(ucov(ij+iip1,l)+ucov(ij,l))
+     .               +0.25*(ucov(ij+iip1,l)+ucov(ij,l))
          ENDDO
          
Index: LMDZ5/branches/testing/libf/dyn3dmem/advtrac_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/advtrac_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/advtrac_loc.F	(revision 2641)
@@ -27,16 +27,12 @@
       USE control_mod, ONLY: iapp_tracvl, day_step, planet_type
       USE advtrac_mod, ONLY: finmasse
+      USE comconst_mod, ONLY: dtvr
       IMPLICIT NONE
 c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comdissip.h"
-#include "comgeom2.h"
-#include "logic.h"
-#include "temps.h"
-#include "ener.h"
-#include "description.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comdissip.h"
+      include "comgeom2.h"
+      include "description.h"
 
 c-------------------------------------------------------------------
@@ -172,5 +168,5 @@
 #endif
          
-	  GOTO 1234     
+          GOTO 1234     
 c-----------------------------------------------------------
 c     Appel des sous programmes d'advection
@@ -184,5 +180,5 @@
         if(iadv(iq).eq.10) THEN
      
-!LF	    call vlsplt_p(q(1,1,iq),2.,massem,wg,pbarug,pbarvg,dtvr)
+!LF            call vlsplt_p(q(1,1,iq),2.,massem,wg,pbarug,pbarvg,dtvr)
 
 c   ----------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dmem/bernoui_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/bernoui_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/bernoui_loc.F	(revision 2641)
@@ -24,7 +24,6 @@
 c   -------------
 c
-#include "dimensions.h"
-#include "paramet.h"
-#include "logic.h"
+      include "dimensions.h"
+      include "paramet.h"
 c
 c   Arguments:
Index: LMDZ5/branches/testing/libf/dyn3dmem/bilan_dyn_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/bilan_dyn_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/bilan_dyn_loc.F	(revision 2641)
@@ -17,13 +17,14 @@
       use misc_mod
       USE write_field_loc
+      USE comconst_mod, ONLY: cpp, pi
+      USE comvert_mod, ONLY: presnivs
+      USE temps_mod, ONLY: annee_ref, day_ref, itau_dyn
+      
       IMPLICIT NONE
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom2.h"
-#include "temps.h"
-#include "iniprint.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom2.h"
+      include "iniprint.h"
 
 c====================================================================
@@ -598,5 +599,5 @@
         do l=1,llm
           Q_cum(:,jjb:jje,l,iQ)=Q_cum(:,jjb:jje,l,iQ) 
-     .	                        /masse_cum(:,jjb:jje,l)
+     .                                /masse_cum(:,jjb:jje,l)
         enddo
 !$OMP ENDDO NOWAIT 
Index: LMDZ5/branches/testing/libf/dyn3dmem/caladvtrac_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/caladvtrac_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/caladvtrac_loc.F	(revision 2641)
@@ -29,7 +29,6 @@
 
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
+      include "dimensions.h"
+      include "paramet.h"
 
 c   Arguments:
@@ -210,5 +209,5 @@
 	call resume_timer(timer_caldyn)
 c$OMP END MASTER
-c$OMP BARRIER	
+c$OMP BARRIER
           iadvtr=0
        ENDIF ! if iadvtr.EQ.iapp_tracvl
Index: LMDZ5/branches/testing/libf/dyn3dmem/caldyn_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/caldyn_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/caldyn_loc.F	(revision 2641)
@@ -12,4 +12,5 @@
       USE caldyn_mod, ONLY: vcont, ucont, ang, p, massebx, masseby,
      &                      vorpot, ecin, bern, massebxy, convm
+      USE comvert_mod, ONLY: ap, bp
       
       IMPLICIT NONE
@@ -31,9 +32,7 @@
 !   ----------------
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
 
 !   Arguments:
Index: LMDZ5/branches/testing/libf/dyn3dmem/call_calfis_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/call_calfis_mod.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/call_calfis_mod.F90	(revision 2641)
@@ -82,9 +82,10 @@
   USE write_field_loc
   USE write_field
+  USE comconst_mod, ONLY: dtphys
+  USE logic_mod, ONLY: leapf, forward, ok_strato
+  USE comvert_mod, ONLY: ap, bp, pressure_exner
+  USE temps_mod, ONLY: day_ini, day_ref, jd_ref, jh_ref, start_time
+  
   IMPLICIT NONE
-    INCLUDE "comconst.h"
-    INCLUDE "comvert.h"
-    INCLUDE "logic.h"
-    INCLUDE "temps.h"
     INCLUDE "iniprint.h"
 
Index: LMDZ5/branches/testing/libf/dyn3dmem/conf_gcm.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/conf_gcm.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/conf_gcm.F90	(revision 2641)
@@ -17,4 +17,13 @@
   USE infotrac, ONLY : type_trac
   use assert_m, only: assert
+  USE comconst_mod, ONLY: dissip_deltaz, dissip_factz, dissip_zref, &
+                          iflag_top_bound, mode_top_bound, tau_top_bound, &
+                          ngroup
+  USE logic_mod, ONLY: fxyhypb, iflag_phys, ok_etat0, ok_gradsfile, &
+                       ok_guide, ok_limit, ok_strato, purmats, read_start, &
+                       ysinus
+  USE serre_mod, ONLY: clon,clat,grossismx,grossismy,dzoomx,dzoomy, &
+                       alphax,alphay,taux,tauy
+  USE temps_mod, ONLY: calend
 
   IMPLICIT NONE
@@ -35,9 +44,5 @@
   include "dimensions.h"
   include "paramet.h"
-  include "logic.h"
-  include "serre.h"
   include "comdissnew.h"
-  include "temps.h"
-  include "comconst.h"
   include "iniprint.h"
 
Index: LMDZ5/branches/testing/libf/dyn3dmem/convmas1_loc.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/convmas1_loc.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/convmas1_loc.F90	(revision 2641)
@@ -12,5 +12,4 @@
   include "paramet.h"
   include "comgeom.h"
-  include "logic.h"
 !===============================================================================
 ! Arguments:
Index: LMDZ5/branches/testing/libf/dyn3dmem/convmas2_loc.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/convmas2_loc.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/convmas2_loc.F90	(revision 2641)
@@ -11,5 +11,4 @@
   include "paramet.h"
   include "comgeom.h"
-  include "logic.h"
 !===============================================================================
 ! Arguments:
Index: LMDZ5/branches/testing/libf/dyn3dmem/convmas_loc.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/convmas_loc.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/convmas_loc.F90	(revision 2641)
@@ -11,5 +11,4 @@
   include "paramet.h"
   include "comgeom.h"
-  include "logic.h"
 !===============================================================================
 ! Arguments:
Index: LMDZ5/branches/testing/libf/dyn3dmem/dissip_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/dissip_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/dissip_loc.F	(revision 2641)
@@ -7,4 +7,5 @@
       USE write_field_loc
       USE dissip_mod, ONLY: dissip_allocate
+      USE comconst_mod, ONLY: dtdiss
       IMPLICIT NONE
 
@@ -28,10 +29,9 @@
 c   -------------
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comgeom.h"
-#include "comdissnew.h"
-#include "comdissipn.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
+      include "comdissnew.h"
+      include "comdissipn.h"
 
 c   Arguments:
Index: LMDZ5/branches/testing/libf/dyn3dmem/dteta1_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/dteta1_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/dteta1_loc.F	(revision 2641)
@@ -21,7 +21,6 @@
 
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "logic.h"
+      include "dimensions.h"
+      include "paramet.h"
 
       REAL teta( ijb_u:ije_u,llm )
Index: LMDZ5/branches/testing/libf/dyn3dmem/dudv2_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/dudv2_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/dudv2_loc.F	(revision 2641)
@@ -23,7 +23,6 @@
 c=======================================================================
 c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comvert.h"
+      include "dimensions.h"
+      include "paramet.h"
 
       REAL teta( ijb_u:ije_u,llm ),pkf( ijb_u:ije_u,llm )
Index: LMDZ5/branches/testing/libf/dyn3dmem/dynetat0_loc.f90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/dynetat0_loc.f90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/dynetat0_loc.f90	(revision 2641)
@@ -12,15 +12,18 @@
   USE control_mod, ONLY: planet_type
   USE assert_eq_m, ONLY: assert_eq
+  USE comvert_mod, ONLY: pa,preff
+  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, im, jm, kappa, lllm, &
+                          omeg, rad
+  USE logic_mod, ONLY: fxyhypb, ysinus
+  USE serre_mod, ONLY: clon, clat, grossismx, grossismy
+  USE temps_mod, ONLY: annee_ref,day_ref,itau_dyn, &
+                       start_time,day_ini,hour_ini
+  USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
+  
   IMPLICIT NONE
   include "dimensions.h"
   include "paramet.h"
-  include "temps.h"
-  include "comconst.h"
-  include "comvert.h"
   include "comgeom.h"
-  include "ener.h"
   include "description.h"
-  include "serre.h"
-  include "logic.h"
   include "iniprint.h"
 !===============================================================================
@@ -99,5 +102,5 @@
   day_ini    = tab_cntrl(30)
   itau_dyn   = tab_cntrl(31)
-!  start_time = tab_cntrl(32)   ????
+  start_time = tab_cntrl(32)
 
 !-------------------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F90	(revision 2641)
@@ -13,15 +13,18 @@
                     NF90_CLOSE,  NF90_PUT_ATT, NF90_UNLIMITED, NF90_CLOBBER
   USE dynredem_mod, ONLY: cre_var, put_var, err, modname, fil
+  USE comvert_mod, ONLY: ap,bp,aps,bps,presnivs,pseudoalt,pa,preff, &
+                         nivsig,nivsigs
+  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, kappa, omeg, rad
+  USE logic_mod, ONLY: fxyhypb, ysinus
+  USE serre_mod, ONLY: clon,clat,grossismx,grossismy,dzoomx,dzoomy, &
+                       taux,tauy
+  USE temps_mod, ONLY: annee_ref, day_ref, itau_dyn, itaufin, start_time
+  USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
+
   IMPLICIT NONE
   include "dimensions.h"
   include "paramet.h"
-  include "comconst.h"
-  include "comvert.h"
   include "comgeom.h"
-  include "temps.h"
-  include "ener.h"
-  include "logic.h"
   include "description.h"
-  include "serre.h"
   include "iniprint.h"
 !===============================================================================
@@ -176,11 +179,11 @@
   USE dynredem_mod, ONLY: dynredem_write_u, dynredem_write_v, dynredem_read_u, &
                           err, modname, fil, msg
+  USE temps_mod, ONLY: itau_dyn, itaufin
+  
   IMPLICIT NONE
   include "dimensions.h"
   include "paramet.h"
   include "description.h"
-  include "comvert.h"
   include "comgeom.h"
-  include "temps.h"
   include "iniprint.h"
 !===============================================================================
Index: LMDZ5/branches/testing/libf/dyn3dmem/exner_hyb_loc_m.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/exner_hyb_loc_m.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/exner_hyb_loc_m.F90	(revision 2641)
@@ -35,11 +35,12 @@
     USE mod_filtreg_p
     USE write_field_loc
+    USE comconst_mod, ONLY: cpp, kappa, r, jmp1
+    USE comvert_mod, ONLY: preff
+    
+    IMPLICIT NONE
     !
     include "dimensions.h"
     include "paramet.h"
-    include "comconst.h"
     include "comgeom.h"
-    include "comvert.h"
-    include "serre.h"
 
     INTEGER  ngrid
Index: LMDZ5/branches/testing/libf/dyn3dmem/exner_milieu_loc_m.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/exner_milieu_loc_m.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/exner_milieu_loc_m.F90	(revision 2641)
@@ -31,11 +31,12 @@
     USE parallel_lmdz
     USE mod_filtreg_p
+    USE comconst_mod, ONLY: cpp, kappa, r, jmp1
+    USE comvert_mod, ONLY: preff
+    
+    IMPLICIT NONE
     !
     include "dimensions.h"
     include "paramet.h"
-    include "comconst.h"
     include "comgeom.h"
-    include "comvert.h"
-    include "serre.h"
 
     INTEGER  ngrid
Index: LMDZ5/branches/testing/libf/dyn3dmem/friction_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/friction_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/friction_loc.F	(revision 2641)
@@ -12,4 +12,5 @@
       USE ioipsl_getincom
 #endif
+      USE comconst_mod, ONLY: pi
       IMPLICIT NONE
 
@@ -26,10 +27,9 @@
 !=======================================================================
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom2.h"
-#include "comconst.h"
-#include "iniprint.h"
-#include "academic.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom2.h"
+      include "iniprint.h"
+      include "academic.h"
 
 ! arguments:
Index: LMDZ5/branches/testing/libf/dyn3dmem/gcm.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/gcm.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/gcm.F90	(revision 2641)
@@ -21,4 +21,10 @@
   USE iniphysiq_mod, ONLY: iniphysiq
 #endif
+  USE comconst_mod, ONLY: cpp, daysec, dtphys, dtvr, g, r, rad
+  USE logic_mod ! all of it, because of copyin clause when calling leapfrog
+  USE temps_mod, ONLY: calend,start_time,annee_ref,day_ref, &
+                       itau_dyn,itau_phy,day_ini,jD_ref,jH_ref,day_end, &
+                       dt,hour_ini,itaufin
+
   IMPLICIT NONE
 
@@ -54,14 +60,7 @@
   include "dimensions.h"
   include "paramet.h"
-  include "comconst.h"
   include "comdissnew.h"
-  include "comvert.h"
   include "comgeom.h"
-  include "logic.h"
-  include "temps.h"
-  include "ener.h"
   include "description.h"
-  include "serre.h"
-  !include "com_io_dyn.h"
   include "iniprint.h"
   include "tracstoke.h"
@@ -452,5 +451,14 @@
   !       write(78,*) 'q',q
 
-  !$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/,/logici/,/logicl/)
+  !!$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/,/logici/,/logicl/)
+  !$OMP PARALLEL DEFAULT(SHARED) &
+  !     Copy all threadprivate variables in temps_mod
+  !$OMP COPYIN(dt,jD_ref,jH_ref,start_time,hour_ini,day_ini,day_end) &
+  !$OMP COPYIN(annee_ref,day_ref,itau_dyn,itau_phy,itaufin,calend) &
+  !     Copy all threadprivate variables from logic_mod
+  !$OMP COPYIN(purmats,forward,leapf,apphys,statcl,conser,apdiss,apdelq) &
+  !$OMP COPYIN(saison,ecripar,fxyhypb,ysinus,read_start,ok_guide) &
+  !$OMP COPYIN(ok_strato,ok_gradsfile,ok_limit,ok_etat0) &
+  !$OMP COPYIN(iflag_phys,iflag_trac)
   CALL leapfrog_loc(ucov,vcov,teta,ps,masse,phis,q,time_0)
   !$OMP END PARALLEL
Index: LMDZ5/branches/testing/libf/dyn3dmem/geopot_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/geopot_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/geopot_loc.F	(revision 2641)
@@ -26,7 +26,6 @@
 c   -------------
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "comvert.h"
+      include "dimensions.h"
+      include "paramet.h"
 
 c   Arguments:
Index: LMDZ5/branches/testing/libf/dyn3dmem/groupe_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/groupe_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/groupe_loc.F	(revision 2641)
@@ -3,4 +3,5 @@
       USE Write_field_loc
       USE groupe_mod
+      USE comconst_mod, ONLY: ngroup
       implicit none
 
@@ -16,9 +17,7 @@
 c   pas besoin de w en entree.
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comgeom2.h"
-#include "comvert.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom2.h"
 
 !     integer ngroup
Index: LMDZ5/branches/testing/libf/dyn3dmem/groupeun_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/groupeun_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/groupeun_loc.F	(revision 2641)
@@ -2,10 +2,10 @@
       USE parallel_lmdz
       USE Write_Field_p
+      USE comconst_mod, ONLY: ngroup
       IMPLICIT NONE
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comgeom2.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom2.h"
 
       INTEGER jjmax,llmax,sb,se,jjb,jje
@@ -136,10 +136,10 @@
 
       USE parallel_lmdz
+      USE comconst_mod, ONLY: ngroup
       IMPLICIT NONE
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comgeom2.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom2.h"
 
 !     INTEGER ngroup
Index: LMDZ5/branches/testing/libf/dyn3dmem/guide_loc_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/guide_loc_mod.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/guide_loc_mod.F90	(revision 2641)
@@ -69,5 +69,6 @@
   SUBROUTINE guide_init
 
-    USE control_mod
+    USE control_mod, ONLY: day_step
+    USE serre_mod, ONLY: grossismx
 
     IMPLICIT NONE
@@ -76,7 +77,4 @@
     INCLUDE "paramet.h"
     INCLUDE "netcdf.inc"
-
-    ! For grossismx:
-    include "serre.h"
 
     INTEGER                :: error,ncidpl,rid,rcod
@@ -346,4 +344,6 @@
     USE control_mod
     USE write_field_loc
+    USE comconst_mod, ONLY: cpp, daysec, dtvr, kappa
+    USE comvert_mod, ONLY: ap, bp, preff, presnivs, pressure_exner
     
     IMPLICIT NONE
@@ -351,6 +351,4 @@
     INCLUDE "dimensions.h"
     INCLUDE "paramet.h"
-    INCLUDE "comconst.h"
-    INCLUDE "comvert.h"
 
     ! Variables entree
@@ -748,4 +746,6 @@
   SUBROUTINE guide_zonave_u(typ,vsize,field)
 
+    USE comconst_mod, ONLY: pi
+    
     IMPLICIT NONE
 
@@ -753,5 +753,4 @@
     INCLUDE "paramet.h"
     INCLUDE "comgeom.h"
-    INCLUDE "comconst.h"
     
     ! input/output variables
@@ -819,4 +818,6 @@
   SUBROUTINE guide_zonave_v(typ,hsize,vsize,field)
 
+    USE comconst_mod, ONLY: pi
+    
     IMPLICIT NONE
 
@@ -824,5 +825,4 @@
     INCLUDE "paramet.h"
     INCLUDE "comgeom.h"
-    INCLUDE "comconst.h"
     
     ! input/output variables
@@ -890,11 +890,11 @@
   USE mod_hallo
   USE Bands
+  USE comconst_mod, ONLY: cpp, kappa
+  USE comvert_mod, ONLY: preff, pressure_exner, bp, ap, disvert_type
   IMPLICIT NONE
 
   include "dimensions.h"
   include "paramet.h"
-  include "comvert.h"
   include "comgeom2.h"
-  include "comconst.h"
 
   REAL, DIMENSION (iip1,jjb_u:jje_u),     INTENT(IN) :: psi ! Psol gcm
@@ -1012,6 +1012,6 @@
 !$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
         DO l=1,llm
-	    DO j=jjbu,jjeu
-		DO i =1, iip1
+            DO j=jjbu,jjeu
+                DO i =1, iip1
                     pls(i,j,l)=(ap(l)+ap(l+1))/2.+psi(i,j)*(bp(l)+bp(l+1))/2.
                 ENDDO
@@ -1030,7 +1030,7 @@
    DO l = 1, llm
        DO j=jjbu,jjeu
-   	DO i =1, iip1
-   	    pls(i,j,l) = preff * ( pk(i,j,l)/cpp) ** unskap
-   	ENDDO
+           DO i =1, iip1
+               pls(i,j,l) = preff * ( pk(i,j,l)/cpp) ** unskap
+           ENDDO
        ENDDO
    ENDDO
@@ -1302,9 +1302,9 @@
         ! Calcul des nouvelles valeurs des niveaux de pression du guidage
         IF (guide_plevs.EQ.1) THEN
-	 CALL Register_Hallo_u(psnat1,1,1,2,2,1,Req)
-	 CALL Register_Hallo_u(psnat2,1,1,2,2,1,Req)
-	 CALL SendRequest(Req)
-!$OMP BARRIER
-	 CALL WaitRequest(Req)
+         CALL Register_Hallo_u(psnat1,1,1,2,2,1,Req)
+         CALL Register_Hallo_u(psnat2,1,1,2,2,1,Req)
+         CALL SendRequest(Req)
+!$OMP BARRIER
+         CALL WaitRequest(Req)
 !$OMP BARRIER
 !$OMP DO
@@ -1320,9 +1320,9 @@
             ENDDO
         ELSE IF (guide_plevs.EQ.2) THEN
-	 CALL Register_Hallo_u(pnat1,llm,1,2,2,1,Req)
-	 CALL Register_Hallo_u(pnat2,llm,1,2,2,1,Req)
-	 CALL SendRequest(Req)
-!$OMP BARRIER
-	 CALL WaitRequest(Req)
+         CALL Register_Hallo_u(pnat1,llm,1,2,2,1,Req)
+         CALL Register_Hallo_u(pnat2,llm,1,2,2,1,Req)
+         CALL SendRequest(Req)
+!$OMP BARRIER
+         CALL WaitRequest(Req)
 !$OMP BARRIER
 !$OMP DO
@@ -1370,11 +1370,12 @@
 ! Calcul des constantes de rappel alpha (=1/tau)
 
+    use comconst_mod, only: pi
+    use serre_mod, only: clat, clon, grossismx, grossismy
+    
     implicit none
 
     include "dimensions.h"
     include "paramet.h"
-    include "comconst.h"
     include "comgeom2.h"
-    include "serre.h"
 
 ! input arguments :
@@ -2127,4 +2128,6 @@
     USE parallel_lmdz
     USE mod_hallo, ONLY : gather_field_u, gather_field_v
+    USE comconst_mod, ONLY: pi
+    USE comvert_mod, ONLY: presnivs
     IMPLICIT NONE
 
@@ -2133,6 +2136,4 @@
     INCLUDE "netcdf.inc"
     INCLUDE "comgeom2.h"
-    INCLUDE "comconst.h"
-    INCLUDE "comvert.h"
     
     ! Variables entree
Index: LMDZ5/branches/testing/libf/dyn3dmem/iniacademic_loc.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/iniacademic_loc.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/iniacademic_loc.F90	(revision 2641)
@@ -18,4 +18,10 @@
 #endif
   USE Write_Field
+  USE comconst_mod, ONLY: cpp, kappa, g, daysec, dtvr, pi, im, jm
+  USE logic_mod, ONLY: iflag_phys, read_start
+  USE comvert_mod, ONLY: ap, bp, preff, presnivs, pressure_exner
+  USE temps_mod, ONLY: annee_ref, day_ini, day_ref
+  USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
+
 
   !   Author:    Frederic Hourdin      original: 15/01/93
@@ -30,12 +36,7 @@
   include "dimensions.h"
   include "paramet.h"
-  include "comvert.h"
-  include "comconst.h"
   include "comgeom.h"
   include "academic.h"
-  include "ener.h"
-  include "temps.h"
   include "iniprint.h"
-  include "logic.h"
 
   !   Arguments:
Index: LMDZ5/branches/testing/libf/dyn3dmem/initdynav_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/initdynav_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/initdynav_loc.F	(revision 2641)
@@ -14,4 +14,8 @@
        use com_io_dyn_mod, only : histaveid,histvaveid,histuaveid,       &
      &        dynhistave_file,dynhistvave_file,dynhistuave_file
+       USE comconst_mod, ONLY: pi
+       USE comvert_mod, ONLY: presnivs
+       USE temps_mod, ONLY: itau_dyn
+       
        implicit none
 
@@ -41,15 +45,9 @@
 C
 C   Declarations
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom.h"
-#include "temps.h"
-#include "ener.h"
-#include "logic.h"
-#include "description.h"
-#include "serre.h"
-#include "iniprint.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
+      include "description.h"
+      include "iniprint.h"
 
 C   Arguments
Index: LMDZ5/branches/testing/libf/dyn3dmem/initfluxsto_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/initfluxsto_p.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/initfluxsto_p.F	(revision 2641)
@@ -13,4 +13,7 @@
        use Write_field
        use misc_mod
+       USE comconst_mod, ONLY: pi
+       USE comvert_mod, ONLY: nivsigs
+       USE temps_mod, ONLY: annee_ref, day_ref, itau_dyn
        
       implicit none
@@ -43,15 +46,9 @@
 C
 C   Declarations
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom.h"
-#include "temps.h"
-#include "ener.h"
-#include "logic.h"
-#include "description.h"
-#include "serre.h"
-#include "iniprint.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
+      include "description.h"
+      include "iniprint.h"
 
 C   Arguments
@@ -106,6 +103,6 @@
       CALL ymds2ju(zan, 1, idayref, 0.0, zjulian)
       tau0 = itau_dyn
-	
-	do jj = 1, jjp1
+        
+        do jj = 1, jjp1
         do ii = 1, iip1
           rlong(ii,jj) = rlonu(ii) * 180. / pi
@@ -165,6 +162,6 @@
      .             1, iip1, 1, jjn,tau0, zjulian, tstep, vhoriid,
      .             filevid,dynv_domain_id)
-	
-      rl(1,1) = 1.	
+        
+      rl(1,1) = 1.
       
       if (mpi_rank==0) then
@@ -191,5 +188,5 @@
       call histhori(fileid, iip1, rlong(:,jjb:jje),jjn,rlat(:,jjb:jje),
      .             'scalar','Grille points scalaires', thoriid)
-	
+        
 C
 C  Appel a histvert pour la grille verticale
@@ -211,6 +208,6 @@
 C
 C  Appels a histdef pour la definition des variables a sauvegarder
-	
-	CALL histdef(fileid, "phis", "Surface geop. height", "-",
+        
+        CALL histdef(fileid, "phis", "Surface geop. height", "-",
      .                iip1,jjn,thoriid, 1,1,1, -99, 32,
      .                "once", t_ops, t_wrt)
@@ -219,8 +216,8 @@
      .                iip1,jjn,thoriid, 1,1,1, -99, 32,
      .                "once", t_ops, t_wrt)
-	
+        
         if (mpi_rank==0) then
-	
-	CALL histdef(filedid, "dtvr", "tps dyn", "s",
+        
+        CALL histdef(filedid, "dtvr", "tps dyn", "s",
      .                1,1,dhoriid, 1,1,1, -99, 32,
      .                "once", t_ops, t_wrt)
@@ -289,5 +286,5 @@
         if (mpi_rank==0) call histsync(filedid)
       endif
-	
+        
 #else
       write(lunout,*)'initfluxsto_p: Needs IOIPSL to function'
Index: LMDZ5/branches/testing/libf/dyn3dmem/inithist_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/inithist_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/inithist_loc.F	(revision 2641)
@@ -14,4 +14,8 @@
        use com_io_dyn_mod, only : histid,histvid,histuid,               &
      &                        dynhist_file,dynhistv_file,dynhistu_file
+       USE comconst_mod, ONLY: pi
+       USE comvert_mod, ONLY: presnivs
+       USE temps_mod, ONLY: itau_dyn
+       
        implicit none
 
@@ -40,15 +44,9 @@
 C
 C   Declarations
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom.h"
-#include "temps.h"
-#include "ener.h"
-#include "logic.h"
-#include "description.h"
-#include "serre.h"
-#include "iniprint.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
+      include "description.h"
+      include "iniprint.h"
 
 C   Arguments
Index: LMDZ5/branches/testing/libf/dyn3dmem/integrd_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/integrd_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/integrd_loc.F	(revision 2641)
@@ -12,4 +12,9 @@
       USE integrd_mod
       USE infotrac, ONLY: ok_iso_verif ! ajout CRisi
+      USE comconst_mod, ONLY: pi
+      USE logic_mod, ONLY: leapf
+      USE comvert_mod, ONLY: ap, bp
+      USE temps_mod, ONLY: dt
+      
       IMPLICIT NONE
 
@@ -30,14 +35,8 @@
 c   -------------
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comgeom.h"
-#include "comvert.h"
-#include "logic.h"
-#include "temps.h"
-#include "serre.h"
-#include "iniprint.h"
-!      include 'mpif.h'
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
+      include "iniprint.h"
 
 c   Arguments:
@@ -335,5 +334,5 @@
       ije=ij_end
 
-	 if (planet_type.eq."earth") then
+         if (planet_type.eq."earth") then
 ! Earth-specific treatment of first 2 tracers (water)
 c$OMP BARRIER
@@ -452,6 +451,6 @@
           DO l = 1, llm
             massem1(ijb:ije,l)=massescr(ijb:ije,l)
-	  ENDDO
-c$OMP END DO NOWAIT	  
+          ENDDO
+c$OMP END DO NOWAIT          
       END IF
 c$OMP BARRIER
Index: LMDZ5/branches/testing/libf/dyn3dmem/leapfrog_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/leapfrog_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/leapfrog_loc.F	(revision 2641)
@@ -32,4 +32,11 @@
        use exner_hyb_loc_m, only: exner_hyb_loc
        use exner_milieu_loc_m, only: exner_milieu_loc
+       USE comconst_mod, ONLY: cpp, dtvr, ihf
+       USE comvert_mod, ONLY: ap, bp, pressure_exner
+       USE logic_mod, ONLY: iflag_phys,ok_guide,forward,leapf,apphys,
+     &                      statcl,conser,apdiss,purmats,ok_strato
+       USE temps_mod, ONLY: itaufin,jD_ref,jH_ref,day_ini,
+     &                        day_ref,start_time,dt
+       
       IMPLICIT NONE
 
@@ -65,19 +72,11 @@
 c   -------------
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comdissnew.h"
-#include "comvert.h"
-#include "comgeom.h"
-#include "logic.h"
-#include "temps.h"
-#include "ener.h"
-#include "description.h"
-#include "serre.h"
-!#include "com_io_dyn.h"
-#include "iniprint.h"
-#include "academic.h"
-!      include "mpif.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comdissnew.h"
+      include "comgeom.h"
+      include "description.h"
+      include "iniprint.h"
+      include "academic.h"
       
       REAL,INTENT(IN) :: time_0 ! not used
@@ -472,5 +471,5 @@
 cym      apphys = .FALSE.
       statcl = .FALSE.
-      conser = .FALSE. ! ie: no output of control variables to stdout in //
+!     conser = .FALSE. ! ie: no output of control variables to stdout in //
       
       if (firstCaldyn) then
@@ -700,4 +699,7 @@
 
 c$OMP MASTER
+      if (mpi_rank==0.AND.conser) THEN
+         WRITE(lunout,*) 'leapfrog_loc, Time step: ',itau,' Day:',time
+      ENDIF
       call VTe(VTcaldyn)
 c$OMP END MASTER      
@@ -1635,5 +1637,5 @@
             IF( MOD(itau,iecri).EQ.0) THEN
              ! Ehouarn: output only during LF or Backward Matsuno
-	     if (leapf.or.(.not.leapf.and.(.not.forward))) then
+             if (leapf.or.(.not.leapf.and.(.not.forward))) then
 
 c$OMP BARRIER
@@ -1645,5 +1647,5 @@
 #ifdef CPP_IOIPSL
              if (ok_dyn_ins) then
-	         CALL writehist_loc(itau,vcov,ucov,teta,pk,phi,q,
+                 CALL writehist_loc(itau,vcov,ucov,teta,pk,phi,q,
      &                              masse,ps,phis)
              endif
Index: LMDZ5/branches/testing/libf/dyn3dmem/logic.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/logic.h	(revision 2594)
+++ 	(revision )
@@ -1,28 +1,0 @@
-!
-! $Id: $
-!
-!
-! NB: keep items of different kinds in seperate common blocs to avoid
-!     "misaligned commons" issues
-!-----------------------------------------------------------------------
-! INCLUDE 'logic.h'
-
-      COMMON/logicl/ purmats,forward,leapf,apphys,                      &
-     &  statcl,conser,apdiss,apdelq,saison,ecripar,fxyhypb,ysinus       &
-     &  ,read_start,ok_guide,ok_strato,ok_gradsfile                     &
-     &  ,ok_limit,ok_etat0,hybrid
-
-      COMMON/logici/ iflag_phys,iflag_trac
-      
-      LOGICAL purmats,forward,leapf,apphys,statcl,conser,               &
-     & apdiss,apdelq,saison,ecripar,fxyhypb,ysinus                      &
-     &  ,read_start,ok_guide,ok_strato,ok_gradsfile                     &
-     &  ,ok_limit,ok_etat0
-     
-      logical hybrid ! vertical coordinate is hybrid if true (sigma otherwise)
-                     ! (only used if disvert_type==2)
-
-      integer iflag_phys,iflag_trac
-!$OMP THREADPRIVATE(/logicl/)
-!$OMP THREADPRIVATE(/logici/)
-!-----------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dmem/logic_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/logic_mod.F90	(revision 2641)
+++ LMDZ5/branches/testing/libf/dyn3dmem/logic_mod.F90	(revision 2641)
@@ -0,0 +1,45 @@
+!
+! $Id: $
+!
+MODULE logic_mod
+
+IMPLICIT NONE
+
+  LOGICAL purmats ! true if time stepping is purely Matsuno scheme
+                  ! false implies Matsuno-Leapfrog time stepping scheme
+  LOGICAL forward ! true if during forward phase of Matsuno step
+  LOGICAL leapf ! true if during a leapfrog time stepping step
+  LOGICAL apphys ! true if during a time step when physics will be called
+  LOGICAL statcl
+  LOGICAL conser
+  LOGICAL apdiss ! true if during a time step when dissipation will be called
+  LOGICAL apdelq
+  LOGICAL saison
+  LOGICAL ecripar
+  LOGICAL fxyhypb ! true if using hyperbolic function discretization
+                  ! for latitudinal grid 
+  LOGICAL ysinus ! true if using sine function discretiation
+                 ! for latitudinal grid
+  LOGICAL read_start ! true if reading a start.nc file to initialize fields
+  LOGICAL ok_guide ! true if nudging
+  LOGICAL ok_strato
+  LOGICAL ok_gradsfile
+  LOGICAL ok_limit
+  LOGICAL ok_etat0
+  LOGICAL hybrid ! vertical coordinate is hybrid if true (sigma otherwise)
+                 ! (only used if disvert_type==2)
+  INTEGER iflag_phys ! type of physics to call: 0 none, 1: phy*** package,
+                     ! 2: Held & Suarez, 101-200: aquaplanets & terraplanets
+  INTEGER iflag_trac
+
+!$OMP THREADPRIVATE(purmats,forward,leapf,apphys,statcl,conser, &
+!$OMP     apdiss,apdelq,saison,ecripar,fxyhypb,ysinus, &
+!$OMP     read_start,ok_guide,ok_strato,ok_gradsfile, &
+!$OMP     ok_limit,ok_etat0,hybrid)
+!$OMP THREADPRIVATE(iflag_phys,iflag_trac)
+
+!WARNING: when adding a threadprivate variable in this module
+!        do not forget to add it to the copyin clause when opening an OpenMP
+!        parallel section. e.g. in gcm before call leapfrog_loc 
+
+END MODULE logic_mod
Index: LMDZ5/branches/testing/libf/dyn3dmem/massbarxy_loc.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/massbarxy_loc.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/massbarxy_loc.F90	(revision 2641)
@@ -10,5 +10,4 @@
   include "dimensions.h"
   include "paramet.h"
-  include "comconst.h"
   include "comgeom.h"
 !===============================================================================
Index: LMDZ5/branches/testing/libf/dyn3dmem/massdair_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/massdair_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/massdair_loc.F	(revision 2641)
@@ -16,8 +16,7 @@
       IMPLICIT NONE
 c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comgeom.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
 c
 c  .....   arguments  ....
Index: LMDZ5/branches/testing/libf/dyn3dmem/mod_hallo.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/mod_hallo.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/mod_hallo.F90	(revision 2641)
@@ -1411,5 +1411,5 @@
          
 #ifdef CPP_MPI
-         call MPI_ISSEND(Buffer(req%Pos),SizeBuffer,MPI_REAL_LMDZ,rank,a_request%tag+1000*omp_rank,     &
+         call MPI_ISEND(Buffer(req%Pos),SizeBuffer,MPI_REAL_LMDZ,rank,a_request%tag+1000*omp_rank,     &
                          COMM_LMDZ,Req%MSG_Request,ierr)
 #endif
Index: LMDZ5/branches/testing/libf/dyn3dmem/parallel_lmdz.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/parallel_lmdz.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/parallel_lmdz.F90	(revision 2641)
@@ -575,5 +575,5 @@
 !$OMP CRITICAL (MPI)
 #ifdef CPP_MPI
-          call MPI_ISSEND(Buffer_send_up,Buffer_Size,MPI_REAL8,MPI_Rank-1,1,     &
+          call MPI_ISEND(Buffer_send_up,Buffer_Size,MPI_REAL8,MPI_Rank-1,1,     &
                           COMM_LMDZ,Request(NbRequest),ierr)
 #endif
@@ -590,5 +590,5 @@
 !$OMP CRITICAL (MPI)
 #ifdef CPP_MPI
-          call MPI_ISSEND(Buffer_send_down,Buffer_Size,MPI_REAL8,MPI_Rank+1,1,     &
+          call MPI_ISEND(Buffer_send_down,Buffer_Size,MPI_REAL8,MPI_Rank+1,1,     &
                           COMM_LMDZ,Request(NbRequest),ierr)
 #endif
Index: LMDZ5/branches/testing/libf/dyn3dmem/qminimum_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/qminimum_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/qminimum_loc.F	(revision 2641)
@@ -7,7 +7,6 @@
 c             pour l'eau vapeur et l'eau liquide
 c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comvert.h"
+      include "dimensions.h"
+      include "paramet.h"
 c
       INTEGER nqtot ! CRisi: on remplace nq par nqtot
Index: LMDZ5/branches/testing/libf/dyn3dmem/sw_case_williamson91_6_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/sw_case_williamson91_6_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/sw_case_williamson91_6_loc.F	(revision 2641)
@@ -27,4 +27,6 @@
 c=======================================================================
       USE parallel_lmdz
+      USE comconst_mod, ONLY: cpp, omeg, rad
+      USE comvert_mod, ONLY: ap, bp, preff
 
       IMPLICIT NONE
@@ -33,10 +35,8 @@
 c   ---------------
 
-#include "dimensions.h"
-#include "paramet.h"
-#include "comvert.h"
-#include "comconst.h"
-#include "comgeom.h"
-#include "iniprint.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
+      include "iniprint.h"
 
 c   Arguments:
Index: LMDZ5/branches/testing/libf/dyn3dmem/temps.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/temps.h	(revision 2594)
+++ 	(revision )
@@ -1,27 +1,0 @@
-!
-! $Id$
-!
-!  ATTENTION!!!!: ce fichier include est compatible format fixe/format libre
-!                 veillez  n'utiliser que des ! pour les commentaires
-!                 et  bien positionner les & des lignes de continuation
-!                 (les placer en colonne 6 et en colonne 73)
-!
-!
-! jD_ref = jour julien de la date de reference (lancement de l'experience)
-! hD_ref = "heure" julienne de la date de reference
-!-----------------------------------------------------------------------
-! INCLUDE 'temps.h'
-
-      COMMON/temps/ dt, jD_ref, jH_ref, start_time,                     &
-     &             day_ini, day_end, annee_ref, day_ref,                &
-     &             itau_dyn, itau_phy, itaufin, calend
-
-
-      INTEGER   itaufin
-      INTEGER itau_dyn, itau_phy 
-      INTEGER day_ini, day_end, annee_ref, day_ref
-      REAL      dt, jD_ref, jH_ref, start_time
-      CHARACTER (len=10) :: calend
-
-!$OMP THREADPRIVATE(/temps/)
-!-----------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dmem/temps_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/temps_mod.F90	(revision 2641)
+++ LMDZ5/branches/testing/libf/dyn3dmem/temps_mod.F90	(revision 2641)
@@ -0,0 +1,33 @@
+!
+! $Id: temps_mod.F90 -1   $
+!
+MODULE temps_mod
+
+IMPLICIT NONE  
+
+  INTEGER   itaufin ! total number of dynamical steps for the run
+  INTEGER   itau_dyn
+  INTEGER   itau_phy
+  INTEGER   day_ini ! initial day # of simulation sequence
+  INTEGER   day_end ! final day # ; i.e. day # when this simulation ends
+  INTEGER   annee_ref
+  INTEGER   day_ref
+  REAL      dt ! (dynamics) time step (changes if doing Matsuno or LF step)
+  REAL      jD_ref ! reference julian day date (beginning of experiment)
+  REAL      jH_ref ! reference julian "hour" of reference julian date
+  REAL      start_time
+  CHARACTER (len=10) :: calend ! calendar type
+
+  ! Additionnal Mars stuff:
+  REAL hour_ini ! initial fraction of day of simulation sequence (0=<hour_ini<1)
+
+!$OMP THREADPRIVATE(dt,jD_ref,jH_ref,start_time,hour_ini,                        &
+!$OMP                day_ini,day_end,annee_ref,day_ref,itau_dyn,itau_phy,itaufin,&
+!$OMP                calend)        
+
+!WARNING: when adding a threadprivate variable in this module
+!        do not forget to add it to the copyin clause when opening an OpenMP
+!        parallel section. e.g. in gcm before call leapfrog_loc and/or
+!        possibly in iniphysiq
+
+END MODULE temps_mod
Index: LMDZ5/branches/testing/libf/dyn3dmem/top_bound_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/top_bound_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/top_bound_loc.F	(revision 2641)
@@ -4,11 +4,13 @@
       SUBROUTINE top_bound_loc(vcov,ucov,teta,masse,dt)
       USE parallel_lmdz
+      USE comconst_mod, ONLY: iflag_top_bound, mode_top_bound,
+     &                        tau_top_bound
+      USE comvert_mod, ONLY: presnivs, preff, scaleheight
+
       IMPLICIT NONE
 c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom2.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom2.h"
 
 
@@ -40,5 +42,5 @@
 ! NB: top_bound sponge is only called from leapfrog if ok_strato=.true.
 
-! sponge parameters: (loaded/set in conf_gcm.F ; stored in comconst.h)
+! sponge parameters: (loaded/set in conf_gcm.F ; stored in comconst_mod)
 !    iflag_top_bound=0 for no sponge
 !    iflag_top_bound=1 for sponge over 4 topmost layers
@@ -74,5 +76,5 @@
       REAL tzon(jjb_u:jje_u,llm)
       
-      integer i	
+      integer i
       REAL,SAVE :: rdamp(llm)
       real,save :: lambda(llm) ! inverse or quenching time scale (Hz)
Index: LMDZ5/branches/testing/libf/dyn3dmem/tourpot_loc.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/tourpot_loc.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/tourpot_loc.F90	(revision 2641)
@@ -11,5 +11,4 @@
   include "paramet.h"
   include "comgeom.h"
-  include "logic.h"
 !===============================================================================
 ! Arguments:
Index: LMDZ5/branches/testing/libf/dyn3dmem/vitvert_loc.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/vitvert_loc.F90	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/vitvert_loc.F90	(revision 2641)
@@ -6,8 +6,9 @@
 ! Purpose: Compute vertical speed at sigma levels.
   USE parallel_lmdz
+  USE comvert_mod, ONLY: bp
+  
   IMPLICIT NONE
   include "dimensions.h"
   include "paramet.h"
-  include "comvert.h"
 !===============================================================================
 ! Arguments:
Index: LMDZ5/branches/testing/libf/dyn3dmem/vlsplt_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/vlsplt_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/vlsplt_loc.F	(revision 2641)
@@ -17,9 +17,6 @@
       IMPLICIT NONE
 c
-#include "dimensions.h"
-#include "paramet.h"
-#include "logic.h"
-#include "comvert.h"
-#include "comconst.h"
+      include "dimensions.h"
+      include "paramet.h"
 c
 c
@@ -417,12 +414,10 @@
       USE parallel_lmdz
       USE infotrac, ONLY : nqtot,nqfils,nqdesc,iqfils ! CRisi
+      USE comconst_mod, ONLY: pi
       IMPLICIT NONE
 c
-#include "dimensions.h"
-#include "paramet.h"
-#include "logic.h"
-#include "comvert.h"
-#include "comconst.h"
-#include "comgeom.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
 c
 c
@@ -875,9 +870,6 @@
       IMPLICIT NONE
 c
-#include "dimensions.h"
-#include "paramet.h"
-#include "logic.h"
-#include "comvert.h"
-#include "comconst.h"
+      include "dimensions.h"
+      include "paramet.h"
 c
 c
Index: LMDZ5/branches/testing/libf/dyn3dmem/vlspltgen_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/vlspltgen_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/vlspltgen_loc.F	(revision 2641)
@@ -31,12 +31,10 @@
      &    ok_iso_verif
       USE vlspltgen_mod
+      USE comconst_mod, ONLY: cpp
       IMPLICIT NONE
 
 c
-#include "dimensions.h"
-#include "paramet.h"
-#include "logic.h"
-#include "comvert.h"
-#include "comconst.h"
+      include "dimensions.h"
+      include "paramet.h"
 
 c
@@ -100,11 +98,11 @@
 
         
-	ijb=ij_begin-iip1
-	ije=ij_end+iip1
-	if (pole_nord) ijb=ij_begin
-	if (pole_sud) ije=ij_end
-	
+        ijb=ij_begin-iip1
+        ije=ij_end+iip1
+        if (pole_nord) ijb=ij_begin
+        if (pole_sud) ije=ij_end
+        
 c$OMP DO SCHEDULE(STATIC,OMP_CHUNK) 
-	DO l = 1, llm
+        DO l = 1, llm
          DO ij = ijb, ije
           tempe(ij) = teta(ij,l) * pk(ij,l) /cpp
@@ -208,19 +206,19 @@
 #endif
         if(iadv(iq) == 0) then
-	
-	  cycle 
-	
-	else if (iadv(iq)==10) then
+        
+          cycle 
+        
+        else if (iadv(iq)==10) then
 
 #ifdef _ADV_HALO        
 ! CRisi: on ajoute les nombres de fils et tableaux des fils
 ! On suppose qu'on ne peut advecter les fils que par le schéma 10.  
-	  call vlx_loc(zq,pente_max,zm,mu,
-     &	             ij_begin,ij_begin+2*iip1-1,iq)
+          call vlx_loc(zq,pente_max,zm,mu,
+     &                     ij_begin,ij_begin+2*iip1-1,iq)
           call vlx_loc(zq,pente_max,zm,mu,
      &               ij_end-2*iip1+1,ij_end,iq)
 #else
-	  call vlx_loc(zq,pente_max,zm,mu,
-     &	             ij_begin,ij_end,iq)
+          call vlx_loc(zq,pente_max,zm,mu,
+     &                     ij_begin,ij_end,iq)
 #endif
 
@@ -240,5 +238,5 @@
           call VTe(VTHallo)
 c$OMP END MASTER
-	else if (iadv(iq)==14) then
+        else if (iadv(iq)==14) then
 
 #ifdef _ADV_HALO           
@@ -268,6 +266,6 @@
 c$OMP END MASTER 
         else
-	
-	  stop 'vlspltgen_p : schema non parallelise'
+        
+          stop 'vlspltgen_p : schema non parallelise'
       
         endif
@@ -301,8 +299,8 @@
 
         if(iadv(iq) == 0) then
-	
-	  cycle 
-	
-	else if (iadv(iq)==10) then
+        
+          cycle 
+        
+        else if (iadv(iq)==10) then
 
 #ifdef _ADV_HALLO
@@ -310,5 +308,5 @@
      &                 ij_begin+2*iip1,ij_end-2*iip1,iq)
 #endif        
-	else if (iadv(iq)==14) then
+        else if (iadv(iq)==14) then
 #ifdef _ADV_HALLO
           call vlxqs_loc(zq,pente_max,zm,mu,
@@ -316,6 +314,6 @@
 #endif    
         else
-	
-	  stop 'vlspltgen_p : schema non parallelise'
+        
+          stop 'vlspltgen_p : schema non parallelise'
       
         endif
@@ -358,12 +356,12 @@
 
         if(iadv(iq) == 0) then
-	
-	  cycle 
-	
-	else if (iadv(iq)==10) then
+        
+          cycle 
+        
+        else if (iadv(iq)==10) then
         
           call vly_loc(zq,pente_max,zm,mv,iq)
   
-	else if (iadv(iq)==14) then
+        else if (iadv(iq)==14) then
       
           call vlyqs_loc(zq,pente_max,zm,mv,
@@ -371,6 +369,6 @@
  
         else
-	
-	  stop 'vlspltgen_p : schema non parallelise'
+        
+          stop 'vlspltgen_p : schema non parallelise'
       
         endif
@@ -389,8 +387,8 @@
 #endif
         if(iadv(iq) == 0) then 
-	  
-	  cycle 
-	
-	else if (iadv(iq)==10 .or. iadv(iq)==14 ) then
+          
+          cycle 
+        
+        else if (iadv(iq)==10 .or. iadv(iq)==14 ) then
 
 c$OMP BARRIER        
@@ -420,9 +418,9 @@
 c$OMP MASTER
           call VTe(VTHallo)
-c$OMP END MASTER	
+c$OMP END MASTER        
 c$OMP BARRIER
         else
-	
-	  stop 'vlspltgen_p : schema non parallelise'
+        
+          stop 'vlspltgen_p : schema non parallelise'
       
         endif
@@ -439,5 +437,5 @@
 c$OMP MASTER
       call VTe(VTHallo)
-c$OMP END MASTER	
+c$OMP END MASTER        
 
 
@@ -451,8 +449,8 @@
 
         if(iadv(iq) == 0) then
-	  
-	  cycle 
-	
-	else if (iadv(iq)==10 .or. iadv(iq)==14 ) then
+          
+          cycle 
+        
+        else if (iadv(iq)==10 .or. iadv(iq)==14 ) then
 c$OMP BARRIER        
 
@@ -464,6 +462,6 @@
 c$OMP BARRIER        
         else
-	
-	  stop 'vlspltgen_p : schema non parallelise'
+        
+          stop 'vlspltgen_p : schema non parallelise'
       
         endif
@@ -501,12 +499,12 @@
 #endif
         if(iadv(iq) == 0) then
-	
-	  cycle 
-	
-	else if (iadv(iq)==10) then
+        
+          cycle 
+        
+        else if (iadv(iq)==10) then
         
           call vly_loc(zq,pente_max,zm,mv,iq)
   
-	else if (iadv(iq)==14) then
+        else if (iadv(iq)==14) then
       
           call vlyqs_loc(zq,pente_max,zm,mv,
@@ -514,6 +512,6 @@
  
         else
-	
-	  stop 'vlspltgen_p : schema non parallelise'
+        
+          stop 'vlspltgen_p : schema non parallelise'
       
         endif
@@ -532,13 +530,13 @@
 #endif
         if(iadv(iq) == 0) then 
-	  
-	  cycle 
-	
-	else if (iadv(iq)==10) then
+          
+          cycle 
+        
+        else if (iadv(iq)==10) then
         
           call vlx_loc(zq,pente_max,zm,mu,
      &               ij_begin,ij_end,iq)
   
-	else if (iadv(iq)==14) then
+        else if (iadv(iq)==14) then
       
           call vlxqs_loc(zq,pente_max,zm,mu,
@@ -546,5 +544,5 @@
  
         else
-	
+        
           stop 'vlspltgen_p : schema non parallelise'
       
@@ -574,6 +572,6 @@
            DO ij=ijb,ije
 c             print *,'zq-->',ij,l,iq,zq(ij,l,iq)
-c	     print *,'q-->',ij,l,iq,q(ij,l,iq)
-	     q(ij,l,iq)=zq(ij,l,iq)
+c             print *,'q-->',ij,l,iq,q(ij,l,iq)
+             q(ij,l,iq)=zq(ij,l,iq)
            ENDDO
         ENDDO
Index: LMDZ5/branches/testing/libf/dyn3dmem/vlspltqs_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/vlspltqs_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/vlspltqs_loc.F	(revision 2641)
@@ -12,9 +12,6 @@
       IMPLICIT NONE
 c
-#include "dimensions.h"
-#include "paramet.h"
-#include "logic.h"
-#include "comvert.h"
-#include "comconst.h"
+      include "dimensions.h"
+      include "paramet.h"
 c
 c
@@ -174,9 +171,9 @@
 c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
         DO l=1,llm 
-	  iadvplus(ip1jm+1:ip1jmp1,l)=0
+          iadvplus(ip1jm+1:ip1jmp1,l)=0
         ENDDO
 c$OMP END DO NOWAIT
       endif
-      	
+              
 c   calcul des flux a gauche et a droite
 
@@ -414,5 +411,5 @@
 c    ********************************************************************
 c     q,masse_adv_v,w sont des arguments d'entree  pour le s-pg ....
-c     qsat 	       est   un argument de sortie pour le s-pg ....
+c     qsat                est   un argument de sortie pour le s-pg ....
 c
 c
@@ -420,12 +417,10 @@
       USE parallel_lmdz
       USE infotrac, ONLY : nqtot,nqfils,nqdesc,iqfils ! CRisi  
+      USE comconst_mod, ONLY: pi
       IMPLICIT NONE
 c
-#include "dimensions.h"
-#include "paramet.h"
-#include "logic.h"
-#include "comvert.h"
-#include "comconst.h"
-#include "comgeom.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
 c
 c
@@ -582,5 +577,5 @@
          dyq(ij,l)=fn*dyq(ij,l)
         ENDDO
-	  
+          
       ENDIF
       
@@ -603,5 +598,5 @@
         ENDDO
         
-c   calcul des pentes limites aux poles	
+c   calcul des pentes limites aux poles        
         fs=1.
         DO ij=1,iim
@@ -614,5 +609,5 @@
          dyq(ip1jm+ij,l)=fs*dyq(ip1jm+ij,l)
         ENDDO
-	
+        
       ENDIF
 
@@ -779,10 +774,10 @@
               masse(ij,l,iq)=newmasse
            ENDDO
-	 
-	 ENDIF
          
-	 IF (pole_sud) THEN
-	 
-	   convps  = -SSUM(iim,qbyv(ip1jm-iim,l,iq),iq,1)/apols
+         ENDIF
+         
+         IF (pole_sud) THEN
+         
+           convps  = -SSUM(iim,qbyv(ip1jm-iim,l,iq),iq,1)/apols
            convmps = -SSUM(iim,masse_adv_v(ip1jm-iim,l),1)/apols
            DO ij = ip1jm+1,ip1jmp1
@@ -792,6 +787,6 @@
               masse(ij,l,iq)=newmasse
            ENDDO
-	 
-	 ENDIF
+         
+         ENDIF
 c.-. fin ancienne version
 
Index: LMDZ5/branches/testing/libf/dyn3dmem/writedynav_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/writedynav_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/writedynav_loc.F	(revision 2641)
@@ -13,4 +13,7 @@
       USE infotrac, ONLY : nqtot, ttext
       use com_io_dyn_mod, only : histaveid,histvaveid,histuaveid
+      USE comconst_mod, ONLY: cpp
+      USE temps_mod, ONLY: itau_dyn
+      
       implicit none
 
@@ -41,15 +44,9 @@
 C
 C   Declarations
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom.h"
-#include "temps.h"
-#include "ener.h"
-#include "logic.h"
-#include "description.h"
-#include "serre.h"
-#include "iniprint.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
+      include "description.h"
+      include "iniprint.h"
 
 C
Index: LMDZ5/branches/testing/libf/dyn3dmem/writehist_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/writehist_loc.F	(revision 2594)
+++ LMDZ5/branches/testing/libf/dyn3dmem/writehist_loc.F	(revision 2641)
@@ -13,4 +13,7 @@
       USE infotrac, ONLY : nqtot, ttext
       use com_io_dyn_mod, only : histid,histvid,histuid
+      USE comconst_mod, ONLY: cpp
+      USE temps_mod, ONLY: itau_dyn
+      
       implicit none
 
@@ -41,15 +44,9 @@
 C
 C   Declarations
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom.h"
-#include "temps.h"
-#include "ener.h"
-#include "logic.h"
-#include "description.h"
-#include "serre.h"
-#include "iniprint.h"
+      include "dimensions.h"
+      include "paramet.h"
+      include "comgeom.h"
+      include "description.h"
+      include "iniprint.h"
 
 C
