| 1 | MODULE infotrac_phy |
|---|
| 2 | |
|---|
| 3 | USE strings_mod, ONLY: msg, fmsg, test, strIdx, int2str |
|---|
| 4 | |
|---|
| 5 | USE readTracFiles_mod, ONLY: getKey_init, getKey, indexUpdate, delPhase, phases_sep, known_phases, nphases |
|---|
| 6 | |
|---|
| 7 | USE trac_types_mod, ONLY: tra, iso, kys |
|---|
| 8 | |
|---|
| 9 | IMPLICIT NONE |
|---|
| 10 | |
|---|
| 11 | PRIVATE |
|---|
| 12 | |
|---|
| 13 | !=== FOR TRACERS: |
|---|
| 14 | PUBLIC :: tra, tracers, type_trac !--- Derived type, full database, tracers type keyword |
|---|
| 15 | PUBLIC :: nqtot, nbtr, nqo !--- Main dimensions |
|---|
| 16 | PUBLIC :: init_infotrac_phy !--- Initialization |
|---|
| 17 | PUBLIC :: itr_indice !--- Indexes of the tracers passed to phytrac |
|---|
| 18 | PUBLIC :: niadv !--- Indexes of true tracers (<=nqtot, such that iadv(idx)>0) |
|---|
| 19 | PUBLIC :: pbl_flg, conv_flg, solsym |
|---|
| 20 | |
|---|
| 21 | !=== FOR ISOTOPES: General |
|---|
| 22 | !--- General |
|---|
| 23 | PUBLIC :: iso, isotopes, nbIso !--- Derived type, full isotopes families database + nb of families |
|---|
| 24 | PUBLIC :: isoSelect , ixIso !--- Isotopes family selection tool + selected family index |
|---|
| 25 | !=== FOR ISOTOPES: Specific to H2O isotopes |
|---|
| 26 | PUBLIC :: iH2O, tnat, alpha_ideal !--- H2O isotopes index, natural abundance, fractionning coeff. |
|---|
| 27 | !=== FOR ISOTOPES: Depending on 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, nzon, npha, nitr !--- " " numbers + isotopes & tagging tracers number |
|---|
| 31 | PUBLIC :: iZonIso, iTraPha !--- 2D index tables to get "iq" index |
|---|
| 32 | PUBLIC :: isoCheck !--- Run isotopes checking routines |
|---|
| 33 | |
|---|
| 34 | !=== FOR BOTH TRACERS AND ISOTOPES |
|---|
| 35 | PUBLIC :: getKey !--- Get a key from "tracers" or "isotope" |
|---|
| 36 | |
|---|
| 37 | !=== FOR STRATOSPHERIC AEROSOLS |
|---|
| 38 | #ifdef CPP_StratAer |
|---|
| 39 | PUBLIC :: nbtr_bin, nbtr_sulgas, id_OCS_strat, id_H2SO4_strat, id_SO2_strat, id_BIN01_strat, id_TEST_strat |
|---|
| 40 | #endif |
|---|
| 41 | |
|---|
| 42 | INTERFACE isoSelect; MODULE PROCEDURE isoSelectByIndex, isoSelectByName; END INTERFACE isoSelect |
|---|
| 43 | |
|---|
| 44 | !=== CONVENTIONS FOR TRACERS NUMBERS: |
|---|
| 45 | ! |--------------------+----------------------+-----------------+---------------+----------------------------| |
|---|
| 46 | ! | water in different | water tagging | water isotopes | other tracers | additional tracers moments | |
|---|
| 47 | ! | phases: H2O-[gls] | isotopes | | | for higher order schemes | |
|---|
| 48 | ! |--------------------+----------------------+-----------------+---------------+----------------------------| |
|---|
| 49 | ! | | | | | | |
|---|
| 50 | ! |<-- nqo -->|<-- nqo*niso* nzon -->|<-- nqo*niso -->|<-- nbtr -->|<-- (nmom) -->| |
|---|
| 51 | ! | | | | |
|---|
| 52 | ! | |<-- nqo*niso*(nzon+1) = nqo*nitr -->|<-- nqtottr = nbtr + nmom -->| |
|---|
| 53 | ! | = nqtot - nqo*(nitr+1) | |
|---|
| 54 | ! | | |
|---|
| 55 | ! |<-- nqtrue = nbtr + nqo*(nitr+1) -->| | |
|---|
| 56 | ! | | |
|---|
| 57 | ! |<-- nqtot = nqtrue + nmom -->| |
|---|
| 58 | ! | | |
|---|
| 59 | ! |----------------------------------------------------------------------------------------------------------| |
|---|
| 60 | ! NOTES FOR THIS TABLE: |
|---|
| 61 | ! * The used "niso", "nzon" and "nitr" are the H2O components of "isotopes(ip)" (isotopes(ip)%prnt == 'H2O'), |
|---|
| 62 | ! since water is so far the sole tracers family removed from the main tracers table. |
|---|
| 63 | ! * For water, "nqo" is equal to the more general field "isotopes(ip)%npha". |
|---|
| 64 | ! * "niso", "nzon", "nitr", "npha" are defined for other isotopic tracers families, if any. |
|---|
| 65 | ! |
|---|
| 66 | !=== TRACERS DESCRIPTOR: DERIVED TYPE EMBEDDING MOST OF THE USEFUL QUANTITIES (LENGTH: nqtot) |
|---|
| 67 | ! Each entry is accessible using "%" sign. |
|---|
| 68 | ! |------------+-------------------------------------------------+-------------+------------------------+ |
|---|
| 69 | ! | entry | Meaning | Former name | Possible values | |
|---|
| 70 | ! |------------+-------------------------------------------------+-------------+------------------------+ |
|---|
| 71 | ! | name | Name (short) | tname | | |
|---|
| 72 | ! | nam1 | Name of the 1st generation ancestor | / | | |
|---|
| 73 | ! | prnt | Name of the parent | / | | |
|---|
| 74 | ! | lnam | Long name (with adv. scheme suffix) for outputs | ttext | | |
|---|
| 75 | ! | type | Type (so far: tracer or tag) | / | tracer,tag | |
|---|
| 76 | ! | phas | Phases list ("g"as / "l"iquid / "s"olid) | / | [g][l][s] | |
|---|
| 77 | ! | comp | Name(s) of the merged/cumulated section(s) | / | coma-separated names | |
|---|
| 78 | ! | iadv | Advection scheme number | iadv | 1-20,30 exc. 3-9,15,19 | |
|---|
| 79 | ! | igen | Generation (>=1) | / | | |
|---|
| 80 | ! | itr | Index in "tr_seri" (0: absent from physics) | cf. niadv | 1:nqtottr | |
|---|
| 81 | ! | iprnt | Index of the parent tracer | iqpere | 1:nqtot | |
|---|
| 82 | ! | idesc | Indexes of the childs (all generations) | iqfils | 1:nqtot | |
|---|
| 83 | ! | ndesc | Number of the descendants (all generations) | nqdesc | 1:nqtot | |
|---|
| 84 | ! | nchld | Number of childs (first generation only) | nqfils | 1:nqtot | |
|---|
| 85 | ! | keys | key/val pairs accessible with "getKey" routine | / | | |
|---|
| 86 | ! | iso_num | Isotope name index in iso(igr)%name(:) | iso_indnum | 1:niso | |
|---|
| 87 | ! | iso_zon | Isotope zone index in iso(igr)%zone(:) | zone_num | 1:nzon | |
|---|
| 88 | ! | iso_pha | Isotope phase index in iso(igr)%phas | phase_num | 1:npha | |
|---|
| 89 | ! +------------+-------------------------------------------------+-------------+------------------------+ |
|---|
| 90 | ! |
|---|
| 91 | !=== ISOTOPES DESCRIPTOR: DERIVED TYPE EMBEDDING MOST OF THE USEFUL QUANTITIES (LENGTH: NUMBER OF ISOTOPES FAMILIES USED) |
|---|
| 92 | ! Each entry is accessible using "%" sign. |
|---|
| 93 | ! |------------+-------------------------------------------------+-------------+-----------------------+ |
|---|
| 94 | ! | entry | Meaning | Former name | Possible values | |
|---|
| 95 | ! |------------+-------------------------------------------------+-------------+-----------------------+ |
|---|
| 96 | ! | prnt | Parent tracer (isotopes family name) | | | |
|---|
| 97 | ! | trac, nitr | Isotopes & tagging tracers + number of elements | | | |
|---|
| 98 | ! | zone, nzon | Geographic tagging zones + number of elements | | | |
|---|
| 99 | ! | phas, npha | Phases list + number of elements | | [g][l][s], 1:3 | |
|---|
| 100 | ! | niso | Number of isotopes, excluding tagging tracers | | | |
|---|
| 101 | ! | iTraPha | Index in "xt" = f(iname(niso+1:nitr),iphas) | iqiso | 1:niso | |
|---|
| 102 | ! | iZonIso | Index in "xt" = f(izone, iname(1:niso)) | index_trac | 1:nzon | |
|---|
| 103 | ! |------------+-------------------------------------------------+-------------+-----------------------+ |
|---|
| 104 | |
|---|
| 105 | !=== DIMENSIONS OF THE TRACERS TABLES AND OTHER SCALAR VARIABLES |
|---|
| 106 | INTEGER, SAVE :: nqtot, & !--- Tracers nb in dynamics (incl. higher moments & water) |
|---|
| 107 | nbtr, & !--- Tracers nb in physics (excl. higher moments & water) |
|---|
| 108 | nqo, & !--- Number of water phases |
|---|
| 109 | nbIso !--- Number of available isotopes family |
|---|
| 110 | CHARACTER(LEN=256), SAVE :: type_trac !--- Keyword for tracers type |
|---|
| 111 | !$OMP THREADPRIVATE(nqtot, nbtr, nqo, nbIso, type_trac) |
|---|
| 112 | |
|---|
| 113 | !=== DERIVED TYPES EMBEDDING MOST INFORMATIONS ABOUT TRACERS AND ISOTOPES FAMILIES |
|---|
| 114 | TYPE(tra), TARGET, SAVE, ALLOCATABLE :: tracers(:) !=== TRACERS DESCRIPTORS VECTOR |
|---|
| 115 | TYPE(iso), TARGET, SAVE, ALLOCATABLE :: isotopes(:) !=== ISOTOPES PARAMETERS VECTOR |
|---|
| 116 | !$OMP THREADPRIVATE(tracers, isotopes) |
|---|
| 117 | |
|---|
| 118 | !=== ALIASES FOR CURRENTLY SELECTED ISOTOPES FAMILY OF VARIABLES EMBEDDED IN THE VECTOR "isotopes" |
|---|
| 119 | TYPE(iso), 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(kys), SAVE, POINTER :: isoKeys(:) !--- ONE SET OF KEYS FOR EACH ISOTOPE (LISTED IN isoName) |
|---|
| 123 | CHARACTER(LEN=256), 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, nzon, & !--- NUMBER OF ISOTOPES, TAGGING ZONES AND PHASES |
|---|
| 127 | npha, nitr !--- NUMBER OF PHASES AND ISOTOPES + ISOTOPIC TAGGING TRACERS |
|---|
| 128 | INTEGER, SAVE, POINTER :: iZonIso(:,:) !--- INDEX IN "isoTrac" AS f(tagging zone, isotope) |
|---|
| 129 | INTEGER, SAVE, POINTER :: iTraPha(:,:) !--- INDEX IN "isoTrac" AS f(isotopic tracer, phase) |
|---|
| 130 | !$OMP THREADPRIVATE(isotope, ixIso,iH2O, isoCheck, isoKeys, isoName,isoZone,isoPhas, niso,nzon,npha,nitr, iZonIso,iTraPha) |
|---|
| 131 | |
|---|
| 132 | !=== VARIABLES EMBEDDED IN "tracers", BUT DUPLICATED, AS THEY ARE RATHER FREQUENTLY USED + VARIABLES FOR INCA |
|---|
| 133 | REAL, SAVE, ALLOCATABLE :: tnat(:), & !--- Natural relative abundance of water isotope (niso) |
|---|
| 134 | alpha_ideal(:) !--- Ideal fractionning coefficient (for initial state) (niso) |
|---|
| 135 | INTEGER, SAVE, ALLOCATABLE :: conv_flg(:), & !--- Convection activation ; needed for INCA (nbtr) |
|---|
| 136 | pbl_flg(:), & !--- Boundary layer activation ; needed for INCA (nbtr) |
|---|
| 137 | itr_indice(:), & !--- Indexes of the tracers passed to phytrac (nqtottr) |
|---|
| 138 | niadv(:) !--- Indexes of true tracers (<=nqtot, such that iadv(idx)>0) |
|---|
| 139 | CHARACTER(LEN=8), SAVE, ALLOCATABLE :: solsym(:) !--- Names from INCA (nbtr) |
|---|
| 140 | !OMP THREADPRIVATE(tnat, alpha_ideal, conv_flg, pbl_flg, itr_indice, niadv, solsym) |
|---|
| 141 | |
|---|
| 142 | #ifdef CPP_StratAer |
|---|
| 143 | !=== SPECIFIC TO STRATOSPHERIC AEROSOLS (CK/OB) |
|---|
| 144 | INTEGER, SAVE :: nbtr_bin, nbtr_sulgas, id_OCS_strat, id_H2SO4_strat, id_SO2_strat, id_BIN01_strat, id_TEST_strat |
|---|
| 145 | !OMP THREADPRIVATE(nbtr_bin, nbtr_sulgas, id_OCS_strat, id_H2SO4_strat, id_SO2_strat, id_BIN01_strat, id_TEST_strat) |
|---|
| 146 | #endif |
|---|
| 147 | |
|---|
| 148 | CONTAINS |
|---|
| 149 | |
|---|
| 150 | SUBROUTINE init_infotrac_phy(tracers_, isotopes_, type_trac_, solsym_, nbtr_, niadv_, pbl_flg_, conv_flg_) |
|---|
| 151 | ! transfer information on tracers from dynamics to physics |
|---|
| 152 | USE print_control_mod, ONLY: prt_level, lunout |
|---|
| 153 | IMPLICIT NONE |
|---|
| 154 | TYPE(tra), INTENT(IN) :: tracers_(:) |
|---|
| 155 | TYPE(iso), INTENT(IN) :: isotopes_(:) |
|---|
| 156 | CHARACTER(LEN=*), INTENT(IN) :: type_trac_, solsym_(:) |
|---|
| 157 | INTEGER, INTENT(IN) :: nbtr_, niadv_(:), pbl_flg_(:), conv_flg_(:) |
|---|
| 158 | |
|---|
| 159 | CHARACTER(LEN=256) :: modname="init_infotrac_phy" |
|---|
| 160 | INTEGER :: iq |
|---|
| 161 | LOGICAL :: lerr |
|---|
| 162 | |
|---|
| 163 | tracers = tracers_ |
|---|
| 164 | isotopes = isotopes_ |
|---|
| 165 | type_trac = type_trac_ |
|---|
| 166 | solsym = solsym_ |
|---|
| 167 | nqtot = SIZE(tracers_) |
|---|
| 168 | nqo = COUNT(delPhase(tracers%name)=='H2O' .AND. tracers%igen==1) |
|---|
| 169 | nbtr = nbtr_ |
|---|
| 170 | niadv = niadv_ |
|---|
| 171 | nbIso = SIZE(isotopes_) |
|---|
| 172 | pbl_flg = pbl_flg_ |
|---|
| 173 | conv_flg = conv_flg_ |
|---|
| 174 | |
|---|
| 175 | CALL msg('nqtot = '//TRIM(int2str(nqtot))) |
|---|
| 176 | CALL msg('nbtr = '//TRIM(int2str(nbtr))) |
|---|
| 177 | CALL msg('nqo = '//TRIM(int2str(nqo))) |
|---|
| 178 | |
|---|
| 179 | !=== Specific to water |
|---|
| 180 | CALL getKey_init(tracers, isotopes) |
|---|
| 181 | IF(.NOT.isoSelect('H2O')) THEN |
|---|
| 182 | iH2O = ixIso |
|---|
| 183 | lerr = getKey('tnat' ,tnat, isoName(1:isotope%niso)) |
|---|
| 184 | lerr = getKey('alpha',alpha_ideal, isoName(1:isotope%niso)) |
|---|
| 185 | END IF |
|---|
| 186 | itr_indice = PACK(tracers(:)%itr, MASK = tracers(:)%itr/=0) |
|---|
| 187 | !? CDC isoInit => A VOIR !! |
|---|
| 188 | |
|---|
| 189 | #ifdef CPP_StratAer |
|---|
| 190 | IF (type_trac == 'coag') THEN |
|---|
| 191 | nbtr_bin = COUNT([(tracers(iq)%name(1:3)=='BIN', iq=1, nqtot)]); CALL msg('nbtr_bin =', nbtr_bin) |
|---|
| 192 | nbtr_sulgas = COUNT([(tracers(iq)%name(1:3)=='GAS', iq=1, nqtot)]); CALL msg('nbtr_sulgas =', nbtr_sulgas) |
|---|
| 193 | id_BIN01_strat = MAX(0, strIdx(tracers(:)%name, 'BIN01' ) - nqo); CALL msg('id_BIN01_strat =', id_BIN01_strat) |
|---|
| 194 | id_OCS_strat = MAX(0, strIdx(tracers(:)%name, 'GASOSC' ) - nqo); CALL msg('id_OCS_strat =', id_OCS_strat) |
|---|
| 195 | id_SO2_strat = MAX(0, strIdx(tracers(:)%name, 'GASSO2' ) - nqo); CALL msg('id_SO2_strat =', id_SO2_strat) |
|---|
| 196 | id_H2SO4_strat = MAX(0, strIdx(tracers(:)%name, 'GASH2SO4') - nqo); CALL msg('id_H2SO4_strat =', id_H2SO4_strat) |
|---|
| 197 | id_TEST_strat = MAX(0, strIdx(tracers(:)%name, 'GASTEST' ) - nqo); CALL msg('id_TEST_strat =', id_TEST_strat) |
|---|
| 198 | END IF |
|---|
| 199 | #endif |
|---|
| 200 | |
|---|
| 201 | END SUBROUTINE init_infotrac_phy |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | !============================================================================================================================== |
|---|
| 205 | !=== THE ROUTINE isoSelect IS USED TO SWITCH FROM AN ISOTOPE FAMILY TO ANOTHER: ISOTOPES DEPENDENT PARAMETERS ARE UPDATED |
|---|
| 206 | ! Singe generic "isoSelect" routine, using the predefined parent index (fast version) or its name (first call). |
|---|
| 207 | !============================================================================================================================== |
|---|
| 208 | LOGICAL FUNCTION isoSelectByName(iName, lVerbose) RESULT(lerr) |
|---|
| 209 | IMPLICIT NONE |
|---|
| 210 | CHARACTER(LEN=*), INTENT(IN) :: iName |
|---|
| 211 | LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose |
|---|
| 212 | INTEGER :: iIso |
|---|
| 213 | LOGICAL :: lV |
|---|
| 214 | lV = .FALSE.; IF(PRESENT(lVerbose)) lV = lVerbose |
|---|
| 215 | iIso = strIdx(isotopes(:)%prnt, iName) |
|---|
| 216 | lerr = iIso == 0 |
|---|
| 217 | CALL msg(lerr .AND. lV, 'no isotope family named "'//TRIM(iName)//'"') |
|---|
| 218 | IF(lerr) RETURN |
|---|
| 219 | lerr = isoSelectByIndex(iIso) |
|---|
| 220 | END FUNCTION isoSelectByName |
|---|
| 221 | !============================================================================================================================== |
|---|
| 222 | LOGICAL FUNCTION isoSelectByIndex(iIso, lVerbose) RESULT(lerr) |
|---|
| 223 | IMPLICIT NONE |
|---|
| 224 | INTEGER, INTENT(IN) :: iIso |
|---|
| 225 | LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose |
|---|
| 226 | LOGICAL :: lv |
|---|
| 227 | lv = .FALSE.; IF(PRESENT(lVerbose)) lv = lVerbose |
|---|
| 228 | lerr = .FALSE. |
|---|
| 229 | IF(iIso == ixIso) RETURN !--- Nothing to do if the index is already OK |
|---|
| 230 | lerr = iIso<=0 .OR. iIso>nbIso |
|---|
| 231 | CALL msg(lerr .AND. lV, 'Inconsistent isotopes family index '//TRIM(int2str(iIso))//': should be > 0 and <= ' & |
|---|
| 232 | //TRIM(int2str(nbIso))//'"') |
|---|
| 233 | IF(lerr) RETURN |
|---|
| 234 | ixIso = iIso !--- Update currently selected family index |
|---|
| 235 | isotope => isotopes(ixIso) !--- Select corresponding component |
|---|
| 236 | isoKeys => isotope%keys; niso = isotope%niso |
|---|
| 237 | isoName => isotope%trac; nitr = isotope%nitr |
|---|
| 238 | isoZone => isotope%zone; nzon = isotope%nzon |
|---|
| 239 | isoPhas => isotope%phas; npha = isotope%npha |
|---|
| 240 | iZonIso => isotope%iZonIso; isoCheck = isotope%check |
|---|
| 241 | iTraPha => isotope%iTraPha |
|---|
| 242 | END FUNCTION isoSelectByIndex |
|---|
| 243 | !============================================================================================================================== |
|---|
| 244 | |
|---|
| 245 | END MODULE infotrac_phy |
|---|