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