source: LMDZ6/trunk/libf/dyn3d_common/infotrac.F90 @ 4291

Last change on this file since 4291 was 4193, checked in by dcugnet, 2 years ago
  • Modifications in readSections to allow a continuation line character "\": in both "tracer.def" and "isotopes_params.def", information for a single tracer or isotope can now be stored on several lines.
  • Modifications in "dispTable" and associated routines to allow too wide tables to be displayed as several shorter sub-tables: each sub-table is at most "nMaxCol" characters wide (typically: number of characters displayable in a tandard screen window) and the first "nHead" columns (typically: name, index, etc.) are duplicated in each sub-table. A default value for nMaxCol, called maxTableWidth (currently = 192) is available in readTracFiles_mod.
  • Subroutine "readIsotopesFile" becomes a function with a boolean returned error value "lerr" used to trigger an external aborting function (no STOP).
  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:keywords set to Id
File size: 34.7 KB
Line 
1!$Id: infotrac.F90 4193 2022-07-04 21:45:46Z evignon $
2!
3MODULE infotrac
4
5   USE       strings_mod, ONLY: msg, find, strIdx,  strFind, strParse, dispTable, int2str,  reduceExpr, &
6                          cat, fmsg, test, strTail, strHead, strStack, strReduce, bool2str, maxlen, testFile
7   USE readTracFiles_mod, ONLY: trac_type, readTracersFiles, addPhase, indexUpdate,  nphases, ancestor,  &
8                                isot_type, old2newName,      delPhase,               getKey_init, tran0, &
9                                keys_type, initIsotopes,     getPhase, known_phases, getKey, setGeneration, &
10                                maxTableWidth
11   IMPLICIT NONE
12
13   PRIVATE
14
15   !=== FOR TRACERS:
16   PUBLIC :: infotrac_init                                 !--- Initialization of the tracers
17   PUBLIC :: tracers, type_trac, types_trac                !--- Full tracers database, tracers type keyword
18   PUBLIC :: nqtot,   nbtr,   nqo,   nqCO2,   nqtottr      !--- Main dimensions
19   PUBLIC :: conv_flg, pbl_flg                             !--- Convection & boundary layer activation keys
20
21   !=== FOR ISOTOPES: General
22   PUBLIC :: isotopes,  nbIso                              !--- Derived type, full isotopes families database + nb of families
23   PUBLIC :: isoSelect, ixIso                              !--- Isotopes family selection tool + selected family index
24   !=== FOR ISOTOPES: Specific to water
25   PUBLIC :: iH2O, tnat, alpha_ideal                       !--- H2O isotopes index, natural abundance, fractionning coeff.
26   PUBLIC :: min_qParent, min_qMass, min_ratio             !--- Min. values for various isotopic quantities
27   !=== FOR ISOTOPES: Depending on the selected isotopes family
28   PUBLIC :: isotope, isoKeys                              !--- Selected isotopes database + associated keys (cf. getKey)
29   PUBLIC :: isoName, isoZone, isoPhas                     !--- Isotopes and tagging zones names, phases
30   PUBLIC :: niso,    nzone,   nphas,   ntiso              !---  " " numbers + isotopes & tagging tracers number
31   PUBLIC :: itZonIso                                      !--- idx "it" (in "isoName(1:niso)") = function(tagging idx, isotope idx)
32   PUBLIC :: iqIsoPha                                      !--- idx "iq" (in "qx") = function(isotope idx, phase idx) + aliases
33   PUBLIC :: isoCheck                                      !--- Run isotopes checking routines
34   !=== FOR BOTH TRACERS AND ISOTOPES
35   PUBLIC :: getKey                                        !--- Get a key from "tracers" or "isotope"
36
37   INTERFACE isoSelect; MODULE PROCEDURE isoSelectByIndex, isoSelectByName; END INTERFACE isoSelect
38
39!=== CONVENTIONS FOR TRACERS NUMBERS:
40!  |--------------------+-----------------------+-----------------+---------------+----------------------------|
41!  | water in different |    water tagging      |  water isotopes | other tracers | additional tracers moments |
42!  | phases: H2O_[gls]  |      isotopes         |                 |               |  for higher order schemes  |
43!  |--------------------+-----------------------+-----------------+---------------+----------------------------|
44!  |                    |                       |                 |               |                            |
45!  |<--     nqo      -->|<-- nqo*niso* nzone -->|<-- nqo*niso  -->|<--  nbtr   -->|<--        (nmom)        -->|         
46!  |                    |                                         |                                            |
47!  |                    |<-- nqo*niso*(nzone+1)  =   nqo*ntiso -->|<--    nqtottr = nbtr + nmom             -->|
48!  |                                                                              = nqtot - nqo*(ntiso+1)      |
49!  |                                                                                                           |
50!  |<--                        nqtrue  =  nbtr + nqo*(ntiso+1)                 -->|                            |
51!  |                                                                                                           |
52!  |<--                        nqtot   =  nqtrue + nmom                                                     -->|
53!  |                                                                                                           |
54!  |-----------------------------------------------------------------------------------------------------------|
55!  NOTES FOR THIS TABLE:
56!  * Used "niso", "nzone" and "ntiso" are components of "isotopes(ip)" for water (isotopes(ip)%parent == 'H2O'),
57!    since water is so far the sole tracers family, except passive CO2, removed from the main tracers table.
58!  * For water, "nqo" is equal to the more general field "isotopes(ip)%nphas".
59!  * "niso", "nzone", "ntiso", "nphas" are defined for other isotopic tracers families, if any.
60!
61!=== DERIVED TYPE EMBEDDING MOST OF THE TRACERS-RELATED QUANTITIES (LENGTH: nqtot)
62!    Each entry is accessible using "%" sign.
63!  |-------------+------------------------------------------------------+-------------+------------------------+
64!  |  entry      | Meaning                                              | Former name | Possible values        |
65!  |-------------+------------------------------------------------------+-------------+------------------------+
66!  | name        | Name (short)                                         | tname       |                        |
67!  | gen0Name    | Name of the 1st generation ancestor                  | /           |                        |
68!  | parent      | Name of the parent                                   | /           |                        |
69!  | longName    | Long name (with adv. scheme suffix) for outputs      | ttext       |                        |
70!  | type        | Type (so far: tracer or tag)                         | /           | tracer,tag             |
71!  | phase       | Phases list ("g"as / "l"iquid / "s"olid)             | /           | [g][l][s]              |
72!  | component   | Name(s) of the merged/cumulated section(s)           | /           | coma-separated names   |
73!  | iadv        | Advection scheme number                              | iadv        | 1-20,30 exc. 3-9,15,19 |
74!  | iGeneration | Generation (>=1)                                     | /           |                        |
75!  | isAdvected  | advected tracers flag (.TRUE. if iadv >= 0)          | /           | nqtrue  .TRUE. values  |
76!  | isInPhysics | tracers not extracted from the main table in physics | /           | nqtottr .TRUE. values  |
77!  | iqParent    | Index of the parent tracer                           | iqpere      | 1:nqtot                |
78!  | iqDescen    | Indexes of the childs       (all generations)        | iqfils      | 1:nqtot                |
79!  | nqDescen    | Number of the descendants   (all generations)        | nqdesc      | 1:nqtot                |
80!  | nqChilds    | Number of childs            (1st generation only)    | nqfils      | 1:nqtot                |
81!  | iso_iGroup  | Isotopes group index in isotopes(:)                  | /           | 1:nbIso                |
82!  | iso_iName   | Isotope  name  index in isotopes(iso_iGroup)%trac(:) | iso_indnum  | 1:niso                 |
83!  | iso_iZone   | Isotope  zone  index in isotopes(iso_iGroup)%zone(:) | zone_num    | 1:nzone                |
84!  | iso_iPhas   | Isotope  phase index in isotopes(iso_iGroup)%phas(:) | phase_num   | 1:nphas                |
85!  | keys        | key/val pairs accessible with "getKey" routine       | /           |                        |
86!  +-------------+------------------------------------------------------+-------------+------------------------+
87!
88!=== DERIVED TYPE EMBEDDING MOST OF THE ISOTOPES-RELATED QUANTITIES (LENGTH: nbIso, NUMBER OF ISOTOPES FAMILIES)
89!    Each entry is accessible using "%" sign.
90!  |-----------------+--------------------------------------------------+--------------------+-----------------+
91!  |  entry | length | Meaning                                          |    Former name     | Possible values |
92!  |-----------------+--------------------------------------------------+--------------------+-----------------+
93!  | parent          | Parent tracer (isotopes family name)             |                    |                 |
94!  | keys   | niso   | Isotopes keys/values pairs list + number         |                    |                 |
95!  | trac   | ntiso  | Isotopes + tagging tracers list + number         | / | ntraciso       |                 |
96!  | zone   | nzone  | Geographic tagging zones   list + number         | / | ntraceurs_zone |                 |
97!  | phase  | nphas  | Phases                     list + number         |                    | [g][l][s], 1:3  |
98!  | iqIsoPha        | Index in "qx"           = f(name(1:ntiso)),phas) | iqiso              | 1:nqtot         |
99!  | itZonIso        | Index in "trac(1:ntiso)"= f(zone, name(1:niso))  | index_trac         | 1:ntiso         |
100!  +-----------------+--------------------------------------------------+--------------------+-----------------+
101
102   REAL, PARAMETER :: min_qParent = 1.e-30, min_qMass = 1.e-18, min_ratio = 1.e-16 ! MVals et CRisi
103
104   !=== DIMENSIONS OF THE TRACERS TABLES AND OTHER SCALAR VARIABLES
105   INTEGER,                 SAVE :: nqtot,  &                   !--- Tracers nb in dynamics (incl. higher moments + H2O)
106                                    nbtr,   &                   !--- Tracers nb in physics  (excl. higher moments + H2O)
107                                    nqo,    &                   !--- Number of water phases
108                                    nbIso,  &                   !--- Number of available isotopes family
109                                    nqtottr, &                  !--- Number of tracers passed to phytrac (TO BE DELETED ?)
110                                    nqCO2                       !--- Number of tracers of CO2  (ThL)
111   CHARACTER(LEN=maxlen),   SAVE :: type_trac                   !--- Keyword for tracers type(s)
112   CHARACTER(LEN=maxlen),   SAVE, ALLOCATABLE :: types_trac(:)  !--- Keyword for tracers type(s), parsed version
113
114   !=== DERIVED TYPES EMBEDDING MOST INFORMATIONS ABOUT TRACERS AND ISOTOPES FAMILIES
115   TYPE(trac_type), TARGET, SAVE, ALLOCATABLE ::  tracers(:)    !=== TRACERS DESCRIPTORS VECTOR
116   TYPE(isot_type), TARGET, SAVE, ALLOCATABLE :: isotopes(:)    !=== ISOTOPES PARAMETERS VECTOR
117
118   !=== ALIASES FOR CURRENTLY SELECTED ISOTOPES FAMILY OF VARIABLES EMBEDDED IN THE VECTOR "isotopes"
119   TYPE(isot_type),         SAVE, POINTER :: isotope            !--- CURRENTLY SELECTED ISOTOPES FAMILY DESCRIPTOR
120   INTEGER,                 SAVE          :: ixIso, iH2O        !--- Index of the selected isotopes family and H2O family
121   LOGICAL,                 SAVE          :: isoCheck           !--- Flag to trigger the checking routines
122   TYPE(keys_type),         SAVE, POINTER :: isoKeys(:)         !--- ONE SET OF KEYS FOR EACH ISOTOPE (LISTED IN isoName)
123   CHARACTER(LEN=maxlen),   SAVE, POINTER :: isoName(:),   &    !--- ISOTOPES NAMES FOR THE CURRENTLY SELECTED FAMILY
124                                             isoZone(:),   &    !--- TAGGING ZONES  FOR THE CURRENTLY SELECTED FAMILY
125                                             isoPhas            !--- USED PHASES    FOR THE CURRENTLY SELECTED FAMILY
126   INTEGER,                 SAVE          ::  niso, nzone, &    !--- NUMBER OF ISOTOPES, TAGGING ZONES AND PHASES
127                                             nphas, ntiso       !--- NUMBER OF PHASES AND ISOTOPES + ISOTOPIC TAGGING TRACERS
128   INTEGER,                 SAVE, POINTER ::itZonIso(:,:), &    !--- INDEX IN "isoTrac" AS f(tagging zone idx,  isotope idx)
129                                            iqIsoPha(:,:)       !--- INDEX IN "qx"      AS f(isotopic tracer idx, phase idx)
130
131   !=== VARIABLES FOR ISOTOPES INITIALIZATION AND FOR INCA
132   REAL,                SAVE, ALLOCATABLE ::     tnat(:), &     !--- Natural relative abundance of water isotope        (niso)
133                                          alpha_ideal(:)        !--- Ideal fractionning coefficient (for initial state) (niso)
134   INTEGER,             SAVE, ALLOCATABLE :: conv_flg(:), &     !--- Convection     activation ; needed for INCA        (nbtr)
135                                              pbl_flg(:)        !--- Boundary layer activation ; needed for INCA        (nbtr)
136
137CONTAINS
138
139SUBROUTINE infotrac_init
140   USE control_mod, ONLY: planet_type, config_inca
141#ifdef REPROBUS
142   USE CHEM_REP,    ONLY: Init_chem_rep_trac
143#endif
144   IMPLICIT NONE
145!==============================================================================================================================
146!
147!   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
148!   -------
149!
150!   Modifications:
151!   --------------
152!   05/94: F.Forget      Modif special traceur
153!   02/02: M-A Filiberti Lecture de traceur.def
154!   01/22: D. Cugnet     Nouveaux tracer.def et tracer_*.def + encapsulation (types trac_type et isot_type)
155!
156!   Objet:
157!   ------
158!   GCM LMD nouvelle grille
159!
160!==============================================================================================================================
161!   ... modification de l'integration de q ( 26/04/94 ) ....
162!------------------------------------------------------------------------------------------------------------------------------
163! Declarations:
164   INCLUDE "dimensions.h"
165   INCLUDE "iniprint.h"
166
167!------------------------------------------------------------------------------------------------------------------------------
168! Local variables
169   INTEGER, ALLOCATABLE :: hadv(:), vadv(:)                          !--- Horizontal/vertical transport scheme number
170#ifdef INCA
171   INTEGER, ALLOCATABLE :: had (:), hadv_inca(:), conv_flg_inca(:), &!--- Variables specific to INCA
172                           vad (:), vadv_inca(:),  pbl_flg_inca(:)
173   CHARACTER(LEN=8), ALLOCATABLE :: solsym_inca(:)                   !--- Tracers names for INCA
174   INTEGER :: nqINCA
175#endif
176   CHARACTER(LEN=2)      ::   suff(9)                                !--- Suffixes for schemes of order 3 or 4 (Prather)
177   CHARACTER(LEN=3)      :: descrq(30)                               !--- Advection scheme description tags
178   CHARACTER(LEN=maxlen) :: msg1                                     !--- String for messages
179   INTEGER :: fType                                                  !--- Tracers description file type ; 0: none
180                                                                     !--- 1/2/3: "traceur.def"/"tracer.def"/"tracer_*.def"
181   INTEGER :: nqtrue                                                 !--- Tracers nb from tracer.def (no higher order moments)
182   INTEGER :: iad                                                    !--- Advection scheme number
183   INTEGER :: ic, ip, np, iq, jq, it, nt, im, nm, ix, iz, nz, k      !--- Indexes and temporary variables
184   LOGICAL :: lerr, ll
185   CHARACTER(LEN=1) :: p
186   TYPE(trac_type), ALLOCATABLE, TARGET :: ttr(:)
187   TYPE(trac_type), POINTER             :: t1, t(:)
188   TYPE(isot_type), POINTER             :: iso
189
190   CHARACTER(LEN=maxlen), ALLOCATABLE :: tnom_0(:), tnom_transp(:)   !--- Tracer short name + transporting fluid name
191   CHARACTER(LEN=maxlen)              :: tchaine
192   INTEGER :: ierr
193
194   CHARACTER(LEN=*), PARAMETER :: modname="infotrac_init"
195!------------------------------------------------------------------------------------------------------------------------------
196! Initialization :
197!------------------------------------------------------------------------------------------------------------------------------
198   suff          = ['x ','y ','z ','xx','xy','xz','yy','yz','zz']
199   descrq( 1: 2) = ['LMV','BAK']
200   descrq(10:20) = ['VL1','VLP','FH1','FH2','VLH','   ','PPM','PPS','PPP','   ','SLP']
201   descrq(30)    =  'PRA'
202   
203   CALL msg('type_trac = "'//TRIM(type_trac)//'"', modname)
204   IF(strParse(type_trac, '|', types_trac, n=nt)) CALL abort_gcm(modname,'can''t parse "type_trac = '//TRIM(type_trac)//'"',1)
205
206   !---------------------------------------------------------------------------------------------------------------------------
207   DO it = 1, nt                                                          !--- nt>1=> "type_trac": coma-separated keywords list
208   !---------------------------------------------------------------------------------------------------------------------------
209      !--- MESSAGE ABOUT THE CHOSEN CONFIGURATION
210      msg1 = 'For type_trac = "'//TRIM(types_trac(it))//'":'
211      SELECT CASE(types_trac(it))
212         CASE('inca'); CALL msg(TRIM(msg1)//' coupling with INCA chemistry model, config_inca='//config_inca, modname)
213         CASE('inco'); CALL msg(TRIM(msg1)//' coupling jointly with INCA and CO2 cycle',  modname)
214         CASE('repr'); CALL msg(TRIM(msg1)//' coupling with REPROBUS chemistry model',    modname)
215         CASE('co2i'); CALL msg(TRIM(msg1)//' you have chosen to run with CO2 cycle',     modname)
216         CASE('coag'); CALL msg(TRIM(msg1)//' tracers are treated for COAGULATION tests', modname)
217         CASE('lmdz'); CALL msg(TRIM(msg1)//' tracers are treated in LMDZ only',          modname)
218         CASE DEFAULT; CALL abort_gcm(modname,'type_trac='//TRIM(types_trac(it))//' not possible yet.',1)
219      END SELECT
220
221      !--- COHERENCE TEST BETWEEN "type_trac" AND "config_inca"
222      IF(ANY(['inca', 'inco'] == types_trac(it)) .AND. ALL(['aero', 'aeNP', 'chem'] /= config_inca)) &
223         CALL abort_gcm(modname, 'Incoherence between type_trac and config_inca. Please modify "run.def"',1)
224
225      !--- COHERENCE TEST BETWEEN "type_trac" AND PREPROCESSING KEYS
226      SELECT CASE(types_trac(it))
227         CASE('inca', 'inco')
228#ifndef INCA
229            CALL abort_gcm(modname, 'You must add cpp key INCA and compile with INCA code', 1)
230#endif
231         CASE('repr')
232#ifndef REPROBUS
233            CALL abort_gcm(modname, 'You must add cpp key REPROBUS and compile with REPROBUS code', 1)
234#endif
235         CASE('coag')
236#ifndef CPP_StratAer
237            CALL abort_gcm(modname, 'You must add cpp key StratAer and compile with StratAer code', 1)
238#endif
239      END SELECT
240
241   !---------------------------------------------------------------------------------------------------------------------------
242   END DO
243   !---------------------------------------------------------------------------------------------------------------------------
244
245   !--- DISABLE "config_inca" OPTION FOR A RUN WITHOUT "INCA" IF IT DIFFERS FROM "none"
246   IF(fmsg('Setting config_inca="none" as you do not couple with INCA model', &
247         modname, ALL(types_trac /= 'inca') .AND. ALL(types_trac /= 'inco') .AND. config_inca /= 'none')) config_inca = 'none'
248
249   nqCO2 = 0; IF(ANY(types_trac == 'inco')) nqCO2 = 1
250
251!==============================================================================================================================
252! 1) Get the numbers of: true (first order only) tracers "nqtrue", water tracers "nqo" (vapor/liquid/solid)
253!==============================================================================================================================
254   IF(readTracersFiles(type_trac, fType, tracers)) CALL abort_gcm(modname, 'problem with tracers file(s)',1)
255   IF(fType == 0) CALL abort_gcm(modname, 'Missing tracers file: "traceur.def", "tracer.def" or "tracer_<keyword>.def file.',1)
256   !---------------------------------------------------------------------------------------------------------------------------
257   IF(fType == 1 .AND. ANY(['inca','inco'] == type_trac)) THEN       !=== FOUND OLD STYLE INCA "traceur.def" (single type_trac)
258   !---------------------------------------------------------------------------------------------------------------------------
259#ifdef INCA
260      nqo = SIZE(tracers)
261      IF(nqCO2==1 .AND. nqo==4) nqo = 3                              !--- Force nqo to 3 (ThL)
262      CALL Init_chem_inca_trac(nqINCA)                               !--- Get nqINCA from INCA
263      nbtr = nqINCA + nqCO2                                          !--- Number of tracers passed to phytrac
264      nqtrue = nbtr + nqo                                            !--- Total number of "true" tracers
265      IF(ALL([2,3] /= nqo)) CALL abort_gcm(modname, 'Only 2 or 3 water phases allowed ; found nqo='//TRIM(int2str(nqo)), 1)
266      ALLOCATE(hadv(nqtrue), hadv_inca(nqINCA), conv_flg_inca(nqINCA), solsym_inca(nqINCA))
267      ALLOCATE(vadv(nqtrue), vadv_inca(nqINCA),  pbl_flg_inca(nqINCA))
268      CALL init_transport(solsym_inca, conv_flg_inca, pbl_flg_inca, hadv_inca, vadv_inca)
269      ALLOCATE(ttr(nqtrue))
270      ttr(1:nqo+nqCO2)                    = tracers
271      ttr(1    :      nqo   )%component   = 'lmdz'
272      ttr(1+nqo:nqCO2+nqo   )%component   = 'co2i'
273      ttr(1+nqo+nqCO2:nqtrue)%component   = 'inca'
274      ttr(1+nqo      :nqtrue)%name        = [('CO2     ', k=1, nqCO2), solsym_inca]
275      ttr(1+nqo+nqCO2:nqtrue)%parent      = tran0
276      ttr(1+nqo+nqCO2:nqtrue)%phase       = 'g'
277      lerr = getKey('hadv', had, ky=tracers(:)%keys)
278      lerr = getKey('vadv', vad, ky=tracers(:)%keys)
279      hadv(1:nqo) = had(:); hadv(nqo+1:nqtrue) = hadv_inca
280      vadv(1:nqo) = vad(:); vadv(nqo+1:nqtrue) = vadv_inca
281      CALL MOVE_ALLOC(FROM=ttr, TO=tracers)
282      CALL setGeneration(tracers)                                    !--- SET FIELDS %iGeneration, %gen0Name
283      DEALLOCATE(had, hadv_inca, vad, vadv_inca, conv_flg_inca, pbl_flg_inca, solsym_inca)
284#endif
285   !---------------------------------------------------------------------------------------------------------------------------
286   ELSE                                                              !=== FOUND NEW STYLE TRACERS CONFIGURATION FILE(S)
287   !---------------------------------------------------------------------------------------------------------------------------
288      nqo    =        COUNT(delPhase(tracers(:)%name)     == 'H2O' &
289                               .AND. tracers(:)%component == 'lmdz') !--- Number of water phases
290      nqtrue = SIZE(tracers)                                         !--- Total number of "true" tracers
291      nbtr   = nqtrue-COUNT(delPhase(tracers(:)%gen0Name) == 'H2O' &
292                               .AND. tracers(:)%component == 'lmdz') !--- Number of tracers passed to phytrac
293#ifdef INCA
294      nqINCA = COUNT(tracers(:)%component == 'inca')
295#endif
296      lerr = getKey('hadv', hadv, ky=tracers(:)%keys)
297      lerr = getKey('vadv', vadv, ky=tracers(:)%keys)
298   !---------------------------------------------------------------------------------------------------------------------------
299   END IF
300   !---------------------------------------------------------------------------------------------------------------------------
301
302   CALL getKey_init(tracers)
303
304   !--- Transfert the number of tracers to Reprobus
305#ifdef REPROBUS
306   CALL Init_chem_rep_trac(nbtr, nqo, tracers(:)%name)
307#endif
308
309!==============================================================================================================================
310! 2) Calculate nqtot, number of tracers needed (greater if advection schemes 20 or 30 have been chosen).
311!==============================================================================================================================
312   DO iq = 1, nqtrue
313      IF( hadv(iq)<20 .OR. (ANY(hadv(iq)==[20,30]) .AND. hadv(iq)==vadv(iq)) ) CYCLE
314      WRITE(msg1,'("The choice hadv=",i0,", vadv=",i0,a)')hadv(iq),vadv(iq),' for "'//TRIM(tracers(iq)%name)//'" is not available'
315      CALL abort_gcm(modname, TRIM(msg1), 1)
316   END DO
317   nqtot =    COUNT( hadv< 20 .AND. vadv< 20 ) &                     !--- No additional tracer
318         +  4*COUNT( hadv==20 .AND. vadv==20 ) &                     !--- 3  additional tracers
319         + 10*COUNT( hadv==30 .AND. vadv==30 )                       !--- 9  additional tracers
320
321   !--- More tracers due to the choice of advection scheme => assign total number of tracers
322   IF( nqtot /= nqtrue ) THEN
323      CALL msg('The choice of advection scheme for one or more tracers makes it necessary to add tracers')
324      CALL msg('The number of true tracers is '//TRIM(int2str(nqtrue)))
325      CALL msg('The total number of tracers needed is '//TRIM(int2str(nqtot)))
326   END IF
327
328!==============================================================================================================================
329! 3) Determine the advection scheme choice for water and tracers "iadv" and the fields long name, isAdvected.
330!     iadv = 1    "LMDZ-specific humidity transport" (for H2O vapour)          LMV
331!     iadv = 2    backward                           (for H2O liquid)          BAK
332!     iadv = 14   Van-Leer + specific humidity, modified by Francis Codron     VLH
333!     iadv = 10   Van-Leer (chosen for vapour and liquid water)                VL1
334!     iadv = 11   Van-Leer for hadv and PPM version (Monotonic) for vadv       VLP
335!     iadv = 12   Frederic Hourdin I                                           FH1
336!     iadv = 13   Frederic Hourdin II                                          FH2
337!     iadv = 16   Monotonic         PPM (Collela & Woodward 1984)              PPM
338!     iadv = 17   Semi-monotonic    PPM (overshoots allowed)                   PPS
339!     iadv = 18   Definite positive PPM (overshoots and undershoots allowed)   PPP
340!     iadv = 20   Slopes                                                       SLP
341!     iadv = 30   Prather                                                      PRA
342!
343!        In array q(ij,l,iq) : iq = 1/2[/3]    for vapour/liquid[/ice] water
344!        And optionaly:        iq = 3[4],nqtot for other tracers
345!==============================================================================================================================
346   ALLOCATE(ttr(nqtot))
347   jq = nqtrue+1; tracers(:)%iadv = -1
348   DO iq = 1, nqtrue
349      t1 => tracers(iq)
350
351      !--- VERIFY THE CHOICE OF ADVECTION SCHEME
352      iad = -1
353      IF(hadv(iq)     ==    vadv(iq)    ) iad = hadv(iq)
354      IF(hadv(iq)==10 .AND. vadv(iq)==16) iad = 11
355      WRITE(msg1,'("Bad choice of advection scheme for ",a,": hadv = ",i0,", vadv = ",i0)')TRIM(t1%name), hadv(iq), vadv(iq)
356      IF(iad == -1) CALL abort_gcm(modname, msg1, 1)
357
358      !--- SET FIELDS %longName, %iadv, %isAdvected, %isInPhysics
359      t1%longName   = t1%name; IF(iad > 0) t1%longName=TRIM(t1%name)//descrq(iad)
360      t1%iadv       = iad
361      t1%isAdvected = iad >= 0
362      t1%isInPhysics= delPhase(t1%gen0Name) /= 'H2O' &
363                          .OR. t1%component /= 'lmdz' !=== OTHER EXCEPTIONS TO BE ADDED: CO2i, SURSATURATED WATER CLOUD...
364      ttr(iq)       = t1
365
366      !--- DEFINE THE HIGHER ORDER TRACERS, IF ANY
367      nm = 0
368      IF(iad == 20) nm = 3                                           !--- 2nd order scheme
369      IF(iad == 30) nm = 9                                           !--- 3rd order scheme
370      IF(nm == 0) CYCLE                                              !--- No higher moments
371      ttr(jq+1:jq+nm)             = t1
372      ttr(jq+1:jq+nm)%name        = [(TRIM(t1%name)    //'-'//TRIM(suff(im)), im=1, nm) ]
373      ttr(jq+1:jq+nm)%parent      = [(TRIM(t1%parent)  //'-'//TRIM(suff(im)), im=1, nm) ]
374      ttr(jq+1:jq+nm)%longName    = [(TRIM(t1%longName)//'-'//TRIM(suff(im)), im=1, nm) ]
375      ttr(jq+1:jq+nm)%iadv        = [(-iad,    im=1, nm) ]
376      ttr(jq+1:jq+nm)%isAdvected  = [(.FALSE., im=1, nm) ]
377      jq = jq + nm
378   END DO
379   DEALLOCATE(hadv, vadv)
380   CALL MOVE_ALLOC(FROM=ttr, TO=tracers)
381
382   !--- SET FIELDS %iqParent, %nqChilds, %iGeneration, %iqDescen, %nqDescen
383   CALL indexUpdate(tracers)
384
385   !=== TEST ADVECTION SCHEME
386   DO iq=1,nqtot ; t1 => tracers(iq); iad = t1%iadv
387
388      !--- ONLY TESTED VALUES FOR TRACERS FOR NOW:               iadv = 14, 10 (and 0 for non-transported tracers)
389      IF(ALL([10,14,0] /= iad)) &
390         CALL abort_gcm(modname, 'Not tested for iadv='//TRIM(int2str(iad))//' ; 10 or 14 only are allowed !', 1)
391
392      !--- ONLY TESTED VALUES FOR PARENTS HAVING CHILDS FOR NOW: iadv = 14, 10 (PARENTS: TRACERS OF GENERATION 1)
393      IF(ALL([10,14] /= iad) .AND. t1%iGeneration == 1 .AND. ANY(tracers(:)%iGeneration > 1)) &
394         CALL abort_gcm(modname, 'iadv='//TRIM(int2str(iad))//' not implemented for parents ; 10 or 14 only are allowed !', 1)
395
396      !--- ONLY TESTED VALUES FOR CHILDS FOR NOW:                iadv = 10     (CHILDS:  TRACERS OF GENERATION GREATER THAN 1)
397      IF(fmsg('WARNING ! iadv='//TRIM(int2str(iad))//' not implemented for childs. Setting iadv=10 for "'//TRIM(t1%name)//'"',&
398         modname, iad /= 10 .AND. t1%iGeneration > 1)) t1%iadv = 10
399
400      !--- ONLY VALID SCHEME NUMBER FOR WATER VAPOUR:            iadv = 14
401      ll = t1%name /= addPhase('H2O','g')
402      IF(fmsg('WARNING ! iadv=14 is valid for water vapour only. Setting iadv=10 for "'//TRIM(t1%name)//'".', &
403         modname, iad == 14 .AND. ll))                 t1%iadv = 10
404   END DO
405
406   niso = 0; nzone=0; nphas=nqo; ntiso = 0; isoCheck=.FALSE.
407   IF(initIsotopes(tracers, isotopes)) CALL abort_gcm(modname, 'Problem when reading isotopes parameters', 1)
408   nbIso = SIZE(isotopes)
409   nqtottr = nqtot - COUNT(tracers%gen0Name == 'H2O' .AND. tracers%component == 'lmdz')
410   IF(nbIso/=0) THEN                        !--- ISOTOPES FOUND
411
412      !=== READ PHYSICAL PARAMETERS FROM "isotopes_params.def" FILE SPECIFIC TO WATER ISOTOPES
413      !    DONE HERE, AND NOT ONLY IN "infotrac_phy", BECAUSE SOME PHYSICAL PARAMS ARE NEEDED FOR RESTARTS (tnat, alpha_ideal)
414      CALL getKey_init(tracers, isotopes)
415      IF(isoSelect('H2O')) RETURN           !--- Select water isotopes ; finished if no water isotopes
416      iH2O = ixIso                          !--- Keep track of water family index
417      IF(getKey('tnat' , tnat,        isoName(1:niso))) CALL abort_gcm(modname, 'can''t read "tnat"', 1)
418      IF(getKey('alpha', alpha_ideal, isoName(1:niso))) CALL abort_gcm(modname, 'can''t read "alpha_ideal"', 1)
419
420      !=== MAKE SURE THE MEMBERS OF AN ISOTOPES FAMILY ARE PRESENT IN THE SAME PHASES
421      DO ix = 1, nbIso
422         iso => isotopes(ix)
423         !--- Check whether each isotope and tagging isotopic tracer is present in the same number of phases
424         DO it = 1, iso%ntiso
425            np = SUM([(COUNT(tracers(:)%name == addPhase(iso%trac(it), iso%phase(ip:ip))), ip=1, iso%nphas)])
426            IF(np == iso%nphas) CYCLE
427            WRITE(msg1,'("Found ",i0," phases for ",a," instead of ",i0)')np, TRIM(iso%trac(it)), iso%nphas
428            CALL abort_gcm(modname, msg1, 1)
429         END DO
430         DO it = 1, iso%niso
431            nz = SUM([(COUNT(iso%trac == TRIM(iso%trac(it))//'_'//iso%zone(iz)), iz=1, iso%nzone)])
432            IF(nz == iso%nzone) CYCLE
433            WRITE(msg1,'("Found ",i0," tagging zones for ",a," instead of ",i0)')nz, TRIM(iso%trac(it)), iso%nzone
434            CALL abort_gcm(modname, msg1, 1)
435         END DO
436      END DO
437   END IF
438
439   !--- Convection / boundary layer activation for all tracers
440   ALLOCATE(conv_flg(nbtr)); conv_flg(1:nbtr) = 1
441   ALLOCATE( pbl_flg(nbtr));  pbl_flg(1:nbtr) = 1
442
443   !--- Note: nqtottr can differ from nbtr when nmom/=0
444!   IF(COUNT(tracers%iso_iName == 0) - COUNT(delPhase(tracers%name) == 'H2O' .AND. tracers%component == 'lmdz') /= nqtottr) &
445!      CALL abort_gcm('infotrac_init', 'pb dans le calcul de nqtottr', 1)
446
447   !=== DISPLAY THE RESULTS
448   CALL msg('nqo    = '//TRIM(int2str(nqo)),    modname)
449   CALL msg('nbtr   = '//TRIM(int2str(nbtr)),   modname)
450   CALL msg('nqtrue = '//TRIM(int2str(nqtrue)), modname)
451   CALL msg('nqtot  = '//TRIM(int2str(nqtot)),  modname)
452   CALL msg('niso   = '//TRIM(int2str(niso)),   modname)
453   CALL msg('ntiso  = '//TRIM(int2str(ntiso)),  modname)
454#ifdef INCA
455   CALL msg('nqCO2  = '//TRIM(int2str(nqCO2)),  modname)
456   CALL msg('nqINCA = '//TRIM(int2str(nqINCA)), modname)
457#endif
458   t => tracers
459   CALL msg('Information stored in infotrac :', modname)
460   IF(dispTable('isssssssssiiiiiiiii', &
461      ['iq    ', 'name  ', 'lName ', 'gen0N ', 'parent', 'type  ', 'phase ', 'compon', 'isAdv ', 'isPhy ', &
462       'iadv  ', 'iGen  ', 'iqPar ', 'nqDes ', 'nqChld', 'iGroup', 'iName ', 'iZone ', 'iPhase'],          &
463      cat(t%name, t%longName, t%gen0Name, t%parent, t%type, t%phase, t%component, bool2str(t%isAdvected),  &
464                                                                                  bool2str(t%isInPhysics)),&
465      cat([(iq, iq=1, nqtot)], t%iadv, t%iGeneration, t%iqParent, t%nqDescen, t%nqChilds, t%iso_iGroup,    &
466                  t%iso_iName, t%iso_iZone, t%iso_iPhase), nColMax=maxTableWidth, nHead=2, sub=modname))   &
467      CALL abort_gcm(modname, "problem with the tracers table content", 1)
468   IF(niso > 0) THEN
469      CALL msg('Where, for isotopes family "'//TRIM(isotope%parent)//'":', modname)
470      CALL msg('  isoKeys = '//strStack(isoKeys%name), modname)
471      CALL msg('  isoName = '//strStack(isoName),      modname)
472      CALL msg('  isoZone = '//strStack(isoZone),      modname)
473      CALL msg('  isoPhas = '//TRIM(isoPhas),          modname)
474   ELSE
475      CALL msg('No isotopes identified.', modname)
476   END IF
477   CALL msg('end', modname)
478
479END SUBROUTINE infotrac_init
480
481
482!==============================================================================================================================
483!=== THE ROUTINE isoSelect IS USED TO SWITCH FROM AN ISOTOPE FAMILY TO ANOTHER: ISOTOPES DEPENDENT PARAMETERS ARE UPDATED
484!     Single generic "isoSelect" routine, using the predefined index of the parent (fast version) or its name (first call).
485!==============================================================================================================================
486LOGICAL FUNCTION isoSelectByName(iName, lVerbose) RESULT(lerr)
487   IMPLICIT NONE
488   CHARACTER(LEN=*),  INTENT(IN)  :: iName
489   LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose
490   INTEGER :: iIso
491   LOGICAL :: lV
492   lV = .FALSE.; IF(PRESENT(lVerbose)) lV = lVerbose
493   iIso = strIdx(isotopes(:)%parent, iName)
494   lerr = iIso == 0
495   IF(lerr) THEN
496      niso = 0; ntiso = 0; nzone=0; nphas=nqo; isoCheck=.FALSE.
497      CALL msg('no isotope family named "'//TRIM(iName)//'"', ll=lV)
498      RETURN
499   END IF
500   lerr = isoSelectByIndex(iIso, lV)
501END FUNCTION isoSelectByName
502!==============================================================================================================================
503LOGICAL FUNCTION isoSelectByIndex(iIso, lVerbose) RESULT(lerr)
504   IMPLICIT NONE
505   INTEGER,           INTENT(IN) :: iIso
506   LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose
507   LOGICAL :: lv
508   lv = .FALSE.; IF(PRESENT(lVerbose)) lv = lVerbose
509   lerr = .FALSE.
510   IF(iIso == ixIso) RETURN                                          !--- Nothing to do if the index is already OK
511   lerr = iIso<=0 .OR. iIso>nbIso
512   CALL msg('Inconsistent isotopes family index '//TRIM(int2str(iIso))//': should be > 0 and <= '//TRIM(int2str(nbIso))//'"',&
513            ll=lerr .AND. lV)
514   IF(lerr) RETURN
515   ixIso = iIso                                                      !--- Update currently selected family index
516   isotope  => isotopes(ixIso)                                       !--- Select corresponding component
517   isoKeys  => isotope%keys;     niso     = isotope%niso
518   isoName  => isotope%trac;     ntiso    = isotope%ntiso
519   isoZone  => isotope%zone;     nzone    = isotope%nzone
520   isoPhas  => isotope%phase;    nphas    = isotope%nphas
521   itZonIso => isotope%itZonIso; isoCheck = isotope%check
522   iqIsoPha => isotope%iqIsoPha
523END FUNCTION isoSelectByIndex
524!==============================================================================================================================
525
526END MODULE infotrac
Note: See TracBrowser for help on using the repository browser.