Index: /trunk/DOC/chantiers/commit_importants.log
===================================================================
--- /trunk/DOC/chantiers/commit_importants.log	(revision 491)
+++ /trunk/DOC/chantiers/commit_importants.log	(revision 492)
@@ -997,2 +997,47 @@
 - exner_hyb_p.F : correction bug OMP majeur
 - exner_milieu_p.F : correction bug OMP majeur
+
+*********************
+**** commit_v492 ****
+*********************
+Ehouarn: mises à jour des dynamiques (seq et //) pour suivre les 
+développements de LMDZ5 terrestre (LMDZ5 trunk, rev 1605)
+
+* grid:
+- dimension/makdim: mise à jour du script + commentaires
+
+* filtrez:
+- filtreg_mod.F90: correction sur la taille des tableaux à allouer
+
+* dyn3d:
+- leapfrog.F : ajout possibilité de démarrer un run à n'importe quelle heure
+- dynredem.F : ajout possibilité de démarrer à n'importe quelle heure +
+              utilisation du flag "type_trac" au lieu de "config_inca"
+- control_mod.F90 : ajout de "starttime", heure de départ
+- dynetat0.F : ajout "start_time" dans tab_cntrl(32)
+- gcm.F : utilisation du flag "type_trac" au lieu de "config_inca" +
+          possibilité de démarrer à n'importe quelle heure
+- ce0l.F : utilisation du flag "type_trac" au lieu de "config_inca"
+- iniacademic.F90 : correction valeur de la pression de surface pour
+                    aqua et terra-planètes
+- conf_gcm.F : ajout lecture des flags "starttime" et "type_trac"
+- infotrac.F : gestion des cas INCA et Reprobus
+- temps.h : ajout de "start_time"
+
+* dyn3dpar:
+- Idem que pour dyn3d pour le fichiers identiques entre dyn3d et dyn3dpar:
+  dynredem.F, control_mod.F90, dynetat0.F, iniacademic.F90
+- temps.h : ajout de "start_time"
+- conf_gcm.F : ajout lecture des flags "starttime" et "type_trac" et
+               changement du nom du fichier de sortie "standard"
+- gcm.F : utilisation du flag "type_trac" au lieu de "config_inca" +
+          possibilité de démarrer à n'importe quelle heure
+- parallel.F90 : gestion des sorties "standard" dans plusieurs fichiers (1 par
+                 processus MPI)
+- leapfrog_p.F : ajout possibilité de démarrer un run à n'importe quelle heure
+                 et suppression de la variable "verbose"
+- dynredem_p.F : ajout possibilité de démarrer à n'importe quelle heure +
+                 utilisation du flag "type_trac" au lieu de "config_inca"
+- ce0l.F : utilisation du flag "type_trac" au lieu de "config_inca"
+- filtreg_p.F : ajout de flags cpp autour de l'utilisation de la BLAS et
+                realisation des calculs via matmul() sinon
Index: /trunk/DOC/chantiers/meschantiers-Ehouarn.txt
===================================================================
--- /trunk/DOC/chantiers/meschantiers-Ehouarn.txt	(revision 491)
+++ /trunk/DOC/chantiers/meschantiers-Ehouarn.txt	(revision 492)
@@ -14,5 +14,5 @@
   
 - dernière mise à jour des dynamiques (par rapport au trunk de LMDZ5 
-  "Terrestre" rev. 1560) avec la rev 270.
+  "Terrestre" rev. 1605) avec la rev 492.
   Reste à faire l'exercice de validation des modifs en //...
 
Index: /trunk/LMDZ.COMMON/libf/dyn3d/ce0l.F90
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3d/ce0l.F90	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3d/ce0l.F90	(revision 492)
@@ -28,5 +28,5 @@
   IMPLICIT NONE
 #ifndef CPP_EARTH
-  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
+  WRITE(*,*)'limit_netcdf: Earth-specific program, needs Earth physics'
 #else
 !-------------------------------------------------------------------------------
@@ -67,5 +67,5 @@
 #endif
 
-  IF (config_inca /= 'none') THEN
+  IF (type_trac == 'inca') THEN
 #ifdef INCA
     CALL init_const_lmdz(nbtr,anneeref,dayref,iphysiq,day_step,nday)
Index: /trunk/LMDZ.COMMON/libf/dyn3d/conf_gcm.F
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3d/conf_gcm.F	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3d/conf_gcm.F	(revision 492)
@@ -13,4 +13,5 @@
       use ioipsl_getincom
 #endif
+      USE infotrac, ONLY : type_trac
       IMPLICIT NONE
 c-----------------------------------------------------------------------
@@ -156,4 +157,12 @@
       nday = 10
       CALL getin('nday',nday)
+
+!Config  Key  = starttime
+!Config  Desc = Heure de depart de la simulation
+!Config  Def  = 0
+!Config  Help = Heure de depart de la simulation
+!Config         en jour
+      starttime = 0
+      CALL getin('starttime',starttime)
 
 !Config  Key  = less1day
@@ -600,4 +609,14 @@
        offline = .FALSE.
        CALL getin('offline',offline)
+     
+!Config  Key  = type_trac
+!Config  Desc = Choix de couplage avec model de chimie INCA ou REPROBUS
+!Config  Def  = lmdz
+!Config  Help = 
+!Config         'lmdz' = pas de couplage, pur LMDZ
+!Config         'inca' = model de chime INCA 
+!Config         'repr' = model de chime REPROBUS
+      type_trac = 'lmdz'
+      CALL getin('type_trac',type_trac)
 
 !Config  Key  = config_inca
@@ -677,4 +696,5 @@
       write(lunout,*)' tauyy = ', tauyy
       write(lunout,*)' offline = ', offline
+      write(lunout,*)' type_trac = ', type_trac
       write(lunout,*)' config_inca = ', config_inca
       write(lunout,*)' ok_dynzon = ', ok_dynzon 
@@ -795,4 +815,14 @@
        offline = .FALSE.
        CALL getin('offline',offline)
+
+!Config  Key  = type_trac
+!Config  Desc = Choix de couplage avec model de chimie INCA ou REPROBUS
+!Config  Def  = lmdz
+!Config  Help = 
+!Config         'lmdz' = pas de couplage, pur LMDZ
+!Config         'inca' = model de chime INCA 
+!Config         'repr' = model de chime REPROBUS
+      type_trac = 'lmdz'
+      CALL getin('type_trac',type_trac)
 
 !Config  Key  = config_inca
@@ -921,4 +951,5 @@
       write(lunout,*)' tauy = ', tauy
       write(lunout,*)' offline = ', offline
+      write(lunout,*)' type_trac = ', type_trac
       write(lunout,*)' config_inca = ', config_inca
       write(lunout,*)' ok_dynzon = ', ok_dynzon
Index: /trunk/LMDZ.COMMON/libf/dyn3d/control_mod.F90
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3d/control_mod.F90	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3d/control_mod.F90	(revision 492)
@@ -10,5 +10,5 @@
   IMPLICIT NONE
 
-  REAL    :: periodav
+  REAL    :: periodav, starttime
   INTEGER :: nday,day_step,iperiod,iapp_tracvl,nsplit_phys
   INTEGER :: iconser,iecri,dissip_period,iphysiq,iecrimoy
Index: /trunk/LMDZ.COMMON/libf/dyn3d/dynetat0.F
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3d/dynetat0.F	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3d/dynetat0.F	(revision 492)
@@ -119,4 +119,5 @@
       day_ini = tab_cntrl(30)
       itau_dyn = tab_cntrl(31)
+      start_time = tab_cntrl(32)
 c   .................................................................
 c
Index: /trunk/LMDZ.COMMON/libf/dyn3d/dynredem.F
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3d/dynredem.F	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3d/dynredem.F	(revision 492)
@@ -120,4 +120,6 @@
        tab_cntrl(30) = REAL(iday_end)
        tab_cntrl(31) = REAL(itau_dyn + itaufin)
+c start_time: start_time of simulation (not necessarily 0.)
+       tab_cntrl(32) = start_time
 c
 c    .........................................................
@@ -640,5 +642,5 @@
 #endif
 
-      IF (config_inca /= 'none') THEN
+      IF (type_trac == 'inca') THEN
 ! Ajout Anne pour lecture valeurs traceurs dans un fichier start_trac.nc
          ierr_file = NF_OPEN ("start_trac.nc", NF_NOWRITE,nid_trac)
@@ -653,5 +655,5 @@
       do iq=1,nqtot 
 
-         IF (config_inca == 'none') THEN
+         IF (type_trac /= 'inca') THEN
             ierr = NF_INQ_VARID(nid, tname(iq), nvarid)
             IF (ierr .NE. NF_NOERR) THEN
@@ -665,5 +667,5 @@
             ierr = NF_PUT_VAR_REAL (nid,nvarid,q(1,1,iq))
 #endif
-        ELSE ! config_inca = 'chem' ou 'aero'
+        ELSE ! type_trac = inca
 ! lecture de la valeur du traceur dans start_trac.nc
            IF (ierr_file .ne. 2) THEN
@@ -729,5 +731,5 @@
 #endif
           ENDIF ! (ierr_file .ne. 2)
-       END IF   ! config_inca
+       END IF   !type_trac
       
       ENDDO
Index: /trunk/LMDZ.COMMON/libf/dyn3d/gcm.F
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3d/gcm.F	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3d/gcm.F	(revision 492)
@@ -223,5 +223,5 @@
 c-----------------------------------------------------------------------
 
-      IF (config_inca /= 'none') THEN
+      IF (type_trac == 'inca') THEN
 #ifdef INCA
       call init_const_lmdz(nbtr,anneeref,dayref,iphysiq,day_step,nday, 
@@ -277,5 +277,5 @@
       endif ! of if (read_start)
 
-      IF (config_inca /= 'none') THEN
+      IF (type_trac == 'inca') THEN
 #ifdef INCA
          call init_inca_dim(klon,llm,iim,jjm,
@@ -319,4 +319,15 @@
 C on remet le calendrier à zero si demande
 c
+      IF (start_time /= starttime) then
+        WRITE(lunout,*)' GCM: Attention l''heure de depart lue dans le'
+     &,' fichier restart ne correspond pas à celle lue dans le run.def'
+        IF (raz_date == 1) then
+          WRITE(lunout,*)'Je prends l''heure lue dans run.def'
+          start_time = starttime
+        ELSE
+          WRITE(lunout,*)'Je m''arrete'
+          CALL abort
+        ENDIF
+      ENDIF
       IF (raz_date == 1) THEN
         annee_ref = anneeref
Index: /trunk/LMDZ.COMMON/libf/dyn3d/infotrac.F90
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3d/infotrac.F90	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3d/infotrac.F90	(revision 492)
@@ -32,4 +32,7 @@
   SUBROUTINE infotrac_init
     USE control_mod
+#ifdef REPROBUS
+    USE CHEM_REP, ONLY : Init_chem_rep_trac
+#endif
     IMPLICIT NONE
 !=======================================================================
@@ -85,12 +88,37 @@
     
     IF (planet_type=='earth') THEN
-     IF (config_inca=='none') THEN
-       type_trac='lmdz'
+     ! Coherence test between parameter type_trac, config_inca and preprocessing keys
+     IF (type_trac=='inca') THEN
+       WRITE(lunout,*) 'You have choosen to couple with INCA chemestry model : type_trac=', &
+            type_trac,' config_inca=',config_inca
+       IF (config_inca/='aero' .AND. config_inca/='chem') THEN
+          WRITE(lunout,*) 'Incoherence between type_trac and config_inca. Model stops. Modify run.def'
+          CALL abort_gcm('infotrac_init','Incoherence between type_trac and config_inca',1)
+       END IF
+#ifndef INCA
+       WRITE(lunout,*) 'To run this option you must add cpp key INCA and compile with INCA code'
+       CALL abort_gcm('infotrac_init','You must compile with cpp key INCA',1)
+#endif
+     ELSE IF (type_trac=='repr') THEN
+       WRITE(lunout,*) 'You have choosen to couple with REPROBUS chemestry model : type_trac=', type_trac
+#ifndef REPROBUS
+       WRITE(lunout,*) 'To run this option you must add cpp key REPROBUS and compile with REPRPBUS code'
+       CALL abort_gcm('infotrac_init','You must compile with cpp key REPROBUS',1)
+#endif
+     ELSE IF (type_trac == 'lmdz') THEN
+       WRITE(lunout,*) 'Tracers are treated in LMDZ only : type_trac=', type_trac
      ELSE
-       type_trac='inca'
+       WRITE(lunout,*) 'type_trac=',type_trac,' not possible. Model stops'
+       CALL abort_gcm('infotrac_init','bad parameter',1)
+     END IF
+
+     ! Test if config_inca is other then none for run without INCA
+     IF (type_trac/='inca' .AND. config_inca/='none') THEN
+       WRITE(lunout,*) 'config_inca will now be changed to none as you do not couple with INCA model'
+       config_inca='none'
      END IF
     ELSE
      type_trac='plnt'  ! planets... May want to dissociate between each later.
-    ENDIF
+    ENDIF ! of IF (planet_type=='earth')
 
 !-----------------------------------------------------------------------
@@ -101,17 +129,17 @@
 !-----------------------------------------------------------------------
     IF (planet_type=='earth') THEN
-     IF (type_trac == 'lmdz') THEN
+     IF (type_trac == 'lmdz' .OR. type_trac == 'repr') THEN
        OPEN(90,file='traceur.def',form='formatted',status='old', iostat=ierr)
        IF(ierr.EQ.0) THEN
-          WRITE(lunout,*) 'Open traceur.def : ok'
+          WRITE(lunout,*) trim(modname),': Open traceur.def : ok'
           READ(90,*) nqtrue
        ELSE 
-          WRITE(lunout,*) 'Problem in opening traceur.def'
-          WRITE(lunout,*) 'ATTENTION using defaut values'
+          WRITE(lunout,*) trim(modname),': Problem in opening traceur.def'
+          WRITE(lunout,*) trim(modname),': WARNING using defaut values'
           nqtrue=4 ! Defaut value
        END IF
        ! For Earth, water vapour & liquid tracers are not in the physics
        nbtr=nqtrue-2
-     ELSE
+     ELSE ! type_trac=inca
        ! nbtr has been read from INCA by init_cont_lmdz() in gcm.F 
        nqtrue=nbtr+2
@@ -121,4 +149,11 @@
        WRITE(lunout,*) trim(modname),': nqtrue=',nqtrue, ' is not allowded. 2 tracers is the minimum'
        CALL abort_gcm('infotrac_init','Not enough tracers',1)
+     END IF
+
+! Transfert number of tracers to Reprobus
+     IF (type_trac == 'repr') THEN
+#ifdef REPROBUS
+       CALL Init_chem_rep_trac(nbtr)
+#endif
      END IF
 
@@ -173,5 +208,5 @@
 !---------------------------------------------------------------------
     IF (planet_type=='earth') THEN
-     IF (type_trac == 'lmdz') THEN
+     IF (type_trac == 'lmdz' .OR. type_trac == 'repr') THEN
        IF(ierr.EQ.0) THEN
           ! Continue to read tracer.def
Index: /trunk/LMDZ.COMMON/libf/dyn3d/iniacademic.F90
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3d/iniacademic.F90	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3d/iniacademic.F90	(revision 492)
@@ -209,8 +209,13 @@
         ! surface pressure
         if (iflag_phys>2) then
-           ps(:)=108080.  ! Earth aqua/terra planets
-        else
+           ! specific value for CMIP5 aqua/terra planets
+           ! "Specify the initial dry mass to be equivalent to
+           !  a global mean surface pressure (101325 minus 245) Pa."
+           ps(:)=101080.  
+        else
+           ! use reference surface pressure
            ps(:)=preff
         endif
+        
         ! ground geopotential
         phis(:)=0.
Index: /trunk/LMDZ.COMMON/libf/dyn3d/leapfrog.F
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3d/leapfrog.F	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3d/leapfrog.F	(revision 492)
@@ -270,7 +270,10 @@
    1  CONTINUE
 
-      jD_cur = jD_ref + day_ini - day_ref + int (itau * dtvr / daysec) 
-      jH_cur = jH_ref +                                                 &
+      jD_cur = jD_ref + day_ini - day_ref +                             &
+     &          int (itau * dtvr / daysec) 
+      jH_cur = jH_ref + start_time +                                    &
      &          (itau * dtvr / daysec - int(itau * dtvr / daysec)) 
+      jD_cur = jD_cur + int(jH_cur)
+      jH_cur = jH_cur - int(jH_cur)
 
 
@@ -422,8 +425,10 @@
 !           rdaym_ini  = itau * dtvr / daysec
 !           rdayvrai   = rdaym_ini  + day_ini
-           jD_cur = jD_ref + day_ini - day_ref
-     $        + int (itau * dtvr / daysec) 
-           jH_cur = jH_ref +                                            &
-     &              (itau * dtvr / daysec - int(itau * dtvr / daysec)) 
+           jD_cur = jD_ref + day_ini - day_ref +                        &
+     &          int (itau * dtvr / daysec) 
+           jH_cur = jH_ref + start_time +                               &
+     &          (itau * dtvr / daysec - int(itau * dtvr / daysec)) 
+           jD_cur = jD_cur + int(jH_cur)
+           jH_cur = jH_cur - int(jH_cur)
 !         write(lunout,*)'itau, jD_cur = ', itau, jD_cur, jH_cur
 !         call ju2ymds(jD_cur+jH_cur, an, mois, jour, secondes)
@@ -727,5 +732,5 @@
                 call abort_gcm(modname,abort_message,0)
               else
-                CALL dynredem1("restart.nc",0.0,
+                CALL dynredem1("restart.nc",start_time,
      &                         vcov,ucov,teta,q,masse,ps)
               endif ! of if (planet_type.eq."mars")
@@ -847,5 +852,5 @@
                   call abort_gcm(modname,abort_message,0)
                 else
-                  CALL dynredem1("restart.nc",0.0,
+                  CALL dynredem1("restart.nc",start_time,
      &                         vcov,ucov,teta,q,masse,ps)
                 endif ! of if (planet_type.eq."mars")
Index: /trunk/LMDZ.COMMON/libf/dyn3d/temps.h
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3d/temps.h	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3d/temps.h	(revision 492)
@@ -1,4 +1,4 @@
 !
-! $Id: temps.h 1279 2009-12-10 09:02:56Z fairhead $
+! $Id: temps.h 1577 2011-10-20 15:06:47Z fairhead $
 !
 !  ATTENTION!!!!: ce fichier include est compatible format fixe/format libre
@@ -14,10 +14,12 @@
 
       COMMON/temps/itaufin, dt, day_ini, day_end, annee_ref, day_ref,   &
-     &             itau_dyn, itau_phy, jD_ref, jH_ref, calend
+     &             itau_dyn, itau_phy, jD_ref, jH_ref, calend,          &
+     &             start_time
+
 
       INTEGER   itaufin
       INTEGER itau_dyn, itau_phy
       INTEGER day_ini, day_end, annee_ref, day_ref
-      REAL      dt, jD_ref, jH_ref
+      REAL      dt, jD_ref, jH_ref, start_time
       CHARACTER (len=10) :: calend
 
Index: /trunk/LMDZ.COMMON/libf/dyn3dpar/ce0l.F90
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3dpar/ce0l.F90	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3dpar/ce0l.F90	(revision 492)
@@ -1,4 +1,4 @@
 !
-! $Id: ce0l.F90 1511 2011-04-28 15:21:47Z jghattas $
+! $Id: ce0l.F90 1600 2011-12-06 13:16:30Z jghattas $
 !
 !-------------------------------------------------------------------------------
@@ -19,5 +19,8 @@
   USE dimphy
   USE comgeomphy
+  USE mod_phys_lmdz_para, mpi_root_xx=>mpi_root
+  USE mod_const_mpi
   USE infotrac
+  USE parallel, ONLY: finalize_parallel
 
 #ifdef CPP_IOIPSL
@@ -28,5 +31,5 @@
   IMPLICIT NONE
 #ifndef CPP_EARTH
-  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
+  WRITE(*,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
 #else
 !-------------------------------------------------------------------------------
@@ -39,5 +42,10 @@
 #include "temps.h"
 #include "logic.h"
+#ifdef CPP_MPI
+      include 'mpif.h'
+#endif
+
   INTEGER, PARAMETER            :: longcles=20
+  INTEGER                       :: ierr
   REAL,    DIMENSION(longcles)  :: clesphy0
   REAL,    DIMENSION(iip1,jjp1) :: masque
@@ -47,6 +55,16 @@
   CALL conf_gcm( 99, .TRUE. , clesphy0 )
 
+#ifdef CPP_MPI
+  CALL init_mpi
+#endif
+
   CALL Init_Phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
   WRITE(lunout,*)'---> klon=',klon
+  IF (mpi_size>1 .OR. omp_size>1) THEN
+       CALL abort_gcm('ce0l','In parallel mode,                         &
+ &                 ce0l must be called only                             &
+ &                 for 1 process and 1 task',1)
+  ENDIF
+
   CALL InitComgeomphy
 
@@ -67,9 +85,12 @@
 #endif
 
-  IF (config_inca /= 'none') THEN
+  IF (type_trac == 'inca') THEN
 #ifdef INCA
-    CALL init_const_lmdz(nbtr,anneeref,dayref,iphysiq,day_step,nday)
-    CALL init_inca_para(iim,jjm+1,klon,1,klon_mpi_para_nb,0)
-    WRITE(lunout,*)'nbtr =' , nbtr 
+      CALL init_const_lmdz( &
+         nbtr,anneeref,dayref,&
+         iphysiq,day_step,nday,& 
+         nbsrf, is_oce,is_sic,&
+         is_ter,is_lic)
+      
 #endif
   END IF
@@ -100,4 +121,12 @@
      CALL grilles_gcm_netcdf_sub(masque,phis)
   END IF
+  
+#ifdef CPP_MPI
+!$OMP MASTER
+  CALL MPI_FINALIZE(ierr)
+  IF (ierr /= 0) CALL abort_gcm('ce0l','Error in MPI_FINALIZE',1)
+!$OMP END MASTER
+#endif
+
 #endif
 ! of #ifndef CPP_EARTH #else
Index: /trunk/LMDZ.COMMON/libf/dyn3dpar/conf_gcm.F
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3dpar/conf_gcm.F	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3dpar/conf_gcm.F	(revision 492)
@@ -17,4 +17,5 @@
       use parallel, ONLY : omp_chunk
       USE control_mod
+      USE infotrac, ONLY : type_trac
       IMPLICIT NONE
 c-----------------------------------------------------------------------
@@ -97,5 +98,7 @@
       CALL getin('lunout', lunout)
       IF (lunout /= 5 .and. lunout /= 6) THEN
-        OPEN(lunout,FILE='lmdz.out')
+        OPEN(UNIT=lunout,FILE='lmdz.out_0000',ACTION='write', 
+     &          STATUS='unknown',FORM='formatted')
+
       ENDIF
 
@@ -166,4 +169,12 @@
       nday = 10
       CALL getin('nday',nday)
+
+!Config  Key  = starttime
+!Config  Desc = Heure de depart de la simulation
+!Config  Def  = 0
+!Config  Help = Heure de depart de la simulation
+!Config         en jour
+      starttime = 0
+      CALL getin('starttime',starttime)
 
 !Config  Key  = less1day
@@ -623,4 +634,14 @@
        END IF
        
+!Config  Key  = type_trac
+!Config  Desc = Choix de couplage avec model de chimie INCA ou REPROBUS
+!Config  Def  = lmdz
+!Config  Help = 
+!Config         'lmdz' = pas de couplage, pur LMDZ
+!Config         'inca' = model de chime INCA 
+!Config         'repr' = model de chime REPROBUS
+      type_trac = 'lmdz'
+      CALL getin('type_trac',type_trac)
+
 !Config  Key  = config_inca
 !Config  Desc = Choix de configuration de INCA
@@ -699,4 +720,5 @@
       write(lunout,*)' tauyy = ', tauyy
       write(lunout,*)' offline = ', offline
+      write(lunout,*)' type_trac = ', type_trac
       write(lunout,*)' config_inca = ', config_inca
       write(lunout,*)' ok_dynzon = ', ok_dynzon 
@@ -825,4 +847,14 @@
      &         'only the file phystoke.nc will still be created ' 
        END IF
+
+!Config  Key  = type_trac
+!Config  Desc = Choix de couplage avec model de chimie INCA ou REPROBUS
+!Config  Def  = lmdz
+!Config  Help = 
+!Config         'lmdz' = pas de couplage, pur LMDZ
+!Config         'inca' = model de chime INCA 
+!Config         'repr' = model de chime REPROBUS
+      type_trac = 'lmdz'
+      CALL getin('type_trac',type_trac)
 
 !Config  Key  = config_inca
@@ -974,4 +1006,5 @@
       write(lunout,*)' tauy = ', tauy
       write(lunout,*)' offline = ', offline
+      write(lunout,*)' type_trac = ', type_trac
       write(lunout,*)' config_inca = ', config_inca
       write(lunout,*)' ok_dynzon = ', ok_dynzon 
Index: /trunk/LMDZ.COMMON/libf/dyn3dpar/control_mod.F90
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3dpar/control_mod.F90	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3dpar/control_mod.F90	(revision 492)
@@ -10,5 +10,5 @@
   IMPLICIT NONE
 
-  REAL    :: periodav
+  REAL    :: periodav, starttime
   INTEGER :: nday,day_step,iperiod,iapp_tracvl,nsplit_phys
   INTEGER :: iconser,iecri,dissip_period,iphysiq,iecrimoy
Index: /trunk/LMDZ.COMMON/libf/dyn3dpar/dynetat0.F
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3dpar/dynetat0.F	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3dpar/dynetat0.F	(revision 492)
@@ -119,4 +119,5 @@
       day_ini = tab_cntrl(30)
       itau_dyn = tab_cntrl(31)
+      start_time = tab_cntrl(32)
 c   .................................................................
 c
Index: /trunk/LMDZ.COMMON/libf/dyn3dpar/dynredem.F
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3dpar/dynredem.F	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3dpar/dynredem.F	(revision 492)
@@ -120,4 +120,6 @@
        tab_cntrl(30) = REAL(iday_end)
        tab_cntrl(31) = REAL(itau_dyn + itaufin)
+c start_time: start_time of simulation (not necessarily 0.)
+       tab_cntrl(32) = start_time
 c
 c    .........................................................
@@ -136,5 +138,5 @@
 c
       ierr = NF_PUT_ATT_TEXT (nid, NF_GLOBAL, "title", 27,
-     .                       "Fichier demmarage dynamique")
+     .                       "Fichier demarrage dynamique")
 c
 c Definir les dimensions du fichiers:
@@ -536,5 +538,4 @@
 #include "iniprint.h"
 
-
       INTEGER l
       REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) 
@@ -641,5 +642,5 @@
 #endif
 
-      IF (config_inca /= 'none') THEN
+      IF (type_trac == 'inca') THEN
 ! Ajout Anne pour lecture valeurs traceurs dans un fichier start_trac.nc
          ierr_file = NF_OPEN ("start_trac.nc", NF_NOWRITE,nid_trac)
@@ -654,5 +655,5 @@
       do iq=1,nqtot 
 
-         IF (config_inca == 'none') THEN
+         IF (type_trac /= 'inca') THEN
             ierr = NF_INQ_VARID(nid, tname(iq), nvarid)
             IF (ierr .NE. NF_NOERR) THEN
@@ -666,5 +667,5 @@
             ierr = NF_PUT_VAR_REAL (nid,nvarid,q(1,1,iq))
 #endif
-        ELSE ! config_inca = 'chem' ou 'aero'
+        ELSE ! type_trac = inca
 ! lecture de la valeur du traceur dans start_trac.nc
            IF (ierr_file .ne. 2) THEN
@@ -730,5 +731,5 @@
 #endif
           ENDIF ! (ierr_file .ne. 2)
-       END IF   ! config_inca
+       END IF   !type_trac
       
       ENDDO
Index: /trunk/LMDZ.COMMON/libf/dyn3dpar/dynredem_p.F
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3dpar/dynredem_p.F	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3dpar/dynredem_p.F	(revision 492)
@@ -1,4 +1,4 @@
 !
-! $Id: dynredem_p.F 1403 2010-07-01 09:02:53Z fairhead $
+! $Id: dynredem_p.F 1577 2011-10-20 15:06:47Z fairhead $
 !
 c
@@ -120,4 +120,6 @@
        tab_cntrl(30) =  REAL(iday_end)
        tab_cntrl(31) =  REAL(itau_dyn + itaufin)
+c start_time: start_time of simulation (not necessarily 0.)
+       tab_cntrl(32) = start_time
 c
 c    .........................................................
@@ -650,5 +652,5 @@
 #endif
 
-      IF (config_inca /= 'none') THEN
+      IF (type_trac == 'inca') THEN
 ! Ajout Anne pour lecture valeurs traceurs dans un fichier start_trac.nc
          inquire(FILE="start_trac.nc", EXIST=exist_file) 
@@ -667,5 +669,5 @@
       do iq=1,nqtot 
 
-         IF (config_inca == 'none') THEN
+         IF (type_trac /= 'inca') THEN
             ierr = NF_INQ_VARID(nid, tname(iq), nvarid)
             IF (ierr .NE. NF_NOERR) THEN
@@ -678,5 +680,5 @@
             ierr = NF_PUT_VAR_REAL (nid,nvarid,q(1,1,iq))
 #endif
-        ELSE ! config_inca = 'chem' ou 'aero'
+        ELSE ! type_trac = inca
 ! lecture de la valeur du traceur dans start_trac.nc
            IF (ierr_file .ne. 2) THEN
@@ -732,5 +734,5 @@
 #endif
           ENDIF ! (ierr_file .ne. 2)
-       END IF   ! config_inca
+       END IF   ! type_trac
       
       ENDDO
Index: /trunk/LMDZ.COMMON/libf/dyn3dpar/filtreg_p.F
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3dpar/filtreg_p.F	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3dpar/filtreg_p.F	(revision 492)
@@ -208,24 +208,39 @@
                IF( ifiltre.EQ.-2 )   THEN
                   DO j = jdfil,jffil
+#ifdef BLAS
                      CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matrinvn(1,1,j), iim, 
      &                    champ_loc(1,j,1), iip1*nlat, 0.0,
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
+#else
+                     champ_fft(:,j-jdfil+1,:)
+     &                    =matmul(matrinvn(:,:,j),champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
                ELSE IF ( griscal )     THEN
                   DO j = jdfil,jffil
+#ifdef BLAS
                      CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matriceun(1,1,j), iim, 
      &                    champ_loc(1,j,1), iip1*nlat, 0.0,
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
+#else
+                     champ_fft(:,j-jdfil+1,:)
+     &                    =matmul(matriceun(:,:,j),champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
                ELSE 
                   DO j = jdfil,jffil
+#ifdef BLAS
                      CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matricevn(1,1,j), iim, 
      &                    champ_loc(1,j,1), iip1*nlat, 0.0, 
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
+#else
+                     champ_fft(:,j-jdfil+1,:)
+     &                    =matmul(matricevn(:,:,j),champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
@@ -236,8 +251,14 @@
                IF( ifiltre.EQ.-2 )   THEN
                   DO j = jdfil,jffil
+#ifdef BLAS
                      CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matrinvs(1,1,j-jfiltsu+1), iim, 
      &                    champ_loc(1,j,1), iip1*nlat, 0.0, 
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
+#else
+                     champ_fft(:,j-jdfil+1,:)
+     &                    =matmul(matrinvs(:,:,j-jfiltsu+1),
+     &                            champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
@@ -245,8 +266,14 @@
                   
                   DO j = jdfil,jffil
+#ifdef BLAS
                      CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matriceus(1,1,j-jfiltsu+1), iim, 
      &                    champ_loc(1,j,1), iip1*nlat, 0.0, 
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
+#else
+                     champ_fft(:,j-jdfil+1,:)
+     &                    =matmul(matriceus(:,:,j-jfiltsu+1),
+     &                            champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
@@ -254,8 +281,14 @@
                   
                   DO j = jdfil,jffil
+#ifdef BLAS
                      CALL DGEMM("N", "N", iim, nbniv_loc, iim, 1.0, 
      &                    matricevs(1,1,j-jfiltsv+1), iim, 
      &                    champ_loc(1,j,1), iip1*nlat, 0.0, 
      &                    champ_fft(1,j-jdfil+1,1), iip1*nlat)
+#else
+                     champ_fft(:,j-jdfil+1,:)
+     &                    =matmul(matricevs(:,:,j-jfiltsv+1),
+     &                            champ_loc(:iim,j,:))
+#endif
                   ENDDO
                   
Index: /trunk/LMDZ.COMMON/libf/dyn3dpar/gcm.F
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3dpar/gcm.F	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3dpar/gcm.F	(revision 492)
@@ -250,5 +250,5 @@
 c-----------------------------------------------------------------------
 
-      IF (config_inca /= 'none') THEN
+      IF (type_trac == 'inca') THEN
 #ifdef INCA
          call init_const_lmdz(
@@ -337,4 +337,15 @@
 C on remet le calendrier à zero si demande
 c
+      IF (start_time /= starttime) then
+        WRITE(lunout,*)' GCM: Attention l''heure de depart lue dans le'
+     &,' fichier restart ne correspond pas à celle lue dans le run.def'
+        IF (raz_date == 1) then
+          WRITE(lunout,*)'Je prends l''heure lue dans run.def'
+          start_time = starttime
+        ELSE
+          WRITE(lunout,*)'Je m''arrete'
+          CALL abort
+        ENDIF
+      ENDIF
       IF (raz_date == 1) THEN
         annee_ref = anneeref
@@ -480,5 +491,5 @@
 c   Initialisation des dimensions d'INCA :
 c   --------------------------------------
-      IF (config_inca /= 'none') THEN
+      IF (type_trac == 'inca') THEN
 #ifdef INCA
 !$OMP PARALLEL
Index: /trunk/LMDZ.COMMON/libf/dyn3dpar/infotrac.F90
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3dpar/infotrac.F90	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3dpar/infotrac.F90	(revision 492)
@@ -32,4 +32,7 @@
   SUBROUTINE infotrac_init
     USE control_mod
+#ifdef REPROBUS
+    USE CHEM_REP, ONLY : Init_chem_rep_trac
+#endif
     IMPLICIT NONE
 !=======================================================================
@@ -85,12 +88,37 @@
     
     IF (planet_type=='earth') THEN
-     IF (config_inca=='none') THEN
-       type_trac='lmdz'
+     ! Coherence test between parameter type_trac, config_inca and preprocessing keys
+     IF (type_trac=='inca') THEN
+       WRITE(lunout,*) 'You have choosen to couple with INCA chemestry model : type_trac=', &
+            type_trac,' config_inca=',config_inca
+       IF (config_inca/='aero' .AND. config_inca/='chem') THEN
+          WRITE(lunout,*) 'Incoherence between type_trac and config_inca. Model stops. Modify run.def'
+          CALL abort_gcm('infotrac_init','Incoherence between type_trac and config_inca',1)
+       END IF
+#ifndef INCA
+       WRITE(lunout,*) 'To run this option you must add cpp key INCA and compile with INCA code'
+       CALL abort_gcm('infotrac_init','You must compile with cpp key INCA',1)
+#endif
+     ELSE IF (type_trac=='repr') THEN
+       WRITE(lunout,*) 'You have choosen to couple with REPROBUS chemestry model : type_trac=', type_trac
+#ifndef REPROBUS
+       WRITE(lunout,*) 'To run this option you must add cpp key REPROBUS and compile with REPRPBUS code'
+       CALL abort_gcm('infotrac_init','You must compile with cpp key REPROBUS',1)
+#endif
+     ELSE IF (type_trac == 'lmdz') THEN
+       WRITE(lunout,*) 'Tracers are treated in LMDZ only : type_trac=', type_trac
      ELSE
-       type_trac='inca'
+       WRITE(lunout,*) 'type_trac=',type_trac,' not possible. Model stops'
+       CALL abort_gcm('infotrac_init','bad parameter',1)
+     END IF
+
+     ! Test if config_inca is other then none for run without INCA
+     IF (type_trac/='inca' .AND. config_inca/='none') THEN
+       WRITE(lunout,*) 'config_inca will now be changed to none as you do not couple with INCA model'
+       config_inca='none'
      END IF
     ELSE
      type_trac='plnt'  ! planets... May want to dissociate between each later.
-    ENDIF
+    ENDIF ! of IF (planet_type=='earth')
 
 !-----------------------------------------------------------------------
@@ -101,17 +129,17 @@
 !-----------------------------------------------------------------------
     IF (planet_type=='earth') THEN
-     IF (type_trac == 'lmdz') THEN
+     IF (type_trac == 'lmdz' .OR. type_trac == 'repr') THEN
        OPEN(90,file='traceur.def',form='formatted',status='old', iostat=ierr)
        IF(ierr.EQ.0) THEN
-          WRITE(lunout,*) 'Open traceur.def : ok'
+          WRITE(lunout,*) trim(modname),': Open traceur.def : ok'
           READ(90,*) nqtrue
        ELSE 
-          WRITE(lunout,*) 'Problem in opening traceur.def'
-          WRITE(lunout,*) 'ATTENTION using defaut values'
+          WRITE(lunout,*) trim(modname),': Problem in opening traceur.def'
+          WRITE(lunout,*) trim(modname),': WARNING using defaut values'
           nqtrue=4 ! Defaut value
        END IF
        ! For Earth, water vapour & liquid tracers are not in the physics
        nbtr=nqtrue-2
-     ELSE
+     ELSE ! type_trac=inca
        ! nbtr has been read from INCA by init_cont_lmdz() in gcm.F 
        nqtrue=nbtr+2
@@ -121,4 +149,11 @@
        WRITE(lunout,*) trim(modname),': nqtrue=',nqtrue, ' is not allowded. 2 tracers is the minimum'
        CALL abort_gcm('infotrac_init','Not enough tracers',1)
+     END IF
+
+! Transfert number of tracers to Reprobus
+     IF (type_trac == 'repr') THEN
+#ifdef REPROBUS
+       CALL Init_chem_rep_trac(nbtr)
+#endif
      END IF
 
@@ -173,5 +208,5 @@
 !---------------------------------------------------------------------
     IF (planet_type=='earth') THEN
-     IF (type_trac == 'lmdz') THEN
+     IF (type_trac == 'lmdz' .OR. type_trac == 'repr') THEN
        IF(ierr.EQ.0) THEN
           ! Continue to read tracer.def
Index: /trunk/LMDZ.COMMON/libf/dyn3dpar/iniacademic.F90
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3dpar/iniacademic.F90	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3dpar/iniacademic.F90	(revision 492)
@@ -209,8 +209,13 @@
         ! surface pressure
         if (iflag_phys>2) then
-           ps(:)=108080.  ! Earth aqua/terra planets
-        else
+           ! specific value for CMIP5 aqua/terra planets
+           ! "Specify the initial dry mass to be equivalent to
+           !  a global mean surface pressure (101325 minus 245) Pa."
+           ps(:)=101080.  
+        else
+           ! use reference surface pressure
            ps(:)=preff
         endif
+        
         ! ground geopotential
         phis(:)=0.
Index: /trunk/LMDZ.COMMON/libf/dyn3dpar/leapfrog_p.F
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3dpar/leapfrog_p.F	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3dpar/leapfrog_p.F	(revision 492)
@@ -198,5 +198,4 @@
 
       INTEGER :: true_itau
-      LOGICAL :: verbose=.true.
       INTEGER :: iapptrac
       INTEGER :: AdjustCount
@@ -282,7 +281,12 @@
    1  CONTINUE
 
-      jD_cur = jD_ref + day_ini - day_ref + int (itau * dtvr / daysec) 
-      jH_cur = jH_ref +                                                 &
+      jD_cur = jD_ref + day_ini - day_ref +                             &
+     &          int (itau * dtvr / daysec) 
+      jH_cur = jH_ref + start_time +                                    &
      &          (itau * dtvr / daysec - int(itau * dtvr / daysec)) 
+      if (jH_cur > 1.0 ) then
+        jD_cur = jD_cur +1.
+        jH_cur = jH_cur -1.
+      endif
 
 
@@ -441,5 +445,5 @@
            call allgather_timer_average
 
-        if (Verbose) then
+        if (prt_level > 9) then
         
         print *,'*********************************'
@@ -761,7 +765,11 @@
            jD_cur = jD_ref + day_ini - day_ref
      $        + int (itau * dtvr / daysec) 
-           jH_cur = jH_ref +                                            &
+           jH_cur = jH_ref + start_time +                                &
      &              (itau * dtvr / daysec - int(itau * dtvr / daysec)) 
 !         call ju2ymds(jD_cur+jH_cur, an, mois, jour, secondes)
+           if (jH_cur > 1.0 ) then
+             jD_cur = jD_cur +1.
+             jH_cur = jH_cur -1.
+           endif
 
 c rajout debug
Index: /trunk/LMDZ.COMMON/libf/dyn3dpar/parallel.F90
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3dpar/parallel.F90	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3dpar/parallel.F90	(revision 492)
@@ -1,4 +1,4 @@
 ! 
-! $Id: parallel.F90 1487 2011-02-11 15:07:54Z jghattas $
+! $Id: parallel.F90 1575 2011-09-21 13:57:48Z jghattas $
 !
   module parallel
@@ -43,5 +43,7 @@
       integer, dimension(3) :: blocklen,type
       integer :: comp_id
-
+      character(len=4)  :: num
+      character(len=20) :: filename
+ 
 #ifdef CPP_OMP    
       INTEGER :: OMP_GET_NUM_THREADS
@@ -75,5 +77,16 @@
         mpi_rank=0
       ENDIF
-  
+
+
+! Open text output file with mpi_rank in suffix of file name 
+      IF (lunout /= 5 .and. lunout /= 6) THEN
+         WRITE(num,'(I4.4)') mpi_rank
+         filename='lmdz.out_'//num
+         IF (mpi_rank .NE. 0) THEN
+            OPEN(UNIT=lunout,FILE=TRIM(filename),ACTION='write', &
+               STATUS='unknown',FORM='formatted',IOSTAT=ierr) 
+         ENDIF
+      ENDIF
+
       
       allocate(jj_begin_para(0:mpi_size-1))
Index: /trunk/LMDZ.COMMON/libf/dyn3dpar/temps.h
===================================================================
--- /trunk/LMDZ.COMMON/libf/dyn3dpar/temps.h	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/dyn3dpar/temps.h	(revision 492)
@@ -14,10 +14,12 @@
 
       COMMON/temps/itaufin, dt, day_ini, day_end, annee_ref, day_ref,   &
-     &             itau_dyn, itau_phy, jD_ref, jH_ref, calend
+     &             itau_dyn, itau_phy, jD_ref, jH_ref, calend,          &
+     &             start_time
+
 
       INTEGER   itaufin
       INTEGER itau_dyn, itau_phy
       INTEGER day_ini, day_end, annee_ref, day_ref
-      REAL      dt, jD_ref, jH_ref
+      REAL      dt, jD_ref, jH_ref, start_time
       CHARACTER (len=10) :: calend
 
Index: /trunk/LMDZ.COMMON/libf/filtrez/filtreg_mod.F90
===================================================================
--- /trunk/LMDZ.COMMON/libf/filtrez/filtreg_mod.F90	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/filtrez/filtreg_mod.F90	(revision 492)
@@ -1,2 +1,5 @@
+!
+! $Id $
+!
 MODULE filtreg_mod
 
@@ -42,5 +45,4 @@
     INTEGER ixmineq
 #endif
-    EXTERNAL  inifgn
     !
     ! ------------------------------------------------------------
@@ -71,7 +73,7 @@
     CALL inifgn(eignvl)
     !
-    PRINT *,' EIGNVL '
+    PRINT *,'inifilr: EIGNVL '
     PRINT 250,eignvl
-250 FORMAT( 1x,5e13.6)
+250 FORMAT( 1x,5e14.6)
     !
     ! compute eigenvalues and eigenfunctions
@@ -113,4 +115,10 @@
 #endif
     !
+    ! For a regular grid, we want the filter to start at latitudes
+    ! corresponding to lengths dx of the same size as dy (in terms
+    ! of angles: dx=2*dy) => at colat0=0.5 (i.e. colatitude=30 degrees
+    !  <=> latitude=60 degrees).
+    ! Same idea for the zoomed grid: start filtering polewards as soon
+    ! as length dx becomes of the same size as dy 
     !
     colat0  =  MIN( 0.5, dymin/dxmin )
@@ -158,16 +166,25 @@
     imx  = iim
     !
-    PRINT *,' TRUNCATION AT ',imx
-    !
+    PRINT *,'inifilr: TRUNCATION AT ',imx
+    !
+! Ehouarn: set up some defaults
+    jfiltnu=2 ! avoid north pole
+    jfiltsu=jjm ! avoid south pole (which is at jjm+1)
+    jfiltnv=1 ! NB: no poles on the V grid
+    jfiltsv=jjm
+
     DO j = 2, jjm/2+1
        cof = COS( rlatu(j) )/ colat0
        IF ( cof .LT. 1. ) THEN
-          IF( rlamda(imx) * COS(rlatu(j) ).LT.1. ) jfiltnu= j
+          IF( rlamda(imx) * COS(rlatu(j) ).LT.1. ) THEN
+            jfiltnu= j
+          ENDIF
        ENDIF
 
        cof = COS( rlatu(jjp1-j+1) )/ colat0
        IF ( cof .LT. 1. ) THEN
-          IF( rlamda(imx) * COS(rlatu(jjp1-j+1) ).LT.1. ) &
+          IF( rlamda(imx) * COS(rlatu(jjp1-j+1) ).LT.1. ) THEN
                jfiltsu= jjp1-j+1
+          ENDIF
        ENDIF
     ENDDO
@@ -176,16 +193,18 @@
        cof = COS( rlatv(j) )/ colat0
        IF ( cof .LT. 1. ) THEN
-          IF( rlamda(imx) * COS(rlatv(j) ).LT.1. ) jfiltnv= j
+          IF( rlamda(imx) * COS(rlatv(j) ).LT.1. ) THEN
+            jfiltnv= j
+          ENDIF
        ENDIF
 
        cof = COS( rlatv(jjm-j+1) )/ colat0
        IF ( cof .LT. 1. ) THEN
-          IF( rlamda(imx) * COS(rlatv(jjm-j+1) ).LT.1. ) &
+          IF( rlamda(imx) * COS(rlatv(jjm-j+1) ).LT.1. ) THEN
                jfiltsv= jjm-j+1
+          ENDIF
        ENDIF
     ENDDO
     !                                 
 
-    IF ( jfiltnu.LE.0 ) jfiltnu=1
     IF( jfiltnu.GT. jjm/2 +1 )  THEN
        PRINT *,' jfiltnu en dehors des valeurs acceptables ' ,jfiltnu
@@ -193,5 +212,4 @@
     ENDIF
 
-    IF( jfiltsu.LE.0) jfiltsu=1
     IF( jfiltsu.GT.  jjm  +1 )  THEN
        PRINT *,' jfiltsu en dehors des valeurs acceptables ' ,jfiltsu
@@ -199,5 +217,4 @@
     ENDIF
 
-    IF( jfiltnv.LE.0) jfiltnv=1
     IF( jfiltnv.GT. jjm/2    )  THEN
        PRINT *,' jfiltnv en dehors des valeurs acceptables ' ,jfiltnv
@@ -205,5 +222,4 @@
     ENDIF
 
-    IF( jfiltsv.LE.0) jfiltsv=1
     IF( jfiltsv.GT.     jjm  )  THEN
        PRINT *,' jfiltsv en dehors des valeurs acceptables ' ,jfiltsv
@@ -211,14 +227,14 @@
     ENDIF
 
-    PRINT *,' jfiltnv jfiltsv jfiltnu jfiltsu ' , &
+    PRINT *,'inifilr: jfiltnv jfiltsv jfiltnu jfiltsu ' , &
          jfiltnv,jfiltsv,jfiltnu,jfiltsu
 
     IF(first_call_inifilr) THEN
        ALLOCATE(matriceun(iim,iim,jfiltnu))
-       ALLOCATE(matriceus(iim,iim,jfiltsu))
+       ALLOCATE(matriceus(iim,iim,jjm-jfiltsu+1))
        ALLOCATE(matricevn(iim,iim,jfiltnv))
-       ALLOCATE(matricevs(iim,iim,jfiltsv))
+       ALLOCATE(matricevs(iim,iim,jjm-jfiltsv+1))
        ALLOCATE( matrinvn(iim,iim,jfiltnu))
-       ALLOCATE( matrinvs(iim,iim,jfiltsu))
+       ALLOCATE( matrinvs(iim,iim,jjm-jfiltsu+1))
        first_call_inifilr = .FALSE.
     ENDIF
@@ -230,4 +246,5 @@
     !
     DO j = 1,jjm
+    !default initialization: all modes are retained (i.e. no filtering)
        modfrstu( j ) = iim
        modfrstv( j ) = iim
@@ -306,5 +323,6 @@
 
     IF(jfiltnv.GE.jjm/2 .OR. jfiltnu.GE.jjm/2)THEN
-
+! Ehouarn: and what are these for??? Trying to handle a limit case
+!          where filters extend to and meet at the equator?
        IF(jfiltnv.EQ.jfiltsv)jfiltsv=1+jfiltnv
        IF(jfiltnu.EQ.jfiltsu)jfiltsu=1+jfiltnu
@@ -334,5 +352,5 @@
              eignft(i,k) = eignfnv(k,i) * coff
           ENDDO
-       ENDDO
+       ENDDO ! of DO i=1,iim
 #ifdef CRAY
        CALL MXM( eignfnv,iim,eignft,iim,matriceun(1,1,j),iim )
@@ -350,9 +368,9 @@
              ENDDO
           ENDDO
-       ENDDO
-#endif
-#endif
-
-    ENDDO
+       ENDDO ! of DO k = 1, iim
+#endif
+#endif
+
+    ENDDO ! of DO j = 2, jfiltnu
 
     DO j = jfiltsu, jjm
@@ -364,5 +382,5 @@
              eignft(i,k) = eignfnv(k,i) * coff
           ENDDO
-       ENDDO
+       ENDDO ! of DO i=1,iim
 #ifdef CRAY
        CALL MXM(eignfnv,iim,eignft,iim,matriceus(1,1,j-jfiltsu+1),iim)
@@ -381,9 +399,9 @@
              ENDDO
           ENDDO
-       ENDDO
-#endif
-#endif
-
-    ENDDO
+       ENDDO ! of DO k = 1, iim
+#endif
+#endif
+
+    ENDDO ! of DO j = jfiltsu, jjm
 
     !   ...................................................................
@@ -421,5 +439,5 @@
 #endif
 
-    ENDDO
+    ENDDO ! of DO j = 1, jfiltnv
 
     DO j = jfiltsv, jjm
@@ -452,5 +470,5 @@
 #endif
 
-    ENDDO
+    ENDDO ! of DO j = jfiltsv, jjm
 
     !   ...................................................................
@@ -488,5 +506,5 @@
 #endif
 
-    ENDDO
+    ENDDO ! of DO j = 2, jfiltnu
 
     DO j = jfiltsu, jjm
@@ -518,5 +536,5 @@
 #endif
 
-    ENDDO
+    ENDDO ! of DO j = jfiltsu, jjm
 
     IF (use_filtre_fft) THEN
Index: /trunk/LMDZ.COMMON/libf/grid/dimension/makdim
===================================================================
--- /trunk/LMDZ.COMMON/libf/grid/dimension/makdim	(revision 491)
+++ /trunk/LMDZ.COMMON/libf/grid/dimension/makdim	(revision 492)
@@ -1,48 +1,48 @@
-for i in $* ; do
-   list=$list.$i
+#!/bin/bash
+#set -xv
+
+# sanity check: do we have the required argument ?
+if (( $# < 1 )) || (( $# > 3 ))
+then
+ echo "Wrong number of parameters in $0 !!!"
+ echo " Usage:"
+ echo "  $0 [im] [jm] lm"
+ echo " where im, jm and lm are the dimensions"
+ exit
+fi
+
+# build "fichnom", the relevant 'dimensions.im.jm.lm' file name
+for i in $*
+  do
+  list=$list.$i
 done
 fichdim=dimensions${list}
 
-if [ ! -f $fichdim ] ; then
-# si le fichier de dimensions n'existe pas, on le cree
+if [ ! -f $fichdim ]
+    then
+#    echo "$fichdim does not exist"
 
-  if [ $# -ge 3 ] ; then
-     im=$1
-     jm=$2
-     lm=$3
-     n2=$1
-     ndm=1
+    # assign values of im, jm and lm
+    if [ $# -ge 3 ]
+        then
+        im=$1
+        jm=$2
+        lm=$3
+        ndm=1
+    elif [ $# -ge 2 ]
+        then
+        im=1
+        jm=$1
+        lm=$2
+        ndm=1
+    elif [ $# -ge 1 ]
+        then
+        im=1
+        jm=1
+        lm=$1
+        ndm=1
+    fi
 
-# Le test suivant est commente car il est inutile avec le nouveau 
-# filtre filtrez. Attention avec le "vieux" filtre (F. Forget,11/1994)
-#
-#     while [ "$n2" -gt 2 ]; do
-#       n2=`expr $n2 / 2`
-#       ndm=`expr $ndm + 1`
-#       echo $n2
-#    done
-#    if [ "$n2" != 2 ] ; then
-#       echo le nombre de longitude doit etre une puissance de 2
-#       exit
-#    fi
-
-
-  else if [ $# -ge 2 ] ; then
-      im=1
-      jm=$1
-      lm=$2
-      ndm=1
-  else if [ $# -ge 1 ] ; then
-      im=1
-      jm=1
-      lm=$1
-      ndm=1
-  else
-         echo il faut au moins une dimension
-         exit
-  fi
-fi
-fi
-
+# since the file doesn't exist, we create it
 cat << EOF > $fichdim
 !-----------------------------------------------------------------------
@@ -62,4 +62,8 @@
 fi
 
+# remove 'old' dimensions.h file (if any) and replace it with new one
+if [ -f ../dimensions.h ] ; then
 \rm ../dimensions.h
+fi
 tar cf - $fichdim | ( cd .. ; tar xf - ; mv $fichdim dimensions.h )
+# line above is a trick to preserve time of creation of dimensions.h files
