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

Last change on this file since 4154 was 4154, checked in by dcugnet, 2 years ago

Fixes needed because gfortran is not as permissive as ifort is with scalar pointers.

  • 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: 46.8 KB
Line 
1!$Id: infotrac.F90 4154 2022-05-18 13:56:49Z dcugnet $
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   IMPLICIT NONE
11
12   PRIVATE
13
14   !=== FOR TRACERS:
15   PUBLIC :: infotrac_init                                 !--- Initialization of the tracers
16   PUBLIC :: tracers, type_trac                            !--- Full tracers database, tracers type keyword
17   PUBLIC :: nqtot,   nbtr,   nqo,   nqCO2,   nqtottr      !--- Main dimensions
18   PUBLIC :: conv_flg, pbl_flg                             !--- Convection & boundary layer activation keys
19
20   !=== FOR ISOTOPES: General
21   PUBLIC :: isotopes,  nbIso                              !--- Derived type, full isotopes families database + nb of families
22   PUBLIC :: isoSelect, ixIso                              !--- Isotopes family selection tool + selected family index
23   !=== FOR ISOTOPES: Specific to water
24   PUBLIC :: iH2O, tnat, alpha_ideal                       !--- H2O isotopes index, natural abundance, fractionning coeff.
25   PUBLIC :: min_qParent, min_qMass, min_ratio             !--- Min. values for various isotopic quantities
26   !=== FOR ISOTOPES: Depending on the selected isotopes family
27   PUBLIC :: isotope, isoKeys                              !--- Selected isotopes database + associated keys (cf. getKey)
28   PUBLIC :: isoName, isoZone, isoPhas                     !--- Isotopes and tagging zones names, phases
29   PUBLIC :: niso,    nzone,   nphas,   ntiso              !---  " " numbers + isotopes & tagging tracers number
30   PUBLIC :: itZonIso                                      !--- idx "it" (in "isoName(1:niso)") = function(tagging idx, isotope idx)
31   PUBLIC :: iqIsoPha                                      !--- idx "iq" (in "qx") = function(isotope idx, phase idx) + aliases
32   PUBLIC :: isoCheck                                      !--- Run isotopes checking routines
33   !=== FOR BOTH TRACERS AND ISOTOPES
34   PUBLIC :: getKey                                        !--- Get a key from "tracers" or "isotope"
35
36   INTERFACE isoSelect; MODULE PROCEDURE isoSelectByIndex, isoSelectByName; END INTERFACE isoSelect
37
38!=== CONVENTIONS FOR TRACERS NUMBERS:
39!  |--------------------+-----------------------+-----------------+---------------+----------------------------|
40!  | water in different |    water tagging      |  water isotopes | other tracers | additional tracers moments |
41!  | phases: H2O_[gls]  |      isotopes         |                 |               |  for higher order schemes  |
42!  |--------------------+-----------------------+-----------------+---------------+----------------------------|
43!  |                    |                       |                 |               |                            |
44!  |<--     nqo      -->|<-- nqo*niso* nzone -->|<-- nqo*niso  -->|<--  nbtr   -->|<--        (nmom)        -->|         
45!  |                    |                                         |                                            |
46!  |                    |<-- nqo*niso*(nzone+1)  =   nqo*ntiso -->|<--    nqtottr = nbtr + nmom             -->|
47!  |                                                                              = nqtot - nqo*(ntiso+1)      |
48!  |                                                                                                           |
49!  |<--                        nqtrue  =  nbtr + nqo*(ntiso+1)                 -->|                            |
50!  |                                                                                                           |
51!  |<--                        nqtot   =  nqtrue + nmom                                                     -->|
52!  |                                                                                                           |
53!  |-----------------------------------------------------------------------------------------------------------|
54!  NOTES FOR THIS TABLE:
55!  * Used "niso", "nzone" and "ntiso" are components of "isotopes(ip)" for water (isotopes(ip)%parent == 'H2O'),
56!    since water is so far the sole tracers family, except passive CO2, removed from the main tracers table.
57!  * For water, "nqo" is equal to the more general field "isotopes(ip)%nphas".
58!  * "niso", "nzone", "ntiso", "nphas" are defined for other isotopic tracers families, if any.
59!
60!=== DERIVED TYPE EMBEDDING MOST OF THE TRACERS-RELATED QUANTITIES (LENGTH: nqtot)
61!    Each entry is accessible using "%" sign.
62!  |-------------+------------------------------------------------------+-------------+------------------------+
63!  |  entry      | Meaning                                              | Former name | Possible values        |
64!  |-------------+------------------------------------------------------+-------------+------------------------+
65!  | name        | Name (short)                                         | tname       |                        |
66!  | gen0Name    | Name of the 1st generation ancestor                  | /           |                        |
67!  | parent      | Name of the parent                                   | /           |                        |
68!  | longName    | Long name (with adv. scheme suffix) for outputs      | ttext       |                        |
69!  | type        | Type (so far: tracer or tag)                         | /           | tracer,tag             |
70!  | phase       | Phases list ("g"as / "l"iquid / "s"olid)             | /           | [g][l][s]              |
71!  | component   | Name(s) of the merged/cumulated section(s)           | /           | coma-separated names   |
72!  | iadv        | Advection scheme number                              | iadv        | 1-20,30 exc. 3-9,15,19 |
73!  | iGeneration | Generation (>=1)                                     | /           |                        |
74!  | isAdvected  | advected tracers flag (.TRUE. if iadv >= 0)          | /           | nqtrue  .TRUE. values  |
75!  | isInPhysics | tracers not extracted from the main table in physics | /           | nqtottr .TRUE. values  |
76!  | iqParent    | Index of the parent tracer                           | iqpere      | 1:nqtot                |
77!  | iqDescen    | Indexes of the childs       (all generations)        | iqfils      | 1:nqtot                |
78!  | nqDescen    | Number of the descendants   (all generations)        | nqdesc      | 1:nqtot                |
79!  | nqChilds    | Number of childs            (1st generation only)    | nqfils      | 1:nqtot                |
80!  | iso_iGroup  | Isotopes group index in isotopes(:)                  | /           | 1:nbIso                |
81!  | iso_iName   | Isotope  name  index in isotopes(iso_iGroup)%trac(:) | iso_indnum  | 1:niso                 |
82!  | iso_iZone   | Isotope  zone  index in isotopes(iso_iGroup)%zone(:) | zone_num    | 1:nzone                |
83!  | iso_iPhas   | Isotope  phase index in isotopes(iso_iGroup)%phas(:) | phase_num   | 1:nphas                |
84!  | keys        | key/val pairs accessible with "getKey" routine       | /           |                        |
85!  +-------------+------------------------------------------------------+-------------+------------------------+
86!
87!=== DERIVED TYPE EMBEDDING MOST OF THE ISOTOPES-RELATED QUANTITIES (LENGTH: nbIso, NUMBER OF ISOTOPES FAMILIES)
88!    Each entry is accessible using "%" sign.
89!  |-----------------+--------------------------------------------------+--------------------+-----------------+
90!  |  entry | length | Meaning                                          |    Former name     | Possible values |
91!  |-----------------+--------------------------------------------------+--------------------+-----------------+
92!  | parent          | Parent tracer (isotopes family name)             |                    |                 |
93!  | keys   | niso   | Isotopes keys/values pairs list + number         |                    |                 |
94!  | trac   | ntiso  | Isotopes + tagging tracers list + number         | / | ntraciso       |                 |
95!  | zone   | nzone  | Geographic tagging zones   list + number         | / | ntraceurs_zone |                 |
96!  | phase  | nphas  | Phases                     list + number         |                    | [g][l][s], 1:3  |
97!  | iqIsoPha        | Index in "qx"           = f(name(1:ntiso)),phas) | iqiso              | 1:nqtot         |
98!  | itZonIso        | Index in "trac(1:ntiso)"= f(zone, name(1:niso))  | index_trac         | 1:ntiso         |
99!  +-----------------+--------------------------------------------------+--------------------+-----------------+
100
101   REAL, PARAMETER :: min_qParent = 1.e-30, min_qMass = 1.e-18, min_ratio = 1.e-16 ! MVals et CRisi
102
103   !=== DIMENSIONS OF THE TRACERS TABLES AND OTHER SCALAR VARIABLES
104   INTEGER,                 SAVE :: nqtot,  &                   !--- Tracers nb in dynamics (incl. higher moments + H2O)
105                                    nbtr,   &                   !--- Tracers nb in physics  (excl. higher moments + H2O)
106                                    nqo,    &                   !--- Number of water phases
107                                    nbIso,  &                   !--- Number of available isotopes family
108                                    nqtottr, &                  !--- Number of tracers passed to phytrac (TO BE DELETED ?)
109                                    nqCO2                       !--- Number of tracers of CO2  (ThL)
110   CHARACTER(LEN=maxlen),   SAVE :: type_trac                   !--- Keyword for tracers type
111
112   !=== DERIVED TYPES EMBEDDING MOST INFORMATIONS ABOUT TRACERS AND ISOTOPES FAMILIES
113   TYPE(trac_type), TARGET, SAVE, ALLOCATABLE ::  tracers(:)    !=== TRACERS DESCRIPTORS VECTOR
114   TYPE(isot_type), TARGET, SAVE, ALLOCATABLE :: isotopes(:)    !=== ISOTOPES PARAMETERS VECTOR
115
116   !=== ALIASES FOR CURRENTLY SELECTED ISOTOPES FAMILY OF VARIABLES EMBEDDED IN THE VECTOR "isotopes"
117   TYPE(isot_type),         SAVE, POINTER :: isotope            !--- CURRENTLY SELECTED ISOTOPES FAMILY DESCRIPTOR
118   INTEGER,                 SAVE          :: ixIso, iH2O        !--- Index of the selected isotopes family and H2O family
119   LOGICAL,                 SAVE          :: isoCheck           !--- Flag to trigger the checking routines
120   TYPE(keys_type),         SAVE, POINTER :: isoKeys(:)         !--- ONE SET OF KEYS FOR EACH ISOTOPE (LISTED IN isoName)
121   CHARACTER(LEN=maxlen),   SAVE, POINTER :: isoName(:),   &    !--- ISOTOPES NAMES FOR THE CURRENTLY SELECTED FAMILY
122                                             isoZone(:),   &    !--- TAGGING ZONES  FOR THE CURRENTLY SELECTED FAMILY
123                                             isoPhas            !--- USED PHASES    FOR THE CURRENTLY SELECTED FAMILY
124   INTEGER,                 SAVE          ::  niso, nzone, &    !--- NUMBER OF ISOTOPES, TAGGING ZONES AND PHASES
125                                             nphas, ntiso       !--- NUMBER OF PHASES AND ISOTOPES + ISOTOPIC TAGGING TRACERS
126   INTEGER,                 SAVE, POINTER ::itZonIso(:,:), &    !--- INDEX IN "isoTrac" AS f(tagging zone idx,  isotope idx)
127                                            iqIsoPha(:,:)       !--- INDEX IN "qx"      AS f(isotopic tracer idx, phase idx)
128
129   !=== VARIABLES FOR ISOTOPES INITIALIZATION AND FOR INCA
130   REAL,                SAVE, ALLOCATABLE ::     tnat(:), &     !--- Natural relative abundance of water isotope        (niso)
131                                          alpha_ideal(:)        !--- Ideal fractionning coefficient (for initial state) (niso)
132   INTEGER,             SAVE, ALLOCATABLE :: conv_flg(:), &     !--- Convection     activation ; needed for INCA        (nbtr)
133                                              pbl_flg(:)        !--- Boundary layer activation ; needed for INCA        (nbtr)
134   LOGICAL, PARAMETER :: lOldCode = .FALSE.
135
136CONTAINS
137
138SUBROUTINE infotrac_init
139   USE control_mod, ONLY: planet_type, config_inca
140#ifdef REPROBUS
141   USE CHEM_REP,    ONLY: Init_chem_rep_trac
142#endif
143   IMPLICIT NONE
144!==============================================================================================================================
145!
146!   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
147!   -------
148!
149!   Modifications:
150!   --------------
151!   05/94: F.Forget      Modif special traceur
152!   02/02: M-A Filiberti Lecture de traceur.def
153!   01/22: D. Cugnet     Nouveaux tracer.def et tracer_*.def + encapsulation (types trac_type et isot_type)
154!
155!   Objet:
156!   ------
157!   GCM LMD nouvelle grille
158!
159!==============================================================================================================================
160!   ... modification de l'integration de q ( 26/04/94 ) ....
161!------------------------------------------------------------------------------------------------------------------------------
162! Declarations:
163   INCLUDE "dimensions.h"
164   INCLUDE "iniprint.h"
165
166!------------------------------------------------------------------------------------------------------------------------------
167! Local variables
168   INTEGER, ALLOCATABLE :: hadv(:), vadv(:)                          !--- Horizontal/vertical transport scheme number
169#ifdef INCA
170   INTEGER, ALLOCATABLE :: had (:), hadv_inca(:), conv_flg_inca(:), &!--- Variables specific to INCA
171                           vad (:), vadv_inca(:),  pbl_flg_inca(:)
172   CHARACTER(LEN=8), ALLOCATABLE :: solsym_inca(:)                   !--- Tracers names for INCA
173   INTEGER :: nqINCA
174#endif
175   CHARACTER(LEN=2)      ::   suff(9)                                !--- Suffixes for schemes of order 3 or 4 (Prather)
176   CHARACTER(LEN=3)      :: descrq(30)                               !--- Advection scheme description tags
177   CHARACTER(LEN=maxlen) :: msg1                                     !--- String for messages
178   CHARACTER(LEN=maxlen), ALLOCATABLE :: str(:)                      !--- Temporary storage
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(lOldCode) THEN
205      str = [type_trac]; nt = 1
206   ELSE
207      IF(strParse(type_trac, ',', str, n=nt)) CALL abort_gcm(modname,'can''t parse "type_trac = '//TRIM(type_trac)//'"',1)
208   END IF
209
210   !---------------------------------------------------------------------------------------------------------------------------
211   DO it = 1, nt                                                          !--- nt>1=> "type_trac": coma-separated keywords list
212   !---------------------------------------------------------------------------------------------------------------------------
213      !--- MESSAGE ABOUT THE CHOSEN CONFIGURATION
214      msg1 = 'For type_trac = "'//TRIM(str(it))//'":'
215      SELECT CASE(str(it))
216         CASE('inca'); CALL msg(TRIM(msg1)//' coupling with INCA chemistry model, config_inca='//config_inca, modname)
217         CASE('inco'); CALL msg(TRIM(msg1)//' coupling jointly with INCA and CO2 cycle',  modname)
218         CASE('repr'); CALL msg(TRIM(msg1)//' coupling with REPROBUS chemistry model',    modname)
219         CASE('co2i'); CALL msg(TRIM(msg1)//' you have chosen to run with CO2 cycle',     modname)
220         CASE('coag'); CALL msg(TRIM(msg1)//' tracers are treated for COAGULATION tests', modname)
221         CASE('lmdz'); CALL msg(TRIM(msg1)//' tracers are treated in LMDZ only',          modname)
222         CASE DEFAULT; CALL abort_gcm(modname,'type_trac='//TRIM(str(it))//' not possible yet.',1)
223      END SELECT
224
225      !--- COHERENCE TEST BETWEEN "type_trac" AND "config_inca"
226      IF(ANY(['inca', 'inco'] == str(it)) .AND. ALL(['aero', 'aeNP', 'chem'] /= config_inca)) &
227         CALL abort_gcm(modname, 'Incoherence between type_trac and config_inca. Please modify "run.def"',1)
228
229      !--- COHERENCE TEST BETWEEN "type_trac" AND PREPROCESSING KEYS
230      SELECT CASE(str(it))
231         CASE('inca', 'inco')
232#ifndef INCA
233            CALL abort_gcm(modname, 'You must add cpp key INCA and compile with INCA code', 1)
234#endif
235         CASE('repr')
236#ifndef REPROBUS
237            CALL abort_gcm(modname, 'You must add cpp key REPROBUS and compile with REPROBUS code', 1)
238#endif
239         CASE('coag')
240#ifndef CPP_StratAer
241            CALL abort_gcm(modname, 'You must add cpp key StratAer and compile with StratAer code', 1)
242#endif
243      END SELECT
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(['inca', 'inco'] /= str(it)) .AND. config_inca /= 'none')) config_inca = 'none'
248
249   !---------------------------------------------------------------------------------------------------------------------------
250   END DO
251   !---------------------------------------------------------------------------------------------------------------------------
252
253   nqCO2 = 0; IF(ANY(str == 'inco')) nqCO2 = 1
254
255!==============================================================================================================================
256! 1) Get the numbers of: true (first order only) tracers "nqtrue", water tracers "nqo" (vapor/liquid/solid)
257!==============================================================================================================================
258
259!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
260   IF(lOldCode) THEN         !--- "type_trac" is a single keyword => no need to loop on its parsed version "str(:)"
261!------------------------------------------------------------------------------------------------------------------------------
262   !--- Determine nqtrue and (INCA only) nqo, nbtr
263   OPEN(90, FILE='traceur.def', FORM='formatted', STATUS='old', IOSTAT=ierr)
264   IF(ierr /= 0) CALL abort_gcm(modname, 'file "traceur.def" not found !', 1)
265   CALL msg('File "traceur.def" successfully opened.', modname)
266
267   IF(ANY(['inca','inco'] == type_trac)) THEN
268#ifdef INCA
269      READ(90,*) nqo
270      IF(nqCO2==1 .AND. nqo==4) nqo = 3
271      CALL Init_chem_inca_trac(nqINCA)
272      nbtr = nqINCA + nqCO2
273      nqtrue = nbtr + nqo
274      IF(ALL([2,3] /= nqo)) CALL abort_gcm(modname, 'Only 2 or 3 water phases allowed ; found nqo='//TRIM(int2str(nqo)), 1)
275      ALLOCATE(hadv_inca(nqINCA), conv_flg_inca(nqINCA), solsym_inca(nqINCA))
276      ALLOCATE(vadv_inca(nqINCA),  pbl_flg_inca(nqINCA))
277      CALL init_transport(solsym_inca, conv_flg_inca, pbl_flg_inca, hadv_inca, vadv_inca)
278#endif
279   ELSE
280      READ(90,*) nqtrue
281   END IF
282
283   IF (planet_type=="earth" .AND. nqtrue < 2) &
284      CALL abort_gcm('infotrac_init', 'Not enough tracers: nqtrue='//TRIM(int2str(nqtrue))//', 2 tracers is the minimum', 1)
285
286   !--- Allocate variables depending on nqtrue
287   ALLOCATE(hadv(nqtrue), vadv(nqtrue), tnom_0(nqtrue), tnom_transp(nqtrue), tracers(nqtrue))
288
289   !--- Continue to read tracer.def
290   it = 0
291   DO iq = 1, nqtrue
292#ifdef INCA
293      IF(iq > nqo+nqCO2) THEN
294         it = it+1
295         hadv  (iq) = hadv_inca  (it)
296         vadv  (iq) = vadv_inca  (it)
297         tnom_0(iq) = solsym_inca(it)
298         tnom_transp(iq) = 'air'
299         CYCLE
300      END IF
301#endif
302      READ(90,'(I2,X,I2,X,A)',IOSTAT=ierr) hadv(iq),vadv(iq),tchaine
303      IF(ierr/=0) CALL abort_gcm('infotrac_init', 'Pb dans la lecture de traceur.def', 1)
304      jq = INDEX(tchaine(1:LEN_TRIM(tchaine)),' ')
305      CALL msg("Ancienne version de traceur.def: traceurs d'air uniquement", modname, iq==1 .AND. jq==0)
306      CALL msg("Nouvelle version de traceur.def",                            modname, iq==1 .AND. jq/=0)
307      CALL msg('iq, hadv, vadv, tchaine ='//TRIM(strStack(int2str([iq, hadv(iq), vadv(iq)])))//', '//TRIM(tchaine), modname)
308      IF(jq /= 0) THEN                                               !--- Space in the string chain => new format
309         tnom_0     (iq) = tchaine(1:jq-1)
310         tnom_transp(iq) = tchaine(jq+1:)
311      ELSE
312         tnom_0     (iq) = tchaine
313         tnom_transp(iq) = 'air'
314      END IF
315   END DO
316   CLOSE(90)
317
318#ifndef INCA
319   IF(planet_type /= 'earth') nqo = 0                                !--- Same number of tracers in dynamics and physics
320   IF(planet_type == 'earth') nqo = COUNT(delPhase(tnom_0) == 'H2O') !--- for all planets except for Earth
321   nbtr = nqtrue - nqo
322#endif
323
324   CALL msg('RAW CONTENT OF "traceur.def" FILE:', modname)
325   IF(dispTable('iiss', ['hadv  ', 'vadv  ', 'name  ', 'parent'], cat(tnom_0, tnom_transp), cat(hadv, vadv))) &
326      CALL abort_gcm(modname, "problem with the tracers table content", 1)
327
328   !--- SET FIELDS %name, %parent, %phase, %component
329   tracers(:)%name      = old2newName(tnom_0)
330   tracers(:)%parent    = old2newName(tnom_transp)
331   tracers(:)%phase     = [( getPhase(tracers(iq)%name), iq=1, nqtrue )]
332   tracers(:)%component = type_trac
333   DO iq = 1, nqtrue
334      IF(addPhase('H2O',tracers(iq)%phase) == tracers(iq)%name) tracers(iq)%component = 'lmdz'
335   END DO
336   IF(ANY(['inca','inco'] == type_trac)) tracers(1+nqo:nqCO2+nqo)%component = 'co2i'
337   CALL setGeneration(tracers)                                       !--- SET FIELDS %iGeneration, %gen0Name
338   WHERE(tracers(:)%iGeneration == 2) tracers(:)%type = 'tag'        !--- DEFAULT VALUE: "tracer"
339
340   !--- FINALIZE
341   DEALLOCATE(tnom_0, tnom_transp)
342#ifdef INCA
343   DEALLOCATE(hadv_inca, vadv_inca, conv_flg_inca, pbl_flg_inca, solsym_inca)
344#endif
345
346!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
347ELSE
348!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
349   IF(readTracersFiles(type_trac, fType, tracers)) CALL abort_gcm(modname, 'problem with tracers file(s)',1)
350   IF(fType == 0) CALL abort_gcm(modname, 'Missing tracers file: "traceur.def", "tracer.def" or "tracer_<keyword>.def file.',1)
351   !---------------------------------------------------------------------------------------------------------------------------
352   IF(fType == 1 .AND. ANY(['inca','inco'] == type_trac)) THEN       !=== FOUND OLD STYLE INCA "traceur.def" (single type_trac)
353   !---------------------------------------------------------------------------------------------------------------------------
354#ifdef INCA
355      nqo = SIZE(tracers)
356      IF(nqCO2==1 .AND. nqo==4) nqo = 3                              !--- Force nqo to 3 (ThL)
357      CALL Init_chem_inca_trac(nqINCA)                               !--- Get nqINCA from INCA
358      nbtr = nqINCA + nqCO2                                          !--- Number of tracers passed to phytrac
359      nqtrue = nbtr + nqo                                            !--- Total number of "true" tracers
360      IF(ALL([2,3] /= nqo)) CALL abort_gcm(modname, 'Only 2 or 3 water phases allowed ; found nqo='//TRIM(int2str(nqo)), 1)
361      ALLOCATE(hadv(nqtrue), hadv_inca(nqINCA), conv_flg_inca(nqINCA), solsym_inca(nqINCA))
362      ALLOCATE(vadv(nqtrue), vadv_inca(nqINCA),  pbl_flg_inca(nqINCA))
363      CALL init_transport(solsym_inca, conv_flg_inca, pbl_flg_inca, hadv_inca, vadv_inca)
364      ALLOCATE(ttr(nqtrue))
365      ttr(1:nqo+nqCO2)                    = tracers
366      ttr(1    :      nqo   )%component   = 'lmdz'
367      ttr(1+nqo:nqCO2+nqo   )%component   = 'co2i'
368      ttr(1+nqo+nqCO2:nqtrue)%component   = 'inca'
369      ttr(1+nqo      :nqtrue)%name        = [('CO2     ', k=1, nqCO2), solsym_inca]
370      ttr(1+nqo+nqCO2:nqtrue)%parent      = tran0
371      ttr(1+nqo+nqCO2:nqtrue)%phase       = 'g'
372      lerr = getKey('hadv', had, ky=ttr(:)%keys); hadv(:) = [had, hadv_inca]
373      lerr = getKey('vadv', vad, ky=ttr(:)%keys); vadv(:) = [vad, vadv_inca]
374      CALL MOVE_ALLOC(FROM=ttr, TO=tracers)
375      CALL setGeneration(tracers)                                    !--- SET FIELDS %iGeneration, %gen0Name
376      DEALLOCATE(had, hadv_inca, vad, vadv_inca, conv_flg_inca, pbl_flg_inca, solsym_inca)
377#endif
378   !---------------------------------------------------------------------------------------------------------------------------
379   ELSE                                                              !=== FOUND NEW STYLE TRACERS CONFIGURATION FILE(S)
380   !---------------------------------------------------------------------------------------------------------------------------
381      nqo    =        COUNT(delPhase(tracers(:)%name)     == 'H2O' &
382                               .AND. tracers(:)%component == 'lmdz') !--- Number of water phases
383      nqtrue = SIZE(tracers)                                         !--- Total number of "true" tracers
384      nbtr   = nqtrue-COUNT(delPhase(tracers(:)%gen0Name) == 'H2O' &
385                               .AND. tracers(:)%component == 'lmdz') !--- Number of tracers passed to phytrac
386      lerr = getKey('hadv', hadv, ky=tracers(:)%keys)
387      lerr = getKey('vadv', vadv, ky=tracers(:)%keys)
388   !---------------------------------------------------------------------------------------------------------------------------
389   END IF
390   !---------------------------------------------------------------------------------------------------------------------------
391END IF
392!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
393
394   CALL getKey_init(tracers)
395
396   !--- Transfert the number of tracers to Reprobus
397#ifdef REPROBUS
398   CALL Init_chem_rep_trac(nbtr, nqo, tracers(:)%name)
399#endif
400
401!==============================================================================================================================
402! 2) Calculate nqtot, number of tracers needed (greater if advection schemes 20 or 30 have been chosen).
403!==============================================================================================================================
404   DO iq = 1, nqtrue
405      IF( hadv(iq)<20 .OR. (ANY(hadv(iq)==[20,30]) .AND. hadv(iq)==vadv(iq)) ) CYCLE
406      WRITE(msg1,'("The choice hadv=",i0,", vadv=",i0,a)')hadv(iq),vadv(iq),' for "'//TRIM(tracers(iq)%name)//'" is not available'
407      CALL abort_gcm(modname, TRIM(msg1), 1)
408   END DO
409   nqtot =    COUNT( hadv< 20 .AND. vadv< 20 ) &                     !--- No additional tracer
410         +  4*COUNT( hadv==20 .AND. vadv==20 ) &                     !--- 3  additional tracers
411         + 10*COUNT( hadv==30 .AND. vadv==30 )                       !--- 9  additional tracers
412
413   !--- More tracers due to the choice of advection scheme => assign total number of tracers
414   IF( nqtot /= nqtrue ) THEN
415      CALL msg('The choice of advection scheme for one or more tracers makes it necessary to add tracers')
416      CALL msg('The number of true tracers is '//TRIM(int2str(nqtrue)))
417      CALL msg('The total number of tracers needed is '//TRIM(int2str(nqtot)))
418   END IF
419
420!==============================================================================================================================
421! 3) Determine the advection scheme choice for water and tracers "iadv" and the fields long name, isAdvected.
422!     iadv = 1    "LMDZ-specific humidity transport" (for H2O vapour)          LMV
423!     iadv = 2    backward                           (for H2O liquid)          BAK
424!     iadv = 14   Van-Leer + specific humidity, modified by Francis Codron     VLH
425!     iadv = 10   Van-Leer (chosen for vapour and liquid water)                VL1
426!     iadv = 11   Van-Leer for hadv and PPM version (Monotonic) for vadv       VLP
427!     iadv = 12   Frederic Hourdin I                                           FH1
428!     iadv = 13   Frederic Hourdin II                                          FH2
429!     iadv = 16   Monotonic         PPM (Collela & Woodward 1984)              PPM
430!     iadv = 17   Semi-monotonic    PPM (overshoots allowed)                   PPS
431!     iadv = 18   Definite positive PPM (overshoots and undershoots allowed)   PPP
432!     iadv = 20   Slopes                                                       SLP
433!     iadv = 30   Prather                                                      PRA
434!
435!        In array q(ij,l,iq) : iq = 1/2[/3]    for vapour/liquid[/ice] water
436!        And optionaly:        iq = 3[4],nqtot for other tracers
437!==============================================================================================================================
438   ALLOCATE(ttr(nqtot))
439   jq = nqtrue+1; tracers(:)%iadv = -1
440   DO iq = 1, nqtrue
441      t1 => tracers(iq)
442
443      !--- VERIFY THE CHOICE OF ADVECTION SCHEME
444      iad = -1
445      IF(hadv(iq)     ==    vadv(iq)    ) iad = hadv(iq)
446      IF(hadv(iq)==10 .AND. vadv(iq)==16) iad = 11
447      WRITE(msg1,'("Bad choice of advection scheme for ",a,": hadv = ",i0,", vadv = ",i0)')TRIM(t1%name), hadv(iq), vadv(iq)
448      IF(iad == -1) CALL abort_gcm(modname, msg1, 1)
449
450      !--- SET FIELDS %longName, %iadv, %isAdvected, %isInPhysics
451      t1%longName   = t1%name; IF(iad > 0) t1%longName=TRIM(t1%name)//descrq(iad)
452      t1%iadv       = iad
453      t1%isAdvected = iad >= 0
454      t1%isInPhysics= delPhase(t1%gen0Name) /= 'H2O' &
455                          .OR. t1%component /= 'lmdz' !=== OTHER EXCEPTIONS TO BE ADDED: CO2i, SURSATURATED WATER CLOUD...
456      ttr(iq)       = t1
457
458      !--- DEFINE THE HIGHER ORDER TRACERS, IF ANY
459      nm = 0
460      IF(iad == 20) nm = 3                                           !--- 2nd order scheme
461      IF(iad == 30) nm = 9                                           !--- 3rd order scheme
462      IF(nm == 0) CYCLE                                              !--- No higher moments
463      ttr(jq+1:jq+nm)             = t1
464      ttr(jq+1:jq+nm)%name        = [(TRIM(t1%name)    //'-'//TRIM(suff(im)), im=1, nm) ]
465      ttr(jq+1:jq+nm)%parent      = [(TRIM(t1%parent)  //'-'//TRIM(suff(im)), im=1, nm) ]
466      ttr(jq+1:jq+nm)%longName    = [(TRIM(t1%longName)//'-'//TRIM(suff(im)), im=1, nm) ]
467      ttr(jq+1:jq+nm)%iadv        = [(-iad,    im=1, nm) ]
468      ttr(jq+1:jq+nm)%isAdvected  = [(.FALSE., im=1, nm) ]
469      jq = jq + nm
470   END DO
471   DEALLOCATE(hadv, vadv)
472   CALL MOVE_ALLOC(FROM=ttr, TO=tracers)
473
474   !--- SET FIELDS %iqParent, %nqChilds, %iGeneration, %iqDescen, %nqDescen
475   CALL indexUpdate(tracers)
476
477   !=== TEST ADVECTION SCHEME
478   DO iq=1,nqtot ; t1 => tracers(iq); iad = t1%iadv
479
480      !--- ONLY TESTED VALUES FOR TRACERS FOR NOW:               iadv = 14, 10 (and 0 for non-transported tracers)
481      IF(ALL([10,14,0] /= iad)) &
482         CALL abort_gcm(modname, 'Not tested for iadv='//TRIM(int2str(iad))//' ; 10 or 14 only are allowed !', 1)
483
484      !--- ONLY TESTED VALUES FOR PARENTS HAVING CHILDS FOR NOW: iadv = 14, 10 (PARENTS: TRACERS OF GENERATION 1)
485      IF(ALL([10,14] /= iad) .AND. t1%iGeneration == 1 .AND. ANY(tracers(:)%iGeneration > 1)) &
486         CALL abort_gcm(modname, 'iadv='//TRIM(int2str(iad))//' not implemented for parents ; 10 or 14 only are allowed !', 1)
487
488      !--- ONLY TESTED VALUES FOR CHILDS FOR NOW:                iadv = 10     (CHILDS:  TRACERS OF GENERATION GREATER THAN 1)
489      IF(fmsg('WARNING ! iadv='//TRIM(int2str(iad))//' not implemented for childs. Setting iadv=10 for "'//TRIM(t1%name)//'"',&
490         modname, iad /= 10 .AND. t1%iGeneration > 1)) t1%iadv = 10
491
492      !--- ONLY VALID SCHEME NUMBER FOR WATER VAPOUR:            iadv = 14
493      ll = t1%name /= addPhase('H2O','g')
494      IF(fmsg('WARNING ! iadv=14 is valid for water vapour only. Setting iadv=10 for "'//TRIM(t1%name)//'".', &
495         modname, iad == 14 .AND. ll))                 t1%iadv = 10
496   END DO
497
498IF(lOldCode) THEN
499
500   CALL infotrac_setHeredity                !--- SET FIELDS %iqParent, %nqChilds, %iGeneration, %gen0Name, %iqDescen, %nqDescen
501   CALL infotrac_isoinit                    !--- SET FIELDS %type, %iso_iName, %iso_iZone, %iso_iPhase
502   CALL getKey_init(tracers, isotopes)
503   IF(isoSelect('H2O')) RETURN              !--- Select water isotopes ; finished if no water isotopes
504   iH2O = ixIso                             !--- Keep track of water family index
505
506   !--- Remove the isotopic tracers from the tracers list passed to phytrac
507   nbtr    = nbtr -nqo*   ntiso             !--- ISOTOPIC TAGGING TRACERS ARE NOT PASSED TO THE PHYSICS
508   nqtottr = nqtot-nqo*(1+ntiso)            !--- NO H2O-FAMILY    TRACER  IS      PASSED TO THE PHYSICS
509
510ELSE
511
512   niso = 0; nzone=0; nphas=nqo; ntiso = 0; isoCheck=.FALSE.
513   CALL initIsotopes(tracers, isotopes)
514   nbIso = SIZE(isotopes)
515   nqtottr = nqtot - COUNT(tracers%gen0Name == 'H2O' .AND. tracers%component == 'lmdz')
516   IF(nbIso/=0) THEN                        !--- ISOTOPES FOUND
517
518      !=== READ PHYSICAL PARAMETERS FROM "isotopes_params.def" FILE SPECIFIC TO WATER ISOTOPES
519      !    DONE HERE, AND NOT ONLY IN "infotrac_phy", BECAUSE SOME PHYSICAL PARAMS ARE NEEDED FOR RESTARTS (tnat, alpha_ideal)
520      CALL getKey_init(tracers, isotopes)
521      IF(isoSelect('H2O')) RETURN           !--- Select water isotopes ; finished if no water isotopes
522      iH2O = ixIso                          !--- Keep track of water family index
523      IF(getKey('tnat' , tnat,        isoName(1:niso))) CALL abort_gcm(modname, 'can''t read "tnat"', 1)
524      IF(getKey('alpha', alpha_ideal, isoName(1:niso))) CALL abort_gcm(modname, 'can''t read "alpha_ideal"', 1)
525
526      !=== MAKE SURE THE MEMBERS OF AN ISOTOPES FAMILY ARE PRESENT IN THE SAME PHASES
527      DO ix = 1, nbIso
528         iso => isotopes(ix)
529         !--- Check whether each isotope and tagging isotopic tracer is present in the same number of phases
530         DO it = 1, iso%ntiso
531            np = SUM([(COUNT(tracers(:)%name == addPhase(iso%trac(it), iso%phase(ip:ip))), ip=1, iso%nphas)])
532            IF(np == iso%nphas) CYCLE
533            WRITE(msg1,'("Found ",i0," phases for ",a," instead of ",i0)')np, TRIM(iso%trac(it)), iso%nphas
534            CALL abort_gcm(modname, msg1, 1)
535         END DO
536         DO it = 1, iso%niso
537            nz = SUM([(COUNT(iso%trac == TRIM(iso%trac(it))//'_'//iso%zone(iz)), iz=1, iso%nzone)])
538            IF(nz == iso%nzone) CYCLE
539            WRITE(msg1,'("Found ",i0," tagging zones for ",a," instead of ",i0)')nz, TRIM(iso%trac(it)), iso%nzone
540            CALL abort_gcm(modname, msg1, 1)
541         END DO
542      END DO
543   END IF
544
545END IF
546
547   !--- Convection / boundary layer activation for all tracers
548   ALLOCATE(conv_flg(nbtr)); conv_flg(1:nbtr) = 1
549   ALLOCATE( pbl_flg(nbtr));  pbl_flg(1:nbtr) = 1
550
551   !--- Note: nqtottr can differ from nbtr when nmom/=0
552!   IF(COUNT(tracers%iso_iName == 0) - COUNT(delPhase(tracers%name) == 'H2O' .AND. tracers%component == 'lmdz') /= nqtottr) &
553!      CALL abort_gcm('infotrac_init', 'pb dans le calcul de nqtottr', 1)
554
555   !=== DISPLAY THE RESULTS
556   CALL msg('nqo    = '//TRIM(int2str(nqo)),    modname)
557   CALL msg('nbtr   = '//TRIM(int2str(nbtr)),   modname)
558   CALL msg('nqtrue = '//TRIM(int2str(nqtrue)), modname)
559   CALL msg('nqtot  = '//TRIM(int2str(nqtot)),  modname)
560   CALL msg('niso   = '//TRIM(int2str(niso)),   modname)
561   CALL msg('ntiso  = '//TRIM(int2str(ntiso)),  modname)
562#ifdef INCA
563   CALL msg('nqCO2  = '//TRIM(int2str(nqCO2)),  modname)
564   CALL msg('nqINCA = '//TRIM(int2str(nqINCA)), modname)
565#endif
566   t => tracers
567   CALL msg('Information stored in infotrac :', modname)
568   IF(dispTable('isssssssssiiiiiiiii', &
569      ['iq    ', 'name  ', 'lName ', 'gen0N ', 'parent', 'type  ', 'phase ', 'compon', 'isAdv ', 'isPhy ', &
570       'iadv  ', 'iGen  ', 'iqPar ', 'nqDes ', 'nqChld', 'iGroup', 'iName ', 'iZone ', 'iPhase'],          &
571      cat(t%name, t%longName, t%gen0Name, t%parent, t%type, t%phase, t%component, bool2str(t%isAdvected),  &
572                                                                                  bool2str(t%isInPhysics)),&
573      cat([(iq, iq=1, nqtot)], t%iadv, t%iGeneration, t%iqParent, t%nqDescen, t%nqChilds, t%iso_iGroup,    &
574                                                    t%iso_iName, t%iso_iZone, t%iso_iPhase), sub=modname)) &
575      CALL abort_gcm(modname, "problem with the tracers table content", 1)
576   IF(niso > 0) THEN
577      CALL msg('Where, for isotopes family "'//TRIM(isotope%parent)//'":', modname)
578      CALL msg('  isoKeys = '//strStack(isoKeys%name), modname)
579      CALL msg('  isoName = '//strStack(isoName),      modname)
580      CALL msg('  isoZone = '//strStack(isoZone),      modname)
581      CALL msg('  isoPhas = '//TRIM(isoPhas),          modname)
582   ELSE
583      CALL msg('No isotopes identified.', modname)
584   END IF
585   CALL msg('end', modname)
586
587END SUBROUTINE infotrac_init
588
589
590
591SUBROUTINE infotrac_setHeredity
592   !--- Purpose: Set fields %iqParent, %nqChilds, %iGeneration, %iqDescen, %nqDescen (old method)
593   USE strings_mod, ONLY: strIdx
594   INTEGER               :: iq, jq, ipere, ifils
595   INTEGER, ALLOCATABLE  :: iqfils(:,:)
596   CHARACTER(LEN=maxlen) :: msg1, modname='infotrac_init'
597   INCLUDE "iniprint.h"
598
599   !=== SET FIELDS %iqParent, %nqChilds
600   ALLOCATE(iqfils(nqtot,nqtot)); iqfils(:,:) = 0
601   tracers(:)%nqChilds = 0
602   tracers(:)%iqParent = 0
603
604   DO iq = 1, nqtot
605      msg1 = 'Tracer nr. '//TRIM(int2str(iq))//', called "'//TRIM(tracers(iq)%name)//'" is '
606
607      !--- IS IT A GENERATION 0 TRACER ? IF SO, tracers(iq)%iqParent KEEPS ITS DEFAULT VALUE (0)
608      IF(fmsg(TRIM(msg1)//' a parent', modname, tracers(iq)%parent == tran0)) CYCLE
609
610      !--- TRACERS OF GENERATION > 0 ; FIND ITS PARENT INDEX
611      ipere = strIdx(tracers(:)%name, tracers(iq)%parent)
612      IF(ipere == 0)  CALL abort_gcm('infotrac_init', TRIM(msg1)//' an orphan', 1)
613      IF(iq == ipere) CALL abort_gcm('infotrac_init', TRIM(msg1)//' its own parent',1)
614
615      CALL msg(TRIM(msg1)//' the child of '//TRIM(tracers(ipere)%name), modname)
616      tracers(iq)%iqParent    = ipere
617      tracers(ipere)%nqChilds = tracers(ipere)%nqChilds+1
618      iqfils(tracers(ipere)%nqChilds,ipere) = iq
619   END DO
620
621   CALL msg('nqGen0   = '//int2str(COUNT(tracers(:)%parent == 'air')), modname)
622   CALL msg('nqChilds = '//strStack(int2str(tracers(:)%nqChilds)),     modname)
623   CALL msg('iqParent = '//strStack(int2str(tracers(:)%iqParent)),     modname)
624   CALL msg('iqChilds = '//strStack(int2str(PACK(iqfils,MASK=.TRUE.))),modname)
625
626   !=== SET FIELDS %iGeneration, %iqDescen, %nqDescen
627   tracers(:)%iGeneration = 0
628   tracers(:)%nqDescen = 0
629   DO iq = 1, nqtot
630      ifils = iq
631      DO WHILE(tracers(ifils)%iqParent > 0)
632         ipere = tracers(ifils)%iqParent
633         tracers(ipere)%nqDescen = tracers(ipere)%nqDescen+1   
634         tracers(iq)%iGeneration = tracers(iq)%iGeneration+1
635         iqfils(tracers(ipere)%nqDescen,ipere) = iq
636         ifils = ipere
637      END DO
638      msg1 = 'Tracer nr. '//TRIM(int2str(iq))//', called "'//TRIM(tracers(iq)%name)//'" is '
639      CALL msg(TRIM(msg1)//' of generation '//TRIM(int2str(tracers(iq)%iGeneration)), modname)
640   END DO
641   DO iq=1,nqtot
642      tracers(iq)%iqDescen = iqfils(1:tracers(iq)%nqDescen,iq)
643   END DO
644
645   !=== SET FIELD %gen0Name
646   DO iq = 1, nqtot
647      jq=iq; DO WHILE(tracers(jq)%iGeneration > 0); jq=tracers(jq)%iqParent; END DO
648      tracers(iq)%gen0Name = tracers(jq)%name
649   END DO
650
651   CALL msg('nqDescen = '//TRIM(strStack(int2str(tracers(:)%nqDescen))), modname)
652   CALL msg('nqDescen_tot = ' //TRIM(int2str(SUM(tracers(:)%nqDescen))), modname)
653   CALL msg('iqDescen = '//strStack(int2str(PACK(iqfils, MASK=.TRUE.))), modname)
654
655END SUBROUTINE infotrac_setHeredity
656
657
658
659SUBROUTINE infotrac_isoinit
660
661#ifdef CPP_IOIPSL
662   USE IOIPSL
663#else
664   USE ioipsl_getincom
665#endif
666   USE readTracFiles_mod, ONLY: tnom_iso => newH2OIso
667   IMPLICIT NONE
668   INTEGER, ALLOCATABLE  :: nb_iso(:), nb_tiso(:), nb_zone(:), ix(:), iy(:)
669   INTEGER               :: ii, ip, iq, it, iz, ixt
670   TYPE(isot_type), POINTER :: i
671   TYPE(trac_type), POINTER :: t(:), t1
672   CHARACTER(LEN=maxlen)    :: tnom_trac, modname, t0
673   CHARACTER(LEN=maxlen), ALLOCATABLE :: str(:)
674   LOGICAL, DIMENSION(:), ALLOCATABLE :: mask
675   REAL, ALLOCATABLE :: tnat0(:), alpha_ideal0(:)
676   INCLUDE "iniprint.h"
677
678   modname = 'infotrac_isoinit'
679   tnat0       = [ 1.0 ,  155.76e-6, 2005.2e-6, 0.004/100., 0.0 ]    !--- Same length as tnom_iso
680   alpha_ideal0= [ 1.0 ,  1.01,      1.006,     1.003,      1.0 ]    !--- Same length as tnom_iso
681   ALLOCATE(isotopes(1))                                             !--- Only water
682   nbIso = SIZE(isotopes)
683   t => tracers
684   i => isotopes(1)
685   i%parent = 'H2O'
686
687   !--- Effective isotopes names list (embedded in the "keys" field)
688   mask = t%type=='tracer' .AND. t%gen0Name==addPhase('H2O', 'g') .AND. t%iGeneration==1
689   str = PACK(delPhase(t%name), MASK=mask)
690   CALL strReduce(str)
691   i%niso = SIZE(str)
692   ALLOCATE(i%keys(i%niso))
693   i%keys(:)%name = str
694
695   !--- Check whether found isotopes are known
696   mask = [(ALL(tnom_iso /= str(ii)), ii=1, i%niso)]
697   IF(ANY(mask)) CALL abort_gcm(modname, 'The following isotopes are unknown: '//strStack(PACK(str, MASK=mask)), 1)
698
699   !--- Full isotopes list, with isotopes tagging tracers (if any) following the previous list
700   mask = t%type=='tag'    .AND. t%gen0Name==addPhase('H2O', 'g') .AND. t%iGeneration==2
701   str = PACK(delPhase(t%name), MASK=mask)
702   i%ntiso = i%niso + SIZE(str)
703   ALLOCATE(i%trac(i%ntiso))
704   i%trac(:) = [i%keys(:)%name, str]
705
706   !--- Effective tagging zones names list
707   i%zone = strTail(str, '_', .TRUE.)
708   CALL strReduce(i%zone)
709   i%nzone = SIZE(i%zone)
710   IF(i%ntiso /= i%niso*(i%nzone+1)) CALL abort_gcm(modname, 'Error in "ntiso" calculation', 1)
711
712   !--- Effective phases list
713   i%phase = ''
714   DO ip=1,nphases; IF(strIdx(t%name, addPhase('H2O', ip))/=0) i%phase=TRIM(i%phase)//known_phases(ip:ip); END DO
715   i%nphas = LEN_TRIM(i%phase)
716
717   !--- Indexes related to isotopes
718   DO iq = 1, nqtot
719      t1 => tracers(iq)
720      t0 = t1%gen0Name
721      IF(t1%iGeneration==0 .OR. .NOT.t1%isAdvected .OR. delPhase(t0)/='H2O') CYCLE
722      t1%iso_iGroup = 1
723      t1%iso_iPhase = INDEX(i%phase, getPhase(t0))
724      t1%iso_iZone = strIdx(i%zone,  strTail(t1%name, '_'))
725      IF(t1%iso_iZone /= 0) t1%iso_iName = strIdx(i%keys(:)%name, delPhase(t1%parent))
726      IF(t1%iso_iZone == 0) t1%iso_iName = strIdx(i%keys(:)%name, delPhase(t1%name  ))
727   END DO
728
729   !--- Get vectors, one value each "isotope%trac" element (and in the same order)
730   ix = strIdx(tnom_iso, i%trac)
731   iy =   PACK(ix, MASK = ix/=0)
732   tnat        = tnat0       (iy)
733   alpha_ideal = alpha_ideal0(iy)
734
735   !--- Tests
736   nb_iso  = [(COUNT(t%iso_iPhase == ip .AND. t%iGeneration == 1), ip=1, i%nphas)]
737   nb_tiso = [(COUNT(t%iso_iPhase == ip .AND. t%iGeneration == 2), ip=1, i%nphas)]
738   nb_zone = [(COUNT(t%iso_iZone  == iz), iz=1, i%nzone)]
739   IF(ANY(nb_iso (:) /= nb_iso (1))) CALL abort_gcm(modname, 'Phases must have same number of isotopes', 1)
740   IF(ANY(nb_tiso(:) /= nb_tiso(1))) CALL abort_gcm(modname, 'Phases must have same number of tagging tracers', 1)
741   IF(i%nzone >= 1) THEN
742      IF(ANY(nb_zone(:) /= nb_zone(1))) CALL abort_gcm(modname, 'Isotopes must have the same number of tagging tracers', 1)
743   END IF
744
745   !--- Isotopic checking routines activation flag
746   i%check = .FALSE.; IF(i%niso > 0) CALL getin('ok_iso_verif', i%check)
747
748   !--- Table: index in "qx(:)" of an isotope, knowing its indices "it","ip" in "isotope%iName,%iPhase"
749   i%iqIsoPha = RESHAPE([((strIdx(t%name, TRIM(addPhase(i%trac(it),ip,i%phase))),it=1,i%ntiso),ip=1,i%nphas)],[i%ntiso,i%nphas])
750
751   !--- Table: index in "isotope%tracs(:)%name" of an isotopic tagging tracer, knowing its indices "iz","ip" in "isotope%iZone,%iName"
752   i%itZonIso = RESHAPE([((strIdx(i%trac,TRIM(i%trac(it))//'_'//TRIM(i%zone(iz))),iz=1,i%nzone),it=1,i%niso )],[i%nzone,i%niso])
753
754   DO it=1,i%ntiso; CALL msg('iqIsoPha('//TRIM(int2str(it))//',:) = '//strStack(int2str(i%iqIsoPha(it,:))), modname); END DO
755   DO iz=1,i%nzone; CALL msg('itZonIso('//TRIM(int2str(iz))//',:) = '//strStack(int2str(i%itZonIso(iz,:))), modname); END DO
756
757   !--- Finalize :
758   DEALLOCATE(nb_iso)
759
760END SUBROUTINE infotrac_isoinit
761
762
763!==============================================================================================================================
764!=== THE ROUTINE isoSelect IS USED TO SWITCH FROM AN ISOTOPE FAMILY TO ANOTHER: ISOTOPES DEPENDENT PARAMETERS ARE UPDATED
765!     Single generic "isoSelect" routine, using the predefined index of the parent (fast version) or its name (first call).
766!==============================================================================================================================
767LOGICAL FUNCTION isoSelectByName(iName, lVerbose) RESULT(lerr)
768   IMPLICIT NONE
769   CHARACTER(LEN=*),  INTENT(IN)  :: iName
770   LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose
771   INTEGER :: iIso
772   LOGICAL :: lV
773   lV = .FALSE.; IF(PRESENT(lVerbose)) lV = lVerbose
774   iIso = strIdx(isotopes(:)%parent, iName)
775   lerr = iIso == 0
776   IF(lerr) THEN
777      niso = 0; ntiso = 0; nzone=0; nphas=nqo; isoCheck=.FALSE.
778      CALL msg('no isotope family named "'//TRIM(iName)//'"', ll=lV)
779      RETURN
780   END IF
781   lerr = isoSelectByIndex(iIso, lV)
782END FUNCTION isoSelectByName
783!==============================================================================================================================
784LOGICAL FUNCTION isoSelectByIndex(iIso, lVerbose) RESULT(lerr)
785   IMPLICIT NONE
786   INTEGER,           INTENT(IN) :: iIso
787   LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose
788   LOGICAL :: lv
789   lv = .FALSE.; IF(PRESENT(lVerbose)) lv = lVerbose
790   lerr = .FALSE.
791   IF(iIso == ixIso) RETURN                                          !--- Nothing to do if the index is already OK
792   lerr = iIso<=0 .OR. iIso>nbIso
793   CALL msg('Inconsistent isotopes family index '//TRIM(int2str(iIso))//': should be > 0 and <= '//TRIM(int2str(nbIso))//'"',&
794            ll=lerr .AND. lV)
795   IF(lerr) RETURN
796   ixIso = iIso                                                      !--- Update currently selected family index
797   isotope  => isotopes(ixIso)                                       !--- Select corresponding component
798   isoKeys  => isotope%keys;     niso     = isotope%niso
799   isoName  => isotope%trac;     ntiso    = isotope%ntiso
800   isoZone  => isotope%zone;     nzone    = isotope%nzone
801   isoPhas  => isotope%phase;    nphas    = isotope%nphas
802   itZonIso => isotope%itZonIso; isoCheck = isotope%check
803   iqIsoPha => isotope%iqIsoPha
804END FUNCTION isoSelectByIndex
805!==============================================================================================================================
806
807END MODULE infotrac
Note: See TracBrowser for help on using the repository browser.