Changeset 4158 for LMDZ6/trunk/libf/dyn3d_common
- Timestamp:
- May 19, 2022, 10:47:23 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
LMDZ6/trunk/libf/dyn3d_common/infotrac.F90
r4154 r4158 132 132 INTEGER, SAVE, ALLOCATABLE :: conv_flg(:), & !--- Convection activation ; needed for INCA (nbtr) 133 133 pbl_flg(:) !--- Boundary layer activation ; needed for INCA (nbtr) 134 LOGICAL, PARAMETER :: lOldCode = .FALSE.135 134 136 135 CONTAINS … … 202 201 203 202 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 203 IF(strParse(type_trac, ',', str, n=nt)) CALL abort_gcm(modname,'can''t parse "type_trac = '//TRIM(type_trac)//'"',1) 209 204 210 205 !--------------------------------------------------------------------------------------------------------------------------- … … 256 251 ! 1) Get the numbers of: true (first order only) tracers "nqtrue", water tracers "nqo" (vapor/liquid/solid) 257 252 !============================================================================================================================== 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, nbtr263 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)) THEN268 #ifdef INCA269 READ(90,*) nqo270 IF(nqCO2==1 .AND. nqo==4) nqo = 3271 CALL Init_chem_inca_trac(nqINCA)272 nbtr = nqINCA + nqCO2273 nqtrue = nbtr + nqo274 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 #endif279 ELSE280 READ(90,*) nqtrue281 END IF282 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 nqtrue287 ALLOCATE(hadv(nqtrue), vadv(nqtrue), tnom_0(nqtrue), tnom_transp(nqtrue), tracers(nqtrue))288 289 !--- Continue to read tracer.def290 it = 0291 DO iq = 1, nqtrue292 #ifdef INCA293 IF(iq > nqo+nqCO2) THEN294 it = it+1295 hadv (iq) = hadv_inca (it)296 vadv (iq) = vadv_inca (it)297 tnom_0(iq) = solsym_inca(it)298 tnom_transp(iq) = 'air'299 CYCLE300 END IF301 #endif302 READ(90,'(I2,X,I2,X,A)',IOSTAT=ierr) hadv(iq),vadv(iq),tchaine303 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 format309 tnom_0 (iq) = tchaine(1:jq-1)310 tnom_transp(iq) = tchaine(jq+1:)311 ELSE312 tnom_0 (iq) = tchaine313 tnom_transp(iq) = 'air'314 END IF315 END DO316 CLOSE(90)317 318 #ifndef INCA319 IF(planet_type /= 'earth') nqo = 0 !--- Same number of tracers in dynamics and physics320 IF(planet_type == 'earth') nqo = COUNT(delPhase(tnom_0) == 'H2O') !--- for all planets except for Earth321 nbtr = nqtrue - nqo322 #endif323 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, %component329 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_trac333 DO iq = 1, nqtrue334 IF(addPhase('H2O',tracers(iq)%phase) == tracers(iq)%name) tracers(iq)%component = 'lmdz'335 END DO336 IF(ANY(['inca','inco'] == type_trac)) tracers(1+nqo:nqCO2+nqo)%component = 'co2i'337 CALL setGeneration(tracers) !--- SET FIELDS %iGeneration, %gen0Name338 WHERE(tracers(:)%iGeneration == 2) tracers(:)%type = 'tag' !--- DEFAULT VALUE: "tracer"339 340 !--- FINALIZE341 DEALLOCATE(tnom_0, tnom_transp)342 #ifdef INCA343 DEALLOCATE(hadv_inca, vadv_inca, conv_flg_inca, pbl_flg_inca, solsym_inca)344 #endif345 346 !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++347 ELSE348 !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++349 253 IF(readTracersFiles(type_trac, fType, tracers)) CALL abort_gcm(modname, 'problem with tracers file(s)',1) 350 254 IF(fType == 0) CALL abort_gcm(modname, 'Missing tracers file: "traceur.def", "tracer.def" or "tracer_<keyword>.def file.',1) … … 389 293 END IF 390 294 !--------------------------------------------------------------------------------------------------------------------------- 391 END IF392 !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++393 295 394 296 CALL getKey_init(tracers) … … 495 397 modname, iad == 14 .AND. ll)) t1%iadv = 10 496 398 END DO 497 498 IF(lOldCode) THEN499 500 CALL infotrac_setHeredity !--- SET FIELDS %iqParent, %nqChilds, %iGeneration, %gen0Name, %iqDescen, %nqDescen501 CALL infotrac_isoinit !--- SET FIELDS %type, %iso_iName, %iso_iZone, %iso_iPhase502 CALL getKey_init(tracers, isotopes)503 IF(isoSelect('H2O')) RETURN !--- Select water isotopes ; finished if no water isotopes504 iH2O = ixIso !--- Keep track of water family index505 506 !--- Remove the isotopic tracers from the tracers list passed to phytrac507 nbtr = nbtr -nqo* ntiso !--- ISOTOPIC TAGGING TRACERS ARE NOT PASSED TO THE PHYSICS508 nqtottr = nqtot-nqo*(1+ntiso) !--- NO H2O-FAMILY TRACER IS PASSED TO THE PHYSICS509 510 ELSE511 399 512 400 niso = 0; nzone=0; nphas=nqo; ntiso = 0; isoCheck=.FALSE. … … 542 430 END DO 543 431 END IF 544 545 END IF546 432 547 433 !--- Convection / boundary layer activation for all tracers … … 586 472 587 473 END SUBROUTINE infotrac_init 588 589 590 591 SUBROUTINE infotrac_setHeredity592 !--- Purpose: Set fields %iqParent, %nqChilds, %iGeneration, %iqDescen, %nqDescen (old method)593 USE strings_mod, ONLY: strIdx594 INTEGER :: iq, jq, ipere, ifils595 INTEGER, ALLOCATABLE :: iqfils(:,:)596 CHARACTER(LEN=maxlen) :: msg1, modname='infotrac_init'597 INCLUDE "iniprint.h"598 599 !=== SET FIELDS %iqParent, %nqChilds600 ALLOCATE(iqfils(nqtot,nqtot)); iqfils(:,:) = 0601 tracers(:)%nqChilds = 0602 tracers(:)%iqParent = 0603 604 DO iq = 1, nqtot605 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)) CYCLE609 610 !--- TRACERS OF GENERATION > 0 ; FIND ITS PARENT INDEX611 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 = ipere617 tracers(ipere)%nqChilds = tracers(ipere)%nqChilds+1618 iqfils(tracers(ipere)%nqChilds,ipere) = iq619 END DO620 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, %nqDescen627 tracers(:)%iGeneration = 0628 tracers(:)%nqDescen = 0629 DO iq = 1, nqtot630 ifils = iq631 DO WHILE(tracers(ifils)%iqParent > 0)632 ipere = tracers(ifils)%iqParent633 tracers(ipere)%nqDescen = tracers(ipere)%nqDescen+1634 tracers(iq)%iGeneration = tracers(iq)%iGeneration+1635 iqfils(tracers(ipere)%nqDescen,ipere) = iq636 ifils = ipere637 END DO638 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 DO641 DO iq=1,nqtot642 tracers(iq)%iqDescen = iqfils(1:tracers(iq)%nqDescen,iq)643 END DO644 645 !=== SET FIELD %gen0Name646 DO iq = 1, nqtot647 jq=iq; DO WHILE(tracers(jq)%iGeneration > 0); jq=tracers(jq)%iqParent; END DO648 tracers(iq)%gen0Name = tracers(jq)%name649 END DO650 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 655 END SUBROUTINE infotrac_setHeredity656 657 658 659 SUBROUTINE infotrac_isoinit660 661 #ifdef CPP_IOIPSL662 USE IOIPSL663 #else664 USE ioipsl_getincom665 #endif666 USE readTracFiles_mod, ONLY: tnom_iso => newH2OIso667 IMPLICIT NONE668 INTEGER, ALLOCATABLE :: nb_iso(:), nb_tiso(:), nb_zone(:), ix(:), iy(:)669 INTEGER :: ii, ip, iq, it, iz, ixt670 TYPE(isot_type), POINTER :: i671 TYPE(trac_type), POINTER :: t(:), t1672 CHARACTER(LEN=maxlen) :: tnom_trac, modname, t0673 CHARACTER(LEN=maxlen), ALLOCATABLE :: str(:)674 LOGICAL, DIMENSION(:), ALLOCATABLE :: mask675 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_iso680 alpha_ideal0= [ 1.0 , 1.01, 1.006, 1.003, 1.0 ] !--- Same length as tnom_iso681 ALLOCATE(isotopes(1)) !--- Only water682 nbIso = SIZE(isotopes)683 t => tracers684 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==1689 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 = str694 695 !--- Check whether found isotopes are known696 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 list700 mask = t%type=='tag' .AND. t%gen0Name==addPhase('H2O', 'g') .AND. t%iGeneration==2701 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 list707 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 list713 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 DO715 i%nphas = LEN_TRIM(i%phase)716 717 !--- Indexes related to isotopes718 DO iq = 1, nqtot719 t1 => tracers(iq)720 t0 = t1%gen0Name721 IF(t1%iGeneration==0 .OR. .NOT.t1%isAdvected .OR. delPhase(t0)/='H2O') CYCLE722 t1%iso_iGroup = 1723 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 DO728 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 !--- Tests736 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) THEN742 IF(ANY(nb_zone(:) /= nb_zone(1))) CALL abort_gcm(modname, 'Isotopes must have the same number of tagging tracers', 1)743 END IF744 745 !--- Isotopic checking routines activation flag746 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 DO755 DO iz=1,i%nzone; CALL msg('itZonIso('//TRIM(int2str(iz))//',:) = '//strStack(int2str(i%itZonIso(iz,:))), modname); END DO756 757 !--- Finalize :758 DEALLOCATE(nb_iso)759 760 END SUBROUTINE infotrac_isoinit761 474 762 475
Note: See TracChangeset
for help on using the changeset viewer.