| 1 | |
|---|
| 2 | ! $Id: $ |
|---|
| 3 | |
|---|
| 4 | MODULE infotrac_phy |
|---|
| 5 | |
|---|
| 6 | USE strings_mod, ONLY: msg, maxlen, strStack, strHead, strParse, strIdx, int2str |
|---|
| 7 | USE readTracFiles_mod, ONLY: trac_type, isot_type, keys_type, delPhase, getKey, tnom_iso => newH2OIso |
|---|
| 8 | |
|---|
| 9 | IMPLICIT NONE |
|---|
| 10 | |
|---|
| 11 | PRIVATE |
|---|
| 12 | |
|---|
| 13 | !=== FOR TRACERS: |
|---|
| 14 | PUBLIC :: init_infotrac_phy !--- Initialization of the tracers |
|---|
| 15 | PUBLIC :: tracers, type_trac, types_trac !--- Full tracers database, tracers type keyword |
|---|
| 16 | PUBLIC :: nqtot, nbtr, nqo, nqCO2, nqtottr !--- Main dimensions |
|---|
| 17 | PUBLIC :: conv_flg, pbl_flg !--- Convection & boundary layer activation keys |
|---|
| 18 | #ifdef CPP_StratAer |
|---|
| 19 | PUBLIC :: nbtr_bin, nbtr_sulgas !--- Number of aerosols bins and sulfur gases for StratAer model |
|---|
| 20 | PUBLIC :: id_OCS_strat, id_SO2_strat, id_H2SO4_strat, id_BIN01_strat, id_TEST_strat |
|---|
| 21 | #endif |
|---|
| 22 | |
|---|
| 23 | !=== FOR ISOTOPES: General |
|---|
| 24 | PUBLIC :: isotopes, nbIso !--- Derived type, full isotopes families database + nb of families |
|---|
| 25 | PUBLIC :: isoSelect, ixIso !--- Isotopes family selection tool + selected family index |
|---|
| 26 | !=== FOR ISOTOPES: Specific to water |
|---|
| 27 | PUBLIC :: iH2O !--- H2O isotopes index |
|---|
| 28 | !=== FOR ISOTOPES: Depending on the selected isotopes family |
|---|
| 29 | PUBLIC :: isotope, isoKeys !--- Selected isotopes database + associated keys (cf. getKey) |
|---|
| 30 | PUBLIC :: isoName, isoZone, isoPhas !--- Isotopes and tagging zones names, phases |
|---|
| 31 | PUBLIC :: niso, nzone, nphas, ntiso !--- " " numbers + isotopes & tagging tracers number |
|---|
| 32 | PUBLIC :: itZonIso !--- iq = function(tagging zone idx, isotope idx) |
|---|
| 33 | PUBLIC :: iqIsoPha !--- idx of tagging tracer in iName = function(isotope idx, phase idx) |
|---|
| 34 | PUBLIC :: isoCheck !--- Run isotopes checking routines |
|---|
| 35 | !=== FOR BOTH TRACERS AND ISOTOPES |
|---|
| 36 | PUBLIC :: getKey !--- Get a key from "tracers" or "isotope" |
|---|
| 37 | |
|---|
| 38 | INTERFACE isoSelect; MODULE PROCEDURE isoSelectByIndex, isoSelectByName; END INTERFACE isoSelect |
|---|
| 39 | |
|---|
| 40 | !=== CONVENTIONS FOR TRACERS NUMBERS: |
|---|
| 41 | ! |--------------------+-----------------------+-----------------+---------------+----------------------------| |
|---|
| 42 | ! | water in different | water tagging | water isotopes | other tracers | additional tracers moments | |
|---|
| 43 | ! | phases: H2O_[gls] | isotopes | | | for higher order schemes | |
|---|
| 44 | ! |--------------------+-----------------------+-----------------+---------------+----------------------------| |
|---|
| 45 | ! | | | | | | |
|---|
| 46 | ! |<-- nqo -->|<-- nqo*niso* nzone -->|<-- nqo*niso -->|<-- nbtr -->|<-- (nmom) -->| |
|---|
| 47 | ! | | | | |
|---|
| 48 | ! | |<-- nqo*niso*(nzone+1) = nqo*ntiso -->|<-- nqtottr = nbtr + nmom -->| |
|---|
| 49 | ! | = nqtot - nqo*(ntiso+1) | |
|---|
| 50 | ! | | |
|---|
| 51 | ! |<-- nqtrue = nbtr + nqo*(ntiso+1) -->| | |
|---|
| 52 | ! | | |
|---|
| 53 | ! |<-- nqtot = nqtrue + nmom -->| |
|---|
| 54 | ! | | |
|---|
| 55 | ! |-----------------------------------------------------------------------------------------------------------| |
|---|
| 56 | ! NOTES FOR THIS TABLE: |
|---|
| 57 | ! * Used "niso", "nzone" and "ntiso" are components of "isotopes(ip)" for water (isotopes(ip)%parent == 'H2O'), |
|---|
| 58 | ! since water is so far the sole tracers family, except passive CO2, removed from the main tracers table. |
|---|
| 59 | ! * For water, "nqo" is equal to the more general field "isotopes(ip)%nphas". |
|---|
| 60 | ! * "niso", "nzone", "ntiso", "nphas" are defined for other isotopic tracers families, if any. |
|---|
| 61 | ! |
|---|
| 62 | !=== DERIVED TYPE EMBEDDING MOST OF THE TRACERS-RELATED QUANTITIES (LENGTH: nqtot) |
|---|
| 63 | ! Each entry is accessible using "%" sign. |
|---|
| 64 | ! |-------------+------------------------------------------------------+-------------+------------------------+ |
|---|
| 65 | ! | entry | Meaning | Former name | Possible values | |
|---|
| 66 | ! |-------------+------------------------------------------------------+-------------+------------------------+ |
|---|
| 67 | ! | name | Name (short) | tname | | |
|---|
| 68 | ! | gen0Name | Name of the 1st generation ancestor | / | | |
|---|
| 69 | ! | parent | Name of the parent | / | | |
|---|
| 70 | ! | longName | Long name (with adv. scheme suffix) for outputs | ttext | | |
|---|
| 71 | ! | type | Type (so far: tracer or tag) | / | tracer,tag | |
|---|
| 72 | ! | phase | Phases list ("g"as / "l"iquid / "s"olid) | / | [g][l][s] | |
|---|
| 73 | ! | component | Name(s) of the merged/cumulated section(s) | / | coma-separated names | |
|---|
| 74 | ! | iadv | Advection scheme number | iadv | 1-20,30 exc. 3-9,15,19 | |
|---|
| 75 | ! | iGeneration | Generation (>=1) | / | | |
|---|
| 76 | ! | isAdvected | advected tracers flag (.TRUE. if iadv >= 0) | / | nqtrue .TRUE. values | |
|---|
| 77 | ! | isInPhysics | tracers not extracted from the main table in physics | / | nqtottr .TRUE. values | |
|---|
| 78 | ! | iqParent | Index of the parent tracer | iqpere | 1:nqtot | |
|---|
| 79 | ! | iqDescen | Indexes of the childs (all generations) | iqfils | 1:nqtot | |
|---|
| 80 | ! | nqDescen | Number of the descendants (all generations) | nqdesc | 1:nqtot | |
|---|
| 81 | ! | nqChilds | Number of childs (1st generation only) | nqfils | 1:nqtot | |
|---|
| 82 | ! | iso_iGroup | Isotopes group index in isotopes(:) | / | 1:nbIso | |
|---|
| 83 | ! | iso_iName | Isotope name index in isotopes(iso_iGroup)%trac(:) | iso_indnum | 1:niso | |
|---|
| 84 | ! | iso_iZone | Isotope zone index in isotopes(iso_iGroup)%zone(:) | zone_num | 1:nzone | |
|---|
| 85 | ! | iso_iPhas | Isotope phase index in isotopes(iso_iGroup)%phas(:) | phase_num | 1:nphas | |
|---|
| 86 | ! | keys | key/val pairs accessible with "getKey" routine | / | | |
|---|
| 87 | ! +-------------+------------------------------------------------------+-------------+------------------------+ |
|---|
| 88 | ! |
|---|
| 89 | !=== DERIVED TYPE EMBEDDING MOST OF THE ISOTOPES-RELATED QUANTITIES (LENGTH: nbIso, NUMBER OF ISOTOPES FAMILIES) |
|---|
| 90 | ! Each entry is accessible using "%" sign. |
|---|
| 91 | ! |-----------------+--------------------------------------------------+--------------------+-----------------+ |
|---|
| 92 | ! | entry | length | Meaning | Former name | Possible values | |
|---|
| 93 | ! |-----------------+--------------------------------------------------+--------------------+-----------------+ |
|---|
| 94 | ! | parent | Parent tracer (isotopes family name) | | | |
|---|
| 95 | ! | keys | niso | Isotopes keys/values pairs list + number | | | |
|---|
| 96 | ! | trac | ntiso | Isotopes + tagging tracers list + number | / | ntraciso | | |
|---|
| 97 | ! | zone | nzone | Geographic tagging zones list + number | / | ntraceurs_zone | | |
|---|
| 98 | ! | phase | nphas | Phases list + number | | [g][l][s], 1:3 | |
|---|
| 99 | ! | iqIsoPha | Index in "qx" = f(name(1:ntiso)),phas) | iqiso | 1:nqtot | |
|---|
| 100 | ! | itZonIso | Index in "trac(1:ntiso)"= f(zone, name(1:niso)) | index_trac | 1:ntiso | |
|---|
| 101 | ! +-----------------+--------------------------------------------------+--------------------+-----------------+ |
|---|
| 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 | CHARACTER(LEN=maxlen), SAVE, ALLOCATABLE :: types_trac(:) !--- Keyword for tracers type |
|---|
| 112 | !$OMP THREADPRIVATE(nqtot, nbtr, nqo, nbIso, nqtottr, nqCO2, type_trac, types_trac) |
|---|
| 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 | !$OMP THREADPRIVATE(tracers, isotopes) |
|---|
| 118 | |
|---|
| 119 | !=== ALIASES FOR CURRENTLY SELECTED ISOTOPES FAMILY OF VARIABLES EMBEDDED IN THE VECTOR "isotopes" |
|---|
| 120 | TYPE(isot_type), SAVE, POINTER :: isotope !--- CURRENTLY SELECTED ISOTOPES FAMILY DESCRIPTOR |
|---|
| 121 | INTEGER, SAVE :: ixIso, iH2O !--- Index of the selected isotopes family and H2O family |
|---|
| 122 | LOGICAL, SAVE :: isoCheck !--- Flag to trigger the checking routines |
|---|
| 123 | TYPE(keys_type), SAVE, POINTER :: isoKeys(:) !--- ONE SET OF KEYS FOR EACH ISOTOPE (LISTED IN isoName) |
|---|
| 124 | CHARACTER(LEN=maxlen), SAVE, POINTER :: isoName(:), & !--- ISOTOPES NAMES FOR THE CURRENTLY SELECTED FAMILY |
|---|
| 125 | isoZone(:), & !--- TAGGING ZONES FOR THE CURRENTLY SELECTED FAMILY |
|---|
| 126 | isoPhas !--- USED PHASES FOR THE CURRENTLY SELECTED FAMILY |
|---|
| 127 | INTEGER, SAVE :: niso, nzone, & !--- NUMBER OF ISOTOPES, TAGGING ZONES AND PHASES |
|---|
| 128 | nphas, ntiso !--- NUMBER OF PHASES AND ISOTOPES + ISOTOPIC TAGGING TRACERS |
|---|
| 129 | INTEGER, SAVE, POINTER ::itZonIso(:,:), & !--- INDEX IN "isoTrac" AS f(tagging zone idx, isotope idx) |
|---|
| 130 | iqIsoPha(:,:) !--- INDEX IN "qx" AS f(isotopic tracer idx, phase idx) |
|---|
| 131 | !$OMP THREADPRIVATE(isotope, ixIso,iH2O, isoCheck, isoKeys, isoName,isoZone,isoPhas, niso,nzone,nphas,ntiso, itZonIso,iqIsoPha) |
|---|
| 132 | |
|---|
| 133 | !=== VARIABLES FOR ISOTOPES INITIALIZATION AND FOR INCA |
|---|
| 134 | INTEGER, SAVE, ALLOCATABLE ::conv_flg(:), & !--- Convection activation ; needed for INCA (nbtr) |
|---|
| 135 | pbl_flg(:) !--- Boundary layer activation ; needed for INCA (nbtr) |
|---|
| 136 | !$OMP THREADPRIVATE(conv_flg, pbl_flg) |
|---|
| 137 | |
|---|
| 138 | #ifdef CPP_StratAer |
|---|
| 139 | !=== SPECIFIC TO STRATOSPHERIC AEROSOLS (CK/OB) |
|---|
| 140 | INTEGER, SAVE :: nbtr_bin, nbtr_sulgas !--- number of aerosols bins and sulfur gases for StratAer model |
|---|
| 141 | !$OMP THREADPRIVATE(nbtr_bin, nbtr_sulgas) |
|---|
| 142 | INTEGER, SAVE :: id_OCS_strat, id_SO2_strat, id_H2SO4_strat, id_BIN01_strat, id_TEST_strat |
|---|
| 143 | !$OMP THREADPRIVATE(id_OCS_strat, id_SO2_strat, id_H2SO4_strat, id_BIN01_strat, id_TEST_strat) |
|---|
| 144 | #endif |
|---|
| 145 | |
|---|
| 146 | CONTAINS |
|---|
| 147 | |
|---|
| 148 | SUBROUTINE init_infotrac_phy(type_trac_, tracers_, isotopes_, nqtottr_, nqCO2_, pbl_flg_, conv_flg_) |
|---|
| 149 | |
|---|
| 150 | USE print_control_mod, ONLY: prt_level, lunout |
|---|
| 151 | |
|---|
| 152 | IMPLICIT NONE |
|---|
| 153 | CHARACTER(LEN=*),INTENT(IN) :: type_trac_ |
|---|
| 154 | TYPE(trac_type), INTENT(IN) :: tracers_(:) |
|---|
| 155 | TYPE(isot_type), INTENT(IN) :: isotopes_(:) |
|---|
| 156 | INTEGER, INTENT(IN) :: nqtottr_ |
|---|
| 157 | INTEGER, INTENT(IN) :: nqCO2_ |
|---|
| 158 | INTEGER, INTENT(IN) :: conv_flg_(:) |
|---|
| 159 | INTEGER, INTENT(IN) :: pbl_flg_(:) |
|---|
| 160 | |
|---|
| 161 | INTEGER :: iq, ixt |
|---|
| 162 | #ifdef CPP_StratAer |
|---|
| 163 | CHARACTER(LEN=maxlen), ALLOCATABLE :: tnames(:) |
|---|
| 164 | #endif |
|---|
| 165 | CHARACTER(LEN=maxlen) :: modname="init_infotrac_phy" |
|---|
| 166 | |
|---|
| 167 | type_trac = type_trac_ |
|---|
| 168 | IF(strParse(type_trac, '|', types_trac)) CALL abort_physic(modname,'can''t parse "type_trac = '//TRIM(type_trac)//'"',1) |
|---|
| 169 | tracers = tracers_ |
|---|
| 170 | isotopes = isotopes_ |
|---|
| 171 | nqtottr = nqtottr_ |
|---|
| 172 | nqCO2 = nqCO2_ |
|---|
| 173 | pbl_flg = pbl_flg_ |
|---|
| 174 | conv_flg = conv_flg_ |
|---|
| 175 | nqtot = SIZE(tracers_) |
|---|
| 176 | nqo = COUNT(delPhase(tracers%name)=='H2O' .AND. tracers%iGeneration==0 .AND. tracers%component=='lmdz') |
|---|
| 177 | nbtr = SIZE(conv_flg) |
|---|
| 178 | nbIso = SIZE(isotopes_) |
|---|
| 179 | |
|---|
| 180 | !=== Determine selected isotopes class related quantities: |
|---|
| 181 | ! ixIso, isotope, niso,isoKeys, ntiso,isoName, nzone,isoZone, nphas,isoPhas, itZonIso, iqIsoPha, isoCheck |
|---|
| 182 | IF(.NOT.isoSelect('H2O')) iH2O = ixIso |
|---|
| 183 | IF(prt_level > 1) THEN |
|---|
| 184 | CALL msg('nqtot = '//TRIM(int2str(nqtot)), modname) |
|---|
| 185 | CALL msg('nbtr = '//TRIM(int2str(nbtr )), modname) |
|---|
| 186 | CALL msg('nqo = '//TRIM(int2str(nqo )), modname) |
|---|
| 187 | CALL msg('niso = '//TRIM(int2str(niso )), modname) |
|---|
| 188 | CALL msg('ntiso = '//TRIM(int2str(ntiso)), modname) |
|---|
| 189 | CALL msg('nqtottr = '//TRIM(int2str(nqtottr)), modname) |
|---|
| 190 | CALL msg('nqCO2 = '//TRIM(int2str(nqCO2)), modname) |
|---|
| 191 | END IF |
|---|
| 192 | |
|---|
| 193 | #ifdef CPP_StratAer |
|---|
| 194 | IF (ANY(types_trac == 'coag')) THEN |
|---|
| 195 | nbtr_bin = COUNT([(tracers(iq)%name(1:3)=='BIN', iq=1, nqtot)]) |
|---|
| 196 | nbtr_sulgas = COUNT([(tracers(iq)%name(1:3)=='GAS', iq=1, nqtot)]) |
|---|
| 197 | tnames = PACK(tracers(:)%name, MASK=tracers(:)%isInPhysics) |
|---|
| 198 | id_BIN01_strat = strIdx(tnames, 'BIN01' ) |
|---|
| 199 | id_OCS_strat = strIdx(tnames, 'GASOCS' ) |
|---|
| 200 | id_SO2_strat = strIdx(tnames, 'GASSO2' ) |
|---|
| 201 | id_H2SO4_strat = strIdx(tnames, 'GASH2SO4') |
|---|
| 202 | id_TEST_strat = strIdx(tnames, 'GASTEST' ) |
|---|
| 203 | CALL msg('nbtr_bin ='//TRIM(int2str(nbtr_bin )), modname) |
|---|
| 204 | CALL msg('nbtr_sulgas ='//TRIM(int2str(nbtr_sulgas )), modname) |
|---|
| 205 | CALL msg('id_BIN01_strat ='//TRIM(int2str(id_BIN01_strat)), modname) |
|---|
| 206 | CALL msg('id_OCS_strat ='//TRIM(int2str(id_OCS_strat )), modname) |
|---|
| 207 | CALL msg('id_SO2_strat ='//TRIM(int2str(id_SO2_strat )), modname) |
|---|
| 208 | CALL msg('id_H2SO4_strat ='//TRIM(int2str(id_H2SO4_strat)), modname) |
|---|
| 209 | CALL msg('id_TEST_strat ='//TRIM(int2str(id_TEST_strat )), modname) |
|---|
| 210 | END IF |
|---|
| 211 | #endif |
|---|
| 212 | #ifdef ISOVERIF |
|---|
| 213 | CALL msg('iso_iName = '//strStack(int2str(PACK(tracers(:)%iso_iName, MASK=tracers(:)%iso_iGroup==iH2O))), modname) |
|---|
| 214 | #endif |
|---|
| 215 | |
|---|
| 216 | END SUBROUTINE init_infotrac_phy |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | !============================================================================================================================== |
|---|
| 220 | !=== THE ROUTINE isoSelect IS USED TO SWITCH FROM AN ISOTOPE FAMILY TO ANOTHER: ISOTOPES DEPENDENT PARAMETERS ARE UPDATED |
|---|
| 221 | ! Single generic "isoSelect" routine, using the predefined index of the parent (fast version) or its name (first call). |
|---|
| 222 | !============================================================================================================================== |
|---|
| 223 | LOGICAL FUNCTION isoSelectByName(iName, lVerbose) RESULT(lerr) |
|---|
| 224 | IMPLICIT NONE |
|---|
| 225 | CHARACTER(LEN=*), INTENT(IN) :: iName |
|---|
| 226 | LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose |
|---|
| 227 | INTEGER :: iIso |
|---|
| 228 | LOGICAL :: lV |
|---|
| 229 | lV = .FALSE.; IF(PRESENT(lVerbose)) lV = lVerbose |
|---|
| 230 | iIso = strIdx(isotopes(:)%parent, iName) |
|---|
| 231 | lerr = iIso == 0 |
|---|
| 232 | IF(lerr) THEN |
|---|
| 233 | niso = 0; ntiso = 0; nzone=0; nphas=nqo; isoCheck=.FALSE. |
|---|
| 234 | CALL msg('no isotope family named "'//TRIM(iName)//'"', ll=lV) |
|---|
| 235 | RETURN |
|---|
| 236 | END IF |
|---|
| 237 | lerr = isoSelectByIndex(iIso, lV) |
|---|
| 238 | END FUNCTION isoSelectByName |
|---|
| 239 | !============================================================================================================================== |
|---|
| 240 | LOGICAL FUNCTION isoSelectByIndex(iIso, lVerbose) RESULT(lerr) |
|---|
| 241 | IMPLICIT NONE |
|---|
| 242 | INTEGER, INTENT(IN) :: iIso |
|---|
| 243 | LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose |
|---|
| 244 | LOGICAL :: lv |
|---|
| 245 | lv = .FALSE.; IF(PRESENT(lVerbose)) lv = lVerbose |
|---|
| 246 | lerr = .FALSE. |
|---|
| 247 | IF(iIso == ixIso) RETURN !--- Nothing to do if the index is already OK |
|---|
| 248 | lerr = iIso<=0 .OR. iIso>nbIso |
|---|
| 249 | CALL msg('Inconsistent isotopes family index '//TRIM(int2str(iIso))//': should be > 0 and <= '//TRIM(int2str(nbIso))//'"',& |
|---|
| 250 | ll=lerr .AND. lV) |
|---|
| 251 | IF(lerr) RETURN |
|---|
| 252 | ixIso = iIso !--- Update currently selected family index |
|---|
| 253 | isotope => isotopes(ixIso) !--- Select corresponding component |
|---|
| 254 | isoKeys => isotope%keys; niso = isotope%niso |
|---|
| 255 | isoName => isotope%trac; ntiso = isotope%ntiso |
|---|
| 256 | isoZone => isotope%zone; nzone = isotope%nzone |
|---|
| 257 | isoPhas => isotope%phase; nphas = isotope%nphas |
|---|
| 258 | itZonIso => isotope%itZonIso; isoCheck = isotope%check |
|---|
| 259 | iqIsoPha => isotope%iqIsoPha |
|---|
| 260 | END FUNCTION isoSelectByIndex |
|---|
| 261 | !============================================================================================================================== |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | END MODULE infotrac_phy |
|---|