Index: DZ4/branches/LMDZ4-dev/libf/dyn3d/comdiss.h
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/comdiss.h	(revision 1139)
+++ 	(revision )
@@ -1,15 +1,0 @@
-!
-! $Header$
-!
-c-----------------------------------------------------------------------
-c INCLUDE 'comdiss.h'
-
-      INTEGER niter
-      REAL tetau(llm),tetah(llm),cdivu,cdivh,crot
-      LOGICAL dissipst
-
-      COMMON/comdissi/niter
-      COMMON/comdissr/tetau,tetah,cdivu,cdivh,crot
-      COMMON/comdissl/dissipst
-
-c-----------------------------------------------------------------------
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/comdissip.h
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/comdissip.h	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/comdissip.h	(revision 1140)
@@ -2,15 +2,14 @@
 ! $Header$
 !
-c-----------------------------------------------------------------------
-c INCLUDE dissip.h
+!-----------------------------------------------------------------------
+! INCLUDE comdissip.h
 
-      COMMON/comdissip/
-     $    lstardis,niterdis,coefdis,tetavel,tetatemp,gamdissip
+      COMMON/comdissip/                                                 &
+     &    niterdis,coefdis,tetavel,tetatemp,gamdissip
 
 
-      LOGICAL lstardis
       INTEGER niterdis
 
       REAL tetavel,tetatemp,coefdis,gamdissip
 
-c-----------------------------------------------------------------------
+!-----------------------------------------------------------------------
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/conf_gcm.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/conf_gcm.F	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/conf_gcm.F	(revision 1140)
@@ -6,5 +6,10 @@
       SUBROUTINE conf_gcm( tapedef, etatinit, clesphy0 )
 c
+#ifdef CPP_IOIPSL
       use IOIPSL
+#else
+! if not using IOIPSL, we still need to use (a local version of) getin
+      use ioipsl_getincom
+#endif
       IMPLICIT NONE
 c-----------------------------------------------------------------------
@@ -99,4 +104,10 @@
 c  Parametres de controle du run:
 c-----------------------------------------------------------------------
+!Config  Key  = planet_type
+!Config  Desc = planet type ("earth", "mars", "venus", ...)
+!Config  Def  = earth
+!Config  Help = this flag sets the type of atymosphere that is considered
+      planet_type="earth"
+      CALL getin('planet_type',planet_type)
 
 !Config  Key  = dayref
@@ -179,4 +190,11 @@
        CALL getin('periodav',periodav)
 
+!Config  Key  = output_grads_dyn
+!Config  Desc = output dynamics diagnostics in 'dyn.dat' file
+!Config  Def  = n
+!Config  Help = output dynamics diagnostics in Grads-readable 'dyn.dat' file
+       output_grads_dyn=.false.
+       CALL getin('output_grads_dyn',output_grads_dyn)
+
 !Config  Key  = idissip
 !Config  Desc = periode de la dissipation 
@@ -274,4 +292,12 @@
 c    ...............................................................
 
+!Config  Key  =  read_start
+!Config  Desc = Initialize model using a 'start.nc' file
+!Config  Def  = y
+!Config  Help = y: intialize dynamical fields using a 'start.nc' file
+!               n: fields are initialized by 'iniacademic' routine
+       read_start= .true.
+       CALL getin('read_start',read_start)
+
 !Config  Key  = iflag_phys
 !Config  Desc = Avec ls physique 
@@ -330,6 +356,6 @@
 c
       IF( ABS(clat - clatt).GE. 0.001 )  THEN
-        PRINT *,' La valeur de clat passee par run.def est differente de 
-     *  celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de clat passee par run.def',
+     &    ' est differente de celle lue sur le fichier  start '
         STOP
       ENDIF
@@ -345,6 +371,6 @@
 
       IF( ABS(grossismx - grossismxx).GE. 0.001 )  THEN
-        PRINT *,' La valeur de grossismx passee par run.def est differente  
-     *  de celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de grossismx passee par ',
+     &  'run.def est differente de celle lue sur le fichier  start '
         STOP
       ENDIF
@@ -359,11 +385,12 @@
 
       IF( ABS(grossismy - grossismyy).GE. 0.001 )  THEN
-        PRINT *,' La valeur de grossismy passee par run.def est differen
-     * te de celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de grossismy passee par ',
+     & 'run.def est differente de celle lue sur le fichier  start '
         STOP
       ENDIF
       
       IF( grossismx.LT.1. )  THEN
-        PRINT *,' ***  ATTENTION !! grossismx < 1 .   *** '
+        write(lunout,*)
+     &       'conf_gcm: ***  ATTENTION !! grossismx < 1 .   *** '
          STOP
       ELSE
@@ -373,5 +400,6 @@
 
       IF( grossismy.LT.1. )  THEN
-        PRINT *,' ***  ATTENTION !! grossismy < 1 .   *** '
+        write(lunout,*)
+     &       'conf_gcm: ***  ATTENTION !! grossismy < 1 .   *** '
          STOP
       ELSE
@@ -379,5 +407,5 @@
       ENDIF
 
-      PRINT *,' alphax alphay defrun ',alphax,alphay
+      write(lunout,*)'conf_gcm: alphax alphay',alphax,alphay
 c
 c    alphax et alphay sont les anciennes formulat. des grossissements
@@ -394,17 +422,17 @@
 
       IF( .NOT.fxyhypb )  THEN
-           IF( fxyhypbb )     THEN
-              PRINT *,' ********  PBS DANS  DEFRUN  ******** '
-              PRINT *,' *** fxyhypb lu sur le fichier start est F ',
-     *       'alors  qu il est  T  sur  run.def  ***'
+         IF( fxyhypbb )     THEN
+            write(lunout,*)' ********  PBS DANS  CONF_GCM  ******** '
+            write(lunout,*)' *** fxyhypb lu sur le fichier start est ',
+     *       'F alors  qu il est  T  sur  run.def  ***'
               STOP
-           ENDIF
+         ENDIF
       ELSE
-           IF( .NOT.fxyhypbb )   THEN
-              PRINT *,' ********  PBS DANS  DEFRUN  ******** '
-              PRINT *,' ***  fxyhypb lu sur le fichier start est T ',
-     *        'alors  qu il est  F  sur  run.def  ****  '
+         IF( .NOT.fxyhypbb )   THEN
+            write(lunout,*)' ********  PBS DANS  CONF_GCM  ******** '
+            write(lunout,*)' ***  fxyhypb lu sur le fichier start est ',
+     *        'T alors  qu il est  F  sur  run.def  ****  '
               STOP
-           ENDIF
+         ENDIF
       ENDIF
 c
@@ -419,6 +447,6 @@
       IF( fxyhypb )  THEN
        IF( ABS(dzoomx - dzoomxx).GE. 0.001 )  THEN
-        PRINT *,' La valeur de dzoomx passee par run.def est differente 
-     *  de celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de dzoomx passee par ',
+     *  'run.def est differente de celle lue sur le fichier  start '
         STOP
        ENDIF
@@ -435,6 +463,6 @@
       IF( fxyhypb )  THEN
        IF( ABS(dzoomy - dzoomyy).GE. 0.001 )  THEN
-        PRINT *,' La valeur de dzoomy passee par run.def est differente 
-     * de celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de dzoomy passee par ',
+     * 'run.def est differente de celle lue sur le fichier  start '
         STOP
        ENDIF
@@ -450,6 +478,6 @@
       IF( fxyhypb )  THEN
        IF( ABS(taux - tauxx).GE. 0.001 )  THEN
-        PRINT *,' La valeur de taux passee par run.def est differente
-     * de celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de taux passee par ',
+     * 'run.def est differente de celle lue sur le fichier  start '
         STOP
        ENDIF
@@ -465,6 +493,6 @@
       IF( fxyhypb )  THEN
        IF( ABS(tauy - tauyy).GE. 0.001 )  THEN
-        PRINT *,' La valeur de tauy passee par run.def est differente
-     * de celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de tauy passee par ',
+     * 'run.def est differente de celle lue sur le fichier  start '
         STOP
        ENDIF
@@ -484,19 +512,19 @@
 
         IF( .NOT.ysinus )  THEN
-           IF( ysinuss )     THEN
-              PRINT *,' ********  PBS DANS  DEFRUN  ******** '
-              PRINT *,' *** ysinus lu sur le fichier start est F ',
-     *       'alors  qu il est  T  sur  run.def  ***'
+          IF( ysinuss )     THEN
+            write(lunout,*)' ********  PBS DANS  CONF_GCM  ******** '
+            write(lunout,*)' *** ysinus lu sur le fichier start est F',
+     *       ' alors  qu il est  T  sur  run.def  ***'
+            STOP
+          ENDIF
+        ELSE
+          IF( .NOT.ysinuss )   THEN
+            write(lunout,*)' ********  PBS DANS  CONF_GCM  ******** '
+            write(lunout,*)' *** ysinus lu sur le fichier start est T',
+     *        ' alors  qu il est  F  sur  run.def  ****  '
               STOP
-           ENDIF
-        ELSE
-           IF( .NOT.ysinuss )   THEN
-              PRINT *,' ********  PBS DANS  DEFRUN  ******** '
-              PRINT *,' ***  ysinus lu sur le fichier start est T ',
-     *        'alors  qu il est  F  sur  run.def  ****  '
-              STOP
-           ENDIF
+          ENDIF
         ENDIF
-      ENDIF
+      ENDIF ! of IF( .NOT.fxyhypb  )
 c
 !Config  Key  = offline
@@ -521,4 +549,5 @@
       write(lunout,*)' #########################################'
       write(lunout,*)' Configuration des parametres du gcm: '
+      write(lunout,*)' planet_type = ', planet_type
       write(lunout,*)' dayref = ', dayref
       write(lunout,*)' anneeref = ', anneeref
@@ -529,4 +558,5 @@
       write(lunout,*)' iecri = ', iecri
       write(lunout,*)' periodav = ', periodav 
+      write(lunout,*)' output_grads_dyn = ', output_grads_dyn
       write(lunout,*)' idissip = ', idissip
       write(lunout,*)' lstardis = ', lstardis
@@ -539,4 +569,5 @@
       write(lunout,*)' coefdis = ', coefdis
       write(lunout,*)' purmats = ', purmats
+      write(lunout,*)' read_start = ', read_start
       write(lunout,*)' iflag_phys = ', iflag_phys
       write(lunout,*)' iphysiq = ', iphysiq
@@ -590,5 +621,6 @@
 
       IF( grossismx.LT.1. )  THEN
-        PRINT *,' ***  ATTENTION !! grossismx < 1 .   *** '
+        write(lunout,*)
+     &   'conf_gcm: ***  ATTENTION !! grossismx < 1 .   *** '
          STOP
       ELSE
@@ -598,5 +630,6 @@
 
       IF( grossismy.LT.1. )  THEN
-        PRINT *,' ***  ATTENTION !! grossismy < 1 .   *** '
+        write(lunout,*)
+     &  'conf_gcm: ***  ATTENTION !! grossismy < 1 .   *** '
          STOP
       ELSE
@@ -604,5 +637,5 @@
       ENDIF
 
-      PRINT *,' alphax alphay defrun ',alphax,alphay
+      write(lunout,*)'conf_gcm: alphax alphay ',alphax,alphay
 c
 c    alphax et alphay sont les anciennes formulat. des grossissements
@@ -693,4 +726,5 @@
       write(lunout,*)' #########################################'
       write(lunout,*)' Configuration des parametres du gcm: '
+      write(lunout,*)' planet_type = ', planet_type
       write(lunout,*)' dayref = ', dayref
       write(lunout,*)' anneeref = ', anneeref
@@ -701,4 +735,5 @@
       write(lunout,*)' iecri = ', iecri
       write(lunout,*)' periodav = ', periodav 
+      write(lunout,*)' output_grads_dyn = ', output_grads_dyn
       write(lunout,*)' idissip = ', idissip
       write(lunout,*)' lstardis = ', lstardis
@@ -711,11 +746,12 @@
       write(lunout,*)' coefdis = ', coefdis
       write(lunout,*)' purmats = ', purmats
+      write(lunout,*)' read_start = ', read_start
       write(lunout,*)' iflag_phys = ', iflag_phys
       write(lunout,*)' iphysiq = ', iphysiq
-      write(lunout,*)' clonn = ', clonn 
-      write(lunout,*)' clatt = ', clatt
+      write(lunout,*)' clon = ', clon
+      write(lunout,*)' clat = ', clat
       write(lunout,*)' grossismx = ', grossismx
       write(lunout,*)' grossismy = ', grossismy
-      write(lunout,*)' fxyhypbb = ', fxyhypbb
+      write(lunout,*)' fxyhypb = ', fxyhypb
       write(lunout,*)' dzoomx = ', dzoomx
       write(lunout,*)' dzoomy = ', dzoomy
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/control.h
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/control.h	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/control.h	(revision 1140)
@@ -14,5 +14,6 @@
      &              iperiod,iapp_tracvl,iconser,iecri,idissip,iphysiq , &
      &              periodav,iecrimoy,dayref,anneeref,                  &
-     &              raz_date,offline,ip_ebil_dyn,config_inca
+     &              raz_date,offline,ip_ebil_dyn,config_inca,           &
+     &              planet_type,output_grads_dyn
 
       INTEGER   nday,day_step,iperiod,iapp_tracvl,iconser,iecri,        &
@@ -22,3 +23,6 @@
       logical offline
       CHARACTER (len=4) :: config_inca
+      CHARACTER(len=10) :: planet_type ! planet type ('earth','mars',...)
+      LOGICAL :: output_grads_dyn ! output dynamics diagnostics in
+                                  ! binary grads file 'dyn.dat' (y/n)
 !-----------------------------------------------------------------------
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/diagedyn.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/diagedyn.F	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/diagedyn.F	(revision 1140)
@@ -58,6 +58,7 @@
 #include "paramet.h"
 #include "comgeom.h"
-
-#ifdef CPP_PHYS
+#include "iniprint.h"
+
+#ifdef CPP_EARTH
 #include "../phylmd/YOMCST.h"
 #include "../phylmd/YOETHF.h"
@@ -139,5 +140,5 @@
 
 
-#ifdef CPP_PHYS
+#ifdef CPP_EARTH
 c======================================================================
 C     Compute Kinetic enrgy
@@ -314,6 +315,7 @@
 C
 #else
-      print*,'Pour l instant diagedyn a besoin de la physique'
+      write(lunout,*),'diagedyn: Needs Earth physics to function'
 #endif
+! #endif of #ifdef CPP_EARTH 
       RETURN 
       END 
Index: DZ4/branches/LMDZ4-dev/libf/dyn3d/disvert0.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/disvert0.F	(revision 1139)
+++ 	(revision )
@@ -1,183 +1,0 @@
-!
-! $Header$
-!
-c
-c
-      SUBROUTINE disvert0(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
-
-c    Auteur :  P. Le Van .
-c
-      IMPLICIT NONE
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "iniprint.h"
-#include "logic.h"
-c
-c=======================================================================
-c
-c
-c    s = sigma ** kappa   :  coordonnee  verticale
-c    dsig(l)            : epaisseur de la couche l ds la coord.  s
-c    sig(l)             : sigma a l'interface des couches l et l-1
-c    ds(l)              : distance entre les couches l et l-1 en coord.s
-c
-c=======================================================================
-c
-      REAL ap(llmp1),bp(llmp1),dpres(llm),nivsigs(llm),nivsig(llmp1)
-      REAL pa,preff,presnivs(llm)
-c
-c   declarations:
-c   -------------
-c
-      REAL sig(llm+1),dsig(llm)
-       real zzz(1:llm+1)
-       real dzz(1:llm)
-      real zk,zkm1,dzk1,dzk2,k0,k1
-c
-      INTEGER l
-      REAL snorm
-      REAL alpha,beta,gama,delta,deltaz,h
-      INTEGER np,ierr
-      REAL pi,x
-
-      REAL SSUM
-
-      pa        =  50 000.
-      preff     = 101 325.
-
-c
-c-----------------------------------------------------------------------
-c
-      pi=2.*ASIN(1.)
-
-      OPEN(99,file='sigma.def',status='old',form='formatted',
-     s   iostat=ierr)
-
-c-----------------------------------------------------------------------
-c   cas 1 on lit les options dans sigma.def:
-c   ----------------------------------------
-
-      IF (ierr.eq.0) THEN
-
-      READ(99,*) h           ! hauteur d'echelle 8.
-      READ(99,*) deltaz      ! epaiseur de la premiere couche 0.04
-      READ(99,*) beta        ! facteur d'acroissement en haut 1.3
-      READ(99,*) k0          ! nombre de couches dans la transition surf
-      READ(99,*) k1          ! nombre de couches dans la transition haute
-      CLOSE(99)
-      alpha=deltaz/(llm*h)
-      WRITE(lunout,*)'h,alpha,k0,k1,beta'
-
-c     read(*,*) h,deltaz,beta,k0,k1 ! 8 0.04 4 20 1.2
-
-      alpha=deltaz/tanh(1./k0)*2.
-      zkm1=0.
-      sig(1)=1.
-      do l=1,llm
-        sig(l+1)=(cosh(l/k0))**(-alpha*k0/h)
-     + *exp(-alpha/h*tanh((llm-k1)/k0)*beta**(l-(llm-k1))/log(beta))
-        zk=-h*log(sig(l+1))
-
-        dzk1=alpha*tanh(l/k0)
-        dzk2=alpha*tanh((llm-k1)/k0)*beta**(l-(llm-k1))/log(beta)
-        WRITE(lunout,*)l,sig(l+1),zk,zk-zkm1,dzk1,dzk2
-        zkm1=zk
-      enddo
-
-      sig(llm+1)=0.
-
-c
-       DO 2  l = 1, llm
-       dsig(l) = sig(l)-sig(l+1)
-   2   CONTINUE
-c
-
-      ELSE
-c-----------------------------------------------------------------------
-c   cas 2 ancienne discretisation (LMD5...):
-c   ----------------------------------------
-
-      write(lunout,*)'WARNING!!! Ancienne discretisation verticale'
-
-      h=7.
-      snorm  = 0.
-      DO l = 1, llm
-         x = 2.*asin(1.) * (FLOAT(l)-0.5) / float(llm+1)
-
-         IF (ok_strato) THEN
-           dsig(l) =(1.0 + 7.0 * SIN(x)**2)
-     &            *(0.5*(1.-tanh(1.*(x-asin(1.))/asin(1.))))**2        
-         ELSE
-           dsig(l) = 1.0 + 7.0 * SIN(x)**2
-         ENDIF
-
-         snorm = snorm + dsig(l)
-      ENDDO
-      snorm = 1./snorm
-      DO l = 1, llm
-         dsig(l) = dsig(l)*snorm
-      ENDDO
-      sig(llm+1) = 0.
-      DO l = llm, 1, -1
-         sig(l) = sig(l+1) + dsig(l)
-      ENDDO
-
-      ENDIF
-
-
-      DO l=1,llm
-        nivsigs(l) = FLOAT(l)
-      ENDDO
-
-      DO l=1,llmp1
-        nivsig(l)= FLOAT(l)
-      ENDDO
-
-c
-c    ....  Calculs  de ap(l) et de bp(l)  ....
-c    .........................................
-c
-c
-c   .....  pa et preff sont lus  sur les fichiers start par lectba  .....
-c
-
-      bp(llmp1) =   0.
-
-      DO l = 1, llm
-cc
-ccc    ap(l) = 0.
-ccc    bp(l) = sig(l)
-
-      bp(l) = EXP( 1. -1./( sig(l)*sig(l)) )
-      ap(l) = pa * ( sig(l) - bp(l) )
-c
-      ENDDO
-      ap(llmp1) = pa * ( sig(llmp1) - bp(llmp1) )
-
-      write(lunout,*)' BP '
-      write(lunout,*)  bp
-      write(lunout,*)' AP '
-      write(lunout,*)  ap
-
-      write(lunout,*)
-     .'Niveaux de pressions approximatifs aux centres des'
-      write(lunout,*)
-     .'couches calcules pour une pression de surface =',preff
-      write(lunout,*)
-     .'et altitudes equivalentes pour une hauteur d echelle de'
-      write(lunout,*)'8km'
-      DO l = 1, llm
-       dpres(l) = bp(l) - bp(l+1)
-       presnivs(l) = 0.5 *( ap(l)+bp(l)*preff + ap(l+1)+bp(l+1)*preff )
-       write(lunout,*)'PRESNIVS(',l,')=',presnivs(l),'    Z ~ ',
-     .        log(preff/presnivs(l))*8.
-     .  ,'   DZ ~ ',8.*log((ap(l)+bp(l)*preff)/
-     .       max(ap(l+1)+bp(l+1)*preff,1.e-10))
-      ENDDO
-
-      write(lunout,*)' PRESNIVS '
-      write(lunout,*)presnivs
-
-      RETURN
-      END
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/etat0_netcdf.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/etat0_netcdf.F	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/etat0_netcdf.F	(revision 1140)
@@ -5,5 +5,5 @@
 c
       SUBROUTINE etat0_netcdf (interbar, masque)
-    
+#ifdef CPP_EARTH        
       USE startvar
       USE ioipsl
@@ -14,4 +14,6 @@
       USE phys_state_var_mod
       USE filtreg_mod
+#endif
+!#endif of #ifdef CPP_EARTH
       !
       IMPLICIT NONE
@@ -25,4 +27,5 @@
 !     .KLON=KFDIA-KIDIA+1,KLEV=llm
       !
+#ifdef CPP_EARTH    
 #include "comgeom2.h"
 #include "comvert.h"
@@ -31,8 +34,14 @@
 #include "dimsoil.h"
 #include "temps.h"
-      !
+#endif
+!#endif of #ifdef CPP_EARTH
+      ! arguments:
       LOGICAL interbar
+      REAL :: masque(iip1,jjp1)
+
+#ifdef CPP_EARTH
+      ! local variables:
       REAL :: latfi(klon), lonfi(klon)
-      REAL :: orog(iip1,jjp1), rugo(iip1,jjp1), masque(iip1,jjp1)
+      REAL :: orog(iip1,jjp1), rugo(iip1,jjp1)
       REAL :: psol(iip1, jjp1), phis(iip1, jjp1)
       REAL :: p3d(iip1, jjp1, llm+1)
@@ -143,4 +152,5 @@
       !
       preff     = 101325.
+      pa        =  50000.
       unskap = 1./kappa
       !
@@ -168,5 +178,5 @@
 
 
-      CALL inicons0()
+      CALL iniconst()
       CALL inigeom()
 
@@ -759,4 +769,6 @@
       DEALLOCATE(q3d)
 
+#endif 
+!#endif of #ifdef CPP_EARTH
       RETURN
       !
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/gcm.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/gcm.F	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/gcm.F	(revision 1140)
@@ -8,4 +8,7 @@
 #ifdef CPP_IOIPSL
       USE IOIPSL
+#else
+! if not using IOIPSL, we still need to use (a local version of) getin
+      USE ioipsl_getincom
 #endif
 
@@ -17,5 +20,6 @@
 ! A nettoyer. On ne veut qu'une ou deux routines d'interface 
 ! dynamique -> physique pour l'initialisation
-#ifdef CPP_PHYS
+! Ehouarn: for now these only apply to Earth:
+#ifdef CPP_EARTH
       USE dimphy
       USE comgeomphy
@@ -158,26 +162,4 @@
 
 
-c--------------------------------------------------------------------------
-c   Iflag_phys controle l'appel a la physique :
-c   -------------------------------------------
-c      0 : pas de physique
-c      1 : Normale (appel a phylmd, phymars ...)
-c      2 : rappel Newtonien pour la temperature + friction au sol
-      iflag_phys=1
-
-c--------------------------------------------------------------------------
-c   Lecture de l'etat initial :
-c   ---------------------------
-c     T : on lit start.nc
-c     F : le modele s'autoinitialise avec un cas academique (iniacademic)
-      read_start=.true.
-#ifdef CPP_IOIPSL
-#else
-      read_start=.false.
-#endif
-#ifdef CPP_PHYS
-#else
-      read_start=.false.
-#endif
 
 c-----------------------------------------------------------------------
@@ -196,9 +178,10 @@
 c  ---------------------------------------
 c
-#ifdef CPP_IOIPSL
+! Ehouarn: dump possibility of using defrun
+!#ifdef CPP_IOIPSL
       CALL conf_gcm( 99, .TRUE. , clesphy0 )
-#else
-      CALL defrun( 99, .TRUE. , clesphy0 )
-#endif
+!#else
+!      CALL defrun( 99, .TRUE. , clesphy0 )
+!#endif
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -206,8 +189,11 @@
 ! A nettoyer. On ne veut qu'une ou deux routines d'interface 
 ! dynamique -> physique pour l'initialisation
-#ifdef CPP_PHYS
+! Ehouarn : temporarily (?) keep this only for Earth
+      if (planet_type.eq."earth") then
+#ifdef CPP_EARTH
       CALL Init_Phys_lmdz(iim,jjp1,llm,1,(jjm-1)*iim+2)
       call InitComgeomphy
 #endif
+      endif
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -242,7 +228,17 @@
 c  lecture du fichier start.nc
       if (read_start) then
-#ifdef CPP_IOIPSL
+      ! we still need to run iniacademic to initialize some
+      ! constants & fields, if we run the 'newtonian' case:
+        if (iflag_phys.eq.2) then
+          CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
+        endif
+!#ifdef CPP_IOIPSL
+        if (planet_type.eq."earth") then
+#ifdef CPP_EARTH
+! Load an Earth-format start file
          CALL dynetat0("start.nc",vcov,ucov,
      .              teta,q,masse,ps,phis, time_0)
+#endif
+        endif ! of if (planet_type.eq."earth")
 c       write(73,*) 'ucov',ucov
 c       write(74,*) 'vcov',vcov
@@ -251,6 +247,5 @@
 c       write(77,*) 'q',q
 
-#endif
-      endif
+      endif ! of if (read_start)
 
       IF (config_inca /= 'none') THEN
@@ -264,5 +259,5 @@
 c le cas echeant, creation d un etat initial
       IF (prt_level > 9) WRITE(lunout,*)
-     .                 'AVANT iniacademic AVANT AVANT AVANT AVANT'
+     .              'GCM: AVANT iniacademic AVANT AVANT AVANT AVANT'
       if (.not.read_start) then
          CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
@@ -298,5 +293,5 @@
       if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
         write(lunout,*)
-     .  ' Attention les dates initiales lues dans le fichier'
+     .  'GCM: Attention les dates initiales lues dans le fichier'
         write(lunout,*)
      .  ' restart ne correspondent pas a celles lues dans '
@@ -304,5 +299,5 @@
         if (raz_date .ne. 1) then
           write(lunout,*)
-     .    ' On garde les dates du fichier restart'
+     .    'GCM: On garde les dates du fichier restart'
         else
           annee_ref = anneeref
@@ -313,5 +308,5 @@
           time_0 = 0.
           write(lunout,*)
-     .   ' On reinitialise a la date lue dans gcm.def'
+     .   'GCM: On reinitialise a la date lue dans gcm.def'
         endif
       ELSE
@@ -350,6 +345,6 @@
 c   Initialisation de la physique :
 c   -------------------------------
-#ifdef CPP_PHYS
-      IF (call_iniphys.and.iflag_phys.eq.1) THEN
+
+      IF (call_iniphys.and.(iflag_phys.eq.1)) THEN
          latfi(1)=rlatu(1)
          lonfi(1)=0.
@@ -370,10 +365,15 @@
          CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,aire,airefi)
          WRITE(lunout,*)
-     .           'WARNING!!! vitesse verticale nulle dans la physique'
+     .       'GCM: WARNING!!! vitesse verticale nulle dans la physique'
+! Earth:
+         if (planet_type.eq."earth") then
+#ifdef CPP_EARTH
          CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys ,
      ,                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp     )
+#endif
+         endif ! of if (planet_type.eq."earth")
          call_iniphys=.false.
-      ENDIF
-#endif
+      ENDIF ! of IF (call_iniphys.and.(iflag_phys.eq.1))
+!#endif
 
 c  numero de stockage pour les fichiers de redemarrage:
@@ -386,10 +386,15 @@
       day_end = day_ini + nday
       WRITE(lunout,300)day_ini,day_end
+ 300  FORMAT('1'/,15x,'run du jour',i7,2x,'au jour',i7//)
+
+      if (planet_type.eq."earth") then
+#ifdef CPP_EARTH
+      CALL dynredem0("restart.nc", day_end, phis)
+#endif
+      endif
+
+      ecripar = .TRUE.
 
 #ifdef CPP_IOIPSL
-      CALL dynredem0("restart.nc", day_end, phis)
-
-      ecripar = .TRUE.
-
       if ( 1.eq.1) then
       time_step = zdtvr
@@ -409,4 +414,5 @@
 
 #endif
+! #endif of #ifdef CPP_IOIPSL
 
 c  Choix des frequences de stokage pour le offline
@@ -432,8 +438,4 @@
      .              time_0)
 
-
-
- 300  FORMAT('1'/,15x,'run du pas',i7,2x,'au pas',i7,2x,
-     . 'c''est a dire du jour',i7,3x,'au jour',i7//)
       END
 
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/iniacademic.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/iniacademic.F	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/iniacademic.F	(revision 1140)
@@ -45,4 +45,5 @@
 #include "temps.h"
 #include "control.h"
+#include "iniprint.h"
 
 c   Arguments:
@@ -57,18 +58,14 @@
       REAL ps(ip1jmp1)                       ! pression  au sol
       REAL masse(ip1jmp1,llm)                ! masse d'air
+      REAL phis(ip1jmp1)                     ! geopotentiel au sol
+
+c   Local:
+c   ------
+
       REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
       REAL pks(ip1jmp1)                      ! exner au  sol
       REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
       REAL pkf(ip1jmp1,llm)                  ! exner filt.au milieu des couches
-      REAL phis(ip1jmp1)                     ! geopotentiel au sol
       REAL phi(ip1jmp1,llm)                  ! geopotentiel
-
-
-
-
-
-c   Local:
-c   ------
-
       REAL ddsin,tetarappelj,tetarappell,zsig
       real tetajl(jjp1,llm)
@@ -81,37 +78,38 @@
 
 c-----------------------------------------------------------------------
+! 1. Initializations for Earth-like case
+! --------------------------------------
+      if (planet_type=="earth") then
+c
+        time_0=0.
 
-c
-      time_0=0.
+        im         = iim
+        jm         = jjm
+        day_ini    = 0
+        omeg       = 4.*asin(1.)/86400.
+        rad    = 6371229.
+        g      = 9.8
+        daysec = 86400.
+        dtvr    = daysec/FLOAT(day_step)
+        zdtvr=dtvr
+        kappa  = 0.2857143
+        cpp    = 1004.70885
+        preff     = 101325.
+        pa        =  50000.
+        etot0      = 0.
+        ptot0      = 0.
+        ztot0      = 0.
+        stot0      = 0.
+        ang0       = 0.
 
-      im         = iim
-      jm         = jjm
-      day_ini    = 0
-      omeg       = 4.*asin(1.)/86400.
-      rad    = 6371229.
-      g      = 9.8
-      daysec = 86400.
-      dtvr    = daysec/FLOAT(day_step)
-      zdtvr=dtvr
-      kappa  = 0.2857143
-      cpp    = 1004.70885
-      preff     = 101325.
-      pa        =  50 000.
-      etot0      = 0.
-      ptot0      = 0.
-      ztot0      = 0.
-      stot0      = 0.
-      ang0       = 0.
-      pa         = 0.
+        CALL iniconst
+        CALL inigeom
+        CALL inifilr
 
-      CALL inicons0
-      CALL inigeom
-      CALL inifilr
-
-      ps=0.
-      phis=0.
+        ps=0.
+        phis=0.
 c---------------------------------------------------------------------
 
-      taurappel=10.*daysec
+        taurappel=10.*daysec
 
 c---------------------------------------------------------------------
@@ -119,63 +117,63 @@
 c   --------------------------------------
 
-      DO l=1,llm
-       zsig=ap(l)/preff+bp(l)
-       if (zsig.gt.0.3) then
-         lsup=l
-         tetarappell=1./8.*(-log(zsig)-.5)
-         DO j=1,jjp1
-            ddsin=sin(rlatu(j))-sin(pi/20.)
-            tetajl(j,l)=300.*(1+1./18.*(1.-3.*ddsin*ddsin)+tetarappell)
-         ENDDO
-        else
+        DO l=1,llm
+         zsig=ap(l)/preff+bp(l)
+         if (zsig.gt.0.3) then
+           lsup=l
+           tetarappell=1./8.*(-log(zsig)-.5)
+           DO j=1,jjp1
+             ddsin=sin(rlatu(j))-sin(pi/20.)
+             tetajl(j,l)=300.*(1+1./18.*(1.-3.*ddsin*ddsin)+tetarappell)
+           ENDDO
+          else
 c   Choix isotherme au-dessus de 300 mbar
-         do j=1,jjp1
-            tetajl(j,l)=tetajl(j,lsup)*(0.3/zsig)**kappa
-         enddo
-        endif
-      ENDDO
+           do j=1,jjp1
+             tetajl(j,l)=tetajl(j,lsup)*(0.3/zsig)**kappa
+           enddo
+          endif ! of if (zsig.gt.0.3)
+        ENDDO ! of DO l=1,llm
 
-      do l=1,llm
-         do j=1,jjp1
-            do i=1,iip1
-               ij=(j-1)*iip1+i
-               tetarappel(ij,l)=tetajl(j,l)
-            enddo
-         enddo
-      enddo
+        do l=1,llm
+           do j=1,jjp1
+              do i=1,iip1
+                 ij=(j-1)*iip1+i
+                 tetarappel(ij,l)=tetajl(j,l)
+              enddo
+           enddo
+        enddo
 
-c     call dump2d(jjp1,llm,tetajl,'TEQ   ')
+c       call dump2d(jjp1,llm,tetajl,'TEQ   ')
 
-      ps=1.e5
-      phis=0.
-      CALL pression ( ip1jmp1, ap, bp, ps, p       )
-      CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
-      CALL massdair(p,masse)
+        ps=1.e5
+        phis=0.
+        CALL pression ( ip1jmp1, ap, bp, ps, p       )
+        CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
+        CALL massdair(p,masse)
 
 c  intialisation du vent et de la temperature
-      teta(:,:)=tetarappel(:,:)
-      CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
-      call ugeostr(phi,ucov)
-      vcov=0.
-      q(:,:,1   )=1.e-10
-      q(:,:,2   )=1.e-15
-      q(:,:,3:nqtot)=0.
+        teta(:,:)=tetarappel(:,:)
+        CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
+        call ugeostr(phi,ucov)
+        vcov=0.
+        q(:,:,1   )=1.e-10
+        q(:,:,2   )=1.e-15
+        q(:,:,3:nqtot)=0.
 
 
-c   perturbation al\351atoire sur la temp\351rature
-      idum  = -1
-      zz = ran1(idum)
-      idum  = 0
-      do l=1,llm
-         do ij=iip2,ip1jm
-            teta(ij,l)=teta(ij,l)*(1.+0.005*ran1(idum))
-         enddo
-      enddo
+c   perturbation aleatoire sur la temperature
+        idum  = -1
+        zz = ran1(idum)
+        idum  = 0
+        do l=1,llm
+           do ij=iip2,ip1jm
+              teta(ij,l)=teta(ij,l)*(1.+0.005*ran1(idum))
+           enddo
+        enddo
 
-      do l=1,llm
-         do ij=1,ip1jmp1,iip1
-            teta(ij+iim,l)=teta(ij,l)
-         enddo
-      enddo
+        do l=1,llm
+           do ij=1,ip1jmp1,iip1
+              teta(ij+iim,l)=teta(ij,l)
+           enddo
+        enddo
 
 
@@ -187,9 +185,14 @@
 
 c   initialisation d'un traceur sur une colonne
-      j=jjp1*3/4
-      i=iip1/2
-      ij=(j-1)*iip1+i
-      q(ij,:,3)=1.
-
+        j=jjp1*3/4
+        i=iip1/2
+        ij=(j-1)*iip1+i
+        q(ij,:,3)=1.
+      
+      else
+        write(lunout,*)"iniacademic: planet types other than earth",
+     &                 " not implemented (yet)."
+        stop
+      endif ! of if (planet_type=="earth")
       return
       END
Index: DZ4/branches/LMDZ4-dev/libf/dyn3d/inicons0.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/inicons0.F	(revision 1139)
+++ 	(revision )
@@ -1,55 +1,0 @@
-!
-! $Header$
-!
-      SUBROUTINE inicons0
-      IMPLICIT NONE
-c
-c  P. Le Van
-c
-c-----------------------------------------------------------------------
-c   Declarations:
-c   -------------
-c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "temps.h"
-#include "control.h"
-#include "comvert.h"
-#include "comdissnew.h"
-
-
-c
-c
-c
-c-----------------------------------------------------------------------
-c   dimension des boucles:
-c   ----------------------
-
-      im      = iim
-      jm      = jjm
-      lllm    = llm
-      imp1    = iim 
-      jmp1    = jjm + 1
-      lllmm1  = llm - 1
-      lllmp1  = llm + 1
-
-c-----------------------------------------------------------------------
-
-      dtdiss  = idissip * dtvr
-      dtphys  = iphysiq * dtvr
-      unsim   = 1./iim
-      pi      = 2.*ASIN( 1. )
-
-c-----------------------------------------------------------------------
-      r       = cpp * kappa
-
-      PRINT*,' Cp R  kappa ',  cpp, r , kappa
-c
-c-----------------------------------------------------------------------
-
-       CALL disvert0(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
-c
-c
-       RETURN
-       END
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/ioipsl_getincom.F90
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/ioipsl_getincom.F90	(revision 1140)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/ioipsl_getincom.F90	(revision 1140)
@@ -0,0 +1,2609 @@
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Module and routines in this file are taken from IOIPSL
+! files getincom.f90
+! Module names has been changed to avoid problems
+! if compiling model with IOIPSL library
+! Ehouarn - March 2009
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+MODULE ioipsl_getincom
+!---------------------------------------------------------------------
+  USE ioipsl_stringop, &
+ &   ONLY : findpos,nocomma,cmpblank,strlowercase,gensig,find_sig
+!-
+  IMPLICIT NONE
+!-
+  PRIVATE
+  PUBLIC :: getin, getin_dump
+!-
+  INTERFACE getin
+    MODULE PROCEDURE getinrs, getinr1d, getinr2d, &
+ &                   getinis, getini1d, getini2d, &
+ &                   getincs, getinc1d, getinc2d, &
+ &                   getinls, getinl1d, getinl2d
+  END INTERFACE
+!-
+  INTEGER,PARAMETER :: max_files=100
+  CHARACTER(LEN=100),DIMENSION(max_files),SAVE :: filelist
+  INTEGER,SAVE      :: nbfiles
+!-
+  INTEGER,PARAMETER :: max_lines=4000
+  INTEGER,SAVE :: nb_lines
+  CHARACTER(LEN=100),DIMENSION(max_lines),SAVE :: fichier
+  INTEGER,DIMENSION(max_lines),SAVE :: targetsiglist,fromfile,compline
+  CHARACTER(LEN=30),DIMENSION(max_lines),SAVE  :: targetlist
+!-
+! The data base of parameters
+!-
+  INTEGER,PARAMETER :: memslabs=200
+  INTEGER,PARAMETER :: compress_lim = 20
+!-
+  INTEGER,SAVE :: nb_keys=0
+  INTEGER,SAVE :: keymemsize=0
+  INTEGER,SAVE,ALLOCATABLE :: keysig(:)
+  CHARACTER(LEN=30),SAVE,ALLOCATABLE :: keystr(:)
+!-
+! keystatus definition
+! keystatus = 1 : Value comes from run.def
+! keystatus = 2 : Default value is used
+! keystatus = 3 : Some vector elements were taken from default
+!-
+  INTEGER,SAVE,ALLOCATABLE :: keystatus(:)
+!-
+! keytype definition
+! keytype = 1 : Interger
+! keytype = 2 : Real
+! keytype = 3 : Character
+! keytype = 4 : Logical
+!-
+  INTEGER,SAVE,ALLOCATABLE :: keytype(:)
+!-
+! Allow compression for keys (only for integer and real)
+! keycompress < 0 : not compresses
+! keycompress > 0 : number of repeat of the value
+!-
+  INTEGER,SAVE,ALLOCATABLE :: keycompress(:)
+  INTEGER,SAVE,ALLOCATABLE :: keyfromfile(:)
+!-
+  INTEGER,SAVE,ALLOCATABLE :: keymemstart(:)
+  INTEGER,SAVE,ALLOCATABLE :: keymemlen(:)
+!-
+  INTEGER,SAVE,ALLOCATABLE :: intmem(:)
+  INTEGER,SAVE             :: intmemsize=0, intmempos=0
+  REAL,SAVE,ALLOCATABLE :: realmem(:)
+  INTEGER,SAVE          :: realmemsize=0, realmempos=0
+  CHARACTER(LEN=100),SAVE,ALLOCATABLE :: charmem(:)
+  INTEGER,SAVE             :: charmemsize=0, charmempos=0
+  LOGICAL,SAVE,ALLOCATABLE :: logicmem(:)
+  INTEGER,SAVE             :: logicmemsize=0, logicmempos=0
+!-
+CONTAINS
+!-
+!=== REAL INTERFACES
+!-
+SUBROUTINE getinrs (TARGET,ret_val)
+!---------------------------------------------------------------------
+!-  Get a real scalar. We first check if we find it
+!-  in the database and if not we get it from the run.def
+!-
+!-  getinr1d and getinr2d are written on the same pattern
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  REAL :: ret_val
+!-
+  REAL,DIMENSION(1) :: tmp_ret_val
+  INTEGER :: target_sig, pos, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  tmp_ret_val(1) = ret_val
+!-
+  IF (pos < 0) THEN
+!-- Get the information out of the file
+    CALL getfilr (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwr (TARGET,target_sig,status,fileorig,1,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrr (pos,1,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val = tmp_ret_val(1)
+!---------------------
+END SUBROUTINE getinrs
+!-
+!===
+!-
+SUBROUTINE getinr1d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getinrs for details. It is the same thing but for a vector
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  REAL,DIMENSION(:) :: ret_val
+!-
+  REAL,DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig, pos, size_of_in, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+  tmp_ret_val(1:size_of_in) = ret_val(1:size_of_in)
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfilr (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwr &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrr (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val(1:size_of_in) = tmp_ret_val(1:size_of_in)
+!----------------------
+END SUBROUTINE getinr1d
+!-
+!===
+!-
+SUBROUTINE getinr2d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getinrs for details. It is the same thing but for a matrix
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  REAL,DIMENSION(:,:) :: ret_val
+!-
+  REAL,DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig,pos,size_of_in,size_1,size_2,status=0,fileorig
+  INTEGER :: jl, jj, ji
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  size_1 = SIZE(ret_val,1)
+  size_2 = SIZE(ret_val,2)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      tmp_ret_val(jl) = ret_val(ji,jj)
+    ENDDO
+  ENDDO
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfilr (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwr &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrr (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      ret_val(ji,jj) = tmp_ret_val(jl)
+    ENDDO
+  ENDDO
+!----------------------
+END SUBROUTINE getinr2d
+!-
+!===
+!-
+SUBROUTINE getfilr (TARGET,status,fileorig,ret_val)
+!---------------------------------------------------------------------
+!- Subroutine that will extract from the file the values
+!- attributed to the keyword target
+!-
+!- REALS
+!- -----
+!-
+!- target   : in  : CHARACTER(LEN=*)  target for which we will
+!-                                    look in the file
+!- status   : out : INTEGER tells us from where we obtained the data
+!- fileorig : out : The index of the file from which the key comes
+!- ret_val  : out : REAL(nb_to_ret) values read
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER :: status, fileorig
+  REAL,DIMENSION(:) :: ret_val
+!-
+  INTEGER :: nb_to_ret
+  INTEGER :: it, pos, len_str, epos, ppos, int_tmp, status_cnt
+  CHARACTER(LEN=3)  :: cnt, tl, dl
+  CHARACTER(LEN=10) :: fmt
+  CHARACTER(LEN=30) :: full_target
+  CHARACTER(LEN=80) :: str_READ, str_READ_lower, str_tmp
+  INTEGER :: full_target_sig
+  REAL :: compvalue
+!-
+  INTEGER,SAVE :: max_len = 0
+  LOGICAL,SAVE,ALLOCATABLE :: found(:)
+  LOGICAL :: def_beha
+  LOGICAL :: compressed = .FALSE.
+!---------------------------------------------------------------------
+  nb_to_ret = SIZE(ret_val)
+  CALL getin_read
+!-
+! Get the variables and memory we need
+!-
+  IF (max_len == 0) THEN
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  IF (max_len < nb_to_ret) THEN
+    DEALLOCATE(found)
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  found(:) = .FALSE.
+!-
+! See what we find in the files read
+!-
+  DO it=1,nb_to_ret
+!---
+!-
+!-- First try the target as it is
+!---
+    full_target = TARGET(1:len_TRIM(target))
+    CALL gensig (full_target,full_target_sig)
+    CALL find_sig (nb_lines,targetlist,full_target, &
+ &                 targetsiglist,full_target_sig,pos)
+!---
+!-- Another try
+!---
+    IF (pos < 0) THEN
+      WRITE(cnt,'(I3.3)') it
+      full_target = TARGET(1:len_TRIM(target))//'__'//cnt
+      CALL gensig (full_target,full_target_sig)
+      CALL find_sig (nb_lines,targetlist,full_target, &
+ &                   targetsiglist,full_target_sig,pos)
+    ENDIF
+!---
+!-- A priori we dont know from which file the target could come.
+!-- Thus by default we attribute it to the first file :
+!---
+    fileorig = 1
+!--
+    IF (pos > 0) THEN
+!----
+      found(it) = .TRUE.
+      fileorig = fromfile(pos)
+!-----
+!---- DECODE
+!-----
+      str_READ = TRIM(ADJUSTL(fichier(pos)))
+      str_READ_lower = str_READ
+      CALL strlowercase (str_READ_lower)
+!----
+      IF (    (     (INDEX(str_READ_lower,'def') == 1)     &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 3)   )    &
+ &        .OR.(     (INDEX(str_READ_lower,'default') == 1) &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 7)   )   ) THEN
+        def_beha = .TRUE.
+      ELSE
+        def_beha = .FALSE.
+        len_str = LEN_TRIM(str_READ)
+        epos = INDEX(str_READ,'e')
+        ppos = INDEX(str_READ,'.')
+!------
+        IF (epos > 0) THEN
+          WRITE(tl,'(I3.3)') len_str
+          WRITE(dl,'(I3.3)') epos-ppos-1
+          fmt='(e'//tl//'.'//dl//')'
+          READ(str_READ,fmt) ret_val(it)
+        ELSE IF (ppos > 0) THEN
+          WRITE(tl,'(I3.3)') len_str
+          WRITE(dl,'(I3.3)') len_str-ppos
+          fmt='(f'//tl//'.'//dl//')'
+          READ(str_READ,fmt) ret_val(it)
+        ELSE
+          WRITE(tl,'(I3.3)') len_str
+          fmt = '(I'//tl//')'
+          READ(str_READ,fmt) int_tmp
+          ret_val(it) = REAL(int_tmp)
+        ENDIF
+      ENDIF
+!----
+      targetsiglist(pos) = -1
+!-----
+!---- Is this the value of a compressed field ?
+!-----
+      IF (compline(pos) > 0) THEN
+        IF (compline(pos) == nb_to_ret) THEN
+          compressed = .TRUE.
+          compvalue = ret_val(it)
+        ELSE
+          WRITE(*,*) 'WARNING from getfilr'
+          WRITE(*,*) 'For key ',TRIM(TARGET), &
+ & ' we have a compressed field but which does not have the right size.'
+          WRITE(*,*) 'We will try to fix that '
+          compressed = .TRUE.
+          compvalue = ret_val(it)
+        ENDIF
+      ENDIF
+    ELSE
+      found(it) = .FALSE.
+    ENDIF
+  ENDDO
+!--
+! If this is a compressed field then we will uncompress it
+!--
+  IF (compressed) THEN
+    DO it=1,nb_to_ret
+      IF (.NOT. found(it)) THEN
+        ret_val(it) = compvalue
+        found(it) = .TRUE.
+      ENDIF
+    ENDDO
+  ENDIF
+!-
+! Now we get the status for what we found
+!-
+  IF (def_beha) THEN
+    status = 2
+    WRITE(*,*) 'USING DEFAULT BEHAVIOUR FOR ',TRIM(TARGET)
+  ELSE
+    status_cnt = 0
+    DO it=1,nb_to_ret
+      IF (.NOT. found(it)) THEN
+        status_cnt = status_cnt+1
+        IF (nb_to_ret > 1) THEN
+          WRITE(str_tmp,'(a,"__",I3.3)') TRIM(TARGET),it
+        ELSE
+          str_tmp = TRIM(TARGET)
+        ENDIF
+        WRITE(*,*) 'USING DEFAULTS : ',TRIM(str_tmp),'=',ret_val(it)
+      ENDIF
+    ENDDO
+!---
+    IF (status_cnt == 0) THEN
+      status = 1
+    ELSE IF (status_cnt == nb_to_ret) THEN
+      status = 2
+    ELSE
+      status = 3
+    ENDIF
+  ENDIF
+!---------------------
+END SUBROUTINE getfilr
+!-
+!=== INTEGER INTERFACES
+!-
+SUBROUTINE getinis (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- Get a interer scalar. We first check if we find it
+!- in the database and if not we get it from the run.def
+!-
+!- getini1d and getini2d are written on the same pattern
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER :: ret_val
+!-
+  INTEGER,DIMENSION(1) :: tmp_ret_val
+  INTEGER :: target_sig, pos, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  tmp_ret_val(1) = ret_val
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfili (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwi (TARGET,target_sig,status,fileorig,1,tmp_ret_val)
+    ELSE
+!-- Get the value out of the database
+    CALL getdbri (pos,1,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val = tmp_ret_val(1)
+!---------------------
+END SUBROUTINE getinis
+!-
+!===
+!-
+SUBROUTINE getini1d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getinis for details. It is the same thing but for a vector
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER,DIMENSION(:) :: ret_val
+!-
+  INTEGER,DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig, pos, size_of_in, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+  tmp_ret_val(1:size_of_in) = ret_val(1:size_of_in)
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfili (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwi &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbri (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val(1:size_of_in) = tmp_ret_val(1:size_of_in)
+!----------------------
+END SUBROUTINE getini1d
+!-
+!===
+!-
+SUBROUTINE getini2d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getinis for details. It is the same thing but for a matrix
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER,DIMENSION(:,:) :: ret_val
+!-
+  INTEGER,DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig,pos,size_of_in,size_1,size_2,status=0,fileorig
+  INTEGER :: jl, jj, ji
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  size_1 = SIZE(ret_val,1)
+  size_2 = SIZE(ret_val,2)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      tmp_ret_val(jl) = ret_val(ji,jj)
+    ENDDO
+  ENDDO
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfili (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwi &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbri (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      ret_val(ji,jj) = tmp_ret_val(jl)
+    ENDDO
+  ENDDO
+!----------------------
+END SUBROUTINE getini2d
+!-
+!===
+!-
+SUBROUTINE getfili (TARGET,status,fileorig,ret_val)
+!---------------------------------------------------------------------
+!- Subroutine that will extract from the file the values
+!- attributed to the keyword target
+!-
+!- INTEGER
+!- -------
+!-
+!- target   : in  : CHARACTER(LEN=*)  target for which we will
+!-                                    look in the file
+!- status   : out : INTEGER tells us from where we obtained the data
+!- fileorig : out : The index of the file from which the key comes
+!- ret_val  : out : INTEGER(nb_to_ret) values read
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER :: status, fileorig
+  INTEGER :: ret_val(:)
+!-
+  INTEGER :: nb_to_ret
+  INTEGER :: it, pos, len_str, status_cnt
+  CHARACTER(LEN=3)  :: cnt, chlen
+  CHARACTER(LEN=10) ::  fmt
+  CHARACTER(LEN=30) :: full_target
+  CHARACTER(LEN=80) :: str_READ, str_READ_lower, str_tmp
+  INTEGER :: full_target_sig
+  INTEGER :: compvalue
+!-
+  INTEGER,SAVE :: max_len = 0
+  LOGICAL,SAVE,ALLOCATABLE :: found(:)
+  LOGICAL :: def_beha
+  LOGICAL :: compressed = .FALSE.
+!---------------------------------------------------------------------
+  nb_to_ret = SIZE(ret_val)
+  CALL getin_read
+!-
+! Get the variables and memory we need
+!-
+  IF (max_len == 0) THEN
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  IF (max_len < nb_to_ret) THEN
+    DEALLOCATE(found)
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  found(:) = .FALSE.
+!-
+! See what we find in the files read
+!-
+  DO it=1,nb_to_ret
+!---
+!-- First try the target as it is
+!---
+    full_target = TARGET(1:len_TRIM(target))
+    CALL gensig (full_target,full_target_sig)
+    CALL find_sig (nb_lines,targetlist,full_target, &
+ &                 targetsiglist,full_target_sig,pos)
+!---
+!-- Another try
+!---
+    IF (pos < 0) THEN
+      WRITE(cnt,'(I3.3)') it
+      full_target = TARGET(1:len_TRIM(target))//'__'//cnt
+      CALL gensig (full_target,full_target_sig)
+      CALL find_sig (nb_lines,targetlist,full_target, &
+ &                   targetsiglist,full_target_sig,pos)
+    ENDIF
+!---
+!-- A priori we dont know from which file the target could come.
+!-- Thus by default we attribute it to the first file :
+!---
+    fileorig = 1
+!-
+    IF (pos > 0) THEN
+!-----
+      found(it) = .TRUE.
+      fileorig = fromfile(pos)
+!-----
+!---- DECODE
+!----
+      str_READ = TRIM(ADJUSTL(fichier(pos)))
+      str_READ_lower = str_READ
+      CALL strlowercase (str_READ_lower)
+!-----
+      IF (    (     (INDEX(str_READ_lower,'def') == 1)     &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 3)   )    &
+ &        .OR.(     (INDEX(str_READ_lower,'default') == 1) &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 7)   )   ) THEN
+        def_beha = .TRUE.
+      ELSE
+        def_beha = .FALSE.
+        len_str = LEN_TRIM(str_READ)
+        WRITE(chlen,'(I3.3)') len_str
+        fmt = '(I'//chlen//')'
+        READ(str_READ,fmt) ret_val(it)
+      ENDIF
+!-----
+      targetsiglist(pos) = -1
+!-----
+!---- Is this the value of a compressed field ?
+!-----
+      IF (compline(pos) > 0) THEN
+        IF (compline(pos) == nb_to_ret) THEN
+          compressed = .TRUE.
+          compvalue = ret_val(it)
+        ELSE
+          WRITE(*,*) 'WARNING from getfilr'
+          WRITE(*,*) 'For key ',TRIM(TARGET), &
+ & ' we have a compressed field but which does not have the right size.'
+          WRITE(*,*) 'We will try to fix that '
+          compressed = .TRUE.
+          compvalue = ret_val(it)
+        ENDIF
+      ENDIF
+    ELSE
+      found(it) = .FALSE.
+    ENDIF
+  ENDDO
+!-
+! If this is a compressed field then we will uncompress it
+!-
+  IF (compressed) THEN
+    DO it=1,nb_to_ret
+      IF (.NOT. found(it)) THEN
+        ret_val(it) = compvalue
+        found(it) = .TRUE.
+      ENDIF
+    ENDDO
+  ENDIF
+!-
+! Now we get the status for what we found
+!-
+  IF (def_beha) THEN
+    status = 2
+    WRITE(*,*) 'USING DEFAULT BEHAVIOUR FOR ',TRIM(TARGET)
+  ELSE
+    status_cnt = 0
+    DO it=1,nb_to_ret
+      IF (.NOT. found(it)) THEN
+        status_cnt = status_cnt+1
+        IF (nb_to_ret > 1) THEN
+          WRITE(str_tmp,'(a,"__",I3.3)') TRIM(TARGET),it
+        ELSE
+          str_tmp = TRIM(TARGET)
+        ENDIF
+        WRITE(*,*) 'USING DEFAULTS : ',TRIM(str_tmp),'=',ret_val(it)
+      ENDIF
+    ENDDO
+!---
+    IF (status_cnt == 0) THEN
+      status = 1
+    ELSE IF (status_cnt == nb_to_ret) THEN
+      status = 2
+    ELSE
+      status = 3
+    ENDIF
+  ENDIF
+!---------------------
+END SUBROUTINE getfili
+!-
+!=== CHARACTER INTERFACES
+!-
+SUBROUTINE getincs (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- Get a CHARACTER scalar. We first check if we find it
+!- in the database and if not we get it from the run.def
+!-
+!- getinc1d and getinc2d are written on the same pattern
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  CHARACTER(LEN=*) :: ret_val
+!-
+  CHARACTER(LEN=100),DIMENSION(1) :: tmp_ret_val
+  INTEGER :: target_sig, pos, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  tmp_ret_val(1) = ret_val
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfilc (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwc (TARGET,target_sig,status,fileorig,1,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrc (pos,1,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val = tmp_ret_val(1)
+!---------------------
+END SUBROUTINE getincs
+!-
+!===
+!-
+SUBROUTINE getinc1d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getincs for details. It is the same thing but for a vector
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  CHARACTER(LEN=*),DIMENSION(:) :: ret_val
+!-
+  CHARACTER(LEN=100),DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig, pos, size_of_in, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+  tmp_ret_val(1:size_of_in) = ret_val(1:size_of_in)
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfilc (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwc &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrc (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val(1:size_of_in) = tmp_ret_val(1:size_of_in)
+!----------------------
+END SUBROUTINE getinc1d
+!-
+!===
+!-
+SUBROUTINE getinc2d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getincs for details. It is the same thing but for a matrix
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  CHARACTER(LEN=*),DIMENSION(:,:) :: ret_val
+!-
+  CHARACTER(LEN=100),DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig,pos,size_of_in,size_1,size_2,status=0,fileorig
+  INTEGER :: jl,jj,ji
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  size_1 = SIZE(ret_val,1)
+  size_2 = SIZE(ret_val,2)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      tmp_ret_val(jl) = ret_val(ji,jj)
+    ENDDO
+  ENDDO
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfilc (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwc &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrc (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      ret_val(ji,jj) = tmp_ret_val(jl)
+    ENDDO
+  ENDDO
+!----------------------
+END SUBROUTINE getinc2d
+!-
+!===
+!-
+SUBROUTINE getfilc (TARGET,status,fileorig,ret_val)
+!---------------------------------------------------------------------
+!- Subroutine that will extract from the file the values
+!- attributed to the keyword target
+!-
+!- CHARACTER
+!- ---------
+!-
+!- target   : in  : CHARACTER(LEN=*)  target for which we will
+!-                                    look in the file
+!- status   : out : INTEGER tells us from where we obtained the data
+!- fileorig : out : The index of the file from which the key comes
+!- ret_val  : out : CHARACTER(nb_to_ret) values read
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER :: status, fileorig
+  CHARACTER(LEN=*),DIMENSION(:) :: ret_val
+!-
+  INTEGER :: nb_to_ret
+  INTEGER :: it, pos, len_str, status_cnt
+  CHARACTER(LEN=3)  :: cnt
+  CHARACTER(LEN=30) :: full_target
+  CHARACTER(LEN=80) :: str_READ, str_READ_lower, str_tmp
+  INTEGER :: full_target_sig
+!-
+  INTEGER,SAVE :: max_len = 0
+  LOGICAL,DIMENSION(:),SAVE,ALLOCATABLE :: found
+  LOGICAL :: def_beha
+!---------------------------------------------------------------------
+  nb_to_ret = SIZE(ret_val)
+  CALL getin_read
+!-
+! Get the variables and memory we need
+!-
+  IF (max_len == 0) THEN
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  IF (max_len < nb_to_ret) THEN
+    DEALLOCATE(found)
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  found(:) = .FALSE.
+!-
+! See what we find in the files read
+!-
+  DO it=1,nb_to_ret
+!---
+!-- First try the target as it is
+    full_target = TARGET(1:len_TRIM(target))
+    CALL gensig (full_target,full_target_sig)
+    CALL find_sig (nb_lines,targetlist,full_target, &
+ &                 targetsiglist,full_target_sig,pos)
+!---
+!-- Another try
+!---
+    IF (pos < 0) THEN
+      WRITE(cnt,'(I3.3)') it
+      full_target = TARGET(1:len_TRIM(target))//'__'//cnt
+      CALL gensig (full_target,full_target_sig)
+      CALL find_sig (nb_lines,targetlist,full_target, &
+ &                   targetsiglist,full_target_sig,pos)
+    ENDIF
+!---
+!-- A priori we dont know from which file the target could come.
+!-- Thus by default we attribute it to the first file :
+!---
+    fileorig = 1
+!---
+    IF (pos > 0) THEN
+!-----
+      found(it) = .TRUE.
+      fileorig = fromfile(pos)
+!-----
+!---- DECODE
+!-----
+      str_READ = TRIM(ADJUSTL(fichier(pos)))
+      str_READ_lower = str_READ
+      CALL strlowercase (str_READ_lower)
+!-----
+      IF (    (     (INDEX(str_READ_lower,'def') == 1)     &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 3)   )    &
+ &        .OR.(     (INDEX(str_READ_lower,'default') == 1) &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 7)   )   ) THEN
+        def_beha = .TRUE.
+      ELSE
+        def_beha = .FALSE.
+        len_str = LEN_TRIM(str_READ)
+        ret_val(it) = str_READ(1:len_str)
+      ENDIF
+!-----
+      targetsiglist(pos) = -1
+!-----
+    ELSE
+      found(it) = .FALSE.
+    ENDIF
+  ENDDO
+!-
+! Now we get the status for what we found
+!-
+  IF (def_beha) THEN
+    status = 2
+    WRITE(*,*) 'USING DEFAULT BEHAVIOUR FOR ',TRIM(TARGET)
+  ELSE
+    status_cnt = 0
+    DO it=1,nb_to_ret
+      IF (.NOT. found(it)) THEN
+        status_cnt = status_cnt+1
+        IF (nb_to_ret > 1) THEN
+          WRITE(str_tmp,'(a,"__",I3.3)') TRIM(TARGET),it
+        ELSE
+          str_tmp = TARGET(1:len_TRIM(target))
+        ENDIF
+        WRITE(*,*) 'USING DEFAULTS : ',TRIM(str_tmp),'=',ret_val(it)
+      ENDIF
+    ENDDO
+!-
+    IF (status_cnt == 0) THEN
+      status = 1
+    ELSE IF (status_cnt == nb_to_ret) THEN
+      status = 2
+    ELSE
+      status = 3
+    ENDIF
+  ENDIF
+!---------------------
+END SUBROUTINE getfilc
+!-
+!=== LOGICAL INTERFACES
+!-
+SUBROUTINE getinls (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- Get a logical scalar. We first check if we find it
+!- in the database and if not we get it from the run.def
+!-
+!- getinl1d and getinl2d are written on the same pattern
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  LOGICAL :: ret_val
+!-
+  LOGICAL,DIMENSION(1) :: tmp_ret_val
+  INTEGER :: target_sig, pos, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  tmp_ret_val(1) = ret_val
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfill (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwl (TARGET,target_sig,status,fileorig,1,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrl (pos,1,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val = tmp_ret_val(1)
+!---------------------
+END SUBROUTINE getinls
+!-
+!===
+!-
+SUBROUTINE getinl1d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getinls for details. It is the same thing but for a vector
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  LOGICAL,DIMENSION(:) :: ret_val
+!-
+  LOGICAL,DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig, pos, size_of_in, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+  tmp_ret_val(1:size_of_in) = ret_val(1:size_of_in)
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfill (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwl &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrl (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val(1:size_of_in) = tmp_ret_val(1:size_of_in)
+!----------------------
+END SUBROUTINE getinl1d
+!-
+!===
+!-
+SUBROUTINE getinl2d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getinls for details. It is the same thing but for a matrix
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  LOGICAL,DIMENSION(:,:) :: ret_val
+!-
+  LOGICAL,DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig,pos,size_of_in,size_1,size_2,status=0,fileorig
+  INTEGER :: jl,jj,ji
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  size_1 = SIZE(ret_val,1)
+  size_2 = SIZE(ret_val,2)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      tmp_ret_val(jl) = ret_val(ji,jj)
+    ENDDO
+  ENDDO
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfill (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwl &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrl (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      ret_val(ji,jj) = tmp_ret_val(jl)
+    ENDDO
+  ENDDO
+!----------------------
+END SUBROUTINE getinl2d
+!-
+!===
+!-
+SUBROUTINE getfill (TARGET,status,fileorig,ret_val)
+!---------------------------------------------------------------------
+!- Subroutine that will extract from the file the values
+!- attributed to the keyword target
+!-
+!- LOGICAL
+!- -------
+!-
+!- target   : in  : CHARACTER(LEN=*)  target for which we will
+!-                                    look in the file
+!- status   : out : INTEGER tells us from where we obtained the data
+!- fileorig : out : The index of the file from which the key comes
+!- ret_val  : out : LOGICAL(nb_to_ret) values read
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER :: status, fileorig
+  LOGICAL,DIMENSION(:) :: ret_val
+!-
+  INTEGER :: nb_to_ret
+  INTEGER :: it, pos, len_str, ipos_tr, ipos_fl, status_cnt
+  CHARACTER(LEN=3)  :: cnt
+  CHARACTER(LEN=30) :: full_target
+  CHARACTER(LEN=80) :: str_READ, str_READ_lower, str_tmp
+  INTEGER :: full_target_sig
+!-
+  INTEGER,SAVE :: max_len = 0
+  LOGICAL,DIMENSION(:),SAVE,ALLOCATABLE :: found
+  LOGICAL :: def_beha
+!---------------------------------------------------------------------
+  nb_to_ret = SIZE(ret_val)
+  CALL getin_read
+!-
+! Get the variables and memory we need
+!-
+  IF (max_len == 0) THEN
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  IF (max_len < nb_to_ret) THEN
+    DEALLOCATE(found)
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  found(:) = .FALSE.
+!-
+! See what we find in the files read
+!-
+  DO it=1,nb_to_ret
+!---
+!-- First try the target as it is
+!---
+    full_target = TARGET(1:len_TRIM(target))
+    CALL gensig (full_target,full_target_sig)
+    CALL find_sig (nb_lines,targetlist,full_target, &
+ &                 targetsiglist,full_target_sig,pos)
+!---
+!-- Another try
+!---
+    IF (pos < 0) THEN
+      WRITE(cnt,'(I3.3)') it
+      full_target = TARGET(1:len_TRIM(target))//'__'//cnt
+      CALL gensig (full_target,full_target_sig)
+      CALL find_sig (nb_lines,targetlist,full_target, &
+ &                   targetsiglist,full_target_sig,pos)
+    ENDIF
+!---
+!-- A priori we dont know from which file the target could come.
+!-- Thus by default we attribute it to the first file :
+!---
+    fileorig = 1
+!---
+    IF (pos > 0) THEN
+!-----
+      found(it) = .TRUE.
+      fileorig = fromfile(pos)
+!-----
+!---- DECODE
+!-----
+      str_READ = TRIM(ADJUSTL(fichier(pos)))
+      str_READ_lower = str_READ
+      CALL strlowercase (str_READ_lower)
+!-----
+      IF (    (     (INDEX(str_READ_lower,'def') == 1)     &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 3)   )    &
+ &        .OR.(     (INDEX(str_READ_lower,'default') == 1) &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 7)   )   ) THEN
+        def_beha = .TRUE.
+      ELSE
+        def_beha = .FALSE.
+        len_str = LEN_TRIM(str_READ)
+        ipos_tr = -1
+        ipos_fl = -1
+!-------
+        ipos_tr = MAX(INDEX(str_READ,'tru'),INDEX(str_READ,'TRU'), &
+ &                    INDEX(str_READ,'y'),INDEX(str_READ,'Y'))
+        ipos_fl = MAX(INDEX(str_READ,'fal'),INDEX(str_READ,'FAL'), &
+ &                    INDEX(str_READ,'n'),INDEX(str_READ,'N'))
+!-------
+        IF (ipos_tr > 0) THEN
+          ret_val(it) = .TRUE.
+        ELSE IF (ipos_fl > 0) THEN
+          ret_val(it) = .FALSE.
+        ELSE
+          WRITE(*,*) "ERROR : getfill : TARGET ", &
+ &                   TRIM(TARGET)," is not of logical value"
+          STOP 'getinl'
+        ENDIF
+      ENDIF
+!-----
+      targetsiglist(pos) = -1
+!-----
+    ELSE
+!-
+      found(it) = .FALSE.
+!-
+    ENDIF
+!-
+  ENDDO
+!-
+! Now we get the status for what we found
+!-
+  IF (def_beha) THEN
+    status = 2
+    WRITE(*,*) 'USING DEFAULT BEHAVIOUR FOR ',TRIM(TARGET)
+  ELSE
+    status_cnt = 0
+    DO it=1,nb_to_ret
+      IF (.NOT. found(it)) THEN
+        status_cnt = status_cnt+1
+        IF (nb_to_ret > 1) THEN
+          WRITE(str_tmp,'(a,"__",I3.3)') TRIM(TARGET),it
+        ELSE
+          str_tmp = TRIM(TARGET)
+        ENDIF
+        WRITE(*,*) 'USING DEFAULTS : ',TRIM(str_tmp),'=',ret_val(it)
+      ENDIF
+    ENDDO
+!---
+    IF (status_cnt == 0) THEN
+      status = 1
+    ELSE IF (status_cnt == nb_to_ret) THEN
+      status = 2
+    ELSE
+      status = 3
+    ENDIF
+  ENDIF
+!---------------------
+END SUBROUTINE getfill
+!-
+!===
+!-
+SUBROUTINE getin_read
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER,SAVE :: allread=0
+  INTEGER,SAVE :: current,i
+!---------------------------------------------------------------------
+  IF (allread == 0) THEN
+!-- Allocate a first set of memory.
+    CALL getin_allockeys
+    CALL getin_allocmem (1,0)
+    CALL getin_allocmem (2,0)
+    CALL getin_allocmem (3,0)
+    CALL getin_allocmem (4,0)
+!-- Start with reading the files
+    nbfiles = 1
+    filelist(1) = 'run.def'
+    current = 1
+    nb_lines = 0
+!--
+    DO WHILE (current <= nbfiles)
+      CALL getin_readdef (current)
+      current = current+1
+    ENDDO
+    allread = 1
+    CALL getin_checkcohe ()
+  ENDIF
+!------------------------
+END SUBROUTINE getin_read
+!-
+!===
+!-
+  SUBROUTINE getin_readdef(current)
+!---------------------------------------------------------------------
+!- This subroutine will read the files and only keep the
+!- the relevant information. The information is kept as it
+!- found in the file. The data will be analysed later.
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: current
+!-
+  CHARACTER(LEN=100) :: READ_str, NEW_str, new_key, last_key, key_str
+  CHARACTER(LEN=3) :: cnt
+  INTEGER :: nb_lastkey
+!-
+  INTEGER :: eof, ptn, len_str, i, it, iund
+  LOGICAL :: check = .FALSE.
+!---------------------------------------------------------------------
+  eof = 0
+  ptn = 1
+  nb_lastkey = 0
+!-
+  IF (check) THEN
+    WRITE(*,*) 'getin_readdef : Open file ',TRIM(filelist(current))
+  ENDIF
+!-
+  OPEN (22,file=filelist(current),ERR=9997,STATUS="OLD")
+!-
+  DO WHILE (eof /= 1)
+!---
+    CALL getin_skipafew (22,READ_str,eof,nb_lastkey)
+    len_str = LEN_TRIM(READ_str)
+    ptn = INDEX(READ_str,'=')
+!---
+    IF (ptn > 0) THEN
+!---- Get the target
+      key_str = TRIM(ADJUSTL(READ_str(1:ptn-1)))
+!---- Make sure that if a vector keyword has the right length
+      iund =  INDEX(key_str,'__')
+      IF (iund > 0) THEN
+        SELECTCASE( len_trim(key_str)-iund )
+          CASE(2)
+            READ(key_str(iund+2:len_trim(key_str)),'(I1)') it
+          CASE(3)
+            READ(key_str(iund+2:len_trim(key_str)),'(I2)') it
+          CASE(4)
+            READ(key_str(iund+2:len_trim(key_str)),'(I3)') it
+          CASE DEFAULT
+            it = -1
+        END SELECT
+        IF (it > 0) THEN
+          WRITE(cnt,'(I3.3)') it
+          key_str = key_str(1:iund+1)//cnt
+        ELSE
+          WRITE(*,*) &
+ &          'getin_readdef : A very strange key has just been found'
+          WRITE(*,*) 'getin_readdef : ',key_str(1:len_TRIM(key_str))
+          STOP 'getin_readdef'
+        ENDIF
+      ENDIF
+!---- Prepare the content
+      NEW_str = TRIM(ADJUSTL(READ_str(ptn+1:len_str)))
+      CALL nocomma (NEW_str)
+      CALL cmpblank (NEW_str)
+      NEW_str  = TRIM(ADJUSTL(NEW_str))
+      IF (check) THEN
+        WRITE(*,*) &
+ &        '--> getin_readdef : ',TRIM(key_str),' :: ',TRIM(NEW_str)
+      ENDIF
+!---- Decypher the content of NEW_str
+!-
+!---- This has to be a new key word, thus :
+      nb_lastkey = 0
+!----
+      CALL getin_decrypt (current,key_str,NEW_str,last_key,nb_lastkey)
+!----
+    ELSE IF (len_str > 0) THEN
+!---- Prepare the key if we have an old one to which
+!---- we will add the line just read
+      IF (nb_lastkey > 0) THEN
+        iund =  INDEX(last_key,'__')
+        IF (iund > 0) THEN
+!-------- We only continue a keyword, thus it is easy
+          key_str = last_key(1:iund-1)
+        ELSE
+          IF (nb_lastkey /= 1) THEN
+            WRITE(*,*) &
+ &   'getin_readdef : An error has occured. We can not have a scalar'
+            WRITE(*,*) 'getin_readdef : keywod and a vector content'
+            STOP 'getin_readdef'
+          ENDIF
+!-------- The last keyword needs to be transformed into a vector.
+          targetlist(nb_lines) = &
+ &          last_key(1:MIN(len_trim(last_key),30))//'__001'
+          CALL gensig (targetlist(nb_lines),targetsiglist(nb_lines))
+          key_str = last_key(1:len_TRIM(last_key))
+        ENDIF
+      ENDIF
+!---- Prepare the content
+      NEW_str = TRIM(ADJUSTL(READ_str(1:len_str)))
+      CALL getin_decrypt (current,key_str,NEW_str,last_key,nb_lastkey)
+    ELSE
+!---- If we have an empty line the the keyword finishes
+      nb_lastkey = 0
+      IF (check) THEN
+        WRITE(*,*) 'getin_readdef : Have found an emtpy line '
+      ENDIF
+    ENDIF
+  ENDDO
+!-
+  CLOSE(22)
+!-
+  IF (check) THEN
+    OPEN (22,file='run.def.test')
+    DO i=1,nb_lines
+      WRITE(22,*) targetlist(i)," : ",fichier(i)
+    ENDDO
+    CLOSE(22)
+  ENDIF
+!-
+  RETURN
+!-
+9997 WRITE(*,*) "getin_readdef : Could not open file ", &
+          & TRIM(filelist(current))
+!---------------------------
+END SUBROUTINE getin_readdef
+!-
+!===
+!-
+SUBROUTINE getin_decrypt(current,key_str,NEW_str,last_key,nb_lastkey)
+!---------------------------------------------------------------------
+!- This subroutine is going to decypher the line.
+!- It essentialy checks how many items are included and
+!- it they can be attached to a key.
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+! ARGUMENTS
+!-
+  INTEGER :: current, nb_lastkey
+  CHARACTER(LEN=*) :: key_str, NEW_str, last_key
+!-
+! LOCAL
+!-
+  INTEGER :: len_str, blk, nbve, starpos
+  CHARACTER(LEN=100) :: tmp_str, new_key, mult
+  CHARACTER(LEN=3)   :: cnt, chlen
+  CHARACTER(LEN=10)  :: fmt
+!---------------------------------------------------------------------
+  len_str = LEN_TRIM(NEW_str)
+  blk = INDEX(NEW_str(1:len_str),' ')
+  tmp_str = NEW_str(1:len_str)
+!-
+! If the key is a new file then we take it up. Else
+! we save the line and go on.
+!-
+  IF (INDEX(key_str,'INCLUDEDEF') > 0) THEN
+    DO WHILE (blk > 0)
+      IF (nbfiles+1 > max_files) THEN
+        WRITE(*,*) 'FATAL ERROR : Too many files to include'
+        STOP 'getin_readdef'
+      ENDIF
+!-----
+      nbfiles = nbfiles+1
+      filelist(nbfiles) = tmp_str(1:blk)
+!-----
+      tmp_str = TRIM(ADJUSTL(tmp_str(blk+1:LEN_TRIM(tmp_str))))
+      blk = INDEX(tmp_str(1:LEN_TRIM(tmp_str)),' ')
+    ENDDO
+!---
+    IF (nbfiles+1 > max_files) THEN
+      WRITE(*,*) 'FATAL ERROR : Too many files to include'
+      STOP 'getin_readdef'
+    ENDIF
+!---
+    nbfiles =  nbfiles+1
+    filelist(nbfiles) = TRIM(ADJUSTL(tmp_str))
+!---
+    last_key = 'INCLUDEDEF'
+    nb_lastkey = 1
+  ELSE
+!-
+!-- We are working on a new line of input
+!-
+    nb_lines = nb_lines+1
+    IF (nb_lines > max_lines) THEN
+      WRITE(*,*) &
+ &      'Too many line in the run.def files. You need to increase'
+      WRITE(*,*) 'the parameter max_lines in the module getincom.'
+      STOP 'getin_decrypt'
+    ENDIF
+!-
+!-- First we solve the issue of conpressed information. Once
+!-- this is done all line can be handled in the same way.
+!-
+    starpos = INDEX(NEW_str(1:len_str),'*')
+    IF ( (starpos > 0).AND.(tmp_str(1:1) /= '"') &
+ &                    .AND.(tmp_str(1:1) /= "'") ) THEN
+!-----
+      IF (INDEX(key_str(1:len_TRIM(key_str)),'__') > 0) THEN
+        WRITE(*,*) 'ERROR : getin_decrypt'
+        WRITE(*,*) &
+&         'We can not have a compressed field of values for in a'
+        WRITE(*,*) &
+&         'vector notation. If a target is of the type TARGET__1'
+        WRITE(*,*) 'then only a scalar value is allowed'
+        WRITE(*,*) 'The key at fault : ',key_str(1:len_TRIM(key_str))
+        STOP 'getin_decrypt'
+      ENDIF
+!-
+!---- Read the multiplied
+!-
+      mult = TRIM(ADJUSTL(NEW_str(1:starpos-1)))
+!---- Construct the new string and its parameters
+      NEW_str = TRIM(ADJUSTL(NEW_str(starpos+1:len_str)))
+      len_str = LEN_TRIM(NEW_str)
+      blk = INDEX(NEW_str(1:len_str),' ')
+      IF (blk > 1) THEN
+        WRITE(*,*) &
+ &       'This is a strange behavior of getin_decrypt you could report'
+      ENDIF
+      WRITE(chlen,'(I3.3)') LEN_TRIM(mult)
+      fmt = '(I'//chlen//')'
+      READ(mult,fmt) compline(nb_lines)
+!---
+    ELSE
+      compline(nb_lines) = -1
+    ENDIF
+!-
+!-- If there is no space wthin the line then the target is a scalar
+!-- or the element of a properly written vector.
+!-- (ie of the type TARGET__1)
+!-
+    IF (    (blk <= 1) &
+ &      .OR.(tmp_str(1:1) == '"') &
+ &      .OR.(tmp_str(1:1) == "'") ) THEN
+!-
+      IF (nb_lastkey == 0) THEN
+!------ Save info of current keyword as a scalar
+!------ if it is not a continuation
+        targetlist(nb_lines) = key_str(1:MIN(len_trim(key_str),30))
+        last_key = key_str(1:MIN(len_trim(key_str),30))
+        nb_lastkey = 1
+      ELSE
+!------ We are continuing a vector so the keyword needs
+!------ to get the underscores
+        WRITE(cnt,'(I3.3)') nb_lastkey+1
+        targetlist(nb_lines) = &
+ &        key_str(1:MIN(len_trim(key_str),25))//'__'//cnt
+        last_key = key_str(1:MIN(len_trim(key_str),25))//'__'//cnt
+        nb_lastkey = nb_lastkey+1
+      ENDIF
+!-----
+      CALL gensig (targetlist(nb_lines),targetsiglist(nb_lines))
+      fichier(nb_lines) = NEW_str(1:len_str)
+      fromfile(nb_lines) = current
+    ELSE
+!-
+!---- If there are blanks whithin the line then we are dealing
+!---- with a vector and we need to split it in many entries
+!---- with the TRAGET__1 notation.
+!----
+!---- Test if the targer is not already a vector target !
+!-
+      IF (INDEX(TRIM(key_str),'__') > 0) THEN
+        WRITE(*,*) 'ERROR : getin_decrypt'
+        WRITE(*,*) 'We have found a mixed vector notation'
+        WRITE(*,*) 'If a target is of the type TARGET__1'
+        WRITE(*,*) 'then only a scalar value is allowed'
+        WRITE(*,*) 'The key at fault : ',key_str(1:len_TRIM(key_str))
+        STOP 'getin_decrypt'
+      ENDIF
+!-
+      nbve = nb_lastkey
+      nbve = nbve+1
+      WRITE(cnt,'(I3.3)') nbve
+!-
+      DO WHILE (blk > 0)
+!-
+!------ Save the content of target__nbve
+!-
+        fichier(nb_lines) = tmp_str(1:blk)
+        new_key =  key_str(1:MIN(len_trim(key_str),25))//'__'//cnt
+        targetlist(nb_lines) = new_key(1:MIN(len_trim(new_key),30))
+        CALL gensig (targetlist(nb_lines),targetsiglist(nb_lines))
+        fromfile(nb_lines) = current
+!-
+        tmp_str = TRIM(ADJUSTL(tmp_str(blk+1:LEN_TRIM(tmp_str))))
+        blk = INDEX(TRIM(tmp_str),' ')
+!-
+        nb_lines = nb_lines+1
+        IF (nb_lines > max_lines) THEN
+          WRITE(*,*) &
+ &          'Too many line in the run.def files. You need to increase'
+          WRITE(*,*) 'the parameter max_lines in the module getincom.'
+          STOP 'getin_decrypt'
+        ENDIF
+        nbve = nbve+1
+        WRITE(cnt,'(I3.3)') nbve
+!-
+      ENDDO
+!-
+!---- Save the content of the last target
+!-
+      fichier(nb_lines) = tmp_str(1:LEN_TRIM(tmp_str))
+      new_key = key_str(1:MIN(len_trim(key_str),25))//'__'//cnt
+      targetlist(nb_lines) = new_key(1:MIN(len_trim(new_key),30))
+      CALL gensig (targetlist(nb_lines),targetsiglist(nb_lines))
+      fromfile(nb_lines) = current
+!-
+      last_key = key_str(1:MIN(len_trim(key_str),25))//'__'//cnt
+      nb_lastkey = nbve
+!-
+    ENDIF
+!-
+  ENDIF
+!---------------------------
+END SUBROUTINE getin_decrypt
+!-
+!===
+!-
+SUBROUTINE getin_checkcohe ()
+!---------------------------------------------------------------------
+!- This subroutine checks for redundancies.
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+! Arguments
+!-
+!-
+! LOCAL
+!-
+  INTEGER :: line,i,sig
+  INTEGER :: found
+  CHARACTER(LEN=30) :: str
+!---------------------------------------------------------------------
+  DO line=1,nb_lines-1
+!-
+    CALL find_sig &
+ &    (nb_lines-line,targetlist(line+1:nb_lines),targetlist(line), &
+ &     targetsiglist(line+1:nb_lines),targetsiglist(line),found)
+!---
+!-- IF we have found it we have a problem to solve.
+!---
+    IF (found > 0) THEN
+      WRITE(*,*) 'COUNT : ', &
+ &  COUNT(ABS(targetsiglist(line+1:nb_lines)-targetsiglist(line)) < 1)
+!-----
+      WRITE(*,*) &
+ & 'getin_checkcohe : Found a problem on key ',targetlist(line)
+      WRITE(*,*) &
+ & 'getin_checkcohe : The following values were encoutered :'
+      WRITE(*,*) &
+ & '                ',TRIM(targetlist(line)), &
+ &               targetsiglist(line),' == ',fichier(line)
+      WRITE(*,*) &
+ & '                ',TRIM(targetlist(line+found)), &
+ &               targetsiglist(line+found),' == ',fichier(line+found)
+      WRITE(*,*) &
+ & 'getin_checkcohe : We will keep only the last value'
+!-----
+      targetsiglist(line) = 1
+    ENDIF
+  ENDDO
+!-
+END SUBROUTINE getin_checkcohe
+!-
+!===
+!-
+SUBROUTINE getin_skipafew (unit,out_string,eof,nb_lastkey)
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: unit, eof, nb_lastkey
+  CHARACTER(LEN=100) :: dummy
+  CHARACTER(LEN=100) :: out_string
+  CHARACTER(LEN=1) :: first
+!---------------------------------------------------------------------
+  first="#"
+  eof = 0
+  out_string = "    "
+!-
+  DO WHILE (first == "#")
+    READ (unit,'(a100)',ERR=9998,END=7778) dummy
+    dummy = TRIM(ADJUSTL(dummy))
+    first=dummy(1:1)
+    IF (first == "#") THEN
+      nb_lastkey = 0
+    ENDIF
+  ENDDO
+  out_string=dummy
+!-
+  RETURN
+!-
+9998 WRITE(*,*) " GETIN_SKIPAFEW : Error while reading file "
+  STOP 'getin_skipafew'
+!-
+7778 eof = 1
+!----------------------------
+END SUBROUTINE getin_skipafew
+!-
+!=== INTEGER database INTERFACE
+!-
+SUBROUTINE getdbwi &
+ &  (target,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Write the INTEGER data into the data base
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: target
+  INTEGER :: target_sig, status, fileorig, size_of_in
+  INTEGER,DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+!-
+! First check if we have sufficiant space for the new key
+!-
+  IF (nb_keys+1 > keymemsize) THEN
+    CALL getin_allockeys ()
+  ENDIF
+!-
+! Fill out the items of the data base
+!-
+  nb_keys = nb_keys+1
+  keysig(nb_keys) = target_sig
+  keystr(nb_keys) = target(1:MIN(len_trim(target),30))
+  keystatus(nb_keys) = status
+  keytype(nb_keys) = 1
+  keyfromfile(nb_keys) = fileorig
+!-
+! Can we compress the data base entry ?
+!-
+  IF (     (MINVAL(tmp_ret_val) == MAXVAL(tmp_ret_val)) &
+ &    .AND.(size_of_in > compress_lim)) THEN
+    keymemstart(nb_keys) = intmempos+1
+    keycompress(nb_keys) = size_of_in
+    keymemlen(nb_keys) = 1
+  ELSE
+    keymemstart(nb_keys) = intmempos+1
+    keycompress(nb_keys) = -1
+    keymemlen(nb_keys) = size_of_in
+  ENDIF
+!-
+! Before writing the actual size lets see if we have the space
+!-
+  IF (keymemstart(nb_keys)+keymemlen(nb_keys) > intmemsize) THEN
+    CALL getin_allocmem (1,keymemlen(nb_keys))
+  ENDIF
+!-
+  intmem(keymemstart(nb_keys): &
+ &       keymemstart(nb_keys)+keymemlen(nb_keys)-1) = &
+ &  tmp_ret_val(1:keymemlen(nb_keys))
+  intmempos = keymemstart(nb_keys)+keymemlen(nb_keys)-1
+!---------------------
+END SUBROUTINE getdbwi
+!-
+!===
+!-
+SUBROUTINE getdbri (pos,size_of_in,target,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Read the required variables in the database for INTEGERS
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: pos, size_of_in
+  CHARACTER(LEN=*) :: target
+  INTEGER,DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+  IF (keytype(pos) /= 1) THEN
+    WRITE(*,*) 'FATAL ERROR : Wrong data type for keyword ',target
+    STOP 'getdbri'
+  ENDIF
+!-
+  IF (keycompress(pos) > 0) THEN
+    IF ( keycompress(pos) /= size_of_in .OR. keymemlen(pos) /= 1 ) THEN
+      WRITE(*,*) &
+ &      'FATAL ERROR : Wrong compression length for keyword ',target
+      STOP 'getdbri'
+    ELSE
+      tmp_ret_val(1:size_of_in) = intmem(keymemstart(pos))
+    ENDIF
+  ELSE
+    IF (keymemlen(pos) /= size_of_in) THEN
+      WRITE(*,*) 'FATAL ERROR : Wrong array length for keyword ',target
+      STOP 'getdbri'
+    ELSE
+      tmp_ret_val(1:size_of_in) = &
+ &      intmem(keymemstart(pos):keymemstart(pos)+keymemlen(pos)-1)
+    ENDIF
+  ENDIF
+!---------------------
+END SUBROUTINE getdbri
+!-
+!=== REAL database INTERFACE
+!-
+SUBROUTINE getdbwr &
+ &  (target,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Write the REAL data into the data base
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: target
+  INTEGER :: target_sig, status, fileorig, size_of_in
+  REAL,DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+!-
+! First check if we have sufficiant space for the new key
+!-
+  IF (nb_keys+1 > keymemsize) THEN
+    CALL getin_allockeys ()
+  ENDIF
+!-
+! Fill out the items of the data base
+!-
+  nb_keys = nb_keys+1
+  keysig(nb_keys) = target_sig
+  keystr(nb_keys) = target(1:MIN(len_trim(target),30))
+  keystatus(nb_keys) = status
+  keytype(nb_keys) = 2
+  keyfromfile(nb_keys) = fileorig
+!-
+! Can we compress the data base entry ?
+!-
+  IF (     (MINVAL(tmp_ret_val) == MAXVAL(tmp_ret_val)) &
+&     .AND.(size_of_in > compress_lim)) THEN
+    keymemstart(nb_keys) = realmempos+1
+    keycompress(nb_keys) = size_of_in
+    keymemlen(nb_keys) = 1
+  ELSE
+    keymemstart(nb_keys) = realmempos+1
+    keycompress(nb_keys) = -1
+    keymemlen(nb_keys) = size_of_in
+  ENDIF
+!-
+! Before writing the actual size lets see if we have the space
+!-
+  IF (keymemstart(nb_keys)+keymemlen(nb_keys) > realmemsize) THEN
+    CALL getin_allocmem (2,keymemlen(nb_keys))
+  ENDIF
+!-
+  realmem(keymemstart(nb_keys): &
+ &        keymemstart(nb_keys)+keymemlen(nb_keys)-1) = &
+ &  tmp_ret_val(1:keymemlen(nb_keys))
+  realmempos = keymemstart(nb_keys)+keymemlen(nb_keys)-1
+!---------------------
+END SUBROUTINE getdbwr
+!-
+!===
+!-
+SUBROUTINE getdbrr (pos,size_of_in,target,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Read the required variables in the database for REALS
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: pos, size_of_in
+  CHARACTER(LEN=*) :: target
+  REAL,DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+  IF (keytype(pos) /= 2) THEN
+    WRITE(*,*) 'FATAL ERROR : Wrong data type for keyword ',target
+    STOP 'getdbrr'
+  ENDIF
+!-
+  IF (keycompress(pos) > 0) THEN
+    IF (    (keycompress(pos) /= size_of_in) &
+ &      .OR.(keymemlen(pos) /= 1) ) THEN
+      WRITE(*,*) &
+ &      'FATAL ERROR : Wrong compression length for keyword ',target
+      STOP 'getdbrr'
+    ELSE
+      tmp_ret_val(1:size_of_in) = realmem(keymemstart(pos))
+    ENDIF
+  ELSE
+    IF (keymemlen(pos) /= size_of_in) THEN
+      WRITE(*,*) 'FATAL ERROR : Wrong array length for keyword ',target
+      STOP 'getdbrr'
+    ELSE
+      tmp_ret_val(1:size_of_in) = &
+ &      realmem(keymemstart(pos):keymemstart(pos)+keymemlen(pos)-1)
+    ENDIF
+  ENDIF
+!---------------------
+END SUBROUTINE getdbrr
+!-
+!=== CHARACTER database INTERFACE
+!-
+SUBROUTINE getdbwc &
+ &  (target,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Write the CHARACTER data into the data base
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: target
+  INTEGER :: target_sig,status,fileorig,size_of_in
+  CHARACTER(LEN=*),DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+!-
+! First check if we have sufficiant space for the new key
+!-
+  IF (nb_keys+1 > keymemsize) THEN
+    CALL getin_allockeys ()
+  ENDIF
+!-
+! Fill out the items of the data base
+!-
+  nb_keys = nb_keys+1
+  keysig(nb_keys) = target_sig
+  keystr(nb_keys) = target(1:MIN(len_trim(target),30))
+  keystatus(nb_keys) = status
+  keytype(nb_keys) = 3
+  keyfromfile(nb_keys) = fileorig
+  keymemstart(nb_keys) = charmempos+1
+  keymemlen(nb_keys) = size_of_in
+!-
+! Before writing the actual size lets see if we have the space
+!-
+  IF (keymemstart(nb_keys)+keymemlen(nb_keys) > realmemsize) THEN
+    CALL getin_allocmem (3,keymemlen(nb_keys))
+  ENDIF
+!-
+  charmem(keymemstart(nb_keys): &
+ &        keymemstart(nb_keys)+keymemlen(nb_keys)-1) = &
+ &  tmp_ret_val(1:keymemlen(nb_keys))
+  charmempos = keymemstart(nb_keys)+keymemlen(nb_keys)-1
+!---------------------
+END SUBROUTINE getdbwc
+!-
+!===
+!-
+SUBROUTINE getdbrc(pos,size_of_in,target,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Read the required variables in the database for CHARACTER
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: pos, size_of_in
+  CHARACTER(LEN=*) :: target
+  CHARACTER(LEN=*),DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+  IF (keytype(pos) /= 3) THEN
+    WRITE(*,*) 'FATAL ERROR : Wrong data type for keyword ',target
+    STOP 'getdbrc'
+  ENDIF
+!-
+  IF (keymemlen(pos) /= size_of_in) THEN
+    WRITE(*,*) 'FATAL ERROR : Wrong array length for keyword ',target
+    STOP 'getdbrc'
+  ELSE
+    tmp_ret_val(1:size_of_in) = &
+ &    charmem(keymemstart(pos):keymemstart(pos)+keymemlen(pos)-1)
+  ENDIF
+!---------------------
+END SUBROUTINE getdbrc
+!-
+!=== LOGICAL database INTERFACE
+!-
+SUBROUTINE getdbwl &
+ &  (target,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Write the LOGICAL data into the data base
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: target
+  INTEGER :: target_sig, status, fileorig, size_of_in
+  LOGICAL,DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+!-
+! First check if we have sufficiant space for the new key
+!-
+  IF (nb_keys+1 > keymemsize) THEN
+    CALL getin_allockeys ()
+  ENDIF
+!-
+! Fill out the items of the data base
+!-
+  nb_keys = nb_keys+1
+  keysig(nb_keys) = target_sig
+  keystr(nb_keys) = target(1:MIN(len_trim(target),30))
+  keystatus(nb_keys) = status
+  keytype(nb_keys) = 4
+  keyfromfile(nb_keys) = fileorig
+  keymemstart(nb_keys) = logicmempos+1
+  keymemlen(nb_keys) = size_of_in
+!-
+! Before writing the actual size lets see if we have the space
+!-
+  IF (keymemstart(nb_keys)+keymemlen(nb_keys) > logicmemsize) THEN
+    CALL getin_allocmem (4,keymemlen(nb_keys))
+  ENDIF
+!-
+  logicmem(keymemstart(nb_keys): &
+ &         keymemstart(nb_keys)+keymemlen(nb_keys)-1) = &
+ &  tmp_ret_val(1:keymemlen(nb_keys))
+  logicmempos = keymemstart(nb_keys)+keymemlen(nb_keys)-1
+!---------------------
+END SUBROUTINE getdbwl
+!-
+!===
+!-
+SUBROUTINE getdbrl(pos,size_of_in,target,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Read the required variables in the database for LOGICALS
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: pos, size_of_in
+  CHARACTER(LEN=*) :: target
+  LOGICAL,DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+  IF (keytype(pos) /= 4) THEN
+    WRITE(*,*) 'FATAL ERROR : Wrong data type for keyword ',target
+    STOP 'getdbrl'
+  ENDIF
+!-
+  IF (keymemlen(pos) /= size_of_in) THEN
+    WRITE(*,*) 'FATAL ERROR : Wrong array length for keyword ',target
+    STOP 'getdbrl'
+  ELSE
+    tmp_ret_val(1:size_of_in) = &
+ &    logicmem(keymemstart(pos):keymemstart(pos)+keymemlen(pos)-1)
+  ENDIF
+!---------------------
+END SUBROUTINE getdbrl
+!-
+!===
+!-
+SUBROUTINE getin_allockeys ()
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER,ALLOCATABLE :: tmp_int(:)
+  CHARACTER(LEN=100),ALLOCATABLE :: tmp_str(:)
+!-
+  INTEGER :: ier
+!---------------------------------------------------------------------
+!-
+! Either nothing exists in these arrays and it is easy to do
+!-
+  IF (keymemsize == 0) THEN
+!-
+    ALLOCATE(keysig(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keysig to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keystr(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keystr to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keystatus(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keystatus to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keytype(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keytype to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keycompress(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keycompress to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keyfromfile(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keyfromfile to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keymemstart(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keymemstart to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keymemlen(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keymemlen to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    nb_keys = 0
+    keymemsize = memslabs
+    keycompress(:) = -1
+!-
+  ELSE
+!-
+!-- There is something already in the memory,
+!-- we need to transfer and reallocate.
+!-
+    ALLOCATE(tmp_str(keymemsize),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate tmp_str to size ', &
+ &      keymemsize
+      STOP
+    ENDIF
+!-
+    ALLOCATE(tmp_int(keymemsize),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate tmp_int to size ', &
+ &      keymemsize
+      STOP
+    ENDIF
+!-
+    tmp_int(1:keymemsize) = keysig(1:keymemsize)
+    DEALLOCATE(keysig)
+    ALLOCATE(keysig(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keysig to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keysig(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    tmp_str(1:keymemsize) = keystr(1:keymemsize)
+    DEALLOCATE(keystr)
+    ALLOCATE(keystr(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keystr to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keystr(1:keymemsize) = tmp_str(1:keymemsize)
+!-
+    tmp_int(1:keymemsize) = keystatus(1:keymemsize)
+    DEALLOCATE(keystatus)
+    ALLOCATE(keystatus(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keystatus to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keystatus(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    tmp_int(1:keymemsize) = keytype(1:keymemsize)
+    DEALLOCATE(keytype)
+    ALLOCATE(keytype(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keytype to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keytype(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    tmp_int(1:keymemsize) = keycompress(1:keymemsize)
+    DEALLOCATE(keycompress)
+    ALLOCATE(keycompress(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keycompress to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keycompress(:) = -1
+    keycompress(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    tmp_int(1:keymemsize) = keyfromfile(1:keymemsize)
+    DEALLOCATE(keyfromfile)
+    ALLOCATE(keyfromfile(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keyfromfile to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keyfromfile(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    tmp_int(1:keymemsize) = keymemstart(1:keymemsize)
+    DEALLOCATE(keymemstart)
+    ALLOCATE(keymemstart(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keymemstart to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keymemstart(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    tmp_int(1:keymemsize) = keymemlen(1:keymemsize)
+    DEALLOCATE(keymemlen)
+    ALLOCATE(keymemlen(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keymemlen to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keymemlen(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    keymemsize = keymemsize+memslabs
+!-
+    DEALLOCATE(tmp_int)
+    DEALLOCATE(tmp_str)
+  ENDIF
+!-----------------------------
+END SUBROUTINE getin_allockeys
+!-
+!===
+!-
+SUBROUTINE getin_allocmem (type,len_wanted)
+!---------------------------------------------------------------------
+!- Allocate the memory of the data base for all 4 types of memory
+!-
+!- 1 = INTEGER
+!- 2 = REAL
+!- 3 = CHAR
+!- 4 = LOGICAL
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: type, len_wanted
+!-
+  INTEGER,ALLOCATABLE :: tmp_int(:)
+  CHARACTER(LEN=100),ALLOCATABLE :: tmp_char(:)
+  REAL,ALLOCATABLE :: tmp_real(:)
+  LOGICAL,ALLOCATABLE :: tmp_logic(:)
+  INTEGER :: ier
+!---------------------------------------------------------------------
+  SELECT CASE (type)
+  CASE(1)
+    IF (intmemsize == 0) THEN
+      ALLOCATE(intmem(memslabs),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate db-memory intmem to ', &
+ &    memslabs
+        STOP
+      ENDIF
+      intmemsize=memslabs
+    ELSE
+      ALLOCATE(tmp_int(intmemsize),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate tmp_int to ', &
+ &    intmemsize
+        STOP
+      ENDIF
+      tmp_int(1:intmemsize) = intmem(1:intmemsize)
+      DEALLOCATE(intmem)
+      ALLOCATE(intmem(intmemsize+MAX(memslabs,len_wanted)),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to re-allocate db-memory intmem to ', &
+ &    intmemsize+MAX(memslabs,len_wanted)
+        STOP
+      ENDIF
+      intmem(1:intmemsize) = tmp_int(1:intmemsize)
+      intmemsize = intmemsize+MAX(memslabs,len_wanted)
+      DEALLOCATE(tmp_int)
+    ENDIF
+  CASE(2)
+    IF (realmemsize == 0) THEN
+      ALLOCATE(realmem(memslabs),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate db-memory realmem to ', &
+ &    memslabs
+        STOP
+      ENDIF
+      realmemsize =  memslabs
+    ELSE
+      ALLOCATE(tmp_real(realmemsize),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate tmp_real to ', &
+ &    realmemsize
+        STOP
+      ENDIF
+      tmp_real(1:realmemsize) = realmem(1:realmemsize)
+      DEALLOCATE(realmem)
+      ALLOCATE(realmem(realmemsize+MAX(memslabs,len_wanted)),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to re-allocate db-memory realmem to ', &
+ &    realmemsize+MAX(memslabs,len_wanted)
+        STOP
+      ENDIF
+      realmem(1:realmemsize) = tmp_real(1:realmemsize)
+      realmemsize = realmemsize+MAX(memslabs,len_wanted)
+      DEALLOCATE(tmp_real)
+    ENDIF
+  CASE(3)
+    IF (charmemsize == 0) THEN
+      ALLOCATE(charmem(memslabs),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate db-memory charmem to ', &
+ &    memslabs
+        STOP
+      ENDIF
+      charmemsize = memslabs
+    ELSE
+      ALLOCATE(tmp_char(charmemsize),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate tmp_char to ', &
+ &    charmemsize
+        STOP
+      ENDIF
+      tmp_char(1:charmemsize) = charmem(1:charmemsize)
+      DEALLOCATE(charmem)
+      ALLOCATE(charmem(charmemsize+MAX(memslabs,len_wanted)),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to re-allocate db-memory charmem to ', &
+ &    charmemsize+MAX(memslabs,len_wanted)
+        STOP
+      ENDIF
+      charmem(1:charmemsize) = tmp_char(1:charmemsize)
+      charmemsize = charmemsize+MAX(memslabs,len_wanted)
+      DEALLOCATE(tmp_char)
+    ENDIF
+  CASE(4)
+    IF (logicmemsize == 0) THEN
+      ALLOCATE(logicmem(memslabs),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate db-memory logicmem to ', &
+ &    memslabs
+        STOP
+      ENDIF
+      logicmemsize = memslabs
+    ELSE
+      ALLOCATE(tmp_logic(logicmemsize),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate tmp_logic to ', &
+ &    logicmemsize
+        STOP
+      ENDIF
+      tmp_logic(1:logicmemsize) = logicmem(1:logicmemsize)
+      DEALLOCATE(logicmem)
+      ALLOCATE(logicmem(logicmemsize+MAX(memslabs,len_wanted)),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to re-allocate db-memory logicmem to ', &
+ &    logicmemsize+MAX(memslabs,len_wanted)
+        STOP
+      ENDIF
+      logicmem(1:logicmemsize) = tmp_logic(1:logicmemsize)
+      logicmemsize = logicmemsize+MAX(memslabs,len_wanted)
+      DEALLOCATE(tmp_logic)
+    ENDIF
+  CASE DEFAULT
+    WRITE(*,*) 'getin_allocmem : Unknown type : ',type
+    STOP
+  END SELECT
+!----------------------------
+END SUBROUTINE getin_allocmem
+!-
+!===
+!-
+SUBROUTINE getin_dump (fileprefix)
+!---------------------------------------------------------------------
+!- This subroutine will dump the content of the database into  file
+!- which has the same format as the run.def. The idea is that the user
+!- can see which parameters were used and re-use the file for another
+!- run.
+!-
+!- The argument file allows the user to change the name of the file
+!- in which the data will be archived
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(*),OPTIONAL :: fileprefix
+!-
+  CHARACTER(LEN=80) :: usedfileprefix = "used"
+  INTEGER :: ikey,if,iff,iv
+  CHARACTER(LEN=3) :: tmp3
+  CHARACTER(LEN=100) :: tmp_str, used_filename
+  LOGICAL :: check = .FALSE.
+!---------------------------------------------------------------------
+  IF (PRESENT(fileprefix)) THEN
+    usedfileprefix = fileprefix(1:MIN(len_trim(fileprefix),80))
+  ENDIF
+!-
+  DO if=1,nbfiles
+!---
+    used_filename = TRIM(usedfileprefix)//'_'//TRIM(filelist(if))
+    IF (check) THEN
+      WRITE(*,*) &
+ &      'GETIN_DUMP : opens file : ',TRIM(used_filename),' if = ',if
+      WRITE(*,*) 'GETIN_DUMP : NUMBER OF KEYS : ',nb_keys
+    ENDIF
+    OPEN(unit=76,file=used_filename)
+!-
+!-- If this is the first file we need to add the list
+!-- of file which belong to it
+!-
+    IF ( (if == 1) .AND. (nbfiles > 1) ) THEN
+      WRITE(76,*) '# '
+      WRITE(76,*) '# This file is linked to the following files :'
+      WRITE(76,*) '# '
+      DO iff=2,nbfiles
+        WRITE(76,*) 'INCLUDEDEF = ',TRIM(filelist(iff))
+      ENDDO
+      WRITE(76,*) '# '
+    ENDIF
+!---
+    DO ikey=1,nb_keys
+!-
+!---- Is this key form this file ?
+!-
+      IF (keyfromfile(ikey) == if) THEN
+!-
+!---- Write some comments
+!-
+        WRITE(76,*) '#'
+        SELECT CASE (keystatus(ikey))
+        CASE(1)
+          WRITE(76,*) '# Values of ', &
+ &          TRIM(keystr(ikey)),' comes from the run.def.'
+        CASE(2)
+          WRITE(76,*) '# Values of ', &
+ &          TRIM(keystr(ikey)),' are all defaults.'
+        CASE(3)
+          WRITE(76,*) '# Values of ', &
+ &          TRIM(keystr(ikey)),' are a mix of run.def and defaults.'
+        CASE DEFAULT
+          WRITE(76,*) '# Dont know from where the value of ', &
+ &          TRIM(keystr(ikey)),' comes.'
+        END SELECT
+        WRITE(76,*) '#'
+!-
+!---- Write the values
+!-
+        SELECT CASE (keytype(ikey))
+!-
+        CASE(1)
+          IF (keymemlen(ikey) == 1) THEN
+            IF (keycompress(ikey) < 0) THEN
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),' = ',intmem(keymemstart(ikey))
+            ELSE
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),' = ',keycompress(ikey), &
+ &              ' * ',intmem(keymemstart(ikey))
+            ENDIF
+          ELSE
+            DO iv=0,keymemlen(ikey)-1
+              WRITE(tmp3,'(I3.3)') iv+1
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),'__',tmp3, &
+ &              ' = ',intmem(keymemstart(ikey)+iv)
+            ENDDO
+          ENDIF
+!-
+        CASE(2)
+          IF (keymemlen(ikey) == 1) THEN
+            IF (keycompress(ikey) < 0) THEN
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),' = ',realmem(keymemstart(ikey))
+            ELSE
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),' = ',keycompress(ikey),&
+                   & ' * ',realmem(keymemstart(ikey))
+            ENDIF
+          ELSE
+            DO iv=0,keymemlen(ikey)-1
+              WRITE(tmp3,'(I3.3)') iv+1
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),'__',tmp3, &
+ &              ' = ',realmem(keymemstart(ikey)+iv)
+            ENDDO
+          ENDIF
+        CASE(3)
+          IF (keymemlen(ikey) == 1) THEN
+            tmp_str = charmem(keymemstart(ikey))
+            WRITE(76,*) TRIM(keystr(ikey)),' = ',TRIM(tmp_str)
+          ELSE
+            DO iv=0,keymemlen(ikey)-1
+              WRITE(tmp3,'(I3.3)') iv+1
+              tmp_str = charmem(keymemstart(ikey)+iv)
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),'__',tmp3,' = ',TRIM(tmp_str)
+            ENDDO
+          ENDIF
+        CASE(4)
+          IF (keymemlen(ikey) == 1) THEN
+            IF (logicmem(keymemstart(ikey))) THEN
+              WRITE(76,*) TRIM(keystr(ikey)),' = TRUE '
+            ELSE
+              WRITE(76,*) TRIM(keystr(ikey)),' = FALSE '
+            ENDIF
+          ELSE
+            DO iv=0,keymemlen(ikey)-1
+              WRITE(tmp3,'(I3.3)') iv+1
+              IF (logicmem(keymemstart(ikey)+iv)) THEN
+                WRITE(76,*) TRIM(keystr(ikey)),'__',tmp3,' = TRUE '
+              ELSE
+                WRITE(76,*) TRIM(keystr(ikey)),'__',tmp3,' = FALSE '
+              ENDIF
+            ENDDO
+          ENDIF
+!-
+        CASE DEFAULT
+          WRITE(*,*) &
+ &          'FATAL ERROR : Unknown type for variable ', &
+ &          TRIM(keystr(ikey))
+          STOP 'getin_dump'
+        END SELECT
+      ENDIF
+    ENDDO
+!-
+    CLOSE(unit=76)
+!-
+  ENDDO
+!------------------------
+END SUBROUTINE getin_dump
+!-
+!===
+!-
+END MODULE ioipsl_getincom
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/ioipsl_stringop.F90
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/ioipsl_stringop.F90	(revision 1140)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/ioipsl_stringop.F90	(revision 1140)
@@ -0,0 +1,256 @@
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Module and routines in this file are taken from IOIPSL
+! files stringop.f90
+! Module names has been changed to avoid problems
+! if compiling model with IOIPSL library
+! Ehouarn - March 2009
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+MODULE ioipsl_stringop
+!---------------------------------------------------------------------
+!-
+  INTEGER, DIMENSION(30) :: &
+       & prime=(/1,2,3,5,7,11,13,17,19,23,29,31,37,41,43, &
+       & 47,53,59,61,67,71,73,79,83,89,97,101,103,107,109/)
+!-
+!---------------------------------------------------------------------
+CONTAINS
+!=
+   SUBROUTINE cmpblank (str)
+!---------------------------------------------------------------------
+!-
+!---------------------------------------------------------------------
+   CHARACTER(LEN=*),INTENT(inout) :: str
+!-
+   INTEGER :: lcc,ipb
+!---------------------------------------------------------------------
+   lcc = LEN_TRIM(str)
+   ipb = 1
+   DO
+     IF (ipb >= lcc)   EXIT
+     IF (str(ipb:ipb+1) == '  ') THEN
+       str(ipb+1:) = str(ipb+2:lcc)
+       lcc = lcc-1
+     ELSE
+       ipb = ipb+1
+     ENDIF
+   ENDDO
+!-------------------------
+   END SUBROUTINE cmpblank
+!=
+   INTEGER FUNCTION cntpos (c_c,l_c,c_r,l_r)
+!---------------------------------------------------------------------
+!- Finds number of occurences of c_r in c_c
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   CHARACTER(LEN=*),INTENT(in) :: c_c
+   INTEGER,INTENT(IN) :: l_c
+   CHARACTER(LEN=*),INTENT(in) :: c_r
+   INTEGER,INTENT(IN) :: l_r
+!-
+   INTEGER :: ipos,indx,ires
+!---------------------------------------------------------------------
+   cntpos = 0
+   ipos   = 1
+   DO
+     indx = INDEX(c_c(ipos:l_c),c_r(1:l_r))
+     IF (indx > 0) THEN
+       cntpos = cntpos+1
+       ipos   = ipos+indx+l_r-1
+     ELSE
+       EXIT
+     ENDIF
+   ENDDO
+!---------------------
+   END FUNCTION cntpos
+!=
+   INTEGER FUNCTION findpos (c_c,l_c,c_r,l_r)
+!---------------------------------------------------------------------
+!- Finds position of c_r in c_c
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   CHARACTER(LEN=*),INTENT(in) :: c_c
+   INTEGER,INTENT(IN) :: l_c
+   CHARACTER(LEN=*),INTENT(in) :: c_r
+   INTEGER,INTENT(IN) :: l_r
+!---------------------------------------------------------------------
+    findpos = INDEX(c_c(1:l_c),c_r(1:l_r))
+    IF (findpos == 0)   findpos=-1
+!----------------------
+   END FUNCTION findpos
+!=
+   SUBROUTINE find_str (nb_str,str_tab,str_len_tab,str,pos)
+!---------------------------------------------------------------------
+!- This subroutine looks for a string in a table
+!---------------------------------------------------------------------
+!- INPUT
+!-   nb_str      : length of table
+!-   str_tab     : Table  of strings
+!-   str_len_tab : Table  of string-length
+!-   str         : Target we are looking for
+!- OUTPUT
+!-   pos         : -1 if str not found, else value in the table
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   INTEGER :: nb_str
+   CHARACTER(LEN=*),DIMENSION(nb_str) :: str_tab
+   INTEGER,DIMENSION(nb_str) :: str_len_tab
+   CHARACTER(LEN=*) :: str
+   INTEGER :: pos
+!-
+   INTEGER :: i,il
+!---------------------------------------------------------------------
+   pos = -1
+   il = LEN_TRIM(str)
+   IF ( nb_str > 0 ) THEN
+      DO i=1,nb_str
+         IF (     (INDEX(str_tab(i),str(1:il)) > 0) &
+              .AND.(str_len_tab(i) == il) ) THEN
+            pos = i
+            EXIT
+         ENDIF
+      ENDDO
+   ENDIF
+!-------------------------
+   END SUBROUTINE find_str
+!=
+   SUBROUTINE nocomma (str)
+!---------------------------------------------------------------------
+!-
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   CHARACTER(LEN=*) :: str
+!-
+   INTEGER :: i
+!---------------------------------------------------------------------
+   DO i=1,LEN_TRIM(str)
+     IF (str(i:i) == ',')   str(i:i) = ' '
+   ENDDO
+!------------------------
+   END SUBROUTINE nocomma
+!=
+   SUBROUTINE strlowercase (str)
+!---------------------------------------------------------------------
+!- Converts a string into lowercase
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   CHARACTER(LEN=*) :: str
+!-
+   INTEGER :: i,ic
+!---------------------------------------------------------------------
+   DO i=1,LEN_TRIM(str)
+     ic = IACHAR(str(i:i))
+     IF ( (ic >= 65) .AND. (ic <= 90) )   str(i:i) = ACHAR(ic+32)
+   ENDDO
+!-----------------------------
+   END SUBROUTINE strlowercase
+!=
+   SUBROUTINE struppercase (str)
+!---------------------------------------------------------------------
+!- Converts a string into uppercase
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   CHARACTER(LEN=*) :: str
+!-
+   INTEGER :: i,ic
+!---------------------------------------------------------------------
+   DO i=1,LEN_TRIM(str)
+     ic = IACHAR(str(i:i))
+     IF ( (ic >= 97) .AND. (ic <= 122) )   str(i:i) = ACHAR(ic-32)
+   ENDDO
+!-----------------------------
+   END SUBROUTINE struppercase
+!=
+!------------------
+   SUBROUTINE gensig (str, sig)
+!---------------------------------------------------------------------
+!- Generate a signature from the first 30 characters of the string
+!- This signature is not unique and thus when one looks for the
+!- one needs to also verify the string.
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   CHARACTER(LEN=*) :: str
+   INTEGER          :: sig
+!-
+   INTEGER :: i
+!---------------------------------------------------------------------
+   sig = 0
+   DO i=1,MIN(len_trim(str),30)
+      sig = sig  + prime(i)*IACHAR(str(i:i))
+   ENDDO
+!-----------------------------
+ END SUBROUTINE gensig
+!=
+!------------------
+   SUBROUTINE find_sig (nb_sig, str_tab, str, sig_tab, sig, pos)
+!---------------------------------------------------------------------
+!- Find the string signature in a list of signatures
+!---------------------------------------------------------------------
+!- INPUT
+!-   nb_sig      : length of table of signatures
+!-   str_tab     : Table of strings
+!-   str         : Target string we are looking for 
+!-   sig_tab     : Table of signatures
+!-   sig         : Target signature we are looking for
+!- OUTPUT
+!-   pos         : -1 if str not found, else value in the table
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   INTEGER :: nb_sig
+   CHARACTER(LEN=*),DIMENSION(nb_sig) :: str_tab
+   CHARACTER(LEN=*) :: str
+   INTEGER, DIMENSION(nb_sig) :: sig_tab
+   INTEGER :: sig
+!-
+   INTEGER :: pos
+   INTEGER, DIMENSION(nb_sig) :: loczeros
+!-
+   INTEGER :: il, len
+   INTEGER, DIMENSION(1) :: minpos
+!---------------------------------------------------------------------
+!-
+   pos = -1
+   il = LEN_TRIM(str)
+!-
+   IF ( nb_sig > 0 ) THEN
+      !
+      loczeros = ABS(sig_tab(1:nb_sig)-sig)
+      !
+      IF ( COUNT(loczeros < 1) == 1 ) THEN
+         !
+         minpos = MINLOC(loczeros)
+         len = LEN_TRIM(str_tab(minpos(1)))
+         IF ( (INDEX(str_tab(minpos(1)),str(1:il)) > 0) &
+                 .AND.(len == il) ) THEN
+            pos = minpos(1)
+         ENDIF
+         !
+      ELSE IF ( COUNT(loczeros < 1) > 1 ) THEN
+         !
+         DO WHILE (COUNT(loczeros < 1) >= 1 .AND. pos < 0 )
+            minpos = MINLOC(loczeros)
+            len = LEN_TRIM(str_tab(minpos(1)))
+            IF ( (INDEX(str_tab(minpos(1)),str(1:il)) > 0) &
+                 .AND.(len == il) ) THEN
+               pos = minpos(1)
+            ELSE
+               loczeros(minpos(1)) = 99999
+            ENDIF
+         ENDDO
+         !
+      ENDIF
+      !
+   ENDIF
+!-
+ END SUBROUTINE find_sig
+!=
+!------------------
+END MODULE ioipsl_stringop
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/leapfrog.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/leapfrog.F	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3d/leapfrog.F	(revision 1140)
@@ -7,5 +7,7 @@
 
 cIM : pour sortir les param. du modele dans un fis. netcdf 110106
-      USE IOIPSL 
+#ifdef CPP_IOIPSL
+      use IOIPSL
+#endif
       USE infotrac
 
@@ -161,5 +163,5 @@
 
       character*80 dynhist_file, dynhistave_file
-      character*20 modname
+      character(len=20) :: modname
       character*80 abort_message
 
@@ -217,6 +219,6 @@
         call guide(itau,ucov,vcov,teta,q,masse,ps)
       else
-        IF(prt_level>9)WRITE(*,*)'attention on ne guide pas les ',
-     .    '6 dernieres heures'
+        IF(prt_level>9)WRITE(lunout,*)'leapfrog: attention on ne ',
+     .    'guide pas les 6 dernieres heures'
       endif
 #endif
@@ -227,4 +229,6 @@
 c     ENDIF 
 c
+
+! Save fields obtained at previous time step as '...m1'
       CALL SCOPY( ijmllm ,vcov , 1, vcovm1 , 1 )
       CALL SCOPY( ijp1llm,ucov , 1, ucovm1 , 1 )
@@ -242,5 +246,6 @@
       CALL filtreg ( finvmaold ,jjp1, llm, -2,2, .TRUE., 1 )
 
-      call minmax(ijp1llm,q(:,:,3),zqmin,zqmax)
+! Ehouarn: what is this for? zqmin & zqmax are not used anyway ...
+!      call minmax(ijp1llm,q(:,:,3),zqmin,zqmax)
 
    2  CONTINUE
@@ -302,7 +307,7 @@
 
 
-         ENDIF
-c
-      ENDIF
+         ENDIF ! of IF (offline)
+c
+      ENDIF ! of IF( forward. OR . leapf )
 
 
@@ -350,24 +355,28 @@
 c   -----------------------------------------------------
 
-#ifdef CPP_PHYS
 c+jld
 
 c  Diagnostique de conservation de l'énergie : initialisation
-      IF (ip_ebil_dyn.ge.1 ) THEN 
+         IF (ip_ebil_dyn.ge.1 ) THEN 
           ztit='bil dyn'
-          CALL diagedyn(ztit,2,1,1,dtphys
-     e  , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
-      ENDIF 
+! Ehouarn: be careful, diagedyn is Earth-specific (includes ../phylmd/..)!
+           IF (planet_type.eq."earth") THEN
+            CALL diagedyn(ztit,2,1,1,dtphys
+     &    , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
+           ENDIF
+         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
 c-jld
+#ifdef CPP_IOIPSL
 cIM : pour sortir les param. du modele dans un fis. netcdf 110106
-      IF (first) THEN
-       first=.false.
+         IF (first) THEN
+          first=.false.
 #include "ini_paramLMDZ_dyn.h"
-      ENDIF
+         ENDIF
 c
 #include "write_paramLMDZ_dyn.h"
 c
-
-        CALL calfis( lafin ,rdayvrai,time  ,
+#endif
+! #endif of #ifdef CPP_IOIPSL
+         CALL calfis( lafin ,rdayvrai,time  ,
      $               ucov,vcov,teta,q,masse,ps,p,pk,phis,phi ,
      $               du,dv,dteta,dq,
@@ -375,7 +384,7 @@
      $               clesphy0, dufi,dvfi,dtetafi,dqfi,dpfi  )
 
-       IF (ok_strato) THEN
-         CALL top_bound( vcov,ucov,teta, dufi,dvfi,dtetafi)
-       ENDIF
+         IF (ok_strato) THEN
+           CALL top_bound( vcov,ucov,teta, dufi,dvfi,dtetafi)
+         ENDIF
        
 c      ajout des tendances physiques:
@@ -386,13 +395,15 @@
 c
 c  Diagnostique de conservation de l'énergie : difference
-      IF (ip_ebil_dyn.ge.1 ) THEN 
+         IF (ip_ebil_dyn.ge.1 ) THEN 
           ztit='bil phys'
-          CALL diagedyn(ztit,2,1,1,dtphys
-     e  , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
-      ENDIF 
-#endif
+          IF (planet_type.eq."earth") THEN
+           CALL diagedyn(ztit,2,1,1,dtphys
+     &     , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
+          ENDIF
+         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
+
        ENDIF ! of IF( apphys )
 
-      IF(iflag_phys.EQ.2) THEN ! "Newtonian physics" case
+      IF(iflag_phys.EQ.2) THEN ! "Newtonian" case
 c   Calcul academique de la physique = Rappel Newtonien + friction 
 c   --------------------------------------------------------------
@@ -472,5 +483,5 @@
 
 
-      END IF
+      END IF ! of IF(apdiss)
 
 c ajout debug
@@ -545,31 +556,35 @@
 c           IF( MOD(itau,iecri*day_step).EQ.0) THEN
 
-               nbetat = nbetatdem
-       CALL geopot  ( ip1jmp1, teta  , pk , pks,  phis  , phi        )
-        unat=0.
-        do l=1,llm
-           unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
-           vnat(:,l)=vcov(:,l)/cv(:)
-        enddo
-#ifdef CPP_IOIPSL
-c        CALL writehist(histid,histvid,itau,vcov, 
-c     s                       ucov,teta,phi,q,masse,ps,phis)
-#else
+              nbetat = nbetatdem
+              CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
+              unat=0.
+              do l=1,llm
+                unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
+                vnat(:,l)=vcov(:,l)/cv(:)
+              enddo
+#ifdef CPP_IOIPSL
+c             CALL writehist(histid,histvid,itau,vcov, 
+c     &                      ucov,teta,phi,q,masse,ps,phis)
+#endif
+! For some Grads outputs of fields
+             if (output_grads_dyn) then
 #include "write_grads_dyn.h"
-#endif
-
-
-            ENDIF
+             endif
+
+            ENDIF ! of IF(MOD(itau,iecri).EQ.0)
 
             IF(itau.EQ.itaufin) THEN
 
 
-#ifdef CPP_IOIPSL
-       CALL dynredem1("restart.nc",0.0,
-     ,                     vcov,ucov,teta,q,masse,ps)
-#endif
+              if (planet_type.eq."earth") then
+#ifdef CPP_EARTH
+! Write an Earth-format restart file
+                CALL dynredem1("restart.nc",0.0,
+     &                         vcov,ucov,teta,q,masse,ps)
+#endif
+              endif ! of if (planet_type.eq."earth")
 
               CLOSE(99)
-            ENDIF
+            ENDIF ! of IF (itau.EQ.itaufin)
 
 c-----------------------------------------------------------------------
@@ -593,6 +608,6 @@
                         leapf =  .TRUE.
                         dt  =  2.*dtvr
-                        GO TO 2
-                   END IF
+                        GO TO 2 
+                   END IF ! of IF (forward)
             ELSE
 
@@ -602,7 +617,8 @@
                  dt  = 2.*dtvr
                  GO TO 2
-            END IF
-
-      ELSE
+            END IF ! of IF (MOD(itau,iperiod).EQ.0)
+                   !    ELSEIF (MOD(itau-1,iperiod).EQ.0)
+
+      ELSE ! of IF (.not.purmats)
 
 c       ........................................................
@@ -627,7 +643,7 @@
                GO TO 2
 
-            ELSE
-
-            IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
+            ELSE ! of IF(forward)
+
+              IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
                IF(itau.EQ.itaufin) THEN
                   iav=1
@@ -636,5 +652,5 @@
                ENDIF
 #ifdef CPP_IOIPSL
-              CALL writedynav(histaveid, itau,vcov ,
+               CALL writedynav(histaveid, itau,vcov ,
      ,                          ucov,teta,pk,phi,q,masse,ps,phis)
                call bilan_dyn (2,dtvr*iperiod,dtvr*day_step*periodav,
@@ -642,37 +658,41 @@
 #endif
 
-            ENDIF
-
-               IF(MOD(itau,iecri         ).EQ.0) THEN
+              ENDIF ! of IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin)
+
+              IF(MOD(itau,iecri         ).EQ.0) THEN
 c              IF(MOD(itau,iecri*day_step).EQ.0) THEN
-                  nbetat = nbetatdem
-       CALL geopot  ( ip1jmp1, teta  , pk , pks,  phis  , phi       )
-        unat=0.
-        do l=1,llm
-           unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
-           vnat(:,l)=vcov(:,l)/cv(:)
-        enddo
-#ifdef CPP_IOIPSL
-c       CALL writehist( histid, histvid, itau,vcov , 
-c    ,                           ucov,teta,phi,q,masse,ps,phis)
-#else
+                nbetat = nbetatdem
+                CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
+                unat=0.
+                do l=1,llm
+                  unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
+                  vnat(:,l)=vcov(:,l)/cv(:)
+                enddo
+#ifdef CPP_IOIPSL
+c               CALL writehist( histid, histvid, itau,vcov , 
+c    &                           ucov,teta,phi,q,masse,ps,phis)
+#endif
+! For some Grads outputs
+                if (output_grads_dyn) then
 #include "write_grads_dyn.h"
-#endif
-
-
-               ENDIF
-
-#ifdef CPP_IOIPSL
-                 IF(itau.EQ.itaufin)
-     . CALL dynredem1("restart.nc",0.0,
-     .                     vcov,ucov,teta,q,masse,ps)
-#endif
-
-                 forward = .TRUE.
-                 GO TO  1
-
-            ENDIF
-
-      END IF
+                endif
+
+              ENDIF ! of IF(MOD(itau,iecri         ).EQ.0) 
+
+              IF(itau.EQ.itaufin) THEN
+                if (planet_type.eq."earth") then
+#ifdef CPP_EARTH
+                  CALL dynredem1("restart.nc",0.0,
+     &                           vcov,ucov,teta,q,masse,ps)
+#endif
+                endif ! of if (planet_type.eq."earth")
+              ENDIF ! of IF(itau.EQ.itaufin)
+
+              forward = .TRUE.
+              GO TO  1
+
+            ENDIF ! of IF (forward)
+
+      END IF ! of IF(.not.purmats)
 
       STOP
Index: DZ4/branches/LMDZ4-dev/libf/dyn3dpar/comdiss.h
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/comdiss.h	(revision 1139)
+++ 	(revision )
@@ -1,15 +1,0 @@
-!
-! $Header$
-!
-c-----------------------------------------------------------------------
-c INCLUDE 'comdiss.h'
-
-      INTEGER niter
-      REAL tetau(llm),tetah(llm),cdivu,cdivh,crot
-      LOGICAL dissipst
-
-      COMMON/comdissi/niter
-      COMMON/comdissr/tetau,tetah,cdivu,cdivh,crot
-      COMMON/comdissl/dissipst
-
-c-----------------------------------------------------------------------
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/comdissip.h
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/comdissip.h	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/comdissip.h	(revision 1140)
@@ -2,15 +2,14 @@
 ! $Header$
 !
-c-----------------------------------------------------------------------
-c INCLUDE dissip.h
+!-----------------------------------------------------------------------
+! INCLUDE comdissip.h
 
-      COMMON/comdissip/
-     $    lstardis,niterdis,coefdis,tetavel,tetatemp,gamdissip
+      COMMON/comdissip/                                                 &
+     &    niterdis,coefdis,tetavel,tetatemp,gamdissip
 
 
-      LOGICAL lstardis
       INTEGER niterdis
 
       REAL tetavel,tetatemp,coefdis,gamdissip
 
-c-----------------------------------------------------------------------
+!-----------------------------------------------------------------------
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/conf_gcm.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/conf_gcm.F	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/conf_gcm.F	(revision 1140)
@@ -6,5 +6,10 @@
       SUBROUTINE conf_gcm( tapedef, etatinit, clesphy0 )
 c
+#ifdef CPP_IOIPSL
       use IOIPSL
+#else
+! if not using IOIPSL, we still need to use (a local version of) getin
+      use ioipsl_getincom
+#endif
       use misc_mod
       use mod_filtre_fft, ONLY : use_filtre_fft
@@ -99,7 +104,7 @@
 
 !Config  Key  = prt_level
-!Config  Desc = niveau d'impressions de d�bogage
-!Config  Def  = 0
-!Config  Help = Niveau d'impression pour le d�bogage
+!Config  Desc = niveau d'impressions de débogage
+!Config  Def  = 0
+!Config  Help = Niveau d'impression pour le débogage
 !Config         (0 = minimum d'impression)
       prt_level = 0
@@ -109,4 +114,10 @@
 c  Parametres de controle du run:
 c-----------------------------------------------------------------------
+!Config  Key  = planet_type
+!Config  Desc = planet type ("earth", "mars", "venus", ...)
+!Config  Def  = earth
+!Config  Help = this flag sets the type of atymosphere that is considered
+      planet_type="earth"
+      CALL getin('planet_type',planet_type)
 
 !Config  Key  = dayref
@@ -189,4 +200,11 @@
        CALL getin('periodav',periodav)
 
+!Config  Key  = output_grads_dyn
+!Config  Desc = output dynamics diagnostics in 'dyn.dat' file
+!Config  Def  = n
+!Config  Help = output dynamics diagnostics in Grads-readable 'dyn.dat' file
+       output_grads_dyn=.false.
+       CALL getin('output_grads_dyn',output_grads_dyn)
+
 !Config  Key  = idissip
 !Config  Desc = periode de la dissipation 
@@ -284,4 +302,12 @@
 c    ...............................................................
 
+!Config  Key  =  read_start
+!Config  Desc = Initialize model using a 'start.nc' file
+!Config  Def  = y
+!Config  Help = y: intialize dynamical fields using a 'start.nc' file
+!               n: fields are initialized by 'iniacademic' routine
+       read_start= .true.
+       CALL getin('read_start',read_start)
+
 !Config  Key  = iflag_phys
 !Config  Desc = Avec ls physique 
@@ -341,6 +367,6 @@
 c
       IF( ABS(clat - clatt).GE. 0.001 )  THEN
-        PRINT *,' La valeur de clat passee par run.def est differente de 
-     *  celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de clat passee par run.def',
+     &    ' est differente de celle lue sur le fichier  start '
         STOP
       ENDIF
@@ -356,6 +382,6 @@
 
       IF( ABS(grossismx - grossismxx).GE. 0.001 )  THEN
-        PRINT *,' La valeur de grossismx passee par run.def est differente  
-     *  de celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de grossismx passee par ',
+     &  'run.def est differente de celle lue sur le fichier  start '
         STOP
       ENDIF
@@ -370,11 +396,12 @@
 
       IF( ABS(grossismy - grossismyy).GE. 0.001 )  THEN
-        PRINT *,' La valeur de grossismy passee par run.def est differen
-     * te de celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de grossismy passee par ',
+     & 'run.def est differente de celle lue sur le fichier  start '
         STOP
       ENDIF
       
       IF( grossismx.LT.1. )  THEN
-        PRINT *,' ***  ATTENTION !! grossismx < 1 .   *** '
+        write(lunout,*)
+     &       'conf_gcm: ***  ATTENTION !! grossismx < 1 .   *** '
          STOP
       ELSE
@@ -384,5 +411,6 @@
 
       IF( grossismy.LT.1. )  THEN
-        PRINT *,' ***  ATTENTION !! grossismy < 1 .   *** '
+        write(lunout,*)
+     &       'conf_gcm: ***  ATTENTION !! grossismy < 1 .   *** '
          STOP
       ELSE
@@ -390,5 +418,5 @@
       ENDIF
 
-      PRINT *,' alphax alphay defrun ',alphax,alphay
+      write(lunout,*)'conf_gcm: alphax alphay',alphax,alphay
 c
 c    alphax et alphay sont les anciennes formulat. des grossissements
@@ -405,17 +433,17 @@
 
       IF( .NOT.fxyhypb )  THEN
-           IF( fxyhypbb )     THEN
-              PRINT *,' ********  PBS DANS  DEFRUN  ******** '
-              PRINT *,' *** fxyhypb lu sur le fichier start est F ',
-     *       'alors  qu il est  T  sur  run.def  ***'
+         IF( fxyhypbb )     THEN
+            write(lunout,*)' ********  PBS DANS  CONF_GCM  ******** '
+            write(lunout,*)' *** fxyhypb lu sur le fichier start est ',
+     *       'F alors  qu il est  T  sur  run.def  ***'
               STOP
-           ENDIF
+         ENDIF
       ELSE
-           IF( .NOT.fxyhypbb )   THEN
-              PRINT *,' ********  PBS DANS  DEFRUN  ******** '
-              PRINT *,' ***  fxyhypb lu sur le fichier start est T ',
-     *        'alors  qu il est  F  sur  run.def  ****  '
+         IF( .NOT.fxyhypbb )   THEN
+            write(lunout,*)' ********  PBS DANS  CONF_GCM  ******** '
+            write(lunout,*)' ***  fxyhypb lu sur le fichier start est ',
+     *        'T alors  qu il est  F  sur  run.def  ****  '
               STOP
-           ENDIF
+         ENDIF
       ENDIF
 c
@@ -430,6 +458,6 @@
       IF( fxyhypb )  THEN
        IF( ABS(dzoomx - dzoomxx).GE. 0.001 )  THEN
-        PRINT *,' La valeur de dzoomx passee par run.def est differente 
-     *  de celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de dzoomx passee par ',
+     *  'run.def est differente de celle lue sur le fichier  start '
         STOP
        ENDIF
@@ -446,6 +474,6 @@
       IF( fxyhypb )  THEN
        IF( ABS(dzoomy - dzoomyy).GE. 0.001 )  THEN
-        PRINT *,' La valeur de dzoomy passee par run.def est differente 
-     * de celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de dzoomy passee par ',
+     * 'run.def est differente de celle lue sur le fichier  start '
         STOP
        ENDIF
@@ -461,6 +489,6 @@
       IF( fxyhypb )  THEN
        IF( ABS(taux - tauxx).GE. 0.001 )  THEN
-        PRINT *,' La valeur de taux passee par run.def est differente
-     * de celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de taux passee par ',
+     * 'run.def est differente de celle lue sur le fichier  start '
         STOP
        ENDIF
@@ -476,6 +504,6 @@
       IF( fxyhypb )  THEN
        IF( ABS(tauy - tauyy).GE. 0.001 )  THEN
-        PRINT *,' La valeur de tauy passee par run.def est differente
-     * de celle lue sur le fichier  start '
+        write(lunout,*)'conf_gcm: La valeur de tauy passee par ',
+     * 'run.def est differente de celle lue sur le fichier  start '
         STOP
        ENDIF
@@ -495,19 +523,19 @@
 
         IF( .NOT.ysinus )  THEN
-           IF( ysinuss )     THEN
-              PRINT *,' ********  PBS DANS  DEFRUN  ******** '
-              PRINT *,' *** ysinus lu sur le fichier start est F ',
-     *       'alors  qu il est  T  sur  run.def  ***'
+          IF( ysinuss )     THEN
+            write(lunout,*)' ********  PBS DANS  CONF_GCM  ******** '
+            write(lunout,*)' *** ysinus lu sur le fichier start est F',
+     *       ' alors  qu il est  T  sur  run.def  ***'
+            STOP
+          ENDIF
+        ELSE
+          IF( .NOT.ysinuss )   THEN
+            write(lunout,*)' ********  PBS DANS  CONF_GCM  ******** '
+            write(lunout,*)' *** ysinus lu sur le fichier start est T',
+     *        ' alors  qu il est  F  sur  run.def  ****  '
               STOP
-           ENDIF
-        ELSE
-           IF( .NOT.ysinuss )   THEN
-              PRINT *,' ********  PBS DANS  DEFRUN  ******** '
-              PRINT *,' ***  ysinus lu sur le fichier start est T ',
-     *        'alors  qu il est  F  sur  run.def  ****  '
-              STOP
-           ENDIF
+          ENDIF
         ENDIF
-      ENDIF
+      ENDIF ! of IF( .NOT.fxyhypb  )
 c
 !Config  Key  = offline
@@ -532,4 +560,5 @@
       write(lunout,*)' #########################################'
       write(lunout,*)' Configuration des parametres du gcm: '
+      write(lunout,*)' planet_type = ', planet_type
       write(lunout,*)' dayref = ', dayref
       write(lunout,*)' anneeref = ', anneeref
@@ -540,4 +569,5 @@
       write(lunout,*)' iecri = ', iecri
       write(lunout,*)' periodav = ', periodav 
+      write(lunout,*)' output_grads_dyn = ', output_grads_dyn
       write(lunout,*)' idissip = ', idissip
       write(lunout,*)' lstardis = ', lstardis
@@ -550,4 +580,5 @@
       write(lunout,*)' coefdis = ', coefdis
       write(lunout,*)' purmats = ', purmats
+      write(lunout,*)' read_start = ', read_start
       write(lunout,*)' iflag_phys = ', iflag_phys
       write(lunout,*)' clonn = ', clonn 
@@ -600,5 +631,6 @@
 
       IF( grossismx.LT.1. )  THEN
-        PRINT *,' ***  ATTENTION !! grossismx < 1 .   *** '
+        write(lunout,*)
+     &   'conf_gcm: ***  ATTENTION !! grossismx < 1 .   *** '
          STOP
       ELSE
@@ -608,5 +640,6 @@
 
       IF( grossismy.LT.1. )  THEN
-        PRINT *,' ***  ATTENTION !! grossismy < 1 .   *** '
+        write(lunout,*)
+     &  'conf_gcm: ***  ATTENTION !! grossismy < 1 .   *** '
          STOP
       ELSE
@@ -614,5 +647,5 @@
       ENDIF
 
-      PRINT *,' alphax alphay defrun ',alphax,alphay
+      write(lunout,*)'conf_gcm: alphax alphay ',alphax,alphay
 c
 c    alphax et alphay sont les anciennes formulat. des grossissements
@@ -697,5 +730,5 @@
         write(lunout,*)"Le zoom en longitude est incompatible",
      &                 " avec l'utilisation du filtre FFT ",
-     &                 "---> filtre FFT désactivé "
+     &                 "---> filtre FFT dÃ©sactivÃ© "
        use_filtre_fft=.FALSE.
       ENDIF
@@ -704,9 +737,9 @@
       
 !Config  Key  = use_mpi_alloc
-!Config  Desc = Utilise un buffer MPI en m�moire globale
+!Config  Desc = Utilise un buffer MPI en mï¿½moire globale
 !Config  Def  = false
 !Config  Help = permet d'activer l'utilisation d'un buffer MPI
-!Config         en m�moire globale a l'aide de la fonction MPI_ALLOC.
-!Config         Cela peut am�liorer la bande passante des transferts MPI
+!Config         en mï¿½moire globale a l'aide de la fonction MPI_ALLOC.
+!Config         Cela peut amï¿½liorer la bande passante des transferts MPI
 !Config         d'un facteur 2  
       use_mpi_alloc=.FALSE.
@@ -716,7 +749,7 @@
 !Config  Desc = taille des blocs openmp
 !Config  Def  = 1
-!Config  Help = defini la taille des packets d'it�ration openmp
-!Config         distribu�e � chaque t�che lors de l'entr�e dans une
-!Config         boucle parall�lis�e
+!Config  Help = defini la taille des packets d'itï¿½ration openmp
+!Config         distribuï¿½e ï¿½ chaque tï¿½che lors de l'entrï¿½e dans une
+!Config         boucle parallï¿½lisï¿½e
   
       omp_chunk=1
@@ -726,5 +759,5 @@
 !Config  Desc = activation de la version strato
 !Config  Def  = .FALSE.
-!Config  Help = active la version stratosph�rique de LMDZ de F. Lott
+!Config  Help = active la version stratosphï¿½rique de LMDZ de F. Lott
 
       ok_strato=.FALSE.
@@ -741,4 +774,5 @@
       write(lunout,*)' #########################################'
       write(lunout,*)' Configuration des parametres du gcm: '
+      write(lunout,*)' planet_type = ', planet_type
       write(lunout,*)' dayref = ', dayref
       write(lunout,*)' anneeref = ', anneeref
@@ -749,4 +783,5 @@
       write(lunout,*)' iecri = ', iecri
       write(lunout,*)' periodav = ', periodav 
+      write(lunout,*)' output_grads_dyn = ', output_grads_dyn
       write(lunout,*)' idissip = ', idissip
       write(lunout,*)' lstardis = ', lstardis
@@ -759,4 +794,5 @@
       write(lunout,*)' coefdis = ', coefdis
       write(lunout,*)' purmats = ', purmats
+      write(lunout,*)' read_start = ', read_start
       write(lunout,*)' iflag_phys = ', iflag_phys
       write(lunout,*)' clon = ', clon 
@@ -764,5 +800,5 @@
       write(lunout,*)' grossismx = ', grossismx
       write(lunout,*)' grossismy = ', grossismy
-      write(lunout,*)' fxyhypbb = ', fxyhypbb
+      write(lunout,*)' fxyhypb = ', fxyhypb
       write(lunout,*)' dzoomx = ', dzoomx
       write(lunout,*)' dzoomy = ', dzoomy
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/control.h
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/control.h	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/control.h	(revision 1140)
@@ -14,5 +14,6 @@
      &              iperiod,iapp_tracvl,iconser,iecri,idissip,iphysiq , &
      &              periodav,iecrimoy,dayref,anneeref,                  &
-     &              raz_date,offline,ip_ebil_dyn,config_inca
+     &              raz_date,offline,ip_ebil_dyn,config_inca,           &
+     &              planet_type,output_grads_dyn
 
       INTEGER   nday,day_step,iperiod,iapp_tracvl,iconser,iecri,        &
@@ -21,4 +22,7 @@
       REAL periodav
       logical offline
-      CHARACTER*4 config_inca
+      CHARACTER (len=4) :: config_inca
+      CHARACTER(len=10) :: planet_type ! planet type ('earth','mars',...)
+      LOGICAL :: output_grads_dyn ! output dynamics diagnostics in
+                                  ! binary grads file 'dyn.dat' (y/n)
 !-----------------------------------------------------------------------
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/diagedyn.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/diagedyn.F	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/diagedyn.F	(revision 1140)
@@ -58,6 +58,7 @@
 #include "paramet.h"
 #include "comgeom.h"
-
-#ifdef CPP_PHYS
+#include "iniprint.h"
+
+#ifdef CPP_EARTH
 #include "../phylmd/YOMCST.h"
 #include "../phylmd/YOETHF.h"
@@ -139,5 +140,5 @@
 
 
-#ifdef CPP_PHYS
+#ifdef CPP_EARTH
 c======================================================================
 C     Compute Kinetic enrgy
@@ -314,6 +315,7 @@
 C
 #else
-      print*,'Pour l instant diagedyn a besoin de la physique'
+      write(lunout,*),'diagedyn: Needs Earth physics to function'
 #endif
+! #endif of #ifdef CPP_EARTH 
       RETURN 
       END 
Index: DZ4/branches/LMDZ4-dev/libf/dyn3dpar/disvert0.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/disvert0.F	(revision 1139)
+++ 	(revision )
@@ -1,183 +1,0 @@
-!
-! $Header$
-!
-c
-c
-      SUBROUTINE disvert0(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
-
-c    Auteur :  P. Le Van .
-c
-      IMPLICIT NONE
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "iniprint.h"
-#include "logic.h"
-c
-c=======================================================================
-c
-c
-c    s = sigma ** kappa   :  coordonnee  verticale
-c    dsig(l)            : epaisseur de la couche l ds la coord.  s
-c    sig(l)             : sigma a l'interface des couches l et l-1
-c    ds(l)              : distance entre les couches l et l-1 en coord.s
-c
-c=======================================================================
-c
-      REAL ap(llmp1),bp(llmp1),dpres(llm),nivsigs(llm),nivsig(llmp1)
-      REAL pa,preff,presnivs(llm)
-c
-c   declarations:
-c   -------------
-c
-      REAL sig(llm+1),dsig(llm)
-       real zzz(1:llm+1)
-       real dzz(1:llm)
-      real zk,zkm1,dzk1,dzk2,k0,k1
-c
-      INTEGER l
-      REAL snorm
-      REAL alpha,beta,gama,delta,deltaz,h
-      INTEGER np,ierr
-      REAL pi,x
-
-      REAL SSUM
-
-      pa        =  50 000.
-      preff     = 101 325.
-
-c
-c-----------------------------------------------------------------------
-c
-      pi=2.*ASIN(1.)
-
-      OPEN(99,file='sigma.def',status='old',form='formatted',
-     s   iostat=ierr)
-
-c-----------------------------------------------------------------------
-c   cas 1 on lit les options dans sigma.def:
-c   ----------------------------------------
-
-      IF (ierr.eq.0) THEN
-
-      READ(99,*) h           ! hauteur d'echelle 8.
-      READ(99,*) deltaz      ! epaiseur de la premiere couche 0.04
-      READ(99,*) beta        ! facteur d'acroissement en haut 1.3
-      READ(99,*) k0          ! nombre de couches dans la transition surf
-      READ(99,*) k1          ! nombre de couches dans la transition haute
-      CLOSE(99)
-      alpha=deltaz/(llm*h)
-      WRITE(lunout,*)'h,alpha,k0,k1,beta'
-
-c     read(*,*) h,deltaz,beta,k0,k1 ! 8 0.04 4 20 1.2
-
-      alpha=deltaz/tanh(1./k0)*2.
-      zkm1=0.
-      sig(1)=1.
-      do l=1,llm
-        sig(l+1)=(cosh(l/k0))**(-alpha*k0/h)
-     + *exp(-alpha/h*tanh((llm-k1)/k0)*beta**(l-(llm-k1))/log(beta))
-        zk=-h*log(sig(l+1))
-
-        dzk1=alpha*tanh(l/k0)
-        dzk2=alpha*tanh((llm-k1)/k0)*beta**(l-(llm-k1))/log(beta)
-        WRITE(lunout,*)l,sig(l+1),zk,zk-zkm1,dzk1,dzk2
-        zkm1=zk
-      enddo
-
-      sig(llm+1)=0.
-
-c
-       DO 2  l = 1, llm
-       dsig(l) = sig(l)-sig(l+1)
-   2   CONTINUE
-c
-
-      ELSE
-c-----------------------------------------------------------------------
-c   cas 2 ancienne discretisation (LMD5...):
-c   ----------------------------------------
-
-      write(lunout,*)'WARNING!!! Ancienne discretisation verticale'
-
-      h=7.
-      snorm  = 0.
-      DO l = 1, llm
-         x = 2.*asin(1.) * (FLOAT(l)-0.5) / float(llm+1)
-
-         IF (ok_strato) THEN
-           dsig(l) =(1.0 + 7.0 * SIN(x)**2)
-     &            *(0.5*(1.-tanh(1.*(x-asin(1.))/asin(1.))))**2        
-         ELSE
-           dsig(l) = 1.0 + 7.0 * SIN(x)**2
-         ENDIF
-
-         snorm = snorm + dsig(l)
-      ENDDO
-      snorm = 1./snorm
-      DO l = 1, llm
-         dsig(l) = dsig(l)*snorm
-      ENDDO
-      sig(llm+1) = 0.
-      DO l = llm, 1, -1
-         sig(l) = sig(l+1) + dsig(l)
-      ENDDO
-
-      ENDIF
-
-
-      DO l=1,llm
-        nivsigs(l) = FLOAT(l)
-      ENDDO
-
-      DO l=1,llmp1
-        nivsig(l)= FLOAT(l)
-      ENDDO
-
-c
-c    ....  Calculs  de ap(l) et de bp(l)  ....
-c    .........................................
-c
-c
-c   .....  pa et preff sont lus  sur les fichiers start par lectba  .....
-c
-
-      bp(llmp1) =   0.
-
-      DO l = 1, llm
-cc
-ccc    ap(l) = 0.
-ccc    bp(l) = sig(l)
-
-      bp(l) = EXP( 1. -1./( sig(l)*sig(l)) )
-      ap(l) = pa * ( sig(l) - bp(l) )
-c
-      ENDDO
-      ap(llmp1) = pa * ( sig(llmp1) - bp(llmp1) )
-
-      write(lunout,*)' BP '
-      write(lunout,*)  bp
-      write(lunout,*)' AP '
-      write(lunout,*)  ap
-
-      write(lunout,*)
-     .'Niveaux de pressions approximatifs aux centres des'
-      write(lunout,*)
-     .'couches calcules pour une pression de surface =',preff
-      write(lunout,*)
-     .'et altitudes equivalentes pour une hauteur d echelle de'
-      write(lunout,*)'8km'
-      DO l = 1, llm
-       dpres(l) = bp(l) - bp(l+1)
-       presnivs(l) = 0.5 *( ap(l)+bp(l)*preff + ap(l+1)+bp(l+1)*preff )
-       write(lunout,*)'PRESNIVS(',l,')=',presnivs(l),'    Z ~ ',
-     .        log(preff/presnivs(l))*8.
-     .  ,'   DZ ~ ',8.*log((ap(l)+bp(l)*preff)/
-     .       max(ap(l+1)+bp(l+1)*preff,1.e-10))
-      ENDDO
-
-      write(lunout,*)' PRESNIVS '
-      write(lunout,*)presnivs
-
-      RETURN
-      END
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/etat0_netcdf.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/etat0_netcdf.F	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/etat0_netcdf.F	(revision 1140)
@@ -5,5 +5,5 @@
 c
       SUBROUTINE etat0_netcdf (interbar, masque)
-    
+#ifdef CPP_EARTH        
       USE startvar
       USE ioipsl
@@ -14,4 +14,6 @@
       USE filtreg_mod
       USE infotrac
+#endif
+!#endif of #ifdef CPP_EARTH
       !
       IMPLICIT NONE
@@ -25,4 +27,5 @@
 !     .KLON=KFDIA-KIDIA+1,KLEV=llm
       !
+#ifdef CPP_EARTH    
 #include "comgeom2.h"
 #include "comvert.h"
@@ -31,8 +34,14 @@
 #include "dimsoil.h"
 #include "temps.h"
-      !
+#endif
+!#endif of #ifdef CPP_EARTH
+      ! arguments:
       LOGICAL interbar
+      REAL :: masque(iip1,jjp1)
+
+#ifdef CPP_EARTH
+      ! local variables:
       REAL :: latfi(klon), lonfi(klon)
-      REAL :: orog(iip1,jjp1), rugo(iip1,jjp1), masque(iip1,jjp1),
+      REAL :: orog(iip1,jjp1), rugo(iip1,jjp1),
      . psol(iip1, jjp1), phis(iip1, jjp1)
       REAL :: p3d(iip1, jjp1, llm+1)
@@ -144,4 +153,5 @@
       !
       preff     = 101325.
+      pa        =  50000.
       unskap = 1./kappa
       !
@@ -167,5 +177,5 @@
       print*,'dtvr',dtvr
 
-      CALL inicons0()
+      CALL iniconst()
       CALL inigeom()
       !
@@ -754,4 +764,7 @@
       print*,'entree histclo'
       CALL histclo
+
+#endif 
+!#endif of #ifdef CPP_EARTH
       RETURN
       !
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/gcm.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/gcm.F	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/gcm.F	(revision 1140)
@@ -9,18 +9,22 @@
       USE IOIPSL
 #endif
+
       USE mod_const_mpi, ONLY: init_const_mpi
       USE parallel
       USE mod_phys_lmdz_para, ONLY : klon_mpi_para_nb
+      USE infotrac
+      USE mod_interface_dyn_phys
+      USE mod_hallo
+      USE Bands
+
+      USE filtreg_mod
+
+! Ehouarn: for now these only apply to Earth:
+#ifdef CPP_EARTH
       USE mod_grid_phy_lmdz
       USE mod_phys_lmdz_omp_data, ONLY: klon_omp 
       USE dimphy
-      USE infotrac
-      USE mod_interface_dyn_phys
       USE comgeomphy
-      USE mod_hallo
-      USE Bands
-
-      USE filtreg_mod
-
+#endif
       IMPLICIT NONE
 
@@ -160,22 +164,4 @@
       dynhistave_file = 'dyn_hist_ave'
 
-c--------------------------------------------------------------------------
-c   Iflag_phys controle l'appel a la physique :
-c   -------------------------------------------
-c      0 : pas de physique
-c      1 : Normale (appel a phylmd, phymars ...)
-c      2 : rappel Newtonien pour la temperature + friction au sol
-      iflag_phys=1
-
-c--------------------------------------------------------------------------
-c   Lecture de l'etat initial :
-c   ---------------------------
-c     T : on lit start.nc
-c     F : le modele s'autoinitialise avec un cas academique (iniacademic)
-#ifdef CPP_IOIPSL
-      read_start=.true.
-#else
-      read_start=.false.
-#endif
 
 c-----------------------------------------------------------------------
@@ -194,9 +180,10 @@
 c  ---------------------------------------
 c
-#ifdef CPP_IOIPSL
+! Ehouarn: dump possibility of using defrun
+!#ifdef CPP_IOIPSL
       CALL conf_gcm( 99, .TRUE. , clesphy0 )
-#else
-      CALL defrun( 99, .TRUE. , clesphy0 )
-#endif
+!#else
+!      CALL defrun( 99, .TRUE. , clesphy0 )
+!#endif
 c
 c
@@ -208,5 +195,10 @@
       call init_parallel
       call Read_Distrib
-      CALL Init_Phys_lmdz(iim,jjp1,llm,mpi_size,distrib_phys)
+! Ehouarn : temporarily (?) keep this only for Earth
+      if (planet_type.eq."earth") then
+#ifdef CPP_EARTH
+        CALL Init_Phys_lmdz(iim,jjp1,llm,mpi_size,distrib_phys)
+#endif
+      endif ! of if (planet_type.eq."earth")
       CALL set_bands
       CALL Init_interface_dyn_phys
@@ -220,7 +212,12 @@
 c$OMP END PARALLEL
 
+! Ehouarn : temporarily (?) keep this only for Earth
+      if (planet_type.eq."earth") then
+#ifdef CPP_EARTH
 c$OMP PARALLEL
       call InitComgeomphy
 c$OMP END PARALLEL 
+#endif
+      endif ! of if (planet_type.eq."earth")
 
       IF (config_inca /= 'none') THEN
@@ -252,7 +249,17 @@
 c  lecture du fichier start.nc
       if (read_start) then
-#ifdef CPP_IOIPSL
+      ! we still need to run iniacademic to initialize some
+      ! constants & fields, if we run the 'newtonian' case:
+        if (iflag_phys.eq.2) then
+          CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
+        endif
+!#ifdef CPP_IOIPSL
+        if (planet_type.eq."earth") then
+#ifdef CPP_EARTH
+! Load an Earth-format start file
          CALL dynetat0("start.nc",vcov,ucov,
      .              teta,q,masse,ps,phis, time_0)
+#endif
+        endif ! of if (planet_type.eq."earth")
 c       write(73,*) 'ucov',ucov
 c       write(74,*) 'vcov',vcov
@@ -261,10 +268,9 @@
 c       write(77,*) 'q',q
 
-#endif
-      endif
+      endif ! of if (read_start)
 
 c le cas echeant, creation d un etat initial
       IF (prt_level > 9) WRITE(lunout,*)
-     .                 'AVANT iniacademic AVANT AVANT AVANT AVANT'
+     .              'GCM: AVANT iniacademic AVANT AVANT AVANT AVANT'
       if (.not.read_start) then
          CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
@@ -351,5 +357,4 @@
 c   Initialisation de la physique :
 c   -------------------------------
-#ifdef CPP_PHYS
       IF (call_iniphys.and.iflag_phys.eq.1) THEN
          latfi(1)=rlatu(1)
@@ -372,13 +377,14 @@
 
          WRITE(lunout,*)
-     .           'WARNING!!! vitesse verticale nulle dans la physique'
-
+     .       'GCM: WARNING!!! vitesse verticale nulle dans la physique'
+! Earth:
+         if (planet_type.eq."earth") then
+#ifdef CPP_EARTH
          CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys ,
      ,                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp     )
-
+#endif
+         endif ! of if (planet_type.eq."earth")
          call_iniphys=.false.
-
-      ENDIF
-#endif
+      ENDIF ! of IF (call_iniphys.and.(iflag_phys.eq.1))
 
 
@@ -402,10 +408,16 @@
       day_end = day_ini + nday
       WRITE(lunout,300)day_ini,day_end
+ 300  FORMAT('1'/,15x,'run du jour',i7,2x,'au jour',i7//)
+
+!#ifdef CPP_IOIPSL
+      if (planet_type.eq."earth") then
+#ifdef CPP_EARTH
+      CALL dynredem0_p("restart.nc", day_end, phis)
+#endif
+      endif
+
+      ecripar = .TRUE.
 
 #ifdef CPP_IOIPSL
-      CALL dynredem0_p("restart.nc", day_end, phis)
-
-      ecripar = .TRUE.
-
       if ( 1.eq.1) then
       time_step = zdtvr
@@ -425,4 +437,5 @@
 
 #endif
+! #endif of #ifdef CPP_IOIPSL
 
 c  Choix des frequences de stokage pour le offline
@@ -450,6 +463,4 @@
 
 
- 300  FORMAT('1'/,15x,'run du pas',i7,2x,'au pas',i7,2x,
-     . 'c''est a dire du jour',i7,3x,'au jour',i7//)
       END
 
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/iniacademic.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/iniacademic.F	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/iniacademic.F	(revision 1140)
@@ -45,4 +45,5 @@
 #include "temps.h"
 #include "control.h"
+#include "iniprint.h"
 
 c   Arguments:
@@ -57,18 +58,14 @@
       REAL ps(ip1jmp1)                       ! pression  au sol
       REAL masse(ip1jmp1,llm)                ! masse d'air
+      REAL phis(ip1jmp1)                     ! geopotentiel au sol
+
+c   Local:
+c   ------
+
       REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
       REAL pks(ip1jmp1)                      ! exner au  sol
       REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
       REAL pkf(ip1jmp1,llm)                  ! exner filt.au milieu des couches
-      REAL phis(ip1jmp1)                     ! geopotentiel au sol
       REAL phi(ip1jmp1,llm)                  ! geopotentiel
-
-
-
-
-
-c   Local:
-c   ------
-
       REAL ddsin,tetarappelj,tetarappell,zsig
       real tetajl(jjp1,llm)
@@ -81,37 +78,38 @@
 
 c-----------------------------------------------------------------------
+! 1. Initializations for Earth-like case
+! --------------------------------------
+      if (planet_type=="earth") then
+c
+        time_0=0.
 
-c
-      time_0=0.
+        im         = iim
+        jm         = jjm
+        day_ini    = 0
+        omeg       = 4.*asin(1.)/86400.
+        rad    = 6371229.
+        g      = 9.8
+        daysec = 86400.
+        dtvr    = daysec/FLOAT(day_step)
+        zdtvr=dtvr
+        kappa  = 0.2857143
+        cpp    = 1004.70885
+        preff     = 101325.
+        pa        =  50000.
+        etot0      = 0.
+        ptot0      = 0.
+        ztot0      = 0.
+        stot0      = 0.
+        ang0       = 0.
 
-      im         = iim
-      jm         = jjm
-      day_ini    = 0
-      omeg       = 4.*asin(1.)/86400.
-      rad    = 6371229.
-      g      = 9.8
-      daysec = 86400.
-      dtvr    = daysec/FLOAT(day_step)
-      zdtvr=dtvr
-      kappa  = 0.2857143
-      cpp    = 1004.70885
-      preff     = 101325.
-      pa        =  50 000.
-      etot0      = 0.
-      ptot0      = 0.
-      ztot0      = 0.
-      stot0      = 0.
-      ang0       = 0.
-      pa         = 0.
+        CALL iniconst
+        CALL inigeom
+        CALL inifilr
 
-      CALL inicons0
-      CALL inigeom
-      CALL inifilr
-
-      ps=0.
-      phis=0.
+        ps=0.
+        phis=0.
 c---------------------------------------------------------------------
 
-      taurappel=10.*daysec
+        taurappel=10.*daysec
 
 c---------------------------------------------------------------------
@@ -119,63 +117,63 @@
 c   --------------------------------------
 
-      DO l=1,llm
-       zsig=ap(l)/preff+bp(l)
-       if (zsig.gt.0.3) then
-         lsup=l
-         tetarappell=1./8.*(-log(zsig)-.5)
-         DO j=1,jjp1
-            ddsin=sin(rlatu(j))-sin(pi/20.)
-            tetajl(j,l)=300.*(1+1./18.*(1.-3.*ddsin*ddsin)+tetarappell)
-         ENDDO
-        else
+        DO l=1,llm
+         zsig=ap(l)/preff+bp(l)
+         if (zsig.gt.0.3) then
+           lsup=l
+           tetarappell=1./8.*(-log(zsig)-.5)
+           DO j=1,jjp1
+             ddsin=sin(rlatu(j))-sin(pi/20.)
+             tetajl(j,l)=300.*(1+1./18.*(1.-3.*ddsin*ddsin)+tetarappell)
+           ENDDO
+          else
 c   Choix isotherme au-dessus de 300 mbar
-         do j=1,jjp1
-            tetajl(j,l)=tetajl(j,lsup)*(0.3/zsig)**kappa
-         enddo
-        endif
-      ENDDO
+           do j=1,jjp1
+             tetajl(j,l)=tetajl(j,lsup)*(0.3/zsig)**kappa
+           enddo
+          endif ! of if (zsig.gt.0.3)
+        ENDDO ! of DO l=1,llm
 
-      do l=1,llm
-         do j=1,jjp1
-            do i=1,iip1
-               ij=(j-1)*iip1+i
-               tetarappel(ij,l)=tetajl(j,l)
-            enddo
-         enddo
-      enddo
+        do l=1,llm
+           do j=1,jjp1
+              do i=1,iip1
+                 ij=(j-1)*iip1+i
+                 tetarappel(ij,l)=tetajl(j,l)
+              enddo
+           enddo
+        enddo
 
-c     call dump2d(jjp1,llm,tetajl,'TEQ   ')
+c       call dump2d(jjp1,llm,tetajl,'TEQ   ')
 
-      ps=1.e5
-      phis=0.
-      CALL pression ( ip1jmp1, ap, bp, ps, p       )
-      CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
-      CALL massdair(p,masse)
+        ps=1.e5
+        phis=0.
+        CALL pression ( ip1jmp1, ap, bp, ps, p       )
+        CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
+        CALL massdair(p,masse)
 
 c  intialisation du vent et de la temperature
-      teta(:,:)=tetarappel(:,:)
-      CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
-      call ugeostr(phi,ucov)
-      vcov=0.
-      q(:,:,1   )=1.e-10
-      q(:,:,2   )=1.e-15
-      q(:,:,3:nqtot)=0.
+        teta(:,:)=tetarappel(:,:)
+        CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
+        call ugeostr(phi,ucov)
+        vcov=0.
+        q(:,:,1   )=1.e-10
+        q(:,:,2   )=1.e-15
+        q(:,:,3:nqtot)=0.
 
 
-c   perturbation al\351atoire sur la temp\351rature
-      idum  = -1
-      zz = ran1(idum)
-      idum  = 0
-      do l=1,llm
-         do ij=iip2,ip1jm
-            teta(ij,l)=teta(ij,l)*(1.+0.005*ran1(idum))
-         enddo
-      enddo
+c   perturbation aleatoire sur la temperature
+        idum  = -1
+        zz = ran1(idum)
+        idum  = 0
+        do l=1,llm
+           do ij=iip2,ip1jm
+              teta(ij,l)=teta(ij,l)*(1.+0.005*ran1(idum))
+           enddo
+        enddo
 
-      do l=1,llm
-         do ij=1,ip1jmp1,iip1
-            teta(ij+iim,l)=teta(ij,l)
-         enddo
-      enddo
+        do l=1,llm
+           do ij=1,ip1jmp1,iip1
+              teta(ij+iim,l)=teta(ij,l)
+           enddo
+        enddo
 
 
@@ -187,9 +185,14 @@
 
 c   initialisation d'un traceur sur une colonne
-      j=jjp1*3/4
-      i=iip1/2
-      ij=(j-1)*iip1+i
-      q(ij,:,3)=1.
-
+        j=jjp1*3/4
+        i=iip1/2
+        ij=(j-1)*iip1+i
+        q(ij,:,3)=1.
+      
+      else
+        write(lunout,*)"iniacademic: planet types other than earth",
+     &                 " not implemented (yet)."
+        stop
+      endif ! of if (planet_type=="earth")
       return
       END
Index: DZ4/branches/LMDZ4-dev/libf/dyn3dpar/inicons0.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/inicons0.F	(revision 1139)
+++ 	(revision )
@@ -1,55 +1,0 @@
-!
-! $Header$
-!
-      SUBROUTINE inicons0
-      IMPLICIT NONE
-c
-c  P. Le Van
-c
-c-----------------------------------------------------------------------
-c   Declarations:
-c   -------------
-c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "temps.h"
-#include "control.h"
-#include "comvert.h"
-#include "comdissnew.h"
-
-
-c
-c
-c
-c-----------------------------------------------------------------------
-c   dimension des boucles:
-c   ----------------------
-
-      im      = iim
-      jm      = jjm
-      lllm    = llm
-      imp1    = iim 
-      jmp1    = jjm + 1
-      lllmm1  = llm - 1
-      lllmp1  = llm + 1
-
-c-----------------------------------------------------------------------
-
-      dtdiss  = idissip * dtvr
-      dtphys  = iphysiq * dtvr
-      unsim   = 1./iim
-      pi      = 2.*ASIN( 1. )
-
-c-----------------------------------------------------------------------
-      r       = cpp * kappa
-
-      PRINT*,' Cp R  kappa ',  cpp, r , kappa
-c
-c-----------------------------------------------------------------------
-
-       CALL disvert0(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
-c
-c
-       RETURN
-       END
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/ioipsl_getincom.F90
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/ioipsl_getincom.F90	(revision 1140)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/ioipsl_getincom.F90	(revision 1140)
@@ -0,0 +1,2609 @@
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Module and routines in this file are taken from IOIPSL
+! files getincom.f90
+! Module names has been changed to avoid problems
+! if compiling model with IOIPSL library
+! Ehouarn - March 2009
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+MODULE ioipsl_getincom
+!---------------------------------------------------------------------
+  USE ioipsl_stringop, &
+ &   ONLY : findpos,nocomma,cmpblank,strlowercase,gensig,find_sig
+!-
+  IMPLICIT NONE
+!-
+  PRIVATE
+  PUBLIC :: getin, getin_dump
+!-
+  INTERFACE getin
+    MODULE PROCEDURE getinrs, getinr1d, getinr2d, &
+ &                   getinis, getini1d, getini2d, &
+ &                   getincs, getinc1d, getinc2d, &
+ &                   getinls, getinl1d, getinl2d
+  END INTERFACE
+!-
+  INTEGER,PARAMETER :: max_files=100
+  CHARACTER(LEN=100),DIMENSION(max_files),SAVE :: filelist
+  INTEGER,SAVE      :: nbfiles
+!-
+  INTEGER,PARAMETER :: max_lines=4000
+  INTEGER,SAVE :: nb_lines
+  CHARACTER(LEN=100),DIMENSION(max_lines),SAVE :: fichier
+  INTEGER,DIMENSION(max_lines),SAVE :: targetsiglist,fromfile,compline
+  CHARACTER(LEN=30),DIMENSION(max_lines),SAVE  :: targetlist
+!-
+! The data base of parameters
+!-
+  INTEGER,PARAMETER :: memslabs=200
+  INTEGER,PARAMETER :: compress_lim = 20
+!-
+  INTEGER,SAVE :: nb_keys=0
+  INTEGER,SAVE :: keymemsize=0
+  INTEGER,SAVE,ALLOCATABLE :: keysig(:)
+  CHARACTER(LEN=30),SAVE,ALLOCATABLE :: keystr(:)
+!-
+! keystatus definition
+! keystatus = 1 : Value comes from run.def
+! keystatus = 2 : Default value is used
+! keystatus = 3 : Some vector elements were taken from default
+!-
+  INTEGER,SAVE,ALLOCATABLE :: keystatus(:)
+!-
+! keytype definition
+! keytype = 1 : Interger
+! keytype = 2 : Real
+! keytype = 3 : Character
+! keytype = 4 : Logical
+!-
+  INTEGER,SAVE,ALLOCATABLE :: keytype(:)
+!-
+! Allow compression for keys (only for integer and real)
+! keycompress < 0 : not compresses
+! keycompress > 0 : number of repeat of the value
+!-
+  INTEGER,SAVE,ALLOCATABLE :: keycompress(:)
+  INTEGER,SAVE,ALLOCATABLE :: keyfromfile(:)
+!-
+  INTEGER,SAVE,ALLOCATABLE :: keymemstart(:)
+  INTEGER,SAVE,ALLOCATABLE :: keymemlen(:)
+!-
+  INTEGER,SAVE,ALLOCATABLE :: intmem(:)
+  INTEGER,SAVE             :: intmemsize=0, intmempos=0
+  REAL,SAVE,ALLOCATABLE :: realmem(:)
+  INTEGER,SAVE          :: realmemsize=0, realmempos=0
+  CHARACTER(LEN=100),SAVE,ALLOCATABLE :: charmem(:)
+  INTEGER,SAVE             :: charmemsize=0, charmempos=0
+  LOGICAL,SAVE,ALLOCATABLE :: logicmem(:)
+  INTEGER,SAVE             :: logicmemsize=0, logicmempos=0
+!-
+CONTAINS
+!-
+!=== REAL INTERFACES
+!-
+SUBROUTINE getinrs (TARGET,ret_val)
+!---------------------------------------------------------------------
+!-  Get a real scalar. We first check if we find it
+!-  in the database and if not we get it from the run.def
+!-
+!-  getinr1d and getinr2d are written on the same pattern
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  REAL :: ret_val
+!-
+  REAL,DIMENSION(1) :: tmp_ret_val
+  INTEGER :: target_sig, pos, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  tmp_ret_val(1) = ret_val
+!-
+  IF (pos < 0) THEN
+!-- Get the information out of the file
+    CALL getfilr (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwr (TARGET,target_sig,status,fileorig,1,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrr (pos,1,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val = tmp_ret_val(1)
+!---------------------
+END SUBROUTINE getinrs
+!-
+!===
+!-
+SUBROUTINE getinr1d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getinrs for details. It is the same thing but for a vector
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  REAL,DIMENSION(:) :: ret_val
+!-
+  REAL,DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig, pos, size_of_in, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+  tmp_ret_val(1:size_of_in) = ret_val(1:size_of_in)
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfilr (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwr &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrr (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val(1:size_of_in) = tmp_ret_val(1:size_of_in)
+!----------------------
+END SUBROUTINE getinr1d
+!-
+!===
+!-
+SUBROUTINE getinr2d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getinrs for details. It is the same thing but for a matrix
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  REAL,DIMENSION(:,:) :: ret_val
+!-
+  REAL,DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig,pos,size_of_in,size_1,size_2,status=0,fileorig
+  INTEGER :: jl, jj, ji
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  size_1 = SIZE(ret_val,1)
+  size_2 = SIZE(ret_val,2)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      tmp_ret_val(jl) = ret_val(ji,jj)
+    ENDDO
+  ENDDO
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfilr (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwr &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrr (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      ret_val(ji,jj) = tmp_ret_val(jl)
+    ENDDO
+  ENDDO
+!----------------------
+END SUBROUTINE getinr2d
+!-
+!===
+!-
+SUBROUTINE getfilr (TARGET,status,fileorig,ret_val)
+!---------------------------------------------------------------------
+!- Subroutine that will extract from the file the values
+!- attributed to the keyword target
+!-
+!- REALS
+!- -----
+!-
+!- target   : in  : CHARACTER(LEN=*)  target for which we will
+!-                                    look in the file
+!- status   : out : INTEGER tells us from where we obtained the data
+!- fileorig : out : The index of the file from which the key comes
+!- ret_val  : out : REAL(nb_to_ret) values read
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER :: status, fileorig
+  REAL,DIMENSION(:) :: ret_val
+!-
+  INTEGER :: nb_to_ret
+  INTEGER :: it, pos, len_str, epos, ppos, int_tmp, status_cnt
+  CHARACTER(LEN=3)  :: cnt, tl, dl
+  CHARACTER(LEN=10) :: fmt
+  CHARACTER(LEN=30) :: full_target
+  CHARACTER(LEN=80) :: str_READ, str_READ_lower, str_tmp
+  INTEGER :: full_target_sig
+  REAL :: compvalue
+!-
+  INTEGER,SAVE :: max_len = 0
+  LOGICAL,SAVE,ALLOCATABLE :: found(:)
+  LOGICAL :: def_beha
+  LOGICAL :: compressed = .FALSE.
+!---------------------------------------------------------------------
+  nb_to_ret = SIZE(ret_val)
+  CALL getin_read
+!-
+! Get the variables and memory we need
+!-
+  IF (max_len == 0) THEN
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  IF (max_len < nb_to_ret) THEN
+    DEALLOCATE(found)
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  found(:) = .FALSE.
+!-
+! See what we find in the files read
+!-
+  DO it=1,nb_to_ret
+!---
+!-
+!-- First try the target as it is
+!---
+    full_target = TARGET(1:len_TRIM(target))
+    CALL gensig (full_target,full_target_sig)
+    CALL find_sig (nb_lines,targetlist,full_target, &
+ &                 targetsiglist,full_target_sig,pos)
+!---
+!-- Another try
+!---
+    IF (pos < 0) THEN
+      WRITE(cnt,'(I3.3)') it
+      full_target = TARGET(1:len_TRIM(target))//'__'//cnt
+      CALL gensig (full_target,full_target_sig)
+      CALL find_sig (nb_lines,targetlist,full_target, &
+ &                   targetsiglist,full_target_sig,pos)
+    ENDIF
+!---
+!-- A priori we dont know from which file the target could come.
+!-- Thus by default we attribute it to the first file :
+!---
+    fileorig = 1
+!--
+    IF (pos > 0) THEN
+!----
+      found(it) = .TRUE.
+      fileorig = fromfile(pos)
+!-----
+!---- DECODE
+!-----
+      str_READ = TRIM(ADJUSTL(fichier(pos)))
+      str_READ_lower = str_READ
+      CALL strlowercase (str_READ_lower)
+!----
+      IF (    (     (INDEX(str_READ_lower,'def') == 1)     &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 3)   )    &
+ &        .OR.(     (INDEX(str_READ_lower,'default') == 1) &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 7)   )   ) THEN
+        def_beha = .TRUE.
+      ELSE
+        def_beha = .FALSE.
+        len_str = LEN_TRIM(str_READ)
+        epos = INDEX(str_READ,'e')
+        ppos = INDEX(str_READ,'.')
+!------
+        IF (epos > 0) THEN
+          WRITE(tl,'(I3.3)') len_str
+          WRITE(dl,'(I3.3)') epos-ppos-1
+          fmt='(e'//tl//'.'//dl//')'
+          READ(str_READ,fmt) ret_val(it)
+        ELSE IF (ppos > 0) THEN
+          WRITE(tl,'(I3.3)') len_str
+          WRITE(dl,'(I3.3)') len_str-ppos
+          fmt='(f'//tl//'.'//dl//')'
+          READ(str_READ,fmt) ret_val(it)
+        ELSE
+          WRITE(tl,'(I3.3)') len_str
+          fmt = '(I'//tl//')'
+          READ(str_READ,fmt) int_tmp
+          ret_val(it) = REAL(int_tmp)
+        ENDIF
+      ENDIF
+!----
+      targetsiglist(pos) = -1
+!-----
+!---- Is this the value of a compressed field ?
+!-----
+      IF (compline(pos) > 0) THEN
+        IF (compline(pos) == nb_to_ret) THEN
+          compressed = .TRUE.
+          compvalue = ret_val(it)
+        ELSE
+          WRITE(*,*) 'WARNING from getfilr'
+          WRITE(*,*) 'For key ',TRIM(TARGET), &
+ & ' we have a compressed field but which does not have the right size.'
+          WRITE(*,*) 'We will try to fix that '
+          compressed = .TRUE.
+          compvalue = ret_val(it)
+        ENDIF
+      ENDIF
+    ELSE
+      found(it) = .FALSE.
+    ENDIF
+  ENDDO
+!--
+! If this is a compressed field then we will uncompress it
+!--
+  IF (compressed) THEN
+    DO it=1,nb_to_ret
+      IF (.NOT. found(it)) THEN
+        ret_val(it) = compvalue
+        found(it) = .TRUE.
+      ENDIF
+    ENDDO
+  ENDIF
+!-
+! Now we get the status for what we found
+!-
+  IF (def_beha) THEN
+    status = 2
+    WRITE(*,*) 'USING DEFAULT BEHAVIOUR FOR ',TRIM(TARGET)
+  ELSE
+    status_cnt = 0
+    DO it=1,nb_to_ret
+      IF (.NOT. found(it)) THEN
+        status_cnt = status_cnt+1
+        IF (nb_to_ret > 1) THEN
+          WRITE(str_tmp,'(a,"__",I3.3)') TRIM(TARGET),it
+        ELSE
+          str_tmp = TRIM(TARGET)
+        ENDIF
+        WRITE(*,*) 'USING DEFAULTS : ',TRIM(str_tmp),'=',ret_val(it)
+      ENDIF
+    ENDDO
+!---
+    IF (status_cnt == 0) THEN
+      status = 1
+    ELSE IF (status_cnt == nb_to_ret) THEN
+      status = 2
+    ELSE
+      status = 3
+    ENDIF
+  ENDIF
+!---------------------
+END SUBROUTINE getfilr
+!-
+!=== INTEGER INTERFACES
+!-
+SUBROUTINE getinis (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- Get a interer scalar. We first check if we find it
+!- in the database and if not we get it from the run.def
+!-
+!- getini1d and getini2d are written on the same pattern
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER :: ret_val
+!-
+  INTEGER,DIMENSION(1) :: tmp_ret_val
+  INTEGER :: target_sig, pos, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  tmp_ret_val(1) = ret_val
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfili (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwi (TARGET,target_sig,status,fileorig,1,tmp_ret_val)
+    ELSE
+!-- Get the value out of the database
+    CALL getdbri (pos,1,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val = tmp_ret_val(1)
+!---------------------
+END SUBROUTINE getinis
+!-
+!===
+!-
+SUBROUTINE getini1d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getinis for details. It is the same thing but for a vector
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER,DIMENSION(:) :: ret_val
+!-
+  INTEGER,DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig, pos, size_of_in, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+  tmp_ret_val(1:size_of_in) = ret_val(1:size_of_in)
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfili (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwi &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbri (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val(1:size_of_in) = tmp_ret_val(1:size_of_in)
+!----------------------
+END SUBROUTINE getini1d
+!-
+!===
+!-
+SUBROUTINE getini2d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getinis for details. It is the same thing but for a matrix
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER,DIMENSION(:,:) :: ret_val
+!-
+  INTEGER,DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig,pos,size_of_in,size_1,size_2,status=0,fileorig
+  INTEGER :: jl, jj, ji
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  size_1 = SIZE(ret_val,1)
+  size_2 = SIZE(ret_val,2)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      tmp_ret_val(jl) = ret_val(ji,jj)
+    ENDDO
+  ENDDO
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfili (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwi &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbri (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      ret_val(ji,jj) = tmp_ret_val(jl)
+    ENDDO
+  ENDDO
+!----------------------
+END SUBROUTINE getini2d
+!-
+!===
+!-
+SUBROUTINE getfili (TARGET,status,fileorig,ret_val)
+!---------------------------------------------------------------------
+!- Subroutine that will extract from the file the values
+!- attributed to the keyword target
+!-
+!- INTEGER
+!- -------
+!-
+!- target   : in  : CHARACTER(LEN=*)  target for which we will
+!-                                    look in the file
+!- status   : out : INTEGER tells us from where we obtained the data
+!- fileorig : out : The index of the file from which the key comes
+!- ret_val  : out : INTEGER(nb_to_ret) values read
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER :: status, fileorig
+  INTEGER :: ret_val(:)
+!-
+  INTEGER :: nb_to_ret
+  INTEGER :: it, pos, len_str, status_cnt
+  CHARACTER(LEN=3)  :: cnt, chlen
+  CHARACTER(LEN=10) ::  fmt
+  CHARACTER(LEN=30) :: full_target
+  CHARACTER(LEN=80) :: str_READ, str_READ_lower, str_tmp
+  INTEGER :: full_target_sig
+  INTEGER :: compvalue
+!-
+  INTEGER,SAVE :: max_len = 0
+  LOGICAL,SAVE,ALLOCATABLE :: found(:)
+  LOGICAL :: def_beha
+  LOGICAL :: compressed = .FALSE.
+!---------------------------------------------------------------------
+  nb_to_ret = SIZE(ret_val)
+  CALL getin_read
+!-
+! Get the variables and memory we need
+!-
+  IF (max_len == 0) THEN
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  IF (max_len < nb_to_ret) THEN
+    DEALLOCATE(found)
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  found(:) = .FALSE.
+!-
+! See what we find in the files read
+!-
+  DO it=1,nb_to_ret
+!---
+!-- First try the target as it is
+!---
+    full_target = TARGET(1:len_TRIM(target))
+    CALL gensig (full_target,full_target_sig)
+    CALL find_sig (nb_lines,targetlist,full_target, &
+ &                 targetsiglist,full_target_sig,pos)
+!---
+!-- Another try
+!---
+    IF (pos < 0) THEN
+      WRITE(cnt,'(I3.3)') it
+      full_target = TARGET(1:len_TRIM(target))//'__'//cnt
+      CALL gensig (full_target,full_target_sig)
+      CALL find_sig (nb_lines,targetlist,full_target, &
+ &                   targetsiglist,full_target_sig,pos)
+    ENDIF
+!---
+!-- A priori we dont know from which file the target could come.
+!-- Thus by default we attribute it to the first file :
+!---
+    fileorig = 1
+!-
+    IF (pos > 0) THEN
+!-----
+      found(it) = .TRUE.
+      fileorig = fromfile(pos)
+!-----
+!---- DECODE
+!----
+      str_READ = TRIM(ADJUSTL(fichier(pos)))
+      str_READ_lower = str_READ
+      CALL strlowercase (str_READ_lower)
+!-----
+      IF (    (     (INDEX(str_READ_lower,'def') == 1)     &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 3)   )    &
+ &        .OR.(     (INDEX(str_READ_lower,'default') == 1) &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 7)   )   ) THEN
+        def_beha = .TRUE.
+      ELSE
+        def_beha = .FALSE.
+        len_str = LEN_TRIM(str_READ)
+        WRITE(chlen,'(I3.3)') len_str
+        fmt = '(I'//chlen//')'
+        READ(str_READ,fmt) ret_val(it)
+      ENDIF
+!-----
+      targetsiglist(pos) = -1
+!-----
+!---- Is this the value of a compressed field ?
+!-----
+      IF (compline(pos) > 0) THEN
+        IF (compline(pos) == nb_to_ret) THEN
+          compressed = .TRUE.
+          compvalue = ret_val(it)
+        ELSE
+          WRITE(*,*) 'WARNING from getfilr'
+          WRITE(*,*) 'For key ',TRIM(TARGET), &
+ & ' we have a compressed field but which does not have the right size.'
+          WRITE(*,*) 'We will try to fix that '
+          compressed = .TRUE.
+          compvalue = ret_val(it)
+        ENDIF
+      ENDIF
+    ELSE
+      found(it) = .FALSE.
+    ENDIF
+  ENDDO
+!-
+! If this is a compressed field then we will uncompress it
+!-
+  IF (compressed) THEN
+    DO it=1,nb_to_ret
+      IF (.NOT. found(it)) THEN
+        ret_val(it) = compvalue
+        found(it) = .TRUE.
+      ENDIF
+    ENDDO
+  ENDIF
+!-
+! Now we get the status for what we found
+!-
+  IF (def_beha) THEN
+    status = 2
+    WRITE(*,*) 'USING DEFAULT BEHAVIOUR FOR ',TRIM(TARGET)
+  ELSE
+    status_cnt = 0
+    DO it=1,nb_to_ret
+      IF (.NOT. found(it)) THEN
+        status_cnt = status_cnt+1
+        IF (nb_to_ret > 1) THEN
+          WRITE(str_tmp,'(a,"__",I3.3)') TRIM(TARGET),it
+        ELSE
+          str_tmp = TRIM(TARGET)
+        ENDIF
+        WRITE(*,*) 'USING DEFAULTS : ',TRIM(str_tmp),'=',ret_val(it)
+      ENDIF
+    ENDDO
+!---
+    IF (status_cnt == 0) THEN
+      status = 1
+    ELSE IF (status_cnt == nb_to_ret) THEN
+      status = 2
+    ELSE
+      status = 3
+    ENDIF
+  ENDIF
+!---------------------
+END SUBROUTINE getfili
+!-
+!=== CHARACTER INTERFACES
+!-
+SUBROUTINE getincs (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- Get a CHARACTER scalar. We first check if we find it
+!- in the database and if not we get it from the run.def
+!-
+!- getinc1d and getinc2d are written on the same pattern
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  CHARACTER(LEN=*) :: ret_val
+!-
+  CHARACTER(LEN=100),DIMENSION(1) :: tmp_ret_val
+  INTEGER :: target_sig, pos, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  tmp_ret_val(1) = ret_val
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfilc (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwc (TARGET,target_sig,status,fileorig,1,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrc (pos,1,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val = tmp_ret_val(1)
+!---------------------
+END SUBROUTINE getincs
+!-
+!===
+!-
+SUBROUTINE getinc1d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getincs for details. It is the same thing but for a vector
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  CHARACTER(LEN=*),DIMENSION(:) :: ret_val
+!-
+  CHARACTER(LEN=100),DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig, pos, size_of_in, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+  tmp_ret_val(1:size_of_in) = ret_val(1:size_of_in)
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfilc (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwc &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrc (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val(1:size_of_in) = tmp_ret_val(1:size_of_in)
+!----------------------
+END SUBROUTINE getinc1d
+!-
+!===
+!-
+SUBROUTINE getinc2d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getincs for details. It is the same thing but for a matrix
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  CHARACTER(LEN=*),DIMENSION(:,:) :: ret_val
+!-
+  CHARACTER(LEN=100),DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig,pos,size_of_in,size_1,size_2,status=0,fileorig
+  INTEGER :: jl,jj,ji
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  size_1 = SIZE(ret_val,1)
+  size_2 = SIZE(ret_val,2)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      tmp_ret_val(jl) = ret_val(ji,jj)
+    ENDDO
+  ENDDO
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfilc (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwc &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrc (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      ret_val(ji,jj) = tmp_ret_val(jl)
+    ENDDO
+  ENDDO
+!----------------------
+END SUBROUTINE getinc2d
+!-
+!===
+!-
+SUBROUTINE getfilc (TARGET,status,fileorig,ret_val)
+!---------------------------------------------------------------------
+!- Subroutine that will extract from the file the values
+!- attributed to the keyword target
+!-
+!- CHARACTER
+!- ---------
+!-
+!- target   : in  : CHARACTER(LEN=*)  target for which we will
+!-                                    look in the file
+!- status   : out : INTEGER tells us from where we obtained the data
+!- fileorig : out : The index of the file from which the key comes
+!- ret_val  : out : CHARACTER(nb_to_ret) values read
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER :: status, fileorig
+  CHARACTER(LEN=*),DIMENSION(:) :: ret_val
+!-
+  INTEGER :: nb_to_ret
+  INTEGER :: it, pos, len_str, status_cnt
+  CHARACTER(LEN=3)  :: cnt
+  CHARACTER(LEN=30) :: full_target
+  CHARACTER(LEN=80) :: str_READ, str_READ_lower, str_tmp
+  INTEGER :: full_target_sig
+!-
+  INTEGER,SAVE :: max_len = 0
+  LOGICAL,DIMENSION(:),SAVE,ALLOCATABLE :: found
+  LOGICAL :: def_beha
+!---------------------------------------------------------------------
+  nb_to_ret = SIZE(ret_val)
+  CALL getin_read
+!-
+! Get the variables and memory we need
+!-
+  IF (max_len == 0) THEN
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  IF (max_len < nb_to_ret) THEN
+    DEALLOCATE(found)
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  found(:) = .FALSE.
+!-
+! See what we find in the files read
+!-
+  DO it=1,nb_to_ret
+!---
+!-- First try the target as it is
+    full_target = TARGET(1:len_TRIM(target))
+    CALL gensig (full_target,full_target_sig)
+    CALL find_sig (nb_lines,targetlist,full_target, &
+ &                 targetsiglist,full_target_sig,pos)
+!---
+!-- Another try
+!---
+    IF (pos < 0) THEN
+      WRITE(cnt,'(I3.3)') it
+      full_target = TARGET(1:len_TRIM(target))//'__'//cnt
+      CALL gensig (full_target,full_target_sig)
+      CALL find_sig (nb_lines,targetlist,full_target, &
+ &                   targetsiglist,full_target_sig,pos)
+    ENDIF
+!---
+!-- A priori we dont know from which file the target could come.
+!-- Thus by default we attribute it to the first file :
+!---
+    fileorig = 1
+!---
+    IF (pos > 0) THEN
+!-----
+      found(it) = .TRUE.
+      fileorig = fromfile(pos)
+!-----
+!---- DECODE
+!-----
+      str_READ = TRIM(ADJUSTL(fichier(pos)))
+      str_READ_lower = str_READ
+      CALL strlowercase (str_READ_lower)
+!-----
+      IF (    (     (INDEX(str_READ_lower,'def') == 1)     &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 3)   )    &
+ &        .OR.(     (INDEX(str_READ_lower,'default') == 1) &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 7)   )   ) THEN
+        def_beha = .TRUE.
+      ELSE
+        def_beha = .FALSE.
+        len_str = LEN_TRIM(str_READ)
+        ret_val(it) = str_READ(1:len_str)
+      ENDIF
+!-----
+      targetsiglist(pos) = -1
+!-----
+    ELSE
+      found(it) = .FALSE.
+    ENDIF
+  ENDDO
+!-
+! Now we get the status for what we found
+!-
+  IF (def_beha) THEN
+    status = 2
+    WRITE(*,*) 'USING DEFAULT BEHAVIOUR FOR ',TRIM(TARGET)
+  ELSE
+    status_cnt = 0
+    DO it=1,nb_to_ret
+      IF (.NOT. found(it)) THEN
+        status_cnt = status_cnt+1
+        IF (nb_to_ret > 1) THEN
+          WRITE(str_tmp,'(a,"__",I3.3)') TRIM(TARGET),it
+        ELSE
+          str_tmp = TARGET(1:len_TRIM(target))
+        ENDIF
+        WRITE(*,*) 'USING DEFAULTS : ',TRIM(str_tmp),'=',ret_val(it)
+      ENDIF
+    ENDDO
+!-
+    IF (status_cnt == 0) THEN
+      status = 1
+    ELSE IF (status_cnt == nb_to_ret) THEN
+      status = 2
+    ELSE
+      status = 3
+    ENDIF
+  ENDIF
+!---------------------
+END SUBROUTINE getfilc
+!-
+!=== LOGICAL INTERFACES
+!-
+SUBROUTINE getinls (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- Get a logical scalar. We first check if we find it
+!- in the database and if not we get it from the run.def
+!-
+!- getinl1d and getinl2d are written on the same pattern
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  LOGICAL :: ret_val
+!-
+  LOGICAL,DIMENSION(1) :: tmp_ret_val
+  INTEGER :: target_sig, pos, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  tmp_ret_val(1) = ret_val
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfill (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwl (TARGET,target_sig,status,fileorig,1,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrl (pos,1,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val = tmp_ret_val(1)
+!---------------------
+END SUBROUTINE getinls
+!-
+!===
+!-
+SUBROUTINE getinl1d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getinls for details. It is the same thing but for a vector
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  LOGICAL,DIMENSION(:) :: ret_val
+!-
+  LOGICAL,DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig, pos, size_of_in, status=0, fileorig
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+  tmp_ret_val(1:size_of_in) = ret_val(1:size_of_in)
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfill (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwl &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrl (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+  ret_val(1:size_of_in) = tmp_ret_val(1:size_of_in)
+!----------------------
+END SUBROUTINE getinl1d
+!-
+!===
+!-
+SUBROUTINE getinl2d (TARGET,ret_val)
+!---------------------------------------------------------------------
+!- See getinls for details. It is the same thing but for a matrix
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  LOGICAL,DIMENSION(:,:) :: ret_val
+!-
+  LOGICAL,DIMENSION(:),ALLOCATABLE,SAVE :: tmp_ret_val
+  INTEGER,SAVE :: tmp_ret_size = 0
+  INTEGER :: target_sig,pos,size_of_in,size_1,size_2,status=0,fileorig
+  INTEGER :: jl,jj,ji
+!---------------------------------------------------------------------
+!-
+! Compute the signature of the target
+!-
+  CALL gensig (TARGET,target_sig)
+!-
+! Do we have this target in our database ?
+!-
+  CALL find_sig (nb_keys,keystr,target,keysig,target_sig,pos)
+!-
+  size_of_in = SIZE(ret_val)
+  size_1 = SIZE(ret_val,1)
+  size_2 = SIZE(ret_val,2)
+  IF (.NOT.ALLOCATED(tmp_ret_val)) THEN
+    ALLOCATE (tmp_ret_val(size_of_in))
+  ELSE IF (size_of_in > tmp_ret_size) THEN
+    DEALLOCATE (tmp_ret_val)
+    ALLOCATE (tmp_ret_val(size_of_in))
+    tmp_ret_size = size_of_in
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      tmp_ret_val(jl) = ret_val(ji,jj)
+    ENDDO
+  ENDDO
+!-
+  IF (pos < 0) THEN
+!-- Ge the information out of the file
+    CALL getfill (TARGET,status,fileorig,tmp_ret_val)
+!-- Put the data into the database
+    CALL getdbwl &
+ &   (TARGET,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+  ELSE
+!-- Get the value out of the database
+    CALL getdbrl (pos,size_of_in,TARGET,tmp_ret_val)
+  ENDIF
+!-
+  jl=0
+  DO jj=1,size_2
+    DO ji=1,size_1
+      jl=jl+1
+      ret_val(ji,jj) = tmp_ret_val(jl)
+    ENDDO
+  ENDDO
+!----------------------
+END SUBROUTINE getinl2d
+!-
+!===
+!-
+SUBROUTINE getfill (TARGET,status,fileorig,ret_val)
+!---------------------------------------------------------------------
+!- Subroutine that will extract from the file the values
+!- attributed to the keyword target
+!-
+!- LOGICAL
+!- -------
+!-
+!- target   : in  : CHARACTER(LEN=*)  target for which we will
+!-                                    look in the file
+!- status   : out : INTEGER tells us from where we obtained the data
+!- fileorig : out : The index of the file from which the key comes
+!- ret_val  : out : LOGICAL(nb_to_ret) values read
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: TARGET
+  INTEGER :: status, fileorig
+  LOGICAL,DIMENSION(:) :: ret_val
+!-
+  INTEGER :: nb_to_ret
+  INTEGER :: it, pos, len_str, ipos_tr, ipos_fl, status_cnt
+  CHARACTER(LEN=3)  :: cnt
+  CHARACTER(LEN=30) :: full_target
+  CHARACTER(LEN=80) :: str_READ, str_READ_lower, str_tmp
+  INTEGER :: full_target_sig
+!-
+  INTEGER,SAVE :: max_len = 0
+  LOGICAL,DIMENSION(:),SAVE,ALLOCATABLE :: found
+  LOGICAL :: def_beha
+!---------------------------------------------------------------------
+  nb_to_ret = SIZE(ret_val)
+  CALL getin_read
+!-
+! Get the variables and memory we need
+!-
+  IF (max_len == 0) THEN
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  IF (max_len < nb_to_ret) THEN
+    DEALLOCATE(found)
+    ALLOCATE(found(nb_to_ret))
+    max_len = nb_to_ret
+  ENDIF
+  found(:) = .FALSE.
+!-
+! See what we find in the files read
+!-
+  DO it=1,nb_to_ret
+!---
+!-- First try the target as it is
+!---
+    full_target = TARGET(1:len_TRIM(target))
+    CALL gensig (full_target,full_target_sig)
+    CALL find_sig (nb_lines,targetlist,full_target, &
+ &                 targetsiglist,full_target_sig,pos)
+!---
+!-- Another try
+!---
+    IF (pos < 0) THEN
+      WRITE(cnt,'(I3.3)') it
+      full_target = TARGET(1:len_TRIM(target))//'__'//cnt
+      CALL gensig (full_target,full_target_sig)
+      CALL find_sig (nb_lines,targetlist,full_target, &
+ &                   targetsiglist,full_target_sig,pos)
+    ENDIF
+!---
+!-- A priori we dont know from which file the target could come.
+!-- Thus by default we attribute it to the first file :
+!---
+    fileorig = 1
+!---
+    IF (pos > 0) THEN
+!-----
+      found(it) = .TRUE.
+      fileorig = fromfile(pos)
+!-----
+!---- DECODE
+!-----
+      str_READ = TRIM(ADJUSTL(fichier(pos)))
+      str_READ_lower = str_READ
+      CALL strlowercase (str_READ_lower)
+!-----
+      IF (    (     (INDEX(str_READ_lower,'def') == 1)     &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 3)   )    &
+ &        .OR.(     (INDEX(str_READ_lower,'default') == 1) &
+ &             .AND.(LEN_TRIM(str_READ_lower) == 7)   )   ) THEN
+        def_beha = .TRUE.
+      ELSE
+        def_beha = .FALSE.
+        len_str = LEN_TRIM(str_READ)
+        ipos_tr = -1
+        ipos_fl = -1
+!-------
+        ipos_tr = MAX(INDEX(str_READ,'tru'),INDEX(str_READ,'TRU'), &
+ &                    INDEX(str_READ,'y'),INDEX(str_READ,'Y'))
+        ipos_fl = MAX(INDEX(str_READ,'fal'),INDEX(str_READ,'FAL'), &
+ &                    INDEX(str_READ,'n'),INDEX(str_READ,'N'))
+!-------
+        IF (ipos_tr > 0) THEN
+          ret_val(it) = .TRUE.
+        ELSE IF (ipos_fl > 0) THEN
+          ret_val(it) = .FALSE.
+        ELSE
+          WRITE(*,*) "ERROR : getfill : TARGET ", &
+ &                   TRIM(TARGET)," is not of logical value"
+          STOP 'getinl'
+        ENDIF
+      ENDIF
+!-----
+      targetsiglist(pos) = -1
+!-----
+    ELSE
+!-
+      found(it) = .FALSE.
+!-
+    ENDIF
+!-
+  ENDDO
+!-
+! Now we get the status for what we found
+!-
+  IF (def_beha) THEN
+    status = 2
+    WRITE(*,*) 'USING DEFAULT BEHAVIOUR FOR ',TRIM(TARGET)
+  ELSE
+    status_cnt = 0
+    DO it=1,nb_to_ret
+      IF (.NOT. found(it)) THEN
+        status_cnt = status_cnt+1
+        IF (nb_to_ret > 1) THEN
+          WRITE(str_tmp,'(a,"__",I3.3)') TRIM(TARGET),it
+        ELSE
+          str_tmp = TRIM(TARGET)
+        ENDIF
+        WRITE(*,*) 'USING DEFAULTS : ',TRIM(str_tmp),'=',ret_val(it)
+      ENDIF
+    ENDDO
+!---
+    IF (status_cnt == 0) THEN
+      status = 1
+    ELSE IF (status_cnt == nb_to_ret) THEN
+      status = 2
+    ELSE
+      status = 3
+    ENDIF
+  ENDIF
+!---------------------
+END SUBROUTINE getfill
+!-
+!===
+!-
+SUBROUTINE getin_read
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER,SAVE :: allread=0
+  INTEGER,SAVE :: current,i
+!---------------------------------------------------------------------
+  IF (allread == 0) THEN
+!-- Allocate a first set of memory.
+    CALL getin_allockeys
+    CALL getin_allocmem (1,0)
+    CALL getin_allocmem (2,0)
+    CALL getin_allocmem (3,0)
+    CALL getin_allocmem (4,0)
+!-- Start with reading the files
+    nbfiles = 1
+    filelist(1) = 'run.def'
+    current = 1
+    nb_lines = 0
+!--
+    DO WHILE (current <= nbfiles)
+      CALL getin_readdef (current)
+      current = current+1
+    ENDDO
+    allread = 1
+    CALL getin_checkcohe ()
+  ENDIF
+!------------------------
+END SUBROUTINE getin_read
+!-
+!===
+!-
+  SUBROUTINE getin_readdef(current)
+!---------------------------------------------------------------------
+!- This subroutine will read the files and only keep the
+!- the relevant information. The information is kept as it
+!- found in the file. The data will be analysed later.
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: current
+!-
+  CHARACTER(LEN=100) :: READ_str, NEW_str, new_key, last_key, key_str
+  CHARACTER(LEN=3) :: cnt
+  INTEGER :: nb_lastkey
+!-
+  INTEGER :: eof, ptn, len_str, i, it, iund
+  LOGICAL :: check = .FALSE.
+!---------------------------------------------------------------------
+  eof = 0
+  ptn = 1
+  nb_lastkey = 0
+!-
+  IF (check) THEN
+    WRITE(*,*) 'getin_readdef : Open file ',TRIM(filelist(current))
+  ENDIF
+!-
+  OPEN (22,file=filelist(current),ERR=9997,STATUS="OLD")
+!-
+  DO WHILE (eof /= 1)
+!---
+    CALL getin_skipafew (22,READ_str,eof,nb_lastkey)
+    len_str = LEN_TRIM(READ_str)
+    ptn = INDEX(READ_str,'=')
+!---
+    IF (ptn > 0) THEN
+!---- Get the target
+      key_str = TRIM(ADJUSTL(READ_str(1:ptn-1)))
+!---- Make sure that if a vector keyword has the right length
+      iund =  INDEX(key_str,'__')
+      IF (iund > 0) THEN
+        SELECTCASE( len_trim(key_str)-iund )
+          CASE(2)
+            READ(key_str(iund+2:len_trim(key_str)),'(I1)') it
+          CASE(3)
+            READ(key_str(iund+2:len_trim(key_str)),'(I2)') it
+          CASE(4)
+            READ(key_str(iund+2:len_trim(key_str)),'(I3)') it
+          CASE DEFAULT
+            it = -1
+        END SELECT
+        IF (it > 0) THEN
+          WRITE(cnt,'(I3.3)') it
+          key_str = key_str(1:iund+1)//cnt
+        ELSE
+          WRITE(*,*) &
+ &          'getin_readdef : A very strange key has just been found'
+          WRITE(*,*) 'getin_readdef : ',key_str(1:len_TRIM(key_str))
+          STOP 'getin_readdef'
+        ENDIF
+      ENDIF
+!---- Prepare the content
+      NEW_str = TRIM(ADJUSTL(READ_str(ptn+1:len_str)))
+      CALL nocomma (NEW_str)
+      CALL cmpblank (NEW_str)
+      NEW_str  = TRIM(ADJUSTL(NEW_str))
+      IF (check) THEN
+        WRITE(*,*) &
+ &        '--> getin_readdef : ',TRIM(key_str),' :: ',TRIM(NEW_str)
+      ENDIF
+!---- Decypher the content of NEW_str
+!-
+!---- This has to be a new key word, thus :
+      nb_lastkey = 0
+!----
+      CALL getin_decrypt (current,key_str,NEW_str,last_key,nb_lastkey)
+!----
+    ELSE IF (len_str > 0) THEN
+!---- Prepare the key if we have an old one to which
+!---- we will add the line just read
+      IF (nb_lastkey > 0) THEN
+        iund =  INDEX(last_key,'__')
+        IF (iund > 0) THEN
+!-------- We only continue a keyword, thus it is easy
+          key_str = last_key(1:iund-1)
+        ELSE
+          IF (nb_lastkey /= 1) THEN
+            WRITE(*,*) &
+ &   'getin_readdef : An error has occured. We can not have a scalar'
+            WRITE(*,*) 'getin_readdef : keywod and a vector content'
+            STOP 'getin_readdef'
+          ENDIF
+!-------- The last keyword needs to be transformed into a vector.
+          targetlist(nb_lines) = &
+ &          last_key(1:MIN(len_trim(last_key),30))//'__001'
+          CALL gensig (targetlist(nb_lines),targetsiglist(nb_lines))
+          key_str = last_key(1:len_TRIM(last_key))
+        ENDIF
+      ENDIF
+!---- Prepare the content
+      NEW_str = TRIM(ADJUSTL(READ_str(1:len_str)))
+      CALL getin_decrypt (current,key_str,NEW_str,last_key,nb_lastkey)
+    ELSE
+!---- If we have an empty line the the keyword finishes
+      nb_lastkey = 0
+      IF (check) THEN
+        WRITE(*,*) 'getin_readdef : Have found an emtpy line '
+      ENDIF
+    ENDIF
+  ENDDO
+!-
+  CLOSE(22)
+!-
+  IF (check) THEN
+    OPEN (22,file='run.def.test')
+    DO i=1,nb_lines
+      WRITE(22,*) targetlist(i)," : ",fichier(i)
+    ENDDO
+    CLOSE(22)
+  ENDIF
+!-
+  RETURN
+!-
+9997 WRITE(*,*) "getin_readdef : Could not open file ", &
+          & TRIM(filelist(current))
+!---------------------------
+END SUBROUTINE getin_readdef
+!-
+!===
+!-
+SUBROUTINE getin_decrypt(current,key_str,NEW_str,last_key,nb_lastkey)
+!---------------------------------------------------------------------
+!- This subroutine is going to decypher the line.
+!- It essentialy checks how many items are included and
+!- it they can be attached to a key.
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+! ARGUMENTS
+!-
+  INTEGER :: current, nb_lastkey
+  CHARACTER(LEN=*) :: key_str, NEW_str, last_key
+!-
+! LOCAL
+!-
+  INTEGER :: len_str, blk, nbve, starpos
+  CHARACTER(LEN=100) :: tmp_str, new_key, mult
+  CHARACTER(LEN=3)   :: cnt, chlen
+  CHARACTER(LEN=10)  :: fmt
+!---------------------------------------------------------------------
+  len_str = LEN_TRIM(NEW_str)
+  blk = INDEX(NEW_str(1:len_str),' ')
+  tmp_str = NEW_str(1:len_str)
+!-
+! If the key is a new file then we take it up. Else
+! we save the line and go on.
+!-
+  IF (INDEX(key_str,'INCLUDEDEF') > 0) THEN
+    DO WHILE (blk > 0)
+      IF (nbfiles+1 > max_files) THEN
+        WRITE(*,*) 'FATAL ERROR : Too many files to include'
+        STOP 'getin_readdef'
+      ENDIF
+!-----
+      nbfiles = nbfiles+1
+      filelist(nbfiles) = tmp_str(1:blk)
+!-----
+      tmp_str = TRIM(ADJUSTL(tmp_str(blk+1:LEN_TRIM(tmp_str))))
+      blk = INDEX(tmp_str(1:LEN_TRIM(tmp_str)),' ')
+    ENDDO
+!---
+    IF (nbfiles+1 > max_files) THEN
+      WRITE(*,*) 'FATAL ERROR : Too many files to include'
+      STOP 'getin_readdef'
+    ENDIF
+!---
+    nbfiles =  nbfiles+1
+    filelist(nbfiles) = TRIM(ADJUSTL(tmp_str))
+!---
+    last_key = 'INCLUDEDEF'
+    nb_lastkey = 1
+  ELSE
+!-
+!-- We are working on a new line of input
+!-
+    nb_lines = nb_lines+1
+    IF (nb_lines > max_lines) THEN
+      WRITE(*,*) &
+ &      'Too many line in the run.def files. You need to increase'
+      WRITE(*,*) 'the parameter max_lines in the module getincom.'
+      STOP 'getin_decrypt'
+    ENDIF
+!-
+!-- First we solve the issue of conpressed information. Once
+!-- this is done all line can be handled in the same way.
+!-
+    starpos = INDEX(NEW_str(1:len_str),'*')
+    IF ( (starpos > 0).AND.(tmp_str(1:1) /= '"') &
+ &                    .AND.(tmp_str(1:1) /= "'") ) THEN
+!-----
+      IF (INDEX(key_str(1:len_TRIM(key_str)),'__') > 0) THEN
+        WRITE(*,*) 'ERROR : getin_decrypt'
+        WRITE(*,*) &
+&         'We can not have a compressed field of values for in a'
+        WRITE(*,*) &
+&         'vector notation. If a target is of the type TARGET__1'
+        WRITE(*,*) 'then only a scalar value is allowed'
+        WRITE(*,*) 'The key at fault : ',key_str(1:len_TRIM(key_str))
+        STOP 'getin_decrypt'
+      ENDIF
+!-
+!---- Read the multiplied
+!-
+      mult = TRIM(ADJUSTL(NEW_str(1:starpos-1)))
+!---- Construct the new string and its parameters
+      NEW_str = TRIM(ADJUSTL(NEW_str(starpos+1:len_str)))
+      len_str = LEN_TRIM(NEW_str)
+      blk = INDEX(NEW_str(1:len_str),' ')
+      IF (blk > 1) THEN
+        WRITE(*,*) &
+ &       'This is a strange behavior of getin_decrypt you could report'
+      ENDIF
+      WRITE(chlen,'(I3.3)') LEN_TRIM(mult)
+      fmt = '(I'//chlen//')'
+      READ(mult,fmt) compline(nb_lines)
+!---
+    ELSE
+      compline(nb_lines) = -1
+    ENDIF
+!-
+!-- If there is no space wthin the line then the target is a scalar
+!-- or the element of a properly written vector.
+!-- (ie of the type TARGET__1)
+!-
+    IF (    (blk <= 1) &
+ &      .OR.(tmp_str(1:1) == '"') &
+ &      .OR.(tmp_str(1:1) == "'") ) THEN
+!-
+      IF (nb_lastkey == 0) THEN
+!------ Save info of current keyword as a scalar
+!------ if it is not a continuation
+        targetlist(nb_lines) = key_str(1:MIN(len_trim(key_str),30))
+        last_key = key_str(1:MIN(len_trim(key_str),30))
+        nb_lastkey = 1
+      ELSE
+!------ We are continuing a vector so the keyword needs
+!------ to get the underscores
+        WRITE(cnt,'(I3.3)') nb_lastkey+1
+        targetlist(nb_lines) = &
+ &        key_str(1:MIN(len_trim(key_str),25))//'__'//cnt
+        last_key = key_str(1:MIN(len_trim(key_str),25))//'__'//cnt
+        nb_lastkey = nb_lastkey+1
+      ENDIF
+!-----
+      CALL gensig (targetlist(nb_lines),targetsiglist(nb_lines))
+      fichier(nb_lines) = NEW_str(1:len_str)
+      fromfile(nb_lines) = current
+    ELSE
+!-
+!---- If there are blanks whithin the line then we are dealing
+!---- with a vector and we need to split it in many entries
+!---- with the TRAGET__1 notation.
+!----
+!---- Test if the targer is not already a vector target !
+!-
+      IF (INDEX(TRIM(key_str),'__') > 0) THEN
+        WRITE(*,*) 'ERROR : getin_decrypt'
+        WRITE(*,*) 'We have found a mixed vector notation'
+        WRITE(*,*) 'If a target is of the type TARGET__1'
+        WRITE(*,*) 'then only a scalar value is allowed'
+        WRITE(*,*) 'The key at fault : ',key_str(1:len_TRIM(key_str))
+        STOP 'getin_decrypt'
+      ENDIF
+!-
+      nbve = nb_lastkey
+      nbve = nbve+1
+      WRITE(cnt,'(I3.3)') nbve
+!-
+      DO WHILE (blk > 0)
+!-
+!------ Save the content of target__nbve
+!-
+        fichier(nb_lines) = tmp_str(1:blk)
+        new_key =  key_str(1:MIN(len_trim(key_str),25))//'__'//cnt
+        targetlist(nb_lines) = new_key(1:MIN(len_trim(new_key),30))
+        CALL gensig (targetlist(nb_lines),targetsiglist(nb_lines))
+        fromfile(nb_lines) = current
+!-
+        tmp_str = TRIM(ADJUSTL(tmp_str(blk+1:LEN_TRIM(tmp_str))))
+        blk = INDEX(TRIM(tmp_str),' ')
+!-
+        nb_lines = nb_lines+1
+        IF (nb_lines > max_lines) THEN
+          WRITE(*,*) &
+ &          'Too many line in the run.def files. You need to increase'
+          WRITE(*,*) 'the parameter max_lines in the module getincom.'
+          STOP 'getin_decrypt'
+        ENDIF
+        nbve = nbve+1
+        WRITE(cnt,'(I3.3)') nbve
+!-
+      ENDDO
+!-
+!---- Save the content of the last target
+!-
+      fichier(nb_lines) = tmp_str(1:LEN_TRIM(tmp_str))
+      new_key = key_str(1:MIN(len_trim(key_str),25))//'__'//cnt
+      targetlist(nb_lines) = new_key(1:MIN(len_trim(new_key),30))
+      CALL gensig (targetlist(nb_lines),targetsiglist(nb_lines))
+      fromfile(nb_lines) = current
+!-
+      last_key = key_str(1:MIN(len_trim(key_str),25))//'__'//cnt
+      nb_lastkey = nbve
+!-
+    ENDIF
+!-
+  ENDIF
+!---------------------------
+END SUBROUTINE getin_decrypt
+!-
+!===
+!-
+SUBROUTINE getin_checkcohe ()
+!---------------------------------------------------------------------
+!- This subroutine checks for redundancies.
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+! Arguments
+!-
+!-
+! LOCAL
+!-
+  INTEGER :: line,i,sig
+  INTEGER :: found
+  CHARACTER(LEN=30) :: str
+!---------------------------------------------------------------------
+  DO line=1,nb_lines-1
+!-
+    CALL find_sig &
+ &    (nb_lines-line,targetlist(line+1:nb_lines),targetlist(line), &
+ &     targetsiglist(line+1:nb_lines),targetsiglist(line),found)
+!---
+!-- IF we have found it we have a problem to solve.
+!---
+    IF (found > 0) THEN
+      WRITE(*,*) 'COUNT : ', &
+ &  COUNT(ABS(targetsiglist(line+1:nb_lines)-targetsiglist(line)) < 1)
+!-----
+      WRITE(*,*) &
+ & 'getin_checkcohe : Found a problem on key ',targetlist(line)
+      WRITE(*,*) &
+ & 'getin_checkcohe : The following values were encoutered :'
+      WRITE(*,*) &
+ & '                ',TRIM(targetlist(line)), &
+ &               targetsiglist(line),' == ',fichier(line)
+      WRITE(*,*) &
+ & '                ',TRIM(targetlist(line+found)), &
+ &               targetsiglist(line+found),' == ',fichier(line+found)
+      WRITE(*,*) &
+ & 'getin_checkcohe : We will keep only the last value'
+!-----
+      targetsiglist(line) = 1
+    ENDIF
+  ENDDO
+!-
+END SUBROUTINE getin_checkcohe
+!-
+!===
+!-
+SUBROUTINE getin_skipafew (unit,out_string,eof,nb_lastkey)
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: unit, eof, nb_lastkey
+  CHARACTER(LEN=100) :: dummy
+  CHARACTER(LEN=100) :: out_string
+  CHARACTER(LEN=1) :: first
+!---------------------------------------------------------------------
+  first="#"
+  eof = 0
+  out_string = "    "
+!-
+  DO WHILE (first == "#")
+    READ (unit,'(a100)',ERR=9998,END=7778) dummy
+    dummy = TRIM(ADJUSTL(dummy))
+    first=dummy(1:1)
+    IF (first == "#") THEN
+      nb_lastkey = 0
+    ENDIF
+  ENDDO
+  out_string=dummy
+!-
+  RETURN
+!-
+9998 WRITE(*,*) " GETIN_SKIPAFEW : Error while reading file "
+  STOP 'getin_skipafew'
+!-
+7778 eof = 1
+!----------------------------
+END SUBROUTINE getin_skipafew
+!-
+!=== INTEGER database INTERFACE
+!-
+SUBROUTINE getdbwi &
+ &  (target,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Write the INTEGER data into the data base
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: target
+  INTEGER :: target_sig, status, fileorig, size_of_in
+  INTEGER,DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+!-
+! First check if we have sufficiant space for the new key
+!-
+  IF (nb_keys+1 > keymemsize) THEN
+    CALL getin_allockeys ()
+  ENDIF
+!-
+! Fill out the items of the data base
+!-
+  nb_keys = nb_keys+1
+  keysig(nb_keys) = target_sig
+  keystr(nb_keys) = target(1:MIN(len_trim(target),30))
+  keystatus(nb_keys) = status
+  keytype(nb_keys) = 1
+  keyfromfile(nb_keys) = fileorig
+!-
+! Can we compress the data base entry ?
+!-
+  IF (     (MINVAL(tmp_ret_val) == MAXVAL(tmp_ret_val)) &
+ &    .AND.(size_of_in > compress_lim)) THEN
+    keymemstart(nb_keys) = intmempos+1
+    keycompress(nb_keys) = size_of_in
+    keymemlen(nb_keys) = 1
+  ELSE
+    keymemstart(nb_keys) = intmempos+1
+    keycompress(nb_keys) = -1
+    keymemlen(nb_keys) = size_of_in
+  ENDIF
+!-
+! Before writing the actual size lets see if we have the space
+!-
+  IF (keymemstart(nb_keys)+keymemlen(nb_keys) > intmemsize) THEN
+    CALL getin_allocmem (1,keymemlen(nb_keys))
+  ENDIF
+!-
+  intmem(keymemstart(nb_keys): &
+ &       keymemstart(nb_keys)+keymemlen(nb_keys)-1) = &
+ &  tmp_ret_val(1:keymemlen(nb_keys))
+  intmempos = keymemstart(nb_keys)+keymemlen(nb_keys)-1
+!---------------------
+END SUBROUTINE getdbwi
+!-
+!===
+!-
+SUBROUTINE getdbri (pos,size_of_in,target,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Read the required variables in the database for INTEGERS
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: pos, size_of_in
+  CHARACTER(LEN=*) :: target
+  INTEGER,DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+  IF (keytype(pos) /= 1) THEN
+    WRITE(*,*) 'FATAL ERROR : Wrong data type for keyword ',target
+    STOP 'getdbri'
+  ENDIF
+!-
+  IF (keycompress(pos) > 0) THEN
+    IF ( keycompress(pos) /= size_of_in .OR. keymemlen(pos) /= 1 ) THEN
+      WRITE(*,*) &
+ &      'FATAL ERROR : Wrong compression length for keyword ',target
+      STOP 'getdbri'
+    ELSE
+      tmp_ret_val(1:size_of_in) = intmem(keymemstart(pos))
+    ENDIF
+  ELSE
+    IF (keymemlen(pos) /= size_of_in) THEN
+      WRITE(*,*) 'FATAL ERROR : Wrong array length for keyword ',target
+      STOP 'getdbri'
+    ELSE
+      tmp_ret_val(1:size_of_in) = &
+ &      intmem(keymemstart(pos):keymemstart(pos)+keymemlen(pos)-1)
+    ENDIF
+  ENDIF
+!---------------------
+END SUBROUTINE getdbri
+!-
+!=== REAL database INTERFACE
+!-
+SUBROUTINE getdbwr &
+ &  (target,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Write the REAL data into the data base
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: target
+  INTEGER :: target_sig, status, fileorig, size_of_in
+  REAL,DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+!-
+! First check if we have sufficiant space for the new key
+!-
+  IF (nb_keys+1 > keymemsize) THEN
+    CALL getin_allockeys ()
+  ENDIF
+!-
+! Fill out the items of the data base
+!-
+  nb_keys = nb_keys+1
+  keysig(nb_keys) = target_sig
+  keystr(nb_keys) = target(1:MIN(len_trim(target),30))
+  keystatus(nb_keys) = status
+  keytype(nb_keys) = 2
+  keyfromfile(nb_keys) = fileorig
+!-
+! Can we compress the data base entry ?
+!-
+  IF (     (MINVAL(tmp_ret_val) == MAXVAL(tmp_ret_val)) &
+&     .AND.(size_of_in > compress_lim)) THEN
+    keymemstart(nb_keys) = realmempos+1
+    keycompress(nb_keys) = size_of_in
+    keymemlen(nb_keys) = 1
+  ELSE
+    keymemstart(nb_keys) = realmempos+1
+    keycompress(nb_keys) = -1
+    keymemlen(nb_keys) = size_of_in
+  ENDIF
+!-
+! Before writing the actual size lets see if we have the space
+!-
+  IF (keymemstart(nb_keys)+keymemlen(nb_keys) > realmemsize) THEN
+    CALL getin_allocmem (2,keymemlen(nb_keys))
+  ENDIF
+!-
+  realmem(keymemstart(nb_keys): &
+ &        keymemstart(nb_keys)+keymemlen(nb_keys)-1) = &
+ &  tmp_ret_val(1:keymemlen(nb_keys))
+  realmempos = keymemstart(nb_keys)+keymemlen(nb_keys)-1
+!---------------------
+END SUBROUTINE getdbwr
+!-
+!===
+!-
+SUBROUTINE getdbrr (pos,size_of_in,target,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Read the required variables in the database for REALS
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: pos, size_of_in
+  CHARACTER(LEN=*) :: target
+  REAL,DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+  IF (keytype(pos) /= 2) THEN
+    WRITE(*,*) 'FATAL ERROR : Wrong data type for keyword ',target
+    STOP 'getdbrr'
+  ENDIF
+!-
+  IF (keycompress(pos) > 0) THEN
+    IF (    (keycompress(pos) /= size_of_in) &
+ &      .OR.(keymemlen(pos) /= 1) ) THEN
+      WRITE(*,*) &
+ &      'FATAL ERROR : Wrong compression length for keyword ',target
+      STOP 'getdbrr'
+    ELSE
+      tmp_ret_val(1:size_of_in) = realmem(keymemstart(pos))
+    ENDIF
+  ELSE
+    IF (keymemlen(pos) /= size_of_in) THEN
+      WRITE(*,*) 'FATAL ERROR : Wrong array length for keyword ',target
+      STOP 'getdbrr'
+    ELSE
+      tmp_ret_val(1:size_of_in) = &
+ &      realmem(keymemstart(pos):keymemstart(pos)+keymemlen(pos)-1)
+    ENDIF
+  ENDIF
+!---------------------
+END SUBROUTINE getdbrr
+!-
+!=== CHARACTER database INTERFACE
+!-
+SUBROUTINE getdbwc &
+ &  (target,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Write the CHARACTER data into the data base
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: target
+  INTEGER :: target_sig,status,fileorig,size_of_in
+  CHARACTER(LEN=*),DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+!-
+! First check if we have sufficiant space for the new key
+!-
+  IF (nb_keys+1 > keymemsize) THEN
+    CALL getin_allockeys ()
+  ENDIF
+!-
+! Fill out the items of the data base
+!-
+  nb_keys = nb_keys+1
+  keysig(nb_keys) = target_sig
+  keystr(nb_keys) = target(1:MIN(len_trim(target),30))
+  keystatus(nb_keys) = status
+  keytype(nb_keys) = 3
+  keyfromfile(nb_keys) = fileorig
+  keymemstart(nb_keys) = charmempos+1
+  keymemlen(nb_keys) = size_of_in
+!-
+! Before writing the actual size lets see if we have the space
+!-
+  IF (keymemstart(nb_keys)+keymemlen(nb_keys) > realmemsize) THEN
+    CALL getin_allocmem (3,keymemlen(nb_keys))
+  ENDIF
+!-
+  charmem(keymemstart(nb_keys): &
+ &        keymemstart(nb_keys)+keymemlen(nb_keys)-1) = &
+ &  tmp_ret_val(1:keymemlen(nb_keys))
+  charmempos = keymemstart(nb_keys)+keymemlen(nb_keys)-1
+!---------------------
+END SUBROUTINE getdbwc
+!-
+!===
+!-
+SUBROUTINE getdbrc(pos,size_of_in,target,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Read the required variables in the database for CHARACTER
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: pos, size_of_in
+  CHARACTER(LEN=*) :: target
+  CHARACTER(LEN=*),DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+  IF (keytype(pos) /= 3) THEN
+    WRITE(*,*) 'FATAL ERROR : Wrong data type for keyword ',target
+    STOP 'getdbrc'
+  ENDIF
+!-
+  IF (keymemlen(pos) /= size_of_in) THEN
+    WRITE(*,*) 'FATAL ERROR : Wrong array length for keyword ',target
+    STOP 'getdbrc'
+  ELSE
+    tmp_ret_val(1:size_of_in) = &
+ &    charmem(keymemstart(pos):keymemstart(pos)+keymemlen(pos)-1)
+  ENDIF
+!---------------------
+END SUBROUTINE getdbrc
+!-
+!=== LOGICAL database INTERFACE
+!-
+SUBROUTINE getdbwl &
+ &  (target,target_sig,status,fileorig,size_of_in,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Write the LOGICAL data into the data base
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(LEN=*) :: target
+  INTEGER :: target_sig, status, fileorig, size_of_in
+  LOGICAL,DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+!-
+! First check if we have sufficiant space for the new key
+!-
+  IF (nb_keys+1 > keymemsize) THEN
+    CALL getin_allockeys ()
+  ENDIF
+!-
+! Fill out the items of the data base
+!-
+  nb_keys = nb_keys+1
+  keysig(nb_keys) = target_sig
+  keystr(nb_keys) = target(1:MIN(len_trim(target),30))
+  keystatus(nb_keys) = status
+  keytype(nb_keys) = 4
+  keyfromfile(nb_keys) = fileorig
+  keymemstart(nb_keys) = logicmempos+1
+  keymemlen(nb_keys) = size_of_in
+!-
+! Before writing the actual size lets see if we have the space
+!-
+  IF (keymemstart(nb_keys)+keymemlen(nb_keys) > logicmemsize) THEN
+    CALL getin_allocmem (4,keymemlen(nb_keys))
+  ENDIF
+!-
+  logicmem(keymemstart(nb_keys): &
+ &         keymemstart(nb_keys)+keymemlen(nb_keys)-1) = &
+ &  tmp_ret_val(1:keymemlen(nb_keys))
+  logicmempos = keymemstart(nb_keys)+keymemlen(nb_keys)-1
+!---------------------
+END SUBROUTINE getdbwl
+!-
+!===
+!-
+SUBROUTINE getdbrl(pos,size_of_in,target,tmp_ret_val)
+!---------------------------------------------------------------------
+!- Read the required variables in the database for LOGICALS
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: pos, size_of_in
+  CHARACTER(LEN=*) :: target
+  LOGICAL,DIMENSION(:) :: tmp_ret_val
+!---------------------------------------------------------------------
+  IF (keytype(pos) /= 4) THEN
+    WRITE(*,*) 'FATAL ERROR : Wrong data type for keyword ',target
+    STOP 'getdbrl'
+  ENDIF
+!-
+  IF (keymemlen(pos) /= size_of_in) THEN
+    WRITE(*,*) 'FATAL ERROR : Wrong array length for keyword ',target
+    STOP 'getdbrl'
+  ELSE
+    tmp_ret_val(1:size_of_in) = &
+ &    logicmem(keymemstart(pos):keymemstart(pos)+keymemlen(pos)-1)
+  ENDIF
+!---------------------
+END SUBROUTINE getdbrl
+!-
+!===
+!-
+SUBROUTINE getin_allockeys ()
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER,ALLOCATABLE :: tmp_int(:)
+  CHARACTER(LEN=100),ALLOCATABLE :: tmp_str(:)
+!-
+  INTEGER :: ier
+!---------------------------------------------------------------------
+!-
+! Either nothing exists in these arrays and it is easy to do
+!-
+  IF (keymemsize == 0) THEN
+!-
+    ALLOCATE(keysig(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keysig to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keystr(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keystr to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keystatus(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keystatus to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keytype(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keytype to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keycompress(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keycompress to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keyfromfile(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keyfromfile to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keymemstart(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keymemstart to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    ALLOCATE(keymemlen(memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keymemlen to size ', &
+ &      memslabs
+      STOP
+    ENDIF
+!-
+    nb_keys = 0
+    keymemsize = memslabs
+    keycompress(:) = -1
+!-
+  ELSE
+!-
+!-- There is something already in the memory,
+!-- we need to transfer and reallocate.
+!-
+    ALLOCATE(tmp_str(keymemsize),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate tmp_str to size ', &
+ &      keymemsize
+      STOP
+    ENDIF
+!-
+    ALLOCATE(tmp_int(keymemsize),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate tmp_int to size ', &
+ &      keymemsize
+      STOP
+    ENDIF
+!-
+    tmp_int(1:keymemsize) = keysig(1:keymemsize)
+    DEALLOCATE(keysig)
+    ALLOCATE(keysig(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keysig to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keysig(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    tmp_str(1:keymemsize) = keystr(1:keymemsize)
+    DEALLOCATE(keystr)
+    ALLOCATE(keystr(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keystr to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keystr(1:keymemsize) = tmp_str(1:keymemsize)
+!-
+    tmp_int(1:keymemsize) = keystatus(1:keymemsize)
+    DEALLOCATE(keystatus)
+    ALLOCATE(keystatus(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keystatus to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keystatus(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    tmp_int(1:keymemsize) = keytype(1:keymemsize)
+    DEALLOCATE(keytype)
+    ALLOCATE(keytype(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keytype to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keytype(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    tmp_int(1:keymemsize) = keycompress(1:keymemsize)
+    DEALLOCATE(keycompress)
+    ALLOCATE(keycompress(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keycompress to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keycompress(:) = -1
+    keycompress(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    tmp_int(1:keymemsize) = keyfromfile(1:keymemsize)
+    DEALLOCATE(keyfromfile)
+    ALLOCATE(keyfromfile(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keyfromfile to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keyfromfile(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    tmp_int(1:keymemsize) = keymemstart(1:keymemsize)
+    DEALLOCATE(keymemstart)
+    ALLOCATE(keymemstart(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keymemstart to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keymemstart(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    tmp_int(1:keymemsize) = keymemlen(1:keymemsize)
+    DEALLOCATE(keymemlen)
+    ALLOCATE(keymemlen(keymemsize+memslabs),stat=ier)
+    IF (ier /= 0) THEN
+      WRITE(*,*) &
+ &      'getin_allockeys : Can not allocate keymemlen to size ', &
+ &      keymemsize+memslabs
+      STOP
+    ENDIF
+    keymemlen(1:keymemsize) = tmp_int(1:keymemsize)
+!-
+    keymemsize = keymemsize+memslabs
+!-
+    DEALLOCATE(tmp_int)
+    DEALLOCATE(tmp_str)
+  ENDIF
+!-----------------------------
+END SUBROUTINE getin_allockeys
+!-
+!===
+!-
+SUBROUTINE getin_allocmem (type,len_wanted)
+!---------------------------------------------------------------------
+!- Allocate the memory of the data base for all 4 types of memory
+!-
+!- 1 = INTEGER
+!- 2 = REAL
+!- 3 = CHAR
+!- 4 = LOGICAL
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER :: type, len_wanted
+!-
+  INTEGER,ALLOCATABLE :: tmp_int(:)
+  CHARACTER(LEN=100),ALLOCATABLE :: tmp_char(:)
+  REAL,ALLOCATABLE :: tmp_real(:)
+  LOGICAL,ALLOCATABLE :: tmp_logic(:)
+  INTEGER :: ier
+!---------------------------------------------------------------------
+  SELECT CASE (type)
+  CASE(1)
+    IF (intmemsize == 0) THEN
+      ALLOCATE(intmem(memslabs),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate db-memory intmem to ', &
+ &    memslabs
+        STOP
+      ENDIF
+      intmemsize=memslabs
+    ELSE
+      ALLOCATE(tmp_int(intmemsize),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate tmp_int to ', &
+ &    intmemsize
+        STOP
+      ENDIF
+      tmp_int(1:intmemsize) = intmem(1:intmemsize)
+      DEALLOCATE(intmem)
+      ALLOCATE(intmem(intmemsize+MAX(memslabs,len_wanted)),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to re-allocate db-memory intmem to ', &
+ &    intmemsize+MAX(memslabs,len_wanted)
+        STOP
+      ENDIF
+      intmem(1:intmemsize) = tmp_int(1:intmemsize)
+      intmemsize = intmemsize+MAX(memslabs,len_wanted)
+      DEALLOCATE(tmp_int)
+    ENDIF
+  CASE(2)
+    IF (realmemsize == 0) THEN
+      ALLOCATE(realmem(memslabs),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate db-memory realmem to ', &
+ &    memslabs
+        STOP
+      ENDIF
+      realmemsize =  memslabs
+    ELSE
+      ALLOCATE(tmp_real(realmemsize),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate tmp_real to ', &
+ &    realmemsize
+        STOP
+      ENDIF
+      tmp_real(1:realmemsize) = realmem(1:realmemsize)
+      DEALLOCATE(realmem)
+      ALLOCATE(realmem(realmemsize+MAX(memslabs,len_wanted)),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to re-allocate db-memory realmem to ', &
+ &    realmemsize+MAX(memslabs,len_wanted)
+        STOP
+      ENDIF
+      realmem(1:realmemsize) = tmp_real(1:realmemsize)
+      realmemsize = realmemsize+MAX(memslabs,len_wanted)
+      DEALLOCATE(tmp_real)
+    ENDIF
+  CASE(3)
+    IF (charmemsize == 0) THEN
+      ALLOCATE(charmem(memslabs),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate db-memory charmem to ', &
+ &    memslabs
+        STOP
+      ENDIF
+      charmemsize = memslabs
+    ELSE
+      ALLOCATE(tmp_char(charmemsize),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate tmp_char to ', &
+ &    charmemsize
+        STOP
+      ENDIF
+      tmp_char(1:charmemsize) = charmem(1:charmemsize)
+      DEALLOCATE(charmem)
+      ALLOCATE(charmem(charmemsize+MAX(memslabs,len_wanted)),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to re-allocate db-memory charmem to ', &
+ &    charmemsize+MAX(memslabs,len_wanted)
+        STOP
+      ENDIF
+      charmem(1:charmemsize) = tmp_char(1:charmemsize)
+      charmemsize = charmemsize+MAX(memslabs,len_wanted)
+      DEALLOCATE(tmp_char)
+    ENDIF
+  CASE(4)
+    IF (logicmemsize == 0) THEN
+      ALLOCATE(logicmem(memslabs),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate db-memory logicmem to ', &
+ &    memslabs
+        STOP
+      ENDIF
+      logicmemsize = memslabs
+    ELSE
+      ALLOCATE(tmp_logic(logicmemsize),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to allocate tmp_logic to ', &
+ &    logicmemsize
+        STOP
+      ENDIF
+      tmp_logic(1:logicmemsize) = logicmem(1:logicmemsize)
+      DEALLOCATE(logicmem)
+      ALLOCATE(logicmem(logicmemsize+MAX(memslabs,len_wanted)),stat=ier)
+      IF (ier /= 0) THEN
+        WRITE(*,*) &
+ &    'getin_allocmem : Unable to re-allocate db-memory logicmem to ', &
+ &    logicmemsize+MAX(memslabs,len_wanted)
+        STOP
+      ENDIF
+      logicmem(1:logicmemsize) = tmp_logic(1:logicmemsize)
+      logicmemsize = logicmemsize+MAX(memslabs,len_wanted)
+      DEALLOCATE(tmp_logic)
+    ENDIF
+  CASE DEFAULT
+    WRITE(*,*) 'getin_allocmem : Unknown type : ',type
+    STOP
+  END SELECT
+!----------------------------
+END SUBROUTINE getin_allocmem
+!-
+!===
+!-
+SUBROUTINE getin_dump (fileprefix)
+!---------------------------------------------------------------------
+!- This subroutine will dump the content of the database into  file
+!- which has the same format as the run.def. The idea is that the user
+!- can see which parameters were used and re-use the file for another
+!- run.
+!-
+!- The argument file allows the user to change the name of the file
+!- in which the data will be archived
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  CHARACTER(*),OPTIONAL :: fileprefix
+!-
+  CHARACTER(LEN=80) :: usedfileprefix = "used"
+  INTEGER :: ikey,if,iff,iv
+  CHARACTER(LEN=3) :: tmp3
+  CHARACTER(LEN=100) :: tmp_str, used_filename
+  LOGICAL :: check = .FALSE.
+!---------------------------------------------------------------------
+  IF (PRESENT(fileprefix)) THEN
+    usedfileprefix = fileprefix(1:MIN(len_trim(fileprefix),80))
+  ENDIF
+!-
+  DO if=1,nbfiles
+!---
+    used_filename = TRIM(usedfileprefix)//'_'//TRIM(filelist(if))
+    IF (check) THEN
+      WRITE(*,*) &
+ &      'GETIN_DUMP : opens file : ',TRIM(used_filename),' if = ',if
+      WRITE(*,*) 'GETIN_DUMP : NUMBER OF KEYS : ',nb_keys
+    ENDIF
+    OPEN(unit=76,file=used_filename)
+!-
+!-- If this is the first file we need to add the list
+!-- of file which belong to it
+!-
+    IF ( (if == 1) .AND. (nbfiles > 1) ) THEN
+      WRITE(76,*) '# '
+      WRITE(76,*) '# This file is linked to the following files :'
+      WRITE(76,*) '# '
+      DO iff=2,nbfiles
+        WRITE(76,*) 'INCLUDEDEF = ',TRIM(filelist(iff))
+      ENDDO
+      WRITE(76,*) '# '
+    ENDIF
+!---
+    DO ikey=1,nb_keys
+!-
+!---- Is this key form this file ?
+!-
+      IF (keyfromfile(ikey) == if) THEN
+!-
+!---- Write some comments
+!-
+        WRITE(76,*) '#'
+        SELECT CASE (keystatus(ikey))
+        CASE(1)
+          WRITE(76,*) '# Values of ', &
+ &          TRIM(keystr(ikey)),' comes from the run.def.'
+        CASE(2)
+          WRITE(76,*) '# Values of ', &
+ &          TRIM(keystr(ikey)),' are all defaults.'
+        CASE(3)
+          WRITE(76,*) '# Values of ', &
+ &          TRIM(keystr(ikey)),' are a mix of run.def and defaults.'
+        CASE DEFAULT
+          WRITE(76,*) '# Dont know from where the value of ', &
+ &          TRIM(keystr(ikey)),' comes.'
+        END SELECT
+        WRITE(76,*) '#'
+!-
+!---- Write the values
+!-
+        SELECT CASE (keytype(ikey))
+!-
+        CASE(1)
+          IF (keymemlen(ikey) == 1) THEN
+            IF (keycompress(ikey) < 0) THEN
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),' = ',intmem(keymemstart(ikey))
+            ELSE
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),' = ',keycompress(ikey), &
+ &              ' * ',intmem(keymemstart(ikey))
+            ENDIF
+          ELSE
+            DO iv=0,keymemlen(ikey)-1
+              WRITE(tmp3,'(I3.3)') iv+1
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),'__',tmp3, &
+ &              ' = ',intmem(keymemstart(ikey)+iv)
+            ENDDO
+          ENDIF
+!-
+        CASE(2)
+          IF (keymemlen(ikey) == 1) THEN
+            IF (keycompress(ikey) < 0) THEN
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),' = ',realmem(keymemstart(ikey))
+            ELSE
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),' = ',keycompress(ikey),&
+                   & ' * ',realmem(keymemstart(ikey))
+            ENDIF
+          ELSE
+            DO iv=0,keymemlen(ikey)-1
+              WRITE(tmp3,'(I3.3)') iv+1
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),'__',tmp3, &
+ &              ' = ',realmem(keymemstart(ikey)+iv)
+            ENDDO
+          ENDIF
+        CASE(3)
+          IF (keymemlen(ikey) == 1) THEN
+            tmp_str = charmem(keymemstart(ikey))
+            WRITE(76,*) TRIM(keystr(ikey)),' = ',TRIM(tmp_str)
+          ELSE
+            DO iv=0,keymemlen(ikey)-1
+              WRITE(tmp3,'(I3.3)') iv+1
+              tmp_str = charmem(keymemstart(ikey)+iv)
+              WRITE(76,*) &
+ &              TRIM(keystr(ikey)),'__',tmp3,' = ',TRIM(tmp_str)
+            ENDDO
+          ENDIF
+        CASE(4)
+          IF (keymemlen(ikey) == 1) THEN
+            IF (logicmem(keymemstart(ikey))) THEN
+              WRITE(76,*) TRIM(keystr(ikey)),' = TRUE '
+            ELSE
+              WRITE(76,*) TRIM(keystr(ikey)),' = FALSE '
+            ENDIF
+          ELSE
+            DO iv=0,keymemlen(ikey)-1
+              WRITE(tmp3,'(I3.3)') iv+1
+              IF (logicmem(keymemstart(ikey)+iv)) THEN
+                WRITE(76,*) TRIM(keystr(ikey)),'__',tmp3,' = TRUE '
+              ELSE
+                WRITE(76,*) TRIM(keystr(ikey)),'__',tmp3,' = FALSE '
+              ENDIF
+            ENDDO
+          ENDIF
+!-
+        CASE DEFAULT
+          WRITE(*,*) &
+ &          'FATAL ERROR : Unknown type for variable ', &
+ &          TRIM(keystr(ikey))
+          STOP 'getin_dump'
+        END SELECT
+      ENDIF
+    ENDDO
+!-
+    CLOSE(unit=76)
+!-
+  ENDDO
+!------------------------
+END SUBROUTINE getin_dump
+!-
+!===
+!-
+END MODULE ioipsl_getincom
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/ioipsl_stringop.F90
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/ioipsl_stringop.F90	(revision 1140)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/ioipsl_stringop.F90	(revision 1140)
@@ -0,0 +1,256 @@
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Module and routines in this file are taken from IOIPSL
+! files stringop.f90
+! Module names has been changed to avoid problems
+! if compiling model with IOIPSL library
+! Ehouarn - March 2009
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+MODULE ioipsl_stringop
+!---------------------------------------------------------------------
+!-
+  INTEGER, DIMENSION(30) :: &
+       & prime=(/1,2,3,5,7,11,13,17,19,23,29,31,37,41,43, &
+       & 47,53,59,61,67,71,73,79,83,89,97,101,103,107,109/)
+!-
+!---------------------------------------------------------------------
+CONTAINS
+!=
+   SUBROUTINE cmpblank (str)
+!---------------------------------------------------------------------
+!-
+!---------------------------------------------------------------------
+   CHARACTER(LEN=*),INTENT(inout) :: str
+!-
+   INTEGER :: lcc,ipb
+!---------------------------------------------------------------------
+   lcc = LEN_TRIM(str)
+   ipb = 1
+   DO
+     IF (ipb >= lcc)   EXIT
+     IF (str(ipb:ipb+1) == '  ') THEN
+       str(ipb+1:) = str(ipb+2:lcc)
+       lcc = lcc-1
+     ELSE
+       ipb = ipb+1
+     ENDIF
+   ENDDO
+!-------------------------
+   END SUBROUTINE cmpblank
+!=
+   INTEGER FUNCTION cntpos (c_c,l_c,c_r,l_r)
+!---------------------------------------------------------------------
+!- Finds number of occurences of c_r in c_c
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   CHARACTER(LEN=*),INTENT(in) :: c_c
+   INTEGER,INTENT(IN) :: l_c
+   CHARACTER(LEN=*),INTENT(in) :: c_r
+   INTEGER,INTENT(IN) :: l_r
+!-
+   INTEGER :: ipos,indx,ires
+!---------------------------------------------------------------------
+   cntpos = 0
+   ipos   = 1
+   DO
+     indx = INDEX(c_c(ipos:l_c),c_r(1:l_r))
+     IF (indx > 0) THEN
+       cntpos = cntpos+1
+       ipos   = ipos+indx+l_r-1
+     ELSE
+       EXIT
+     ENDIF
+   ENDDO
+!---------------------
+   END FUNCTION cntpos
+!=
+   INTEGER FUNCTION findpos (c_c,l_c,c_r,l_r)
+!---------------------------------------------------------------------
+!- Finds position of c_r in c_c
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   CHARACTER(LEN=*),INTENT(in) :: c_c
+   INTEGER,INTENT(IN) :: l_c
+   CHARACTER(LEN=*),INTENT(in) :: c_r
+   INTEGER,INTENT(IN) :: l_r
+!---------------------------------------------------------------------
+    findpos = INDEX(c_c(1:l_c),c_r(1:l_r))
+    IF (findpos == 0)   findpos=-1
+!----------------------
+   END FUNCTION findpos
+!=
+   SUBROUTINE find_str (nb_str,str_tab,str_len_tab,str,pos)
+!---------------------------------------------------------------------
+!- This subroutine looks for a string in a table
+!---------------------------------------------------------------------
+!- INPUT
+!-   nb_str      : length of table
+!-   str_tab     : Table  of strings
+!-   str_len_tab : Table  of string-length
+!-   str         : Target we are looking for
+!- OUTPUT
+!-   pos         : -1 if str not found, else value in the table
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   INTEGER :: nb_str
+   CHARACTER(LEN=*),DIMENSION(nb_str) :: str_tab
+   INTEGER,DIMENSION(nb_str) :: str_len_tab
+   CHARACTER(LEN=*) :: str
+   INTEGER :: pos
+!-
+   INTEGER :: i,il
+!---------------------------------------------------------------------
+   pos = -1
+   il = LEN_TRIM(str)
+   IF ( nb_str > 0 ) THEN
+      DO i=1,nb_str
+         IF (     (INDEX(str_tab(i),str(1:il)) > 0) &
+              .AND.(str_len_tab(i) == il) ) THEN
+            pos = i
+            EXIT
+         ENDIF
+      ENDDO
+   ENDIF
+!-------------------------
+   END SUBROUTINE find_str
+!=
+   SUBROUTINE nocomma (str)
+!---------------------------------------------------------------------
+!-
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   CHARACTER(LEN=*) :: str
+!-
+   INTEGER :: i
+!---------------------------------------------------------------------
+   DO i=1,LEN_TRIM(str)
+     IF (str(i:i) == ',')   str(i:i) = ' '
+   ENDDO
+!------------------------
+   END SUBROUTINE nocomma
+!=
+   SUBROUTINE strlowercase (str)
+!---------------------------------------------------------------------
+!- Converts a string into lowercase
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   CHARACTER(LEN=*) :: str
+!-
+   INTEGER :: i,ic
+!---------------------------------------------------------------------
+   DO i=1,LEN_TRIM(str)
+     ic = IACHAR(str(i:i))
+     IF ( (ic >= 65) .AND. (ic <= 90) )   str(i:i) = ACHAR(ic+32)
+   ENDDO
+!-----------------------------
+   END SUBROUTINE strlowercase
+!=
+   SUBROUTINE struppercase (str)
+!---------------------------------------------------------------------
+!- Converts a string into uppercase
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   CHARACTER(LEN=*) :: str
+!-
+   INTEGER :: i,ic
+!---------------------------------------------------------------------
+   DO i=1,LEN_TRIM(str)
+     ic = IACHAR(str(i:i))
+     IF ( (ic >= 97) .AND. (ic <= 122) )   str(i:i) = ACHAR(ic-32)
+   ENDDO
+!-----------------------------
+   END SUBROUTINE struppercase
+!=
+!------------------
+   SUBROUTINE gensig (str, sig)
+!---------------------------------------------------------------------
+!- Generate a signature from the first 30 characters of the string
+!- This signature is not unique and thus when one looks for the
+!- one needs to also verify the string.
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   CHARACTER(LEN=*) :: str
+   INTEGER          :: sig
+!-
+   INTEGER :: i
+!---------------------------------------------------------------------
+   sig = 0
+   DO i=1,MIN(len_trim(str),30)
+      sig = sig  + prime(i)*IACHAR(str(i:i))
+   ENDDO
+!-----------------------------
+ END SUBROUTINE gensig
+!=
+!------------------
+   SUBROUTINE find_sig (nb_sig, str_tab, str, sig_tab, sig, pos)
+!---------------------------------------------------------------------
+!- Find the string signature in a list of signatures
+!---------------------------------------------------------------------
+!- INPUT
+!-   nb_sig      : length of table of signatures
+!-   str_tab     : Table of strings
+!-   str         : Target string we are looking for 
+!-   sig_tab     : Table of signatures
+!-   sig         : Target signature we are looking for
+!- OUTPUT
+!-   pos         : -1 if str not found, else value in the table
+!---------------------------------------------------------------------
+   IMPLICIT NONE
+!-
+   INTEGER :: nb_sig
+   CHARACTER(LEN=*),DIMENSION(nb_sig) :: str_tab
+   CHARACTER(LEN=*) :: str
+   INTEGER, DIMENSION(nb_sig) :: sig_tab
+   INTEGER :: sig
+!-
+   INTEGER :: pos
+   INTEGER, DIMENSION(nb_sig) :: loczeros
+!-
+   INTEGER :: il, len
+   INTEGER, DIMENSION(1) :: minpos
+!---------------------------------------------------------------------
+!-
+   pos = -1
+   il = LEN_TRIM(str)
+!-
+   IF ( nb_sig > 0 ) THEN
+      !
+      loczeros = ABS(sig_tab(1:nb_sig)-sig)
+      !
+      IF ( COUNT(loczeros < 1) == 1 ) THEN
+         !
+         minpos = MINLOC(loczeros)
+         len = LEN_TRIM(str_tab(minpos(1)))
+         IF ( (INDEX(str_tab(minpos(1)),str(1:il)) > 0) &
+                 .AND.(len == il) ) THEN
+            pos = minpos(1)
+         ENDIF
+         !
+      ELSE IF ( COUNT(loczeros < 1) > 1 ) THEN
+         !
+         DO WHILE (COUNT(loczeros < 1) >= 1 .AND. pos < 0 )
+            minpos = MINLOC(loczeros)
+            len = LEN_TRIM(str_tab(minpos(1)))
+            IF ( (INDEX(str_tab(minpos(1)),str(1:il)) > 0) &
+                 .AND.(len == il) ) THEN
+               pos = minpos(1)
+            ELSE
+               loczeros(minpos(1)) = 99999
+            ENDIF
+         ENDDO
+         !
+      ENDIF
+      !
+   ENDIF
+!-
+ END SUBROUTINE find_sig
+!=
+!------------------
+END MODULE ioipsl_stringop
Index: /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/leapfrog_p.F
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/leapfrog_p.F	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/libf/dyn3dpar/leapfrog_p.F	(revision 1140)
@@ -4,8 +4,4 @@
 c
 c
-#define IO_DEBUG
-
-#undef CPP_IOIPSL
-#define CPP_IOIPSL
 
       SUBROUTINE leapfrog_p(ucov,vcov,teta,ps,masse,phis,q,clesphy0,
@@ -285,5 +281,5 @@
 c$OMP BARRIER
        else
-          
+! Save fields obtained at previous time step as '...m1'
          ijb=ij_begin
          ije=ij_end
@@ -312,5 +308,5 @@
      .                    llm, -2,2, .TRUE., 1 )
 
-       endif
+       endif ! of if (FirstCaldyn)
        
       forward = .TRUE.
@@ -356,9 +352,9 @@
          IF( MOD(itau,idissip ).EQ.0.AND..NOT.forward ) apdiss = .TRUE.
          IF( MOD(itau,iphysiq ).EQ.0.AND..NOT.forward 
-     s          .and. iflag_phys.NE.0                 ) apphys = .TRUE.
+     s          .and. iflag_phys.EQ.1                 ) apphys = .TRUE.
       ELSE
          IF( MOD(itau   ,iconser) .EQ. 0              ) conser = .TRUE.
          IF( MOD(itau+1,idissip)  .EQ. 0              ) apdiss = .TRUE.
-         IF( MOD(itau+1,iphysiq).EQ.0.AND.iflag_phys.NE.0) apphys=.TRUE.
+         IF( MOD(itau+1,iphysiq).EQ.0.AND.iflag_phys.EQ.1) apphys=.TRUE.
       END IF
 
@@ -537,5 +533,7 @@
 
 c$OMP MASTER
-      IF (prt_level>9)WRITE(lunout,*)"Iteration No",True_itau
+      IF (prt_level>9) THEN
+        WRITE(lunout,*)"leapfrog_p: Iteration No",True_itau
+      ENDIF
 
 
@@ -594,7 +592,7 @@
 
 
-         ENDIF
-c
-      ENDIF
+         ENDIF ! of IF (offline)
+c
+      ENDIF ! of IF( forward. OR . leapf )
 cc$OMP END PARALLEL
 
@@ -673,6 +671,7 @@
 c$OMP MASTER
          call suspend_timer(timer_caldyn)
-         WRITE(lunout,*)'Entree dans la physique : Iteration No ',      &
-     &                   true_itau
+
+         write(lunout,*)
+     &   'leapfrog_p: Entree dans la physique : Iteration No ',true_itau
 c$OMP END MASTER
 
@@ -693,5 +692,4 @@
 c   -----------------------------------------------------
 
-#ifdef CPP_PHYS
 c+jld
 
@@ -699,6 +697,9 @@
       IF (ip_ebil_dyn.ge.1 ) THEN 
           ztit='bil dyn'
-          CALL diagedyn(ztit,2,1,1,dtphys
-     e  , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
+! Ehouarn: be careful, diagedyn is Earth-specific (includes ../phylmd/..)!
+           IF (planet_type.eq."earth") THEN
+            CALL diagedyn(ztit,2,1,1,dtphys
+     &    , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
+           ENDIF
       ENDIF 
 c-jld
@@ -787,5 +788,5 @@
           dpfi_tmp(1:iip1)     = dpfi(ijb:ijb+iim)  
 c$OMP END MASTER
-        endif
+        endif ! of if ( .not. pole_nord)
 
 c$OMP BARRIER
@@ -843,5 +844,5 @@
 c$OMP END MASTER
           
-        endif
+        endif ! of if (.not. pole_nord)
 c$OMP BARRIER
 cc$OMP MASTER        
@@ -932,6 +933,16 @@
 cc$OMP END MASTER
 
-#else
-
+
+c-jld
+c$OMP MASTER
+         call resume_timer(timer_caldyn)
+         if (FirstPhysic) then
+           ok_start_timer=.TRUE.
+           FirstPhysic=.false.
+         endif
+c$OMP END MASTER
+       ENDIF ! of IF( apphys )
+
+      IF(iflag_phys.EQ.2) THEN ! "Newtonian" case
 c   Calcul academique de la physique = Rappel Newtonien + fritcion 
 c   --------------------------------------------------------------
@@ -949,16 +960,6 @@
 
        call friction_p(ucov,vcov,iphysiq*dtvr)
-
-#endif
-
-c-jld
-c$OMP MASTER
-         call resume_timer(timer_caldyn)
-         if (FirstPhysic) then
-           ok_start_timer=.TRUE.
-           FirstPhysic=.false.
-         endif
-c$OMP END MASTER
-       ENDIF
+      ENDIF ! of IF(iflag_phys.EQ.2)
+
 
         CALL pression_p ( ip1jmp1, ap, bp, ps, p                  )
@@ -1312,45 +1313,59 @@
 c      IF( MOD(itau,iecri         ).EQ.0) THEN
 
-           IF( MOD(itau,iecri*day_step).EQ.0) THEN
-c$OMP BARRIER
-c$OMP MASTER
-               nbetat = nbetatdem
-        CALL geopot_p  ( ip1jmp1, teta  , pk , pks,  phis  , phi )
+            IF( MOD(itau,iecri*day_step).EQ.0) THEN
+c$OMP BARRIER
+c$OMP MASTER
+              nbetat = nbetatdem
+              CALL geopot_p(ip1jmp1,teta,pk,pks,phis,phi)
        
 cym        unat=0.
         
-        ijb=ij_begin
-        ije=ij_end
-        
-        if (pole_nord) then
-          ijb=ij_begin+iip1
-          unat(1:iip1,:)=0.
-        endif
-        
-        if (pole_sud) then 
-          ije=ij_end-iip1
-          unat(ij_end-iip1+1:ij_end,:)=0.
-        endif
+              ijb=ij_begin
+              ije=ij_end
+        
+              if (pole_nord) then
+                ijb=ij_begin+iip1
+                unat(1:iip1,:)=0.
+              endif
+        
+              if (pole_sud) then 
+                ije=ij_end-iip1
+                unat(ij_end-iip1+1:ij_end,:)=0.
+              endif
             
-        do l=1,llm
-           unat(ijb:ije,l)=ucov(ijb:ije,l)/cu(ijb:ije)
-        enddo
-
-        ijb=ij_begin
-        ije=ij_end
-        if (pole_sud) ije=ij_end-iip1
-        
-        do l=1,llm
-           vnat(ijb:ije,l)=vcov(ijb:ije,l)/cv(ijb:ije)
-        enddo
+              do l=1,llm
+                unat(ijb:ije,l)=ucov(ijb:ije,l)/cu(ijb:ije)
+              enddo
+
+              ijb=ij_begin
+              ije=ij_end
+              if (pole_sud) ije=ij_end-iip1
+        
+              do l=1,llm
+                vnat(ijb:ije,l)=vcov(ijb:ije,l)/cv(ijb:ije)
+              enddo
         
 #ifdef CPP_IOIPSL
  
-        CALL writehist_p(histid,histvid, itau,vcov, 
-     s                       ucov,teta,phi,q,masse,ps,phis)
+              CALL writehist_p(histid,histvid, itau,vcov, 
+     &                         ucov,teta,phi,q,masse,ps,phis)
 
 #endif
-c$OMP END MASTER
-           ENDIF
+! For some Grads outputs of fields
+              if (output_grads_dyn) then
+! Ehouarn: hope this works the way I think it does:
+                  call Gather_Field(unat,ip1jmp1,llm,0)
+                  call Gather_Field(vnat,ip1jm,llm,0)
+                  call Gather_Field(teta,ip1jmp1,llm,0)
+                  call Gather_Field(ps,ip1jmp1,1,0)
+                  do iq=1,nqtot
+                    call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
+                  enddo
+                  if (mpi_rank==0) then
+#include "write_grads_dyn.h"
+                  endif
+              endif ! of if (output_grads_dyn)
+c$OMP END MASTER
+            ENDIF ! of IF(MOD(itau,iecri).EQ.0)
 
             IF(itau.EQ.itaufin) THEN
@@ -1359,13 +1374,16 @@
 c$OMP MASTER
 
-c#ifdef CPP_IOIPSL
-
-       CALL dynredem1_p("restart.nc",0.0,
-     ,                     vcov,ucov,teta,q,masse,ps)
-c#endif
+              if (planet_type.eq."earth") then
+#ifdef CPP_EARTH
+! Write an Earth-format restart file
+                CALL dynredem1_p("restart.nc",0.0,
+     &                           vcov,ucov,teta,q,masse,ps)
+
+#endif
+              endif ! of if (planet_type.eq."earth")
 
               CLOSE(99)
 c$OMP END MASTER
-            ENDIF
+            ENDIF ! of IF (itau.EQ.itaufin)
 
 c-----------------------------------------------------------------------
@@ -1398,7 +1416,9 @@
                  dt  = 2.*dtvr
                  GO TO 2
-            END IF
-
-      ELSE
+            END IF ! of IF (MOD(itau,iperiod).EQ.0)
+                   !    ELSEIF (MOD(itau-1,iperiod).EQ.0)
+
+
+      ELSE ! of IF (.not.purmats)
 
 c       ........................................................
@@ -1427,7 +1447,7 @@
                GO TO 2
 
-            ELSE
-
-            IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
+            ELSE ! of IF(forward)
+
+              IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
                IF(itau.EQ.itaufin) THEN
                   iav=1
@@ -1438,12 +1458,12 @@
 c$OMP BARRIER
 
-              call Register_Hallo(vcov,ip1jm,llm,1,0,0,1,TestRequest)
-              call SendRequest(TestRequest)
-c$OMP BARRIER
-              call WaitRequest(TestRequest)
-
-c$OMP BARRIER
-c$OMP MASTER
-              CALL writedynav_p(histaveid, itau,vcov ,
+               call Register_Hallo(vcov,ip1jm,llm,1,0,0,1,TestRequest)
+               call SendRequest(TestRequest)
+c$OMP BARRIER
+               call WaitRequest(TestRequest)
+
+c$OMP BARRIER
+c$OMP MASTER
+               CALL writedynav_p(histaveid, itau,vcov ,
      ,                          ucov,teta,pk,phi,q,masse,ps,phis)
                call bilan_dyn_p (2,dtvr*iperiod,dtvr*day_step*periodav,
@@ -1451,5 +1471,6 @@
 c$OMP END MASTER
 #endif
-            ENDIF
+              ENDIF ! of IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin)
+
 
 c               IF(MOD(itau,iecri         ).EQ.0) THEN
@@ -1457,69 +1478,76 @@
 c$OMP BARRIER
 c$OMP MASTER
-                  nbetat = nbetatdem
-       CALL geopot_p( ip1jmp1, teta  , pk , pks,  phis  , phi   )
+                nbetat = nbetatdem
+                CALL geopot_p(ip1jmp1,teta,pk,pks,phis,phi)
 
 cym        unat=0.
-        ijb=ij_begin
-        ije=ij_end
-        
-        if (pole_nord) then
-          ijb=ij_begin+iip1
-          unat(1:iip1,:)=0.
-        endif
-        
-        if (pole_sud) then 
-          ije=ij_end-iip1
-          unat(ij_end-iip1+1:ij_end,:)=0.
-        endif
+                ijb=ij_begin
+                ije=ij_end
+        
+                if (pole_nord) then
+                  ijb=ij_begin+iip1
+                  unat(1:iip1,:)=0.
+                endif
+        
+                if (pole_sud) then 
+                  ije=ij_end-iip1
+                  unat(ij_end-iip1+1:ij_end,:)=0.
+                endif
             
-        do l=1,llm
-           unat(ijb:ije,l)=ucov(ijb:ije,l)/cu(ijb:ije)
-        enddo
-
-        ijb=ij_begin
-        ije=ij_end
-        if (pole_sud) ije=ij_end-iip1
-        
-        do l=1,llm
-           vnat(ijb:ije,l)=vcov(ijb:ije,l)/cv(ijb:ije)
-        enddo
+                do l=1,llm
+                  unat(ijb:ije,l)=ucov(ijb:ije,l)/cu(ijb:ije)
+                enddo
+
+                ijb=ij_begin
+                ije=ij_end
+                if (pole_sud) ije=ij_end-iip1
+        
+                do l=1,llm
+                  vnat(ijb:ije,l)=vcov(ijb:ije,l)/cv(ijb:ije)
+                enddo
 
 #ifdef CPP_IOIPSL
 
-       CALL writehist_p( histid, histvid, itau,vcov , 
-     ,                           ucov,teta,phi,q,masse,ps,phis)
-c#else
-c      call Gather_Field(unat,ip1jmp1,llm,0)
-c      call Gather_Field(vnat,ip1jm,llm,0)
-c      call Gather_Field(teta,ip1jmp1,llm,0)
-c      call Gather_Field(ps,ip1jmp1,1,0)
-c      do iq=1,nqtot
-c        call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
-c      enddo
+                CALL writehist_p(histid, histvid, itau,vcov , 
+     &                           ucov,teta,phi,q,masse,ps,phis)
+#endif
+! For some Grads output (but does it work?)
+                if (output_grads_dyn) then
+                  call Gather_Field(unat,ip1jmp1,llm,0)
+                  call Gather_Field(vnat,ip1jm,llm,0)
+                  call Gather_Field(teta,ip1jmp1,llm,0)
+                  call Gather_Field(ps,ip1jmp1,1,0)
+                  do iq=1,nqtot
+                    call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
+                  enddo
 c      
-c      if (mpi_rank==0) then
-c#include "write_grads_dyn.h"
-c      endif
-#endif
-
-c$OMP END MASTER
-               ENDIF
-
-                 IF(itau.EQ.itaufin) THEN
+                  if (mpi_rank==0) then
+#include "write_grads_dyn.h"
+                  endif
+                endif ! of if (output_grads_dyn)
+
+c$OMP END MASTER
+              ENDIF ! of IF(MOD(itau,iecri*day_step).EQ.0)
+
+              IF(itau.EQ.itaufin) THEN
+                if (planet_type.eq."earth") then
+#ifdef CPP_EARTH
 c$OMP MASTER
                    CALL dynredem1_p("restart.nc",0.0,
      .                               vcov,ucov,teta,q,masse,ps)
 c$OMP END MASTER
-                 ENDIF
-                 forward = .TRUE.
-                 GO TO  1
-
-            ENDIF
-
-      END IF
-c$OMP MASTER
-        call finalize_parallel
-c$OMP END MASTER
-        RETURN
+#endif
+                endif ! of if (planet_type.eq."earth")
+              ENDIF ! of IF(itau.EQ.itaufin)
+
+              forward = .TRUE.
+              GO TO  1
+
+            ENDIF ! of IF (forward)
+
+      END IF ! of IF(.not.purmats)
+c$OMP MASTER
+      call finalize_parallel
+c$OMP END MASTER
+      RETURN
       END
Index: /LMDZ4/branches/LMDZ4-dev/makegcm
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/makegcm	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/makegcm	(revision 1140)
@@ -206,5 +206,9 @@
    set optim90="-Wp'-P' -DCRAY -p$IOIPSLDIR "'-p$(LIBO) -eiv '
    set optim="$optim90"
-   set oplink="-Wl'-DSTACK=128 -f indef' -L$IOIPSLDIR -lioipsl  -L$NCDFLIB -lnetcdf "
+   if ( $io == "ioipsl" ) then
+     set oplink="-Wl'-DSTACK=128 -f indef' -L$IOIPSLDIR -lioipsl  -L$NCDFLIB -lnetcdf "
+   else
+     set oplink="-Wl'-DSTACK=128 -f indef' -L$IOIPSLDIR -L$NCDFLIB -lnetcdf "
+   endif
    set mod_loc_dir=" "
    set mod_suffix=" "
@@ -216,5 +220,9 @@
    set optim90=" -fast -fixed "
    set optimtru90=" -fast -free "
-   set opt_link="-lf77compat -L$MODIPSLDIR -lsechiba -lparameters -lstomate -lioipsl -L$NCDFLIB -lnetcdf "
+   if ( $io == "ioipsl" ) then
+     set opt_link="-lf77compat -L$MODIPSLDIR -lsechiba -lparameters -lstomate -lioipsl -L$NCDFLIB -lnetcdf "
+   else
+     set opt_link="-lf77compat -L$MODIPSLDIR -lsechiba -lparameters -lstomate -L$NCDFLIB -lnetcdf "
+   endif
    set mod_loc_dir=$localdir
    set mod_suffix=mod
@@ -270,5 +278,9 @@
    set optim="$optim90"
    set optimbis=" "
-   set opt_link=" -C hopt -float0 -ew -P static -L$MODIPSLDIR -lioipsl  $NCDFLIB -lnetcdf_i8r8_v "
+   if ( $io == "ioipsl" ) then
+     set opt_link=" -C hopt -float0 -ew -P static -L$MODIPSLDIR -lioipsl  $NCDFLIB -lnetcdf_i8r8_v "
+   else
+     set opt_link=" -C hopt -float0 -ew -P static -L$MODIPSLDIR $NCDFLIB -lnetcdf_i8r8_v "
+   endif
    set mod_loc_dir="."
    set mod_suffix="mod"
@@ -533,5 +545,6 @@
    set phys="L_PHY= LIBPHY="
 else
-   set cppflags="$cppflags -DCPP_PHYS"
+   #Default planet type is Earth
+   set cppflags="$cppflags -DCPP_EARTH"
 endif
 
@@ -685,17 +698,17 @@
 ######################################################################
 
-if ( -f $libf/phy$physique/raddim.h ) then
- if ( -f $libf/phy$physique/raddim.$dimh.h ) then
-  \rm -f $libf/phy$physique/raddim.h
-  cp -p $libf/phy$physique/raddim.$dimh.h $libf/phy$physique/raddim.h
-  echo $libf/phy$physique/raddim.$dimh.h 
-  cat $libf/phy$physique/raddim.$dimh.h 
-  cat $libf/phy$physique/raddim.h
- else
-  echo On peut diminuer la taille de l executable en creant
-  echo le fichier $libf/phy$physique/raddim.$dimh.h
-  \cp -p $libf/phy$physique/raddim.defaut.h $libf/phy$physique/raddim.h
- endif
-endif
+#if ( -f $libf/phy$physique/raddim.h ) then
+# if ( -f $libf/phy$physique/raddim.$dimh.h ) then
+#  \rm -f $libf/phy$physique/raddim.h
+#  cp -p $libf/phy$physique/raddim.$dimh.h $libf/phy$physique/raddim.h
+#  echo $libf/phy$physique/raddim.$dimh.h 
+#  cat $libf/phy$physique/raddim.$dimh.h 
+#  cat $libf/phy$physique/raddim.h
+# else
+#  echo On peut diminuer la taille de l executable en creant
+#  echo le fichier $libf/phy$physique/raddim.$dimh.h
+#  \cp -p $libf/phy$physique/raddim.defaut.h $libf/phy$physique/raddim.h
+# endif
+#endif
 
 ######################################################################
@@ -793,7 +806,15 @@
    set f90=$FC_LINUX
    if ( $FC_LINUX == 'pgf90' ) then
-   set opt_link=" -L$MODIPSLDIR $link_veget -L$NCDFLIB -lioipsl -lnetcdf "
+     if ( $io == "ioipsl" ) then
+       set opt_link=" -L$MODIPSLDIR $link_veget -L$NCDFLIB -lioipsl -lnetcdf "
+     else
+       set opt_link=" -L$MODIPSLDIR $link_veget -L$NCDFLIB -lnetcdf "
+     endif
    else if ($FC_LINUX == 'g95') then
-     set opt_link="-L$MODIPSLDIR $link_veget -lioipsl -L$NCDFLIB -lnetcdf -lioipsl -lnetcdf "
+     if ( $io == "ioipsl" ) then
+       set opt_link="-L$MODIPSLDIR $link_veget -lioipsl -L$NCDFLIB -lnetcdf -lioipsl -lnetcdf "
+     else
+       set opt_link="-L$MODIPSLDIR $link_veget -lioipsl -L$NCDFLIB -lnetcdf -lnetcdf "
+     endif
    else
      set opt_link=" "
@@ -804,5 +825,9 @@
    set f77=f90
    set f90=f90
-   set opt_link="-lf77compat -L$MODIPSLDIR $link_veget -lioipsl -L$NCDFLIB -lnetcdf "
+   if ( $io == "ioipsl" ) then
+     set opt_link="-lf77compat -L$MODIPSLDIR $link_veget -lioipsl -L$NCDFLIB -lnetcdf "
+   else
+     set opt_link="-lf77compat -L$MODIPSLDIR $link_veget -L$NCDFLIB -lnetcdf "
+   endif
 #################
 else if $NEC then
Index: /LMDZ4/branches/LMDZ4-dev/makelmdz_fcm
===================================================================
--- /LMDZ4/branches/LMDZ4-dev/makelmdz_fcm	(revision 1139)
+++ /LMDZ4/branches/LMDZ4-dev/makelmdz_fcm	(revision 1140)
@@ -3,11 +3,11 @@
 # $Header$
 #
-# FH : on ne cr�e plus le fichier arch.mk qui est suppos� exister par
+# FH : on ne crée plus le fichier arch.mk qui est supposé exister par
 # FH : ailleurs.
-# FH : ult�rieurement, ce fichier sera pr�-existant pour une s�rie
-# FH : de configurations en versions optimis�es et debug qui seront
-# FH : li�s (ln -s) avec arch.mk en fonction de l'architecture.
-# FH : Pour le moment, cette version est en test et on peut cr�er les
-# FH : arch.mk en lan�ant une premi�re fois makegcm7.
+# FH : ulterieurement, ce fichier sera pré-existant pour une série
+# FH : de configurations en versions optimisées et debug qui seront
+# FH : liés (ln -s) avec arch.mk en fonction de l'architecture.
+# FH : Pour le moment, cette version est en test et on peut créer les
+# FH : arch.mk en lançant une première fois makegcm.
 #
 set verbose echo
@@ -58,10 +58,10 @@
 Usage :
 makegcm [options] -m arch exec
-[-h]                       : manuel abrégé
+[-h]                       : manuel abrÃ©gÃ©
 [-d [[IMx]JMx]LM]          : IM, JM, LM sont les dims en x, y, z (def: $dim)
 [-p PHYS]                  : compilation avec la physique libf/phyPHYS, (def: lmd)
 [-prod / -dev / -debug]    : compilation en mode production (default) / developpement / debug .
-[-c false/MPI1/MPI2]       : couplé océan : MPI1/MPI2/false (def: false)
-[-v false/true]            : avec ou sans végétation (def: false)
+[-c false/MPI1/MPI2]       : couplÃ© ocÃ©an : MPI1/MPI2/false (def: false)
+[-v false/true]            : avec ou sans vÃ©gÃ©tation (def: false)
 [-chimie INCA/false]       : avec ou sans model de chimie INCA (def: false)
 [-parallel none/mpi/omp/mpi_omp] : parallelisation (default: none) : mpi, openmp ou mixte mpi_openmp
@@ -75,5 +75,5 @@
 [-fcm_path path]           : chemin pour fcm (def: le chemin est suppose deja exister dans le PATH)
  -arch nom_arch            : nom de l'architecture cible
- exec                      : exécutable généré
+ exec                      : exÃ©cutable gÃ©nÃ©rÃ©
 fin
 	exit
@@ -157,5 +157,5 @@
 
 ###############################################################
-# lecture des chemins propres a l'architecture de la machine #
+# lecture des chemins propres à l'architecture de la machine #
 ###############################################################
 
@@ -180,5 +180,6 @@
    
 else
-   set CPP_KEY="$CPP_KEY CPP_PHYS"
+   #Default planet type is Earth
+   set CPP_KEY="$CPP_KEY CPP_EARTH"
 endif
 
