Index: LMDZ6/trunk/libf/phylmd/infotrac_phy.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/infotrac_phy.F90	(revision 5190)
+++ LMDZ6/trunk/libf/phylmd/infotrac_phy.F90	(revision 5199)
@@ -7,4 +7,5 @@
         delPhase, niso, getKey, isot_type, processIsotopes,  isotope, maxTableWidth, iqIsoPha, nphas, ixIso, isoPhas, &
         addPhase, iH2O, addKey, isoSelect, testTracersFiles, isoKeys, indexUpdate,  iqWIsoPha, nbIso, ntiso, isoName, isoCheck
+   USE readTracFiles_mod, ONLY: new2oldH2O
    IMPLICIT NONE
 
@@ -16,24 +17,24 @@
    PUBLIC :: nqtot,   nbtr,   nqo,   nqCO2,   nqtottr      !--- Main dimensions
    PUBLIC :: conv_flg, pbl_flg                             !--- Convection & boundary layer activation keys
-#ifdef CPP_StratAer
+   PUBLIC :: new2oldH2O                                    !--- For backwards compatibility in phyetat0
+   PUBLIC :: addPhase, delPhase                            !--- Add/remove the phase from the name of a tracer
+#if defined CPP_StratAer || defined REPROBUS
    PUBLIC :: nbtr_bin, nbtr_sulgas                         !--- Number of aerosols bins and sulfur gases for StratAer model
    PUBLIC :: id_OCS_strat, id_SO2_strat, id_H2SO4_strat, id_BIN01_strat, id_TEST_strat
 #endif
 
-   !=== FOR WATER
-   PUBLIC :: ivap, iliq, isol
    !=== FOR ISOTOPES: General
    PUBLIC :: isot_type, nbIso                              !--- Derived type, full isotopes families database + nb of families
    PUBLIC :: isoSelect, ixIso                              !--- Isotopes family selection tool + selected family index
    !=== FOR ISOTOPES: Specific to water
-   PUBLIC :: iH2O                                          !--- H2O isotopes class index
+   PUBLIC :: iH2O                                          !--- Value of "ixIso" for "H2O" isotopes class
+   PUBLIC :: ivap, iliq, isol
    !=== FOR ISOTOPES: Depending on the selected isotopes family
-   PUBLIC :: isotope, isoKeys                              !--- Selected isotopes database + associated keys (cf. getKey)
-   PUBLIC :: isoName, isoZone, isoPhas                     !--- Isotopes and tagging zones names, phases
-   PUBLIC :: niso,    nzone,   nphas,   ntiso              !---  " " numbers + isotopes & tagging tracers number
-   PUBLIC :: itZonIso                                      !--- idx "it" (in "isoName(1:niso)") = function(tagging idx, isotope idx)
-   PUBLIC :: iqIsoPha                                      !--- idx "iq" (in "qx") = function(isotope idx, phase idx) + aliases
-   PUBLIC :: iqWIsoPha                                      !--- Same as iqIsoPha but with normal water phases
-
+   PUBLIC :: isotope                                       !--- Selected isotopes database (argument of getKey)
+   PUBLIC :: isoKeys, isoName, isoZone, isoPhas            !--- Isotopes keys & names, tagging zones names, phases
+   PUBLIC ::    niso,   ntiso,   nzone,   nphas            !--- Number of   "   "
+   PUBLIC :: itZonIso                                      !--- Index "it" in "isoName(1:niso)" = f(tagging idx, isotope idx)
+   PUBLIC :: iqIsoPha                                      !--- Index "iq" in "qx"              = f(isotope idx,   phase idx)
+   PUBLIC :: iqWIsoPha                                     !--- Same as iqIsoPha but with normal water phases
    PUBLIC :: isoCheck                                      !--- Run isotopes checking routines
    !=== FOR BOTH TRACERS AND ISOTOPES
@@ -43,5 +44,5 @@
 !  |--------------------+-----------------------+-----------------+---------------+----------------------------|
 !  | water in different |    water tagging      |  water isotopes | other tracers | additional tracers moments |
-!  | phases: H2O_[gls]  |      isotopes         |                 |               |  for higher order schemes  |
+!  | phases: H2O_[glsrb]|      isotopes         |                 |               |  for higher order schemes  |
 !  |--------------------+-----------------------+-----------------+---------------+----------------------------|
 !  |                    |                       |                 |               |                            |
@@ -68,9 +69,11 @@
 !  |-------------+------------------------------------------------------+-------------+------------------------+
 !  | name        | Name (short)                                         | tname       |                        |
+!  | keys        | key/val pairs accessible with "getKey" routine       | /           |                        |
 !  | gen0Name    | Name of the 1st generation ancestor                  | /           |                        |
 !  | parent      | Name of the parent                                   | /           |                        |
 !  | longName    | Long name (with adv. scheme suffix) for outputs      | ttext       |                        |
 !  | type        | Type (so far: tracer or tag)                         | /           | tracer,tag             |
-!  | phase       | Phases list ("g"as / "l"iquid / "s"olid)             | /           | [g][l][s]              |
+!  | phase       | Phases list ("g"as / "l"iquid / "s"olid              |             | [g|l|s|r|b]            |
+!  |             |              "r"(cloud) / "b"lowing)                 | /           |                        |
 !  | component   | Name(s) of the merged/cumulated section(s)           | /           | coma-separated names   |
 !  | iGeneration | Generation (>=1)                                     | /           |                        |
@@ -79,7 +82,6 @@
 !  | nqDescen    | Number of the descendants   (all generations)        | nqdesc      | 1:nqtot                |
 !  | nqChildren  | Number of childs            (1st generation only)    | nqfils      | 1:nqtot                |
-!  | keys        | key/val pairs accessible with "getKey" routine       | /           |                        |
-!  | isAdvected  | advected tracers flag (.TRUE. if iadv >= 0)          | /           | nqtrue  .TRUE. values  |
-!  | isInPhysics | tracers not extracted from the main table in physics | /           | nqtottr .TRUE. values  |
+!  | isAdvected  | Advected tracers flag (.TRUE. if iadv >= 0)          | /           | nqtrue  .TRUE. values  |
+!  | isInPhysics | Tracers not extracted from the main table in physics | /           | nqtottr .TRUE. values  |
 !  | iso_iGroup  | Isotopes group index in isotopes(:)                  | /           | 1:nbIso                |
 !  | iso_iName   | Isotope  name  index in isotopes(iso_iGroup)%trac(:) | iso_indnum  | 1:niso                 |
@@ -97,14 +99,18 @@
 !  | trac   | ntiso  | Isotopes + tagging tracers list + number         | / | ntraciso       |                 |
 !  | zone   | nzone  | Geographic tagging zones   list + number         | / | ntraceurs_zone |                 |
-!  | phase  | nphas  | Phases                     list + number         |                    | [g][l][s], 1:3  |
+!  | phase  | nphas  | Phases                     list + number         |                    | [g|l|s|r|b] 1:5 |
 !  | iqIsoPha        | Index in "qx"           = f(name(1:ntiso)),phas) | iqiso              | 1:nqtot         |
-!  | iqWIsoPha       | Index in "qx"           = f(name(1:ntiso)),phas) | iqiso              | 1:nqtot         |
+!  | iqWIsoPha       | Index in "qx"       = f(name(1:ntiso+nqo)),phas) |   /                | 1:nqtot         |
 !  | itZonIso        | Index in "trac(1:ntiso)"= f(zone, name(1:niso))  | index_trac         | 1:ntiso         |
 !  +-----------------+--------------------------------------------------+--------------------+-----------------+
 
+   !=== INDICES FOR WATER
+   INTEGER, SAVE :: ivap, iliq, isol
+!$OMP THREADPRIVATE(ivap, iliq, isol)
+
    !=== DIMENSIONS OF THE TRACERS TABLES AND OTHER SCALAR VARIABLES
-   INTEGER,               SAVE :: nqtot,  &                     !--- Tracers nb in dynamics (incl. higher moments + H2O)
-                                  nbtr,   &                     !--- Tracers nb in physics  (excl. higher moments + H2O)
-                                  nqo,    &                     !--- Number of water phases
+   INTEGER,               SAVE :: nqtot,   &                    !--- Tracers nb in dynamics (incl. higher moments + H2O)
+                                  nbtr,    &                    !--- Tracers nb in physics  (excl. higher moments + H2O)
+                                  nqo,     &                    !--- Number of water phases
                                   nqtottr, &                    !--- Number of tracers passed to phytrac (TO BE DELETED ?)
                                   nqCO2                         !--- Number of tracers of CO2  (ThL)
@@ -112,14 +118,10 @@
 !$OMP THREADPRIVATE(nqtot, nbtr, nqo, nqtottr, nqCO2, type_trac)
 
-   !=== INDICES OF WATER
-   INTEGER,               SAVE :: ivap,iliq,isol ! Indices for vap, liq and ice
-!$OMP THREADPRIVATE(ivap,iliq,isol)
-
    !=== VARIABLES FOR INCA
-   INTEGER,               SAVE, ALLOCATABLE :: conv_flg(:), &   !--- Convection     activation ; needed for INCA        (nbtr)
-                                                pbl_flg(:)      !--- Boundary layer activation ; needed for INCA        (nbtr)
+   INTEGER, DIMENSION(:), SAVE, ALLOCATABLE :: &
+                    conv_flg, pbl_flg                           !--- Convection / boundary layer activation (nbtr)
 !$OMP THREADPRIVATE(conv_flg, pbl_flg)
 
-#ifdef CPP_StratAer
+#if defined CPP_StratAer || defined REPROBUS
   !=== SPECIFIC TO STRATOSPHERIC AEROSOLS (CK/OB)
   INTEGER, SAVE ::  nbtr_bin, nbtr_sulgas         !--- number of aerosols bins and sulfur gases for StratAer model
@@ -173,15 +175,14 @@
    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=maxlen) :: msg1, texp, ttp                          !--- String for messages and expanded tracers type
+   CHARACTER(LEN=maxlen) :: msg1, texp, ttp                          !--- Strings for messages and expanded tracers type
    INTEGER :: fType                                                  !--- Tracers description file type ; 0: none
                                                                      !--- 1/2/3: "traceur.def"/"tracer.def"/"tracer_*.def"
    INTEGER :: nqtrue                                                 !--- Tracers nb from tracer.def (no higher order moments)
    INTEGER :: iad                                                    !--- Advection scheme number
-   INTEGER :: iq, jq, nt, im, nm, k                                 !--- Indexes and temporary variables
+   INTEGER :: iq, jq, nt, im, nm                                     !--- Indexes and temporary variables
    LOGICAL :: lerr, lInit
    TYPE(trac_type), ALLOCATABLE, TARGET :: ttr(:)
    TYPE(trac_type), POINTER             :: t1, t(:)
-   CHARACTER(LEN=maxlen),   ALLOCATABLE :: types_trac(:)  !--- Keyword for tracers type(s), parsed version
-   
+   CHARACTER(LEN=maxlen),   ALLOCATABLE :: types_trac(:)             !--- Keywords for tracers type(s), parsed version
    CHARACTER(LEN=*), PARAMETER :: modname="init_infotrac_phy"
 !------------------------------------------------------------------------------------------------------------------------------
@@ -202,5 +203,4 @@
    ENDIF
 
-   
    CALL msg('type_trac = "'//TRIM(type_trac)//'"', modname)
    lInit = .NOT.ALLOCATED(tracers)
@@ -243,13 +243,10 @@
 
 !==============================================================================================================================
-! 1) Get the numbers of: true (first order only) tracers "nqtrue", water tracers "nqo" (vapor/liquid/solid)
-!==============================================================================================================================
-   texp = type_trac                                                  !=== EXPANDED VERSION OF "type_trac", WITH "|" SEPARATOR
+! 0) DETERMINE THE TYPE OF THE INPUT TRACERS DESCRIPTION FILE AND READ IT
+!==============================================================================================================================
+   texp = type_trac                                                            !=== EXPANDED (WITH "|" SEPARATOR) "type_trac"
    IF(texp == 'inco') texp = 'co2i|inca'
    IF(texp /= 'lmdz') texp = 'lmdz|'//TRIM(texp)
-
-   !=== DETERMINE THE TYPE OF THE INPUT TRACERS DESCRIPTION FILE
    IF(testTracersFiles(modname, texp, fType, lInit)) CALL abort_physic(modname, 'problem with tracers file(s)',1)
-
    ttp = type_trac; IF(fType /= 1) ttp = texp
 
@@ -262,8 +259,11 @@
 !##############################################################################################################################
 
-   !---------------------------------------------------------------------------------------------------------------------------
-   IF(fType == 0) CALL abort_physic(modname, 'Missing tracers file: "traceur.def", "tracer.def" or "tracer_<keyword>.def file.',1)
-   !---------------------------------------------------------------------------------------------------------------------------
-   IF(fType == 1 .AND. ANY(['inca','inco']==type_trac) .AND. lInit) THEN  !=== FOUND OLD STYLE INCA "traceur.def"
+!==============================================================================================================================
+! 1) Get various numbers: "nqtrue" (first order only tracers), "nqo" (water phases), 'nbtr' (tracers passed to physics), etc.
+!==============================================================================================================================
+   !---------------------------------------------------------------------------------------------------------------------------
+   IF(fType == 0) CALL abort_physic(modname, 'Missing "traceur.def", "tracer.def" or "tracer_<keyword>.def tracers file.',1)
+   !---------------------------------------------------------------------------------------------------------------------------
+   IF(fType == 1 .AND. ANY(['inca', 'inco'] == type_trac) .AND. lInit) THEN  !=== FOUND OLD STYLE INCA "traceur.def"
    !---------------------------------------------------------------------------------------------------------------------------
 #ifdef INCA
@@ -281,5 +281,5 @@
       ttr(1+nqo:nqCO2+nqo   )%component = 'co2i'
       ttr(1+nqo+nqCO2:nqtrue)%component = 'inca'
-      ttr(1+nqo      :nqtrue)%name      = [('CO2     ', k=1, nqCO2), solsym_inca]
+      ttr(1+nqo      :nqtrue)%name      = [('CO2     ', iq=1, nqCO2), solsym_inca]
       ttr(1+nqo+nqCO2:nqtrue)%parent    = tran0
       ttr(1+nqo+nqCO2:nqtrue)%phase     = 'g'
@@ -302,19 +302,17 @@
    ELSE                                                              !=== OTHER CASES (OLD OR NEW FORMAT, NO INCA MODULE)
    !---------------------------------------------------------------------------------------------------------------------------
-      nqo    =        COUNT(delPhase(tracers(:)%name)     == 'H2O' &
-                               .AND. tracers(:)%component == 'lmdz') !--- Number of water phases
-      nqtrue = SIZE(tracers)                                         !--- Total number of "true" tracers
-      nbtr   = nqtrue-COUNT(delPhase(tracers(:)%gen0Name) == 'H2O' &
-                               .AND. tracers(:)%component == 'lmdz') !--- Number of tracers passed to phytrac
+   nqtrue = SIZE(tracers)                                                                               !--- "true" tracers
+   nqo    =      COUNT(tracers(:)%component == 'lmdz' .AND. delPhase(tracers(:)%name)     == 'H2O')     !--- Water phases
+   nbtr = nqtrue-COUNT(tracers(:)%component == 'lmdz' .AND. delPhase(tracers(:)%gen0Name) == 'H2O')     !--- Passed to phytrac
+   nqCO2  =      COUNT( [type_trac == 'inco', type_trac == 'co2i'] )
 #ifdef INCA
-      nqINCA = COUNT(tracers(:)%component == 'inca')
-#endif
-      lerr = getKey('hadv', hadv, ky=tracers(:)%keys)
-      lerr = getKey('vadv', vadv, ky=tracers(:)%keys)
-   !---------------------------------------------------------------------------------------------------------------------------
-   END IF
-   !---------------------------------------------------------------------------------------------------------------------------
-
-   !--- Transfert the number of tracers to Reprobus
+   nqINCA =      COUNT(tracers(:)%component == 'inca')
+#endif
+   IF(getKey('hadv', hadv, ky=tracers(:)%keys)) CALL abort_physic(modname, 'missing key "hadv"', 1)
+   IF(getKey('vadv', vadv, ky=tracers(:)%keys)) CALL abort_physic(modname, 'missing key "vadv"', 1)
+   !---------------------------------------------------------------------------------------------------------------------------
+   END IF
+   !---------------------------------------------------------------------------------------------------------------------------
+
 #ifdef REPROBUS
    CALL Init_chem_rep_trac(nbtr, nqo, tracers(:)%name)
@@ -359,9 +357,8 @@
       IF(iad == -1) CALL abort_physic(modname, msg1, 1)
 
-      !--- SET FIELDS %longName, %isAdvected, %isInPhysics
+      !--- SET FIELDS longName, isAdvected, isInPhysics
       t1%longName   = t1%name; IF(iad > 0) t1%longName=TRIM(t1%name)//descrq(iad)
       t1%isAdvected = iad >= 0
-      t1%isInPhysics= delPhase(t1%gen0Name) /= 'H2O' &
-                          .OR. t1%component /= 'lmdz' !=== OTHER EXCEPTIONS TO BE ADDED: CO2i, SURSATURATED WATER CLOUD...
+      t1%isInPhysics= delPhase(t1%gen0Name) /= 'H2O' .OR. t1%component /= 'lmdz' !=== MORE EXCEPTIONS ? CO2i, SURSAT CLOUD H2O
       ttr(iq)       = t1
 
@@ -372,8 +369,10 @@
       IF(nm == 0) CYCLE                                              !--- No higher moments
       ttr(jq+1:jq+nm)             = t1
-      ttr(jq+1:jq+nm)%name        = [(TRIM(t1%name)    //'-'//TRIM(suff(im)), im=1, nm) ]
-      ttr(jq+1:jq+nm)%parent      = [(TRIM(t1%parent)  //'-'//TRIM(suff(im)), im=1, nm) ]
-      ttr(jq+1:jq+nm)%longName    = [(TRIM(t1%longName)//'-'//TRIM(suff(im)), im=1, nm) ]
-      ttr(jq+1:jq+nm)%isAdvected  = [(.FALSE., im=1, nm) ]
+      ttr(jq+1:jq+nm)%name        = [ (TRIM(t1%name)    //'-'//TRIM(suff(im)), im=1, nm) ]
+      ttr(jq+1:jq+nm)%gen0Name    = [ (TRIM(t1%name)    //'-'//TRIM(suff(im)), im=1, nm) ]
+      ttr(jq+1:jq+nm)%parent      = [ (TRIM(t1%parent)  //'-'//TRIM(suff(im)), im=1, nm) ]
+      ttr(jq+1:jq+nm)%longName    = [ (TRIM(t1%longName)//'-'//TRIM(suff(im)), im=1, nm) ]
+      ttr(jq+1:jq+nm)%isAdvected  = [ (.FALSE., im=1, nm) ]
+      ttr(jq+1:jq+nm)%isInPhysics = [ (.FALSE., im=1, nm) ]
       jq = jq + nm
    END DO
@@ -381,6 +380,6 @@
    CALL MOVE_ALLOC(FROM=ttr, TO=tracers)
 
-   !--- SET FIELDS %iqParent, %nqChildren, %iGeneration, %iqDescen, %nqDescen
-   IF(indexUpdate(tracers)) CALL abort_gcm(modname, 'problem when processing isotopes parameters', 1)
+   !--- SET FIELDS iqParent, iqDescen, nqDescen, nqChildren, iGeneration
+   IF(indexUpdate(tracers)) CALL abort_physic(modname, 'problem with tracers indices update', 1)
 
 !##############################################################################################################################
@@ -404,6 +403,6 @@
 !##############################################################################################################################
    !--- Convection / boundary layer activation for all tracers
-   IF (.NOT.ALLOCATED(conv_flg)) ALLOCATE(conv_flg(nbtr)); conv_flg(1:nbtr) = 1
-   IF (.NOT.ALLOCATED(pbl_flg)) ALLOCATE( pbl_flg(nbtr));  pbl_flg(1:nbtr) = 1
+   IF(.NOT.ALLOCATED(conv_flg)) ALLOCATE(conv_flg(nbtr)); conv_flg(1:nbtr) = 1
+   IF(.NOT.ALLOCATED( pbl_flg)) ALLOCATE( pbl_flg(nbtr));  pbl_flg(1:nbtr) = 1
 
    !--- Note: nqtottr can differ from nbtr when nmom/=0
@@ -424,8 +423,9 @@
 #endif
    t => tracers
-   CALL msg('Information stored in infotrac_phy :', modname)
-   IF(dispTable('issssssssiiiiiiii', ['iq  ', 'name', 'lNam', 'g0Nm', 'prnt', 'type', 'phas', 'comp',      &
-                              'isPh', 'iGen', 'iqPr', 'nqDe', 'nqCh', 'iGrp', 'iNam', 'iZon', 'iPha'],     &
-      cat(t%name, t%longName, t%gen0Name, t%parent, t%type, t%phase, t%component, bool2str(t%isInPhysics)),&
+   CALL msg('Information stored in '//TRIM(modname)//': ', modname)
+   IF(dispTable('isssssssssiiiiiiii', ['iq  ', 'name', 'lNam', 'g0Nm', 'prnt', 'type', 'phas', 'comp',     &
+                       'isPh', 'isAd', 'iGen', 'iqPr', 'nqDe', 'nqCh', 'iGrp', 'iNam', 'iZon', 'iPha'],    &
+      cat(t%name, t%longName, t%gen0Name, t%parent, t%type, t%phase, t%component,                          &
+                                                         bool2str(t%isInPhysics), bool2str(t%isAdvected)), &
       cat([(iq, iq=1, nqtot)], t%iGeneration, t%iqParent, t%nqDescen, t%nqChildren, t%iso_iGroup,          &
                   t%iso_iName, t%iso_iZone, t%iso_iPhase), nColMax=maxTableWidth, nHead=2, sub=modname))   &
