[4143] | 1 | SUBROUTINE check_isotopes_seq(q, ip1jmp1, err_msg) |
---|
| 2 | USE strings_mod, ONLY: maxlen, msg, strIdx, strStack, int2str, real2str |
---|
| 3 | USE infotrac, ONLY: nqtot, niso, nphas, isotope, isoCheck, iqIsoPha, isoSelect, & |
---|
[5214] | 4 | ntiso, iH2O, nzone, tracers, isoName, itZonIso |
---|
| 5 | USE iso_params_mod, ONLY: tnat_H216O, tnat_H217O, tnat_H218O, tnat_HDO, tnat_HTO |
---|
[5201] | 6 | USE ioipsl, ONLY: getin |
---|
[5271] | 7 | USE dimensions_mod, ONLY: iim, jjm, llm, ndm |
---|
| 8 | IMPLICIT NONE |
---|
| 9 | |
---|
[4143] | 10 | REAL, INTENT(INOUT) :: q(ip1jmp1,llm,nqtot) |
---|
| 11 | INTEGER, INTENT(IN) :: ip1jmp1 |
---|
| 12 | CHARACTER(LEN=*), INTENT(IN) :: err_msg !--- Error message to display |
---|
| 13 | CHARACTER(LEN=maxlen) :: modname, msg1, nm(2) |
---|
| 14 | INTEGER :: ixt, ipha, k, i, iq, iiso, izon, ieau, iqeau, iqpar |
---|
[5214] | 15 | INTEGER, ALLOCATABLE :: ix(:) |
---|
[4367] | 16 | REAL, ALLOCATABLE, SAVE :: tnat(:) |
---|
[5214] | 17 | REAL :: xtractot, xiiso, deltaD, q1, q2 |
---|
[4143] | 18 | REAL, PARAMETER :: borne = 1e19, & |
---|
| 19 | errmax = 1e-8, & !--- Max. absolute error |
---|
| 20 | errmaxrel = 1e-3, & !--- Max. relative error |
---|
| 21 | qmin = 1e-11, & |
---|
| 22 | deltaDmax =1000.0, & |
---|
| 23 | deltaDmin =-999.0, & |
---|
| 24 | ridicule = 1e-12 |
---|
[5200] | 25 | INTEGER, SAVE :: iso_eau, iso_O17, iso_O18, iso_HDO, iso_HTO |
---|
[5214] | 26 | LOGICAL :: ltnat1 |
---|
| 27 | LOGICAL, SAVE :: first=.TRUE. |
---|
[2270] | 28 | |
---|
[4143] | 29 | modname='check_isotopes' |
---|
| 30 | IF(.NOT.isoCheck) RETURN !--- No need to check => finished |
---|
| 31 | IF(isoSelect('H2O')) RETURN !--- No H2O isotopes group found |
---|
| 32 | IF(niso == 0) RETURN !--- No isotopes => finished |
---|
| 33 | IF(first) THEN |
---|
[5200] | 34 | ltnat1 = .TRUE.; CALL getin('tnateq1', ltnat1) |
---|
| 35 | ALLOCATE(tnat(niso)) |
---|
[5214] | 36 | iso_eau = strIdx(isoName,'H216O'); IF(iso_eau /= 0) tnat(iso_eau) = tnat_H216O |
---|
| 37 | iso_O17 = strIdx(isoName,'H217O'); IF(iso_O17 /= 0) tnat(iso_O17) = tnat_H217O |
---|
| 38 | iso_O18 = strIdx(isoName,'H218O'); IF(iso_O18 /= 0) tnat(iso_O18) = tnat_H218O |
---|
| 39 | iso_HDO = strIdx(isoName,'HDO'); IF(iso_HDO /= 0) tnat(iso_HDO) = tnat_HDO |
---|
| 40 | iso_HTO = strIdx(isoName,'HTO'); IF(iso_HTO /= 0) tnat(iso_HTO) = tnat_HTO |
---|
| 41 | IF(ltnat1) tnat(:) = 1. |
---|
[4143] | 42 | first = .FALSE. |
---|
| 43 | END IF |
---|
| 44 | CALL msg('31: err_msg='//TRIM(err_msg), modname) |
---|
[2270] | 45 | |
---|
[4143] | 46 | !--- CHECK FOR NaNs (FOR ALL THE ISOTOPES, INCLUDING GEOGRAPHIC TAGGING TRACERS) |
---|
| 47 | modname = 'check_isotopes:iso_verif_noNaN' |
---|
| 48 | DO ixt = 1, ntiso |
---|
| 49 | DO ipha = 1, nphas |
---|
| 50 | iq = iqIsoPha(ixt,ipha) |
---|
| 51 | DO k = 1, llm |
---|
| 52 | DO i = 1, ip1jmp1 |
---|
[5214] | 53 | IF(ABS(q(i,k,iq)) < borne) CYCLE |
---|
[4143] | 54 | WRITE(msg1,'(s,"(",i0,",",i0,",",i0,") = ",ES12.4)')TRIM(isoName(ixt)),i,k,iq,q(i,k,iq) |
---|
| 55 | CALL msg(msg1, modname) |
---|
| 56 | CALL abort_gcm(modname, 'Error with isotopes: '//TRIM(err_msg), 1) |
---|
| 57 | END DO |
---|
| 58 | END DO |
---|
| 59 | END DO |
---|
| 60 | END DO |
---|
[2270] | 61 | |
---|
[4143] | 62 | !--- CHECK CONSERVATION (MAIN ISOTOPE AND PARENT CONCENTRATIONS MUST BE EQUAL) |
---|
| 63 | modname = 'check_isotopes:iso_verif_egalite' |
---|
| 64 | ixt = iso_eau |
---|
| 65 | IF(ixt /= 0) THEN |
---|
| 66 | DO ipha = 1, nphas |
---|
| 67 | iq = iqIsoPha(ixt,ipha) |
---|
| 68 | iqpar = tracers(iq)%iqParent |
---|
| 69 | DO k = 1, llm |
---|
| 70 | DO i = 1, ip1jmp1 |
---|
| 71 | q1 = q(i,k,iqpar) |
---|
| 72 | q2 = q(i,k,iq) |
---|
| 73 | !--- IMPROVEMENT in case at least one isotope is not negligible compared to the main isotopic form. |
---|
| 74 | ! This would be probably required to sum from smallest to highest concentrations ; the corresponding |
---|
| 75 | ! indices vector can be computed once only (in the initializations stage), using mean concentrations. |
---|
| 76 | ! q2 = SUM(q(i,k,tracers(iqPar)%iqDesc), DIM=3) |
---|
| 77 | IF(ABS(q1-q2) <= errmax .OR. ABS(q1-q2)/MAX(MAX(ABS(q1),ABS(q2)),1e-18) <= errmaxrel) THEN |
---|
| 78 | q(i,k,iq) = q1 !--- Bidouille pour convergence |
---|
| 79 | ! q(i,k,tracers(iqPar)%iqDesc) = q(i,k,tracers(iqPar)%iqDesc) * q1 / q2 |
---|
| 80 | CYCLE |
---|
| 81 | END IF |
---|
| 82 | CALL msg('ixt, iq = '//TRIM(strStack(int2str([ixt,iq]))), modname) |
---|
| 83 | msg1 = '('//TRIM(strStack(int2str([i,k])))//')' |
---|
| 84 | CALL msg(TRIM(tracers(iqpar)%name)//TRIM(msg1)//' = '//TRIM(real2str(q1)), modname) |
---|
| 85 | CALL msg(TRIM(tracers(iq )%name)//TRIM(msg1)//' = '//TRIM(real2str(q2)), modname) |
---|
| 86 | CALL abort_gcm(modname, 'Error with isotopes: '//TRIM(err_msg), 1) |
---|
| 87 | END DO |
---|
| 88 | END DO |
---|
| 89 | END DO |
---|
| 90 | END IF |
---|
[2270] | 91 | |
---|
[4143] | 92 | !--- CHECK DELTA ANOMALIES |
---|
| 93 | modname = 'check_isotopes:iso_verif_aberrant' |
---|
| 94 | ix = [ iso_HDO , iso_O18 ] |
---|
| 95 | nm = ['deltaD ', 'deltaO18'] |
---|
| 96 | DO iiso = 1, SIZE(ix) |
---|
| 97 | ixt = ix(iiso) |
---|
| 98 | IF(ixt == 0) CYCLE |
---|
| 99 | DO ipha = 1, nphas |
---|
| 100 | iq = iqIsoPha(ixt,ipha) |
---|
| 101 | iqpar = tracers(iq)%iqParent |
---|
| 102 | DO k = 1, llm |
---|
| 103 | DO i = 1, ip1jmp1 |
---|
| 104 | q1 = q(i,k,iqpar) |
---|
| 105 | q2 = q(i,k,iq) |
---|
| 106 | !--- IMPROVEMENT in case at least one isotope is not negligible compared to the main isotopic form. |
---|
| 107 | ! This would be probably required to sum from smallest to highest concentrations ; the corresponding |
---|
| 108 | ! indices vector can be computed once only (in the initializations stage), using mean concentrations. |
---|
| 109 | ! q2 = SUM(q(i,k,tracers(iqPar)%iqDesc), DIM=3) |
---|
| 110 | IF(q2 <= qmin) CYCLE |
---|
| 111 | deltaD = (q2/q1/tnat(ixt)-1.)*1000. |
---|
| 112 | IF(deltaD <= deltaDmax .AND. deltaD >= deltaDmin) CYCLE |
---|
| 113 | CALL msg('ixt, iq = '//TRIM(strStack(int2str([ixt,iq]))), modname) |
---|
| 114 | msg1 = '('//TRIM(strStack(int2str([i,k])))//')' |
---|
| 115 | CALL msg(TRIM(tracers(iqpar)%name)//TRIM(msg1)//' = '//TRIM(real2str(q1)), modname) |
---|
| 116 | CALL msg(TRIM(tracers(iq )%name)//TRIM(msg1)//' = '//TRIM(real2str(q2)), modname) |
---|
| 117 | CALL msg(TRIM(nm(iiso))//TRIM(real2str(deltaD)), modname) |
---|
| 118 | CALL abort_gcm(modname, 'Error with isotopes: '//TRIM(err_msg), 1) |
---|
| 119 | END DO |
---|
| 120 | END DO |
---|
| 121 | END DO |
---|
| 122 | END DO |
---|
[2270] | 123 | |
---|
[4143] | 124 | IF(nzone == 0) RETURN |
---|
[2270] | 125 | |
---|
[4143] | 126 | !--- CHECK FOR TAGGING TRACERS DELTAD ANOMALIES |
---|
| 127 | modname = 'check_isotopes:iso_verif_aberrant' |
---|
| 128 | IF(iso_eau /= 0 .AND. iso_HDO /= 0) THEN |
---|
| 129 | DO izon = 1, nzone |
---|
| 130 | ixt = itZonIso(izon, iso_HDO) |
---|
| 131 | ieau = itZonIso(izon, iso_eau) |
---|
| 132 | DO ipha = 1, nphas |
---|
| 133 | iq = iqIsoPha(ixt, ipha) |
---|
| 134 | iqeau = iqIsoPha(ieau, ipha) |
---|
| 135 | DO k = 1, llm |
---|
| 136 | DO i = 1, ip1jmp1 |
---|
| 137 | q1 = q(i,k,iqeau) |
---|
| 138 | q2 = q(i,k,iq) |
---|
| 139 | IF(q2<=qmin) CYCLE |
---|
| 140 | deltaD = (q2/q1/tnat(iso_HDO)-1.)*1000. |
---|
| 141 | IF(deltaD <= deltaDmax .AND. deltaD >= deltaDmin) CYCLE |
---|
| 142 | CALL msg('izon, ipha = '//TRIM(strStack(int2str([izon, ipha]))), modname) |
---|
| 143 | CALL msg( 'ixt, ieau = '//TRIM(strStack(int2str([ ixt, ieau]))), modname) |
---|
| 144 | msg1 = '('//TRIM(strStack(int2str([i,k])))//')' |
---|
| 145 | CALL msg(TRIM(tracers(iqeau)%name)//TRIM(msg1)//' = '//TRIM(real2str(q1)), modname) |
---|
| 146 | CALL msg(TRIM(tracers(iq )%name)//TRIM(msg1)//' = '//TRIM(real2str(q2)), modname) |
---|
| 147 | CALL msg('deltaD = '//TRIM(real2str(deltaD)), modname) |
---|
| 148 | CALL abort_gcm(modname, 'Error with isotopes: '//TRIM(err_msg), 1) |
---|
| 149 | END DO |
---|
| 150 | END DO |
---|
| 151 | END DO |
---|
| 152 | END DO |
---|
| 153 | END IF |
---|
[2270] | 154 | |
---|
[4143] | 155 | !--- CHECK FOR TAGGING TRACERS CONSERVATION (PARENT AND TAGGING TRACERS SUM OVER ALL REGIONS MUST BE EQUAL) |
---|
| 156 | DO iiso = 1, niso |
---|
| 157 | DO ipha = 1, nphas |
---|
| 158 | iq = iqIsoPha(iiso, ipha) |
---|
| 159 | DO k = 1, llm |
---|
| 160 | DO i = 1, ip1jmp1 |
---|
| 161 | xiiso = q(i,k,iq) |
---|
| 162 | xtractot = SUM(q(i, k, iqIsoPha(itZonIso(1:nzone,iiso), ipha))) |
---|
| 163 | IF(ABS(xtractot-xiiso) > errmax .AND. ABS(xtractot-xiiso)/MAX(MAX(ABS(xtractot),ABS(xiiso)),1e-18) > errmaxrel) THEN |
---|
| 164 | CALL msg('Error in iso_verif_aberrant trac: '//TRIM(err_msg)) |
---|
| 165 | CALL msg('iiso, ipha = '//TRIM(strStack(int2str([iiso, ipha]))), modname) |
---|
| 166 | CALL msg('q('//TRIM(strStack(int2str([i,k])))//',:) = '//TRIM(strStack(real2str(q(i,k,:)))), modname) |
---|
| 167 | CALL abort_gcm(modname, 'Error with isotopes: '//TRIM(err_msg), 1) |
---|
| 168 | END IF |
---|
| 169 | IF(ABS(xtractot) <= ridicule) CYCLE |
---|
| 170 | DO izon = 1, nzone |
---|
| 171 | q(i,k,iq) = q(i,k,iq) / xtractot * xiiso !--- Bidouille pour convergence |
---|
| 172 | END DO |
---|
| 173 | END DO |
---|
| 174 | END DO |
---|
| 175 | END DO |
---|
| 176 | END DO |
---|
[2270] | 177 | |
---|
[4143] | 178 | END SUBROUTINE check_isotopes_seq |
---|
[2270] | 179 | |
---|