Index: LMDZ6/branches/LMDZ-tracers/libf/dyn3d/dynetat0.F90
===================================================================
--- LMDZ6/branches/LMDZ-tracers/libf/dyn3d/dynetat0.F90	(revision 3957)
+++ LMDZ6/branches/LMDZ-tracers/libf/dyn3d/dynetat0.F90	(revision 3957)
@@ -0,0 +1,217 @@
+SUBROUTINE dynetat0(fichnom,vcov,ucov,teta,q,masse,ps,phis,time)
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , L.Fairhead
+!-------------------------------------------------------------------------------
+! Purpose: Initial state reading.
+!-------------------------------------------------------------------------------
+  USE readTracFiles_mod, ONLY: known_phases, old_phases, nphases, phases_sep
+  USE infotrac,    ONLY: nqtot, niso, tracers, iTraPha, tnat, alpha_ideal, tra
+  USE netcdf,      ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_INQ_VARID, NF90_NoErr, &
+                         NF90_CLOSE, NF90_GET_VAR
+  USE strings_mod, ONLY: strIdx
+  USE control_mod, ONLY: planet_type
+  USE assert_eq_m, ONLY: assert_eq
+  USE comvert_mod, ONLY: pa,preff
+  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, im, jm, kappa, lllm, omeg, rad
+  USE logic_mod, ONLY: fxyhypb, ysinus
+  USE serre_mod, ONLY: clon, clat, grossismx, grossismy
+  USE temps_mod, ONLY: annee_ref, day_ini, day_ref, itau_dyn, start_time
+  USE ener_mod,  ONLY: etot0, ptot0, ztot0, stot0, ang0
+
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom2.h"
+  include "description.h"
+  include "iniprint.h"
+!===============================================================================
+! Arguments:
+  CHARACTER(LEN=*), INTENT(IN) :: fichnom          !--- FILE NAME
+  REAL, INTENT(OUT) ::  vcov(iip1,jjm, llm)        !--- V COVARIANT WIND
+  REAL, INTENT(OUT) ::  ucov(iip1,jjp1,llm)        !--- U COVARIANT WIND
+  REAL, INTENT(OUT) ::  teta(iip1,jjp1,llm)        !--- POTENTIAL TEMP.
+  REAL, INTENT(OUT) ::     q(iip1,jjp1,llm,nqtot)  !--- TRACERS
+  REAL, INTENT(OUT) :: masse(iip1,jjp1,llm)        !--- MASS PER CELL
+  REAL, INTENT(OUT) ::    ps(iip1,jjp1)            !--- GROUND PRESSURE
+  REAL, INTENT(OUT) ::  phis(iip1,jjp1)            !--- GEOPOTENTIAL
+!===============================================================================
+! Local variables:
+  CHARACTER(LEN=256) :: sdum, var, modname, oldH2O
+  INTEGER, PARAMETER :: length=100
+  INTEGER :: iq, fID, vID, idecal, ix, ip
+  REAL    :: time, tab_cntrl(length)               !--- RUN PARAMS TABLE
+  TYPE(tra), POINTER :: tr
+!-------------------------------------------------------------------------------
+  modname="dynetat0"
+
+!--- Initial state file opening
+  var=fichnom
+  CALL err(NF90_OPEN(var,NF90_NOWRITE,fID),"open",var)
+  CALL get_var1("controle",tab_cntrl)
+
+!!! AS: idecal is a hack to be able to read planeto starts...
+!!!     .... while keeping everything OK for LMDZ EARTH
+  IF(planet_type=="generic") THEN
+    WRITE(lunout,*)'NOTE NOTE NOTE : Planeto-like start files'
+    idecal = 4
+    annee_ref  = 2000
+  ELSE
+    WRITE(lunout,*)'NOTE NOTE NOTE : Earth-like start files'
+    idecal = 5
+    annee_ref  = tab_cntrl(5)
+  END IF
+  im         = tab_cntrl(1)
+  jm         = tab_cntrl(2)
+  lllm       = tab_cntrl(3)
+  day_ref    = tab_cntrl(4)
+  rad        = tab_cntrl(idecal+1)
+  omeg       = tab_cntrl(idecal+2)
+  g          = tab_cntrl(idecal+3)
+  cpp        = tab_cntrl(idecal+4)
+  kappa      = tab_cntrl(idecal+5)
+  daysec     = tab_cntrl(idecal+6)
+  dtvr       = tab_cntrl(idecal+7)
+  etot0      = tab_cntrl(idecal+8)
+  ptot0      = tab_cntrl(idecal+9)
+  ztot0      = tab_cntrl(idecal+10)
+  stot0      = tab_cntrl(idecal+11)
+  ang0       = tab_cntrl(idecal+12)
+  pa         = tab_cntrl(idecal+13)
+  preff      = tab_cntrl(idecal+14)
+!
+  clon       = tab_cntrl(idecal+15)
+  clat       = tab_cntrl(idecal+16)
+  grossismx  = tab_cntrl(idecal+17)
+  grossismy  = tab_cntrl(idecal+18)
+!
+  IF ( tab_cntrl(idecal+19)==1. )  THEN
+    fxyhypb  = .TRUE.
+!   dzoomx   = tab_cntrl(25)
+!   dzoomy   = tab_cntrl(26)
+!   taux     = tab_cntrl(28)
+!   tauy     = tab_cntrl(29)
+  ELSE
+    fxyhypb = .FALSE.
+    ysinus  = tab_cntrl(idecal+22)==1.
+  END IF
+
+  day_ini    = tab_cntrl(30)
+  itau_dyn   = tab_cntrl(31)
+  start_time = tab_cntrl(32)
+
+!-------------------------------------------------------------------------------
+  WRITE(lunout,*)TRIM(modname)//': rad,omeg,g,cpp,kappa',rad,omeg,g,cpp,kappa
+  CALL check_dim(im,iim,'im','im')
+  CALL check_dim(jm,jjm,'jm','jm')
+  CALL check_dim(lllm,llm,'lm','lllm')
+  CALL get_var1("rlonu", rlonu)
+  CALL get_var1("rlatu", rlatu)
+  CALL get_var1("rlonv", rlonv)
+  CALL get_var1("rlatv", rlatv)
+  CALL get_var2("cu",       cu)
+  CALL get_var2("cv",       cv)
+  CALL get_var2("aire",   aire)
+  var="temps"
+  IF(NF90_INQ_VARID(fID,var,vID)/=NF90_NoErr) THEN
+    WRITE(lunout,*)TRIM(modname)//": missing field <temps>"
+    WRITE(lunout,*)TRIM(modname)//": trying with <Time>"; var="Time"
+    CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
+  END IF
+  CALL err(NF90_GET_VAR(fID,vID,time),"get",var)
+  CALL get_var2("phisinit", phis)
+  CALL get_var3("ucov",     ucov)
+  CALL get_var3("vcov",     vcov)
+  CALL get_var3("teta",     teta)
+  CALL get_var3("masse",   masse)
+  CALL get_var2("ps",         ps)
+
+!--- Tracers
+  DO iq=1,nqtot
+    tr => tracers(iq)
+    var = tr%name
+    ix = strIdx([('H2O'//phases_sep//known_phases(ip:ip), ip=1, nphases)], var)
+    IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr) THEN
+      CALL get_var3(var, q(:,:,:,iq))
+#ifdef INCA
+    ELSE IF(NF90_INQ_VARID(fID, 'OX', vID) == NF90_NoErr .AND. var == 'O3') THEN
+      WRITE(lunout,*)TRIM(modname)//': Tracer <O3> is missing => initialized to OX'
+      CALL get_var3('OX', q(:,:,:,iq))
+#endif
+    ELSE IF(ix /= 0) THEN              !--- Old file, water: H2Ov/l/i instead of H2O_g/_l/_s
+      oldH2O = 'H2O'//old_phases(ix:ix)
+      IF(NF90_INQ_VARID(fID, oldH2O, vID) == NF90_NoErr) THEN
+        WRITE(lunout,*)TRIM(modname)//': Tracer <'//TRIM(var)//'> is missing => initialized to '//TRIM(oldH2O)
+        CALL get_var3(oldH2O, q(:,:,:,iq))
+      END IF
+    ELSE
+      WRITE(lunout,*)TRIM(modname)//': Tracer <'//TRIM(var)//'> is missing => initialized to zero'
+      q(:,:,:,iq)=0.
+      !--- CRisi: for isotopes, theoretical initialization using very simplified Rayleigh distillation law
+      IF(niso > 0 .AND. tr%iso_num > 0) THEN
+        IF(tr%iso_zon == 0) q(:,:,:,iq) = q(:,:,:,tr%iprnt)         *        tnat(tr%iso_num)  &
+                                        *(q(:,:,:,tr%iprnt)/30.e-3)**(alpha_ideal(tr%iso_num)-1)
+        IF(tr%iso_zon == 1) q(:,:,:,iq) = q(:,:,:,iTraPha(tr%iso_num,tr%iso_pha))
+      END IF
+    END IF
+  END DO
+  CALL err(NF90_CLOSE(fID),"close",fichnom)
+  day_ini=day_ini+INT(time)
+  time=time-INT(time)
+
+
+  CONTAINS
+
+
+SUBROUTINE check_dim(n1,n2,str1,str2)
+  INTEGER,          INTENT(IN) :: n1, n2
+  CHARACTER(LEN=*), INTENT(IN) :: str1, str2
+  CHARACTER(LEN=256) :: s1, s2
+  IF(n1/=n2) THEN
+    s1='value of '//TRIM(str1)//' ='
+    s2=' read in starting file differs from parametrized '//TRIM(str2)//' ='
+    WRITE(sdum,'(10x,a,i4,2x,a,i4)'),TRIM(s1),n1,TRIM(s2),n2
+    CALL ABORT_gcm(TRIM(modname),TRIM(sdum),1)
+  END IF
+END SUBROUTINE check_dim
+
+
+SUBROUTINE get_var1(var, v)
+  CHARACTER(LEN=*), INTENT(IN)  :: var
+  REAL,             INTENT(OUT) :: v(:)
+  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
+  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
+END SUBROUTINE get_var1
+
+
+SUBROUTINE get_var2(var, v)
+  CHARACTER(LEN=*), INTENT(IN)  :: var
+  REAL,             INTENT(OUT) :: v(:,:)
+  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
+  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
+END SUBROUTINE get_var2
+
+
+SUBROUTINE get_var3(var, v)
+  CHARACTER(LEN=*), INTENT(IN)  :: var
+  REAL,             INTENT(OUT) :: v(:,:,:)
+  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
+  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
+END SUBROUTINE get_var3
+
+
+SUBROUTINE err(ierr, typ, nam)
+  INTEGER,          INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
+  CHARACTER(LEN=*), INTENT(IN) :: typ    !--- TYPE OF OPERATION
+  CHARACTER(LEN=*), INTENT(IN) :: nam    !--- FIELD/FILE NAME
+  IF(ierr==NF90_NoERR) RETURN
+  SELECT CASE(typ)
+    CASE('inq');   sdum="Field <"//TRIM(nam)//"> is missing"
+    CASE('get');   sdum="Reading failed for <"//TRIM(nam)//">"
+    CASE('open');  sdum="File opening failed for <"//TRIM(nam)//">"
+    CASE('close'); sdum="File closing failed for <"//TRIM(nam)//">"
+  END SELECT
+  CALL ABORT_gcm(TRIM(modname),TRIM(sdum),ierr)
+END SUBROUTINE err
+
+END SUBROUTINE dynetat0
Index: LMDZ6/branches/LMDZ-tracers/libf/dyn3d/dynetat0.f90
===================================================================
--- LMDZ6/branches/LMDZ-tracers/libf/dyn3d/dynetat0.f90	(revision 3931)
+++ 	(revision )
@@ -1,222 +1,0 @@
-SUBROUTINE dynetat0(fichnom,vcov,ucov,teta,q,masse,ps,phis,time)
-!
-!-------------------------------------------------------------------------------
-! Authors: P. Le Van , L.Fairhead
-!-------------------------------------------------------------------------------
-! Purpose: Initial state reading.
-!-------------------------------------------------------------------------------
-  USE infotrac,    ONLY: nqtot, niso, tracers, iTraPha, tnat, alpha_ideal, tra
-  USE netcdf,      ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_INQ_VARID, NF90_NoErr, &
-                         NF90_CLOSE, NF90_GET_VAR
-  USE strings_mod, ONLY: strIdx
-  USE control_mod, ONLY: planet_type
-  USE assert_eq_m, ONLY: assert_eq
-  USE comvert_mod, ONLY: pa,preff
-  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, im, jm, kappa, lllm, omeg, rad
-  USE logic_mod, ONLY: fxyhypb, ysinus
-  USE serre_mod, ONLY: clon, clat, grossismx, grossismy
-  USE temps_mod, ONLY: annee_ref, day_ini, day_ref, itau_dyn, start_time
-  USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
-
-  IMPLICIT NONE
-  include "dimensions.h"
-  include "paramet.h"
-  include "comgeom2.h"
-  include "description.h"
-  include "iniprint.h"
-!===============================================================================
-! Arguments:
-  CHARACTER(LEN=*), INTENT(IN) :: fichnom          !--- FILE NAME
-  REAL, INTENT(OUT) ::  vcov(iip1,jjm, llm)        !--- V COVARIANT WIND
-  REAL, INTENT(OUT) ::  ucov(iip1,jjp1,llm)        !--- U COVARIANT WIND
-  REAL, INTENT(OUT) ::  teta(iip1,jjp1,llm)        !--- POTENTIAL TEMP.
-  REAL, INTENT(OUT) ::     q(iip1,jjp1,llm,nqtot)  !--- TRACERS
-  REAL, INTENT(OUT) :: masse(iip1,jjp1,llm)        !--- MASS PER CELL
-  REAL, INTENT(OUT) ::    ps(iip1,jjp1)            !--- GROUND PRESSURE
-  REAL, INTENT(OUT) ::  phis(iip1,jjp1)            !--- GEOPOTENTIAL
-!===============================================================================
-! Local variables:
-  CHARACTER(LEN=256) :: sdum, var, modname, oldH2O(3), newH2O(3)
-  INTEGER, PARAMETER :: length=100
-  INTEGER :: iq, fID, vID, idecal, ix!, iml, jml, lml, nqt
-  REAL    :: time, tab_cntrl(length)               !--- RUN PARAMS TABLE
- TYPE(tra), POINTER :: tr
-!-------------------------------------------------------------------------------
-  modname="dynetat0"
-  oldH2O=['H2Ov ','H2Ol ','H2Oi ']
-  newH2O=['H2O-g','H2O-l','H2O-s']
-
-!--- Initial state file opening
-  var=fichnom
-  CALL err(NF90_OPEN(var,NF90_NOWRITE,fID),"open",var)
-  CALL get_var1("controle",tab_cntrl)
-
-!!! AS: idecal is a hack to be able to read planeto starts...
-!!!     .... while keeping everything OK for LMDZ EARTH
-  IF(planet_type=="generic") THEN
-    WRITE(lunout,*)'NOTE NOTE NOTE : Planeto-like start files'
-    idecal = 4
-    annee_ref  = 2000
-  ELSE
-    WRITE(lunout,*)'NOTE NOTE NOTE : Earth-like start files'
-    idecal = 5
-    annee_ref  = tab_cntrl(5)
-  END IF
-  im         = tab_cntrl(1)
-  jm         = tab_cntrl(2)
-  lllm       = tab_cntrl(3)
-  day_ref    = tab_cntrl(4)
-  rad        = tab_cntrl(idecal+1)
-  omeg       = tab_cntrl(idecal+2)
-  g          = tab_cntrl(idecal+3)
-  cpp        = tab_cntrl(idecal+4)
-  kappa      = tab_cntrl(idecal+5)
-  daysec     = tab_cntrl(idecal+6)
-  dtvr       = tab_cntrl(idecal+7)
-  etot0      = tab_cntrl(idecal+8)
-  ptot0      = tab_cntrl(idecal+9)
-  ztot0      = tab_cntrl(idecal+10)
-  stot0      = tab_cntrl(idecal+11)
-  ang0       = tab_cntrl(idecal+12)
-  pa         = tab_cntrl(idecal+13)
-  preff      = tab_cntrl(idecal+14)
-!
-  clon       = tab_cntrl(idecal+15)
-  clat       = tab_cntrl(idecal+16)
-  grossismx  = tab_cntrl(idecal+17)
-  grossismy  = tab_cntrl(idecal+18)
-!
-  IF ( tab_cntrl(idecal+19)==1. )  THEN
-    fxyhypb  = .TRUE.
-!   dzoomx   = tab_cntrl(25)
-!   dzoomy   = tab_cntrl(26)
-!   taux     = tab_cntrl(28)
-!   tauy     = tab_cntrl(29)
-  ELSE
-    fxyhypb = .FALSE.
-    ysinus  = tab_cntrl(idecal+22)==1.
-  END IF
-
-  day_ini    = tab_cntrl(30)
-  itau_dyn   = tab_cntrl(31)
-  start_time = tab_cntrl(32)
-
-!-------------------------------------------------------------------------------
-  WRITE(lunout,*)TRIM(modname)//': rad,omeg,g,cpp,kappa',rad,omeg,g,cpp,kappa
-  CALL check_dim(im,iim,'im','im')
-  CALL check_dim(jm,jjm,'jm','jm')
-  CALL check_dim(lllm,llm,'lm','lllm')
-  CALL get_var1("rlonu",rlonu)
-  CALL get_var1("rlatu",rlatu)
-  CALL get_var1("rlonv",rlonv)
-  CALL get_var1("rlatv",rlatv)
-  CALL get_var2("cu"   ,cu)
-  CALL get_var2("cv"   ,cv)
-  CALL get_var2("aire" ,aire)
-  var="temps"
-  IF(NF90_INQ_VARID(fID,var,vID)/=NF90_NoErr) THEN
-    WRITE(lunout,*)TRIM(modname)//": missing field <temps>"
-    WRITE(lunout,*)TRIM(modname)//": trying with <Time>"; var="Time"
-    CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
-  END IF
-  CALL err(NF90_GET_VAR(fID,vID,time),"get",var)
-  CALL get_var2("phisinit",phis)
-  CALL get_var3("ucov",ucov)
-  CALL get_var3("vcov",vcov)
-  CALL get_var3("teta",teta)
-  CALL get_var3("masse",masse)
-  CALL get_var2("ps",ps)
-
-!--- Tracers
-  DO iq=1,nqtot
-    tr => tracers(iq)
-    var = tr%name
-    IF(NF90_INQ_VARID(fID,var,vID)==NF90_NoErr) THEN
-      CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",var); CYCLE
-#ifdef INCA
-    ELSE IF(var == "O3") THEN          !--- INCA and O3 missing: take OX instead
-      WRITE(lunout,*) 'Tracer O3 is missing - it is initialized to OX'
-        IF(NF90_INQ_VARID(fID,"OX",vID) == NF90_NoErr) THEN
-           CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",var); CYCLE
-        END IF
-#endif
-    ELSE                               !--- Old file, water: H2Ov/l/i instead of H2O-g/-l/-s
-      ix = strIdx(newH2O, var)         !--- Current tracer is water (new name) ?
-      IF(ix /= 0) THEN                 !--- Then read the field, using the old name.
-        IF(NF90_INQ_VARID(fID,oldH2O(ix),vID) == NF90_NoErr) THEN
-           CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",var); CYCLE
-        END IF
-      END IF
-    END IF
-    WRITE(lunout,*)TRIM(modname)//": Tracer <"//TRIM(var)//"> is missing"
-    WRITE(lunout,*)"         It is hence initialized to zero"
-    q(:,:,:,iq)=0.
-    !--- CRisi: for isotops, theoretical initialization using very simplified
-    !           Rayleigh distillation las.
-    IF(niso > 0 .AND. tr%iso_num > 0) THEN
-      IF(tr%iso_zon == 0) q(:,:,:,iq) = q(:,:,:,tr%iprnt)         *        tnat(tr%iso_num)  &
-                                      *(q(:,:,:,tr%iprnt)/30.e-3)**(alpha_ideal(tr%iso_num)-1)
-      IF(tr%iso_zon == 1) q(:,:,:,iq) = q(:,:,:,iTraPha(tr%iso_num,tr%iso_pha))
-    END IF
-  END DO
-
-  CALL err(NF90_CLOSE(fID),"close",fichnom)
-  day_ini=day_ini+INT(time)
-  time=time-INT(time)
-
-
-  CONTAINS
-
-
-SUBROUTINE check_dim(n1,n2,str1,str2)
-  INTEGER,          INTENT(IN) :: n1, n2
-  CHARACTER(LEN=*), INTENT(IN) :: str1, str2
-  CHARACTER(LEN=256) :: s1, s2
-  IF(n1/=n2) THEN
-    s1='value of '//TRIM(str1)//' ='
-    s2=' read in starting file differs from parametrized '//TRIM(str2)//' ='
-    WRITE(sdum,'(10x,a,i4,2x,a,i4)'),TRIM(ADJUSTL(s1)),n1,TRIM(ADJUSTL(s2)),n2
-    CALL ABORT_gcm(TRIM(modname),TRIM(sdum),1)
-  END IF
-END SUBROUTINE check_dim
-
-
-SUBROUTINE get_var1(var,v)
-  CHARACTER(LEN=*), INTENT(IN)  :: var
-  REAL,             INTENT(OUT) :: v(:)
-  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
-  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
-END SUBROUTINE get_var1
-
-
-SUBROUTINE get_var2(var,v)
-  CHARACTER(LEN=*), INTENT(IN)  :: var
-  REAL,             INTENT(OUT) :: v(:,:)
-  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
-  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
-END SUBROUTINE get_var2
-
-
-SUBROUTINE get_var3(var,v)
-  CHARACTER(LEN=*), INTENT(IN)  :: var
-  REAL,             INTENT(OUT) :: v(:,:,:)
-  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
-  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
-END SUBROUTINE get_var3
-
-
-SUBROUTINE err(ierr,typ,nam)
-  INTEGER,          INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
-  CHARACTER(LEN=*), INTENT(IN) :: typ    !--- TYPE OF OPERATION
-  CHARACTER(LEN=*), INTENT(IN) :: nam    !--- FIELD/FILE NAME
-  IF(ierr==NF90_NoERR) RETURN
-  SELECT CASE(typ)
-    CASE('inq');   sdum="Field <"//TRIM(nam)//"> is missing"
-    CASE('get');   sdum="Reading failed for <"//TRIM(nam)//">"
-    CASE('open');  sdum="File opening failed for <"//TRIM(nam)//">"
-    CASE('close'); sdum="File closing failed for <"//TRIM(nam)//">"
-  END SELECT
-  CALL ABORT_gcm(TRIM(modname),TRIM(sdum),ierr)
-END SUBROUTINE err
-
-END SUBROUTINE dynetat0
Index: LMDZ6/branches/LMDZ-tracers/libf/dyn3d_common/infotrac.F90
===================================================================
--- LMDZ6/branches/LMDZ-tracers/libf/dyn3d_common/infotrac.F90	(revision 3931)
+++ LMDZ6/branches/LMDZ-tracers/libf/dyn3d_common/infotrac.F90	(revision 3957)
@@ -1,8 +1,8 @@
 MODULE infotrac
 
-  USE       strings_mod, ONLY: msg, find, strIdx,  strFind,  strHead, dispTable, testFile, cat, get_in,  &
+  USE       strings_mod, ONLY: msg, find, strIdx,  strFind,  strHead, dispTable, testFile, cat, get_in,   &
                               fmsg, test, int2str, strParse, strTail, strReduce, strStack, modname
-  USE readTracFiles_mod, ONLY: readTracersFiles, getKey_init, nphases, delPhase, aliasTracer, &
-                        tran0, readIsotopesFile, getKey, known_phases, addPhase, indexUpdate, initIsotopes
+  USE readTracFiles_mod, ONLY: readTracersFiles, getKey_init, nphases, delPhase, old_phases, aliasTracer, &
+            phases_sep, tran0, readIsotopesFile, getKey, known_phases, addPhase, indexUpdate, initIsotopes
   USE trac_types_mod,    ONLY: tra, iso, kys
 
@@ -45,5 +45,5 @@
 !  |--------------------+----------------------+-----------------+---------------+----------------------------|
 !  | water in different |    water tagging     |  water isotopes | other tracers | additional tracers moments |
-!  | phases: H2O-[gls]  |      isotopes        |                 |               |  for higher order schemes  |
+!  | phases: H2O_[gls]  |      isotopes        |                 |               |  for higher order schemes  |
 !  |--------------------+----------------------+-----------------+---------------+----------------------------|
 !  |                    |                      |                 |               |                            |
@@ -184,5 +184,5 @@
   CHARACTER(LEN=2)   ::   suff(9)                                    !--- Suffixes for schemes of order 3 or 4 (Prather)
   CHARACTER(LEN=3)   :: descrq(30)                                   !--- Advection scheme description tags
-  CHARACTER(LEN=4)   :: oldH2O(3)                                    !--- Old water name for the three phases
+  CHARACTER(LEN=256) :: oldH2O(3)                                    !--- Old water name for the three phases
   CHARACTER(LEN=256) :: newH2O                                       !--- New water name
   CHARACTER(LEN=256) :: msg1, msg2                                   !--- Strings for messages
@@ -283,9 +283,9 @@
       IF(planet_type=='earth') THEN                                  !--- Default for Earth
         nqo = 2; nbtr = 2
-        tracers(:)%name = ['H2O-g','H2O-l','RN   ','PB   ']
-        tracers(:)%prnt = [tran0  ,tran0  ,tran0  ,tran0  ]
-        tracers(:)%igen = [1      ,1      ,1      ,1      ]
-        hadv            = [14     ,10     ,10     ,10     ]
-        vadv            = [14     ,10     ,10     ,10     ]
+        tracers(:)%name = ['H2O'//phases_sep//'g', 'H2O'//phases_sep//'l', 'RN   ', 'PB   ']
+        tracers(:)%prnt = [tran0, tran0, tran0, tran0]
+        tracers(:)%igen = [1    , 1    , 1    , 1    ]
+        hadv            = [14   , 10   , 10   , 10   ]
+        vadv            = [14   , 10   , 10   , 10   ]
       ELSE                                                           !--- Default for other planets
         nqo = 0; nbtr = 1
@@ -329,6 +329,7 @@
         DO ip = 1, SIZE(oldH2O)
           ix = strIdx(tracers(:)%name,oldH2O(ip))                    !--- Old name of water in a specific phase (ix/=0)
+          newH2O = 'H2O'//phases_sep//known_phases(ip:ip)            !--- Corresponding new name
+          IF(ix == 0) ix = strIdx(tracers(:)%name,newH2O)            !--- New name in an old format file (to be avoided...)
           IF(ix == 0) CYCLE
-          newH2O = 'H2O-'//known_phases(ip:ip)                       !--- Corresponding new name
           nqo = nqo+1; tracers(ix)%name = newH2O                     !--- One more water phase ; replace old name with one
           tracers(strFind(tracers(:)%nam1,oldH2O(ip)))%nam1 = newH2O
@@ -341,5 +342,5 @@
     CASE DEFAULT                                                     !=== FOUND NEW STYLE TRACERS CONFIG FILE(S)
     !--------------------------------------------------------------------------------------------------------------------------
-      nqo    = 2; IF(ANY(tracers(:)%name == 'H2O-s')) nqo=3
+      nqo    = 2; IF(ANY(tracers(:)%name == 'H2O'//phases_sep//'s')) nqo=3
       nqtrue = SIZE(tracers, DIM=1)
       nbtr   = nqtrue - nqo
@@ -353,4 +354,6 @@
   IF(.NOT.ALLOCATED(conv_flg)) conv_flg = [(1, it=1, nbtr)]
   IF(.NOT.ALLOCATED( pbl_flg))  pbl_flg = [(1, it=1, nbtr)]
+!print*,'nqo, nbtr = ',nqo,nbtr
+!stop
 
 #ifdef CPP_StratAer
@@ -466,5 +469,5 @@
 
     !--- iadv = 14 IS ONLY VALID FOR WATER VAPOUR
-    IF(fmsg(iad==14 .AND. t1%name(1:5)/='H2O-g', 'WARNING ! '//TRIM(msg1)//', found for "' &
+    IF(fmsg(iad==14 .AND. t1%name(1:5)/='H2O'//phases_sep//'g', 'WARNING ! '//TRIM(msg1)//', found for "' &
                  //TRIM(t1%name)//'" but only valid for water vapour ! Setting iadv=10 for "'//TRIM(t1%name)//'".')) t1%iadv=10
   END DO
Index: LMDZ6/branches/LMDZ-tracers/libf/dyn3dmem/dynetat0_loc.F90
===================================================================
--- LMDZ6/branches/LMDZ-tracers/libf/dyn3dmem/dynetat0_loc.F90	(revision 3931)
+++ LMDZ6/branches/LMDZ-tracers/libf/dyn3dmem/dynetat0_loc.F90	(revision 3957)
@@ -7,18 +7,18 @@
 !-------------------------------------------------------------------------------
   USE parallel_lmdz
-  USE infotrac, ONLY: nqtot, niso, tracers, iTraPha, tnat, alpha_ideal, tra
-  USE netcdf, ONLY: NF90_OPEN,  NF90_INQUIRE_DIMENSION, NF90_INQ_VARID,        &
-      NF90_NOWRITE, NF90_CLOSE, NF90_INQUIRE_VARIABLE,  NF90_GET_VAR, NF90_NoErr
+  USE readTracFiles_mod, ONLY: known_phases, old_phases, nphases, phases_sep
+  USE infotrac,    ONLY: nqtot, niso, tracers, iTraPha, tnat, alpha_ideal, tra
+  USE netcdf,      ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_INQ_VARID, NF90_INQUIRE_DIMENSION, &
+           NF90_INQUIRE, NF90_CLOSE, NF90_GET_VAR, NF90_NoErr,     NF90_INQUIRE_VARIABLE
+  USE strings_mod, ONLY: strIdx
   USE control_mod, ONLY: planet_type
   USE assert_eq_m, ONLY: assert_eq
   USE comvert_mod, ONLY: pa,preff
-  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, im, jm, kappa, lllm, &
-                          omeg, rad
+  USE comconst_mod, ONLY: cpp, daysec, dtvr, g, im, jm, kappa, lllm, omeg, rad
   USE logic_mod, ONLY: fxyhypb, ysinus
   USE serre_mod, ONLY: clon, clat, grossismx, grossismy
-  USE temps_mod, ONLY: annee_ref,day_ref,itau_dyn, &
-                       start_time,day_ini,hour_ini
-  USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
-  
+  USE temps_mod, ONLY: annee_ref, day_ini, day_ref, itau_dyn, start_time
+  USE ener_mod,  ONLY: etot0, ptot0, ztot0, stot0, ang0
+
   IMPLICIT NONE
   include "dimensions.h"
@@ -39,11 +39,8 @@
 !===============================================================================
 ! Local variables:
-  CHARACTER(LEN=256) :: sdum, var, modname
+  CHARACTER(LEN=256) :: sdum, var, modname, oldH2O
   INTEGER, PARAMETER :: length=100
-  INTEGER :: iq, fID, vID, idecal, ierr
+  INTEGER :: iq, fID, vID, idecal, ix, ip, ierr
   REAL    :: time, tab_cntrl(length)               !--- RUN PARAMS TABLE
-  REAL,             ALLOCATABLE :: vcov_glo(:,:),masse_glo(:,:),   ps_glo(:)
-  REAL,             ALLOCATABLE :: ucov_glo(:,:),    q_glo(:,:), phis_glo(:)
-  REAL,             ALLOCATABLE :: teta_glo(:,:)
   TYPE(tra), POINTER :: tr
 !-------------------------------------------------------------------------------
@@ -110,11 +107,11 @@
   CALL check_dim(jm,jjm,'jm','jm')
   CALL check_dim(lllm,llm,'lm','lllm')
-  CALL get_var1("rlonu",rlonu)
-  CALL get_var1("rlatu",rlatu)
-  CALL get_var1("rlonv",rlonv)
-  CALL get_var1("rlatv",rlatv)
-  CALL get_var1("cu"  ,cu)
-  CALL get_var1("cv"  ,cv)
-  CALL get_var1("aire",aire)
+  CALL get_var1("rlonu", rlonu)
+  CALL get_var1("rlatu", rlatu)
+  CALL get_var1("rlonv", rlonv)
+  CALL get_var1("rlatv", rlatv)
+  CALL get_var1("cu",       cu)
+  CALL get_var1("cv",       cv)
+  CALL get_var1("aire",   aire)
 
   var="temps"
@@ -125,54 +122,40 @@
   END IF
   CALL err(NF90_GET_VAR(fID,vID,time),"get",var)
-
-  ALLOCATE(phis_glo(ip1jmp1))
-  CALL get_var1("phisinit",phis_glo)
-  phis (ijb_u:ije_u)  =phis_glo(ijb_u:ije_u);    DEALLOCATE(phis_glo)
-
-  ALLOCATE(ucov_glo(ip1jmp1,llm))
-  CALL get_var2("ucov",ucov_glo)
-  ucov (ijb_u:ije_u,:)=ucov_glo(ijb_u:ije_u,:);  DEALLOCATE(ucov_glo)
-
-  ALLOCATE(vcov_glo(ip1jm,llm))
-  CALL get_var2("vcov",vcov_glo)
-  vcov (ijb_v:ije_v,:)=vcov_glo(ijb_v:ije_v,:);  DEALLOCATE(vcov_glo)
-
-  ALLOCATE(teta_glo(ip1jmp1,llm))
-  CALL get_var2("teta",teta_glo)
-  teta (ijb_u:ije_u,:)=teta_glo(ijb_u:ije_u,:);  DEALLOCATE(teta_glo)
-
-  ALLOCATE(masse_glo(ip1jmp1,llm))
-  CALL get_var2("masse",masse_glo)
-  masse(ijb_u:ije_u,:)=masse_glo(ijb_u:ije_u,:); DEALLOCATE(masse_glo)
-  
-  ALLOCATE(ps_glo(ip1jmp1))
-  CALL get_var1("ps",ps_glo)
-  ps   (ijb_u:ije_u)  =   ps_glo(ijb_u:ije_u);   DEALLOCATE(ps_glo)
+  CALL get_var1("phisinit", phis, ijb_u, ije_u, ip1jmp1)
+  CALL get_var2("ucov",     ucov, ijb_u, ije_u, ip1jmp1)
+  CALL get_var2("vcov",     vcov, ijb_v, ije_v, ip1jm)
+  CALL get_var2("teta",     teta, ijb_u, ije_u, ip1jmp1)
+  CALL get_var2("masse",   masse, ijb_u, ije_u, ip1jmp1)
+  CALL get_var1("ps",         ps, ijb_u, ije_u, ip1jmp1)
 
 !--- Tracers
-  ALLOCATE(q_glo(ip1jmp1,llm))
   DO iq=1,nqtot
     tr => tracers(iq)
     var = tr%name
-    IF(NF90_INQ_VARID(fID,var,vID)==NF90_NoErr) THEN
-      CALL get_var2(var ,q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:); CYCLE
+    ix = strIdx([('H2O'//phases_sep//known_phases(ip:ip), ip=1, nphases)], var)
+    IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr) THEN
+      CALL get_var2(var, q(:,:,iq), ijb_u, ije_u, ip1jmp1)
 #ifdef INCA
-    ELSE IF(NF90_INQ_VARID(fID,"OX",vID) == NF90_NoErr .AND. var == 'O3') THEN
-      WRITE(lunout,*) 'Tracer O3 is missing - it is initialized to OX'
-      CALL get_var2("OX",q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:); CYCLE
+    ELSE IF(NF90_INQ_VARID(fID, 'OX', vID) == NF90_NoErr .AND. var == 'O3') THEN
+      WRITE(lunout,*)TRIM(modname)//': Tracer <O3> is missing => initialized to OX'
+      CALL get_var2('OX', q(:,:,iq), ijb_u, ije_u, ip1jmp1)
 #endif
-    END IF
-    WRITE(lunout,*)TRIM(modname)//": Tracer <"//TRIM(var)//"> is missing"
-    WRITE(lunout,*)"         It is hence initialized to zero"
-    q(ijb_u:ije_u,:,iq)=0.
-   !--- CRisi: for isotops, theoretical initialization using very simplified
-   !           Rayleigh distillation las.
-    IF(niso > 0 .AND. tr%iso_num > 0) THEN
-      IF(tr%iso_zon == 0) q(:,:,iq) = q(:,:,tr%iprnt)         *        tnat(tr%iso_num) &
-                                   * (q(:,:,tr%iprnt)/30.e-3)**(alpha_ideal(tr%iso_num)-1)
-      IF(tr%iso_zon == 1) q(:,:,iq) = q(:,:,iTraPha(tr%iso_num,tr%iso_pha))
+    ELSE IF(ix /= 0) THEN              !--- Old file, water: H2Ov/l/i instead of H2O-g/-l/-s
+      oldH2O = 'H2O'//old_phases(ix:ix)
+      IF(NF90_INQ_VARID(fID, oldH2O, vID) == NF90_NoErr) THEN
+        WRITE(lunout,*)TRIM(modname)//': Tracer <'//TRIM(var)//'> is missing => initialized to '//TRIM(oldH2O)
+        CALL get_var2(oldH2O, q(:,:,iq), ijb_u, ije_u, ip1jmp1)
+      END IF
+    ELSE
+      WRITE(lunout,*)TRIM(modname)//': Tracer <'//TRIM(var)//'> is missing => initialized to zero'
+      q(ijb_u:ije_u,:,iq)=0.
+      !--- CRisi: for isotopes, theoretical initialization using very simplified Rayleigh distillation law
+      IF(niso > 0 .AND. tr%iso_num > 0) THEN
+        IF(tr%iso_zon == 0) q(:,:,iq) = q(:,:,tr%iprnt)         *        tnat(tr%iso_num) &
+                                      *(q(:,:,tr%iprnt)/30.e-3)**(alpha_ideal(tr%iso_num)-1)
+        IF(tr%iso_zon == 1) q(:,:,iq) = q(:,:,iTraPha(tr%iso_num,tr%iso_pha))
+      END IF
     END IF
   END DO
-  DEALLOCATE(q_glo)
   CALL err(NF90_CLOSE(fID),"close",fichnom)
   day_ini=day_ini+INT(time)
@@ -190,5 +173,5 @@
     s1='value of '//TRIM(str1)//' ='
     s2=' read in starting file differs from parametrized '//TRIM(str2)//' ='
-    WRITE(sdum,'(10x,a,i4,2x,a,i4)'),s1,n1,s2,n2
+    WRITE(sdum,'(10x,a,i4,2x,a,i4)'),TRIM(s1),n1,TRIM(s2),n2
     CALL ABORT_gcm(TRIM(modname),TRIM(sdum),1)
   END IF
@@ -196,44 +179,51 @@
 
 
-SUBROUTINE get_var1(var,v)
-  CHARACTER(LEN=*), INTENT(IN)  :: var
-  REAL,             INTENT(OUT) :: v(:)
-  REAL,             ALLOCATABLE :: w2(:,:), w3(:,:,:)
-  INTEGER :: nn(3), dids(3), k, nd, ntot
-
-  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
-  ierr=NF90_INQUIRE_VARIABLE(fID,vID,ndims=nd)
-  IF(nd==1) THEN
-    CALL err(NF90_GET_VAR(fID,vID,v),"get",var); RETURN
-  END IF
-  ierr=NF90_INQUIRE_VARIABLE(fID,vID,dimids=dids)
-  DO k=1,nd; ierr=NF90_INQUIRE_DIMENSION(fID,dids(k),len=nn(k)); END DO
-  ntot=PRODUCT(nn(1:nd))
-  SELECT CASE(nd)
-    CASE(2); ALLOCATE(w2(nn(1),nn(2)))
-      CALL err(NF90_GET_VAR(fID,vID,w2),"get",var)
-      v=RESHAPE(w2,[ntot]); DEALLOCATE(w2)
-    CASE(3); ALLOCATE(w3(nn(1),nn(2),nn(3)))
-      CALL err(NF90_GET_VAR(fID,vID,w3),"get",var)
-      v=RESHAPE(w3,[ntot]); DEALLOCATE(w3)
-  END SELECT
+SUBROUTINE get_var1(var, v, ib, ie, n_glo)
+  CHARACTER(LEN=*),  INTENT(IN)  :: var
+  REAL,              INTENT(OUT) :: v(:)
+  INTEGER, OPTIONAL, INTENT(IN)  :: ib, ie, n_glo
+  REAL, ALLOCATABLE :: w(:,:,:,:), v_glo(:)
+  INTEGER :: nn(4), dids(4), k, nd, ntot
+  CALL err(NF90_INQ_VARID(fID, var, vID), "inq", var)
+  ierr = NF90_INQUIRE_VARIABLE(fID, vID, dimids=dids, ndims=nd)
+  nn(:) = 1; DO k=1,nd; ierr = NF90_INQUIRE_DIMENSION(fID, dids(k), len=nn(k)); END DO
+  ntot = PRODUCT(nn(1:nd))
+  ALLOCATE(w(nn(1), nn(2), nn(3), nn(4)))
+  CALL err(NF90_GET_VAR(fID, vID, w), "get", var)
+  ALLOCATE(v_glo(ntot)); v_glo=RESHAPE(w, [ntot]); DEALLOCATE(w)
+  IF(PRESENT(n_glo).AND.PRESENT(ib).AND.PRESENT(ie)) THEN
+    IF(ntot/=n_glo) CALL abort_gcm(TRIM(modname), 'Shape mismatch for "'//TRIM(var)//'"')
+    v(ib:ie) = v_glo(ib:ie)
+  ELSE
+    v(:) = v_glo(:)
+  END IF
+  DEALLOCATE(v_glo)
 END SUBROUTINE get_var1
 
 
-SUBROUTINE get_var2(var,v)
+SUBROUTINE get_var2(var, v, ib, ie, n_glo)
   CHARACTER(LEN=*), INTENT(IN)  :: var
   REAL,             INTENT(OUT) :: v(:,:)
-  REAL,             ALLOCATABLE :: w4(:,:,:,:)
-  INTEGER :: nn(4), dids(4), k, nd
-  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
-  ierr=NF90_INQUIRE_VARIABLE(fID,vID,dimids=dids,ndims=nd)
-  DO k=1,nd; ierr=NF90_INQUIRE_DIMENSION(fID,dids(k),len=nn(k)); END DO
-  ALLOCATE(w4(nn(1),nn(2),nn(3),nn(4)))
-  CALL err(NF90_GET_VAR(fID,vID,w4),"get",var)
-  v=RESHAPE(w4,[nn(1)*nn(2),nn(3)]); DEALLOCATE(w4)
+  INTEGER,          INTENT(IN)  :: ib, ie, n_glo
+  REAL, ALLOCATABLE :: w(:,:,:,:), v_glo(:,:)
+  INTEGER :: nn(4), dids(4), k, nd, nh, nv, tid
+  CALL err(NF90_INQ_VARID(fID, var, vID), "inq", var)
+  ierr = NF90_INQUIRE_VARIABLE(fID, vID, dimids=dids, ndims=nd)
+  nn(:) = 1; DO k=1,nd; ierr = NF90_INQUIRE_DIMENSION(fID, dids(k), len=nn(k)); END DO
+  IF(NF90_INQUIRE(fID, unlimitedDimId=tid) == NF90_NOERR) THEN
+    nh = PRODUCT(nn(1:nd-2)); nv = nn(nd-1); nn(nd) = 1
+  ELSE
+    nh = PRODUCT(nn(1:nd-1)); nv = nn(nd)
+  END IF
+  ALLOCATE(w(nn(1), nn(2), nn(3), nn(4)))
+  CALL err(NF90_GET_VAR(fID, vID, w), "get", var)
+  ALLOCATE(v_glo(nh, nv)); v_glo = RESHAPE(w, [nh, nv]); DEALLOCATE(w)
+  IF(nh/=n_glo .OR. nv/=llm) CALL abort_gcm(TRIM(modname), 'Shape mismatch for "'//TRIM(var)//'"')
+  v(ib:ie,:) = v_glo(ib:ie,:)
+  DEALLOCATE(v_glo)
 END SUBROUTINE get_var2
 
 
-SUBROUTINE err(ierr,typ,nam)
+SUBROUTINE err(ierr, typ, nam)
   INTEGER,          INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
   CHARACTER(LEN=*), INTENT(IN) :: typ    !--- TYPE OF OPERATION
Index: LMDZ6/branches/LMDZ-tracers/libf/dyn3dmem/vlspltqs_loc.F
===================================================================
--- LMDZ6/branches/LMDZ-tracers/libf/dyn3dmem/vlspltqs_loc.F	(revision 3931)
+++ LMDZ6/branches/LMDZ-tracers/libf/dyn3dmem/vlspltqs_loc.F	(revision 3957)
@@ -481,4 +481,5 @@
       INTEGER ijbm,ijem
 
+      tr => tracers(iq)
       ijb=ij_begin-2*iip1
       ije=ij_end+2*iip1  
Index: LMDZ6/branches/LMDZ-tracers/libf/misc/readTracFiles_mod.f90
===================================================================
--- LMDZ6/branches/LMDZ-tracers/libf/misc/readTracFiles_mod.f90	(revision 3931)
+++ LMDZ6/branches/LMDZ-tracers/libf/misc/readTracFiles_mod.f90	(revision 3957)
@@ -14,5 +14,6 @@
   PUBLIC :: getKey_init, getKey, setDirectKeys                            !--- FUNCTIONS TO GET KEYS FROM tracers & isotopes
 
-  PUBLIC :: known_phases, nphases, phases_names, delPhase, addPhase       !--- PHASES RELATED VARIABLES AND ROUTINES
+  PUBLIC :: known_phases, old_phases, nphases, phases_names, phases_sep, &!--- VARIABLES RELATED TO THE PHASES
+            delPhase, addPhase                                            !--- ROUTINES TO ADD/REMOVE PHASE TO/FROM A NAME
 
   PUBLIC :: tran0, idxAncestor, ancestor                                  !--- GEN 0 TRACER + TOOLS FOR GENERATIONS
@@ -34,8 +35,10 @@
   !--- SOME PARAMETERS THAT ARE NOT LIKELY TO CHANGE OFTEN
   CHARACTER(LEN=256), SAVE      :: tran0        = 'air'              !--- Default transporting fluid
+  CHARACTER(LEN=256), PARAMETER :: old_phases   = 'vli'              !--- Old phases for water (no separator)
   CHARACTER(LEN=256), PARAMETER :: known_phases = 'gls'              !--- Known phases initials
   INTEGER,            PARAMETER :: nphases = LEN_TRIM(known_phases)  !--- Number of phases
   CHARACTER(LEN=256), SAVE      :: phases_names(nphases) &           !--- Known phases names
                                  = ['gaseous', 'liquid ', 'solid  ']
+  CHARACTER(LEN=1),   SAVE      :: phases_sep  =  '_'                !--- Phase separator
   LOGICAL,            SAVE      :: tracs_merge = .TRUE.              !--- Merge/stack tracers lists
   LOGICAL,            SAVE      :: lSortByGen  = .TRUE.              !--- Sort by growing generation
@@ -79,5 +82,5 @@
   CHARACTER(LEN=256),     ALLOCATABLE ::  s(:), sections(:), trac_files(:)
   CHARACTER(LEN=256)   :: str, fname, mesg
-  INTEGER              :: is, nsec, ierr, it, ntrac, ns
+  INTEGER              :: is, nsec, ierr, it, ntrac, ns, ip
   LOGICAL, ALLOCATABLE :: ll(:), lGen3(:)
 !------------------------------------------------------------------------------------------------------------------------------
@@ -97,5 +100,5 @@
   IF(.NOT.testFile('traceur.def') .AND. nsec==1) fType = 1           !--- OLD STYLE FILE
   IF(.NOT.testFile('tracer.def'))                fType = 2           !--- NEW STYLE ; SINGLE  FILE, SEVERAL SECTIONS
-  IF(ALL(ll))                               fType = 3                !--- NEW STYLE ; SEVERAL FILES, SINGLE SECTION USED
+  IF(ALL(ll))                                    fType = 3           !--- NEW STYLE ; SEVERAL FILES, SINGLE SECTION USED
   IF(ANY(ll) .AND. fType/=3) THEN                                    !--- MISSING FILES
     IF(test(checkList(trac_files, .NOT.ll, 'Failed reading tracers description', 'files', 'missing'), lerr)) RETURN
@@ -129,10 +132,9 @@
       CALL msg(ns == 3 .AND. it == 1, 'This file is for air tracers only')
       CALL msg(ns == 4 .AND. it == 1, 'This files specifies the transporting fluid')
-      SELECT CASE(s(3))                                              !--- name and phase of the tracer
-        CASE('H2Ov'); tracs(it)%name = 'H2O-g'; tracs(it)%phas = 'g'
-        CASE('H2Ol'); tracs(it)%name = 'H2O-l'; tracs(it)%phas = 'l'
-        CASE('H2Oi'); tracs(it)%name = 'H2O-s'; tracs(it)%phas = 's'
-        CASE DEFAULT; tracs(it)%name = s(3)   ; tracs(it)%phas = 'g'
-      END SELECT
+      tracs(it)%name = s(3); tracs(it)%phas = known_phases(1:1)      !--- Default: name, gazeous phase "g"
+      DO ip = 1, nphases                                             !--- Deal with old water names
+        IF(s(3) /= 'H2O'//old_phases(ip:ip)) CYCLE
+        tracs(it)%phas = known_phases(ip:ip); tracs(it)%name = 'H2O'//phases_sep//TRIM(tracs(it)%phas)
+      END DO
       tracs(it)%prnt = tran0                                         !--- Default transporting fluid: Air
       IF(ns == 4) tracs(it)%prnt = s(4)                              !--- Transporting fluid name
@@ -549,5 +551,5 @@
         trn=TRIM(tr(iq)%name); nam=trn                               !--- Tracer name (regular case)
         IF(lTg) nam = TRIM(tr(iq)%prnt)                              !--- Parent name (tagging case)
-        IF(lEx) nam = TRIM(nam)//'-'//pha(ip:ip)                     !--- Phase extension needed
+        IF(lEx) nam = TRIM(nam)//phases_sep//pha(ip:ip)              !--- Phase extension needed
         IF(lTg) nam = TRIM(nam)//'_'//TRIM(trn)                      !--- <parent>_<name> for tags
         ttr(it) = tr(iq)                                             !--- Same <key>=<val> pairs
@@ -556,6 +558,6 @@
         ttr(it)%phas = pha(ip:ip)                                    !--- Single phase entry
         IF(lEx.AND.tr(iq)%igen>1) THEN
-          ttr(it)%prnt = TRIM(ttr(it)%prnt)//'-'//pha(ip:ip)
-          ttr(it)%nam1 = TRIM(ttr(it)%nam1)//'-'//pha(ip:ip)
+          ttr(it)%prnt = TRIM(ttr(it)%prnt)//phases_sep//pha(ip:ip)
+          ttr(it)%nam1 = TRIM(ttr(it)%nam1)//phases_sep//pha(ip:ip)
         END IF
         it=it+1
@@ -698,5 +700,5 @@
       tnam = t1(iq)%name                                             !--- Original name
       IF(COUNT(t1%name == tnam) == 1) CYCLE                          !--- Current tracer is not duplicated: finished
-      tnam_new = TRIM(tnam)//'-'//TRIM(sections(is)%name)            !--- Same with section extension
+      tnam_new = TRIM(tnam)//phases_sep//TRIM(sections(is)%name)     !--- Same with section extension
       nq = SUM(nt(1:is-1))                                           !--- Number of tracers in previous sections
       ns = nt(is)                                                    !--- Number of tracers in the current section
@@ -1231,7 +1233,7 @@
   i = INDEX(s, '_'); l = LEN_TRIM(s)
   IF(i == 0) THEN
-    IF(s(l-1:l-1)=='-' .AND. INDEX(known_phases,s(l:l)) /= 0) out = s(1:l-2)
+    IF(s(l-1:l-1)==phases_sep .AND. INDEX(known_phases,s(l:l)) /= 0) out = s(1:l-2)
   ELSE; i=i-1
-    IF(s(i-1:i-1)=='-' .AND. INDEX(known_phases,s(i:i)) /= 0) out = s(1:i-2)//s(i+1:l)
+    IF(s(i-1:i-1)==phases_sep .AND. INDEX(known_phases,s(i:i)) /= 0) out = s(1:i-2)//s(i+1:l)
   END IF
 END FUNCTION delPhase
@@ -1244,6 +1246,6 @@
   IF(s == '') RETURN
   i = INDEX(s, '_'); l = LEN_TRIM(s)
-  IF(i == 0) out =  TRIM(s)//'-'//pha
-  IF(i /= 0) out = s(1:i-1)//'-'//pha//'_'//s(i+1:l)
+  IF(i == 0) out =  TRIM(s)//phases_sep//pha
+  IF(i /= 0) out = s(1:i-1)//phases_sep//pha//'_'//s(i+1:l)
 END FUNCTION addPhase_1
 !------------------------------------------------------------------------------------------------------------------------------
Index: LMDZ6/branches/LMDZ-tracers/libf/misc/strings_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ-tracers/libf/misc/strings_mod.F90	(revision 3931)
+++ LMDZ6/branches/LMDZ-tracers/libf/misc/strings_mod.F90	(revision 3957)
@@ -186,50 +186,64 @@
 
 !==============================================================================================================================
-!=== Extract first or last element of a string "str" delimited by separator "sep" =============================================
-!==============================================================================================================================
-CHARACTER(LEN=256) FUNCTION strHead_1(str,sep) RESULT(out)
+!=== Extract the substring in front of the last (first if lFirst==TRUE) occurrence of separator "sep" in "str" ================
+!==============================================================================================================================
+CHARACTER(LEN=256) FUNCTION strHead_1(str,sep,lFirst) RESULT(out)
   CHARACTER(LEN=*),           INTENT(IN) :: str
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
+  LOGICAL,          OPTIONAL, INTENT(IN) :: lFirst
+  LOGICAL :: lf
+  lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst
   IF(PRESENT(sep)) THEN
-    out = str(1:INDEX(str,sep,.TRUE.)-1)
+    out = str(1:INDEX(str,sep,.NOT.lf)-1)
   ELSE
-    out = str(1:INDEX(str,'/',.TRUE.)-1)
+    out = str(1:INDEX(str,'/',.NOT.lf)-1)
   END IF
   IF(out == '') out = str
 END FUNCTION strHead_1
 !==============================================================================================================================
-CHARACTER(LEN=256) FUNCTION strTail_1(str,sep) RESULT(out)
-  CHARACTER(LEN=*),           INTENT(IN) :: str
-  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
-  IF(PRESENT(sep)) THEN
-    out = str(INDEX(str,sep,.TRUE.)+LEN(sep):LEN_TRIM(str))
-  ELSE
-    out = str(INDEX(str,'/',.TRUE.)+1:LEN_TRIM(str))
-  END IF
-  IF(out == '') out = str
-END FUNCTION strTail_1
-!==============================================================================================================================
-FUNCTION strHead_m(str,sep) RESULT(out)
+FUNCTION strHead_m(str,sep,lFirst) RESULT(out)
   CHARACTER(LEN=256),        ALLOCATABLE :: out(:)
   CHARACTER(LEN=*),           INTENT(IN) :: str(:)
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
+  LOGICAL,          OPTIONAL, INTENT(IN) :: lFirst
+  LOGICAL :: lf
   INTEGER :: k
+  lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst
   IF(PRESENT(sep)) THEN
-    out = [(strHead_1(str(k),sep), k=1, SIZE(str))]
+    out = [(strHead_1(str(k),sep,.NOT.lf),    k=1, SIZE(str))]
   ELSE
-    out = [(strHead_1(str(k)),     k=1, SIZE(str))]
+    out = [(strHead_1(str(k),lFirst=.NOT.lf), k=1, SIZE(str))]
   END IF
 
 END FUNCTION strHead_m
 !==============================================================================================================================
-FUNCTION strTail_m(str,sep) RESULT(out)
+!=== Extract the substring following the last (first if lFirst==TRUE) occurrence of separator "sep" in "str" ==================
+!==============================================================================================================================
+CHARACTER(LEN=256) FUNCTION strTail_1(str,sep,lFirst) RESULT(out)
+  CHARACTER(LEN=*),           INTENT(IN) :: str
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
+  LOGICAL,          OPTIONAL, INTENT(IN) :: lFirst
+  LOGICAL :: lf
+  lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst
+  IF(PRESENT(sep)) THEN
+    out = str(INDEX(str,sep,.NOT.lf)+LEN(sep):LEN_TRIM(str))
+  ELSE
+    out = str(INDEX(str,'/',.NOT.lf)+1:LEN_TRIM(str))
+  END IF
+  IF(out == '') out = str
+END FUNCTION strTail_1
+!==============================================================================================================================
+FUNCTION strTail_m(str,sep,lFirst) RESULT(out)
   CHARACTER(LEN=256),        ALLOCATABLE :: out(:)
   CHARACTER(LEN=*),           INTENT(IN) :: str(:)
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
+  LOGICAL,          OPTIONAL, INTENT(IN) :: lFirst
+  LOGICAL :: lf
   INTEGER :: k
+  lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst
   IF(PRESENT(sep)) THEN
-    out = [(strTail_1(str(k),sep), k=1, SIZE(str))]
+    out = [(strTail_1(str(k),sep,.NOT.lf),    k=1, SIZE(str))]
   ELSE
-    out = [(strTail_1(str(k)),     k=1, SIZE(str))]
+    out = [(strTail_1(str(k),lFirst=.NOT.lf), k=1, SIZE(str))]
   END IF
 END FUNCTION strTail_m
Index: LMDZ6/branches/LMDZ-tracers/libf/phylmd/phyetat0.F90
===================================================================
--- LMDZ6/branches/LMDZ-tracers/libf/phylmd/phyetat0.F90	(revision 3931)
+++ LMDZ6/branches/LMDZ-tracers/libf/phylmd/phyetat0.F90	(revision 3957)
@@ -575,5 +575,6 @@
 USE dimphy, only: klon 
 USE print_control_mod, ONLY: lunout
-
+USE readTracFiles_mod, ONLY: known_phases, old_phases, nphases, phases_sep
+USE strings_mod,       ONLY: strIdx
 IMPLICIT NONE
 
@@ -588,10 +589,19 @@
 ! Local variables
 LOGICAL found
+INTEGER :: ix, ip
+CHARACTER(LEN=256) :: oldname
 
    CALL get_field(name, field, found)
+   ix = strIdx([('trs_H2O'//phases_sep//known_phases(ip:ip), ip=1, nphases)], name)
+   IF (.NOT. found .AND. ix /= 0) THEN           !--- Old file, water: H2Ov/l/i instead of H2O_g/_l/_s
+      oldname = 'trs_H2O'//old_phases(ix:ix)
+      CALL get_field(oldname, field, found)
+   END IF
    IF (.NOT. found) THEN
      WRITE(lunout,*) "phyetat0: Le champ <",TRIM(name),"> est absent"
      WRITE(lunout,*) "Depart legerement fausse. Mais je continue"
      field(:,:)=default
+   ELSE IF(ix /= 0) THEN
+     WRITE(lunout,*)"phyetat0: Le champ <",TRIM(name),"> est absent => initialisation a <"//TRIM(oldname)//">"
    ENDIF
    WRITE(lunout,*) TRIM(name), descr, MINval(field),MAXval(field)
