1 | #--reworked 7/2018 for scenario emissions, ThL |
---|
2 | #--updated on 5/2/2018 with new paths, ThL |
---|
3 | #--updated on 4/5/2017 with improved Sheng & Zwiers algorithm, ThL |
---|
4 | #--corrected some interpolation preprocessing (compared to v4) |
---|
5 | #--updated on 5/5/2017 with correction factor (30/46) on NOx vs. NO |
---|
6 | #--updated on 9/5/2017 with output separation BB/anthro for SO2, NOx and NH3 |
---|
7 | #--corrected on 22/6/2017 for BB: undef values zeroed before remapping |
---|
8 | #--corrected on 26/09/2017 for NOx units: PNNL dataset is kg NO2, VUA is kg NO. |
---|
9 | # INCA expects NO in its AER version. |
---|
10 | # |
---|
11 | #INCA conc_dms flx_nox flx_bc flx_pom flx_bbbc flx_bbpom flx_so2 flx_so4 flx_h2s flx_nh3 |
---|
12 | #CMIP6 species NOx BC OC SO2 NH3 |
---|
13 | # + NMVOC CO |
---|
14 | |
---|
15 | #--INCA example file where dms_conc can be reused |
---|
16 | fileINCAex="/home/oboucher/CMIP6/AER_EMISSIONS/INCAfile/sflx_lmdz_phy_1997.nc" |
---|
17 | |
---|
18 | #--input directory for emissions |
---|
19 | dirin="/prodigfs/project/input4MIPs/CMIP6/ScenarioMIP/IAMC/" |
---|
20 | |
---|
21 | #--LMDz grid information |
---|
22 | grid="144x143" |
---|
23 | gridfile="../GRID/grid-lmdz-lonlat_"${grid} |
---|
24 | nbpoint=$((144*141+2)) |
---|
25 | |
---|
26 | for scen in "ssp119" "ssp126" "ssp245" "ssp370" "ssp434" "ssp460" "ssp534-over" "ssp585" |
---|
27 | do |
---|
28 | |
---|
29 | #--output directory |
---|
30 | dirout="/data/"${USER}"/CMIP6/AEROSOL/ScenarioMIP/${scen}/v1/" |
---|
31 | if [ ! -d ${dirout} ] ; then mkdir -p ${dirout} ; fi |
---|
32 | |
---|
33 | if [ ${scen} == "ssp119" ] ; then prefix="IMAGE" ; fi |
---|
34 | if [ ${scen} == "ssp126" ] ; then prefix="IMAGE" ; fi |
---|
35 | if [ ${scen} == "ssp245" ] ; then prefix="MESSAGE-GLOBIOM" ; fi |
---|
36 | if [ ${scen} == "ssp370" ] ; then prefix="AIM" ; fi |
---|
37 | if [ ${scen} == "ssp434" ] ; then prefix="GCAM4" ; fi |
---|
38 | if [ ${scen} == "ssp460" ] ; then prefix="GCAM4" ; fi |
---|
39 | if [ ${scen} == "ssp534-over" ] ; then prefix="REMIND-MAGPIE" ; fi |
---|
40 | if [ ${scen} == "ssp585" ] ; then prefix="REMIND-MAGPIE" ; fi |
---|
41 | |
---|
42 | #--Unique file for the whole period, so fixed variables: |
---|
43 | year1=2015 |
---|
44 | year2=2100 |
---|
45 | |
---|
46 | #--Loop on species (anthro) |
---|
47 | for species in "BC" "NOx" "OC" "SO2" "NH3" |
---|
48 | do |
---|
49 | |
---|
50 | echo "... "${year}" : Dealing with "${species}" anthro input file..." |
---|
51 | |
---|
52 | if [ ${species} = "BC" ] ; then speciesinca="bc" ; fi |
---|
53 | if [ ${species} = "NOx" ] ; then speciesinca="nox" ; fi |
---|
54 | if [ ${species} = "OC" ] ; then speciesinca="pom" ; fi |
---|
55 | if [ ${species} = "SO2" ] ; then speciesinca="so2" ; fi |
---|
56 | if [ ${species} = "NH3" ] ; then speciesinca="nh3" ; fi |
---|
57 | |
---|
58 | if [ ${species} = "BC" ] ; then speciesUp="BC" ; fi |
---|
59 | if [ ${species} = "NOx" ] ; then speciesUp="NOX" ; fi |
---|
60 | if [ ${species} = "OC" ] ; then speciesUp="OC" ; fi |
---|
61 | if [ ${species} = "SO2" ] ; then speciesUp="SO2" ; fi |
---|
62 | if [ ${species} = "NH3" ] ; then speciesUp="NH3" ; fi |
---|
63 | |
---|
64 | #--input file anthro |
---|
65 | filename=${dirin}IAMC-${prefix}-${scen}-1-1/atmos/mon/${species}_em_anthro/gn/v20180628/${species}-em-anthro_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12.nc |
---|
66 | |
---|
67 | #--input file summed over sectors |
---|
68 | filesum=${dirout}${species}-em-anthro_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_sum.nc |
---|
69 | #--reworked input file |
---|
70 | filetmp=${dirout}${species}-em-anthro_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_tmp.nc |
---|
71 | #--time-interpolated input file |
---|
72 | fileintanthro=${dirout}${species}-em-anthro_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_interp.nc |
---|
73 | |
---|
74 | if [ -f ${fileintanthro} ] |
---|
75 | then |
---|
76 | echo "...Nothing to do!" |
---|
77 | else |
---|
78 | |
---|
79 | rm -f ${filesum} ${filetmp} ${fileintanthro} |
---|
80 | |
---|
81 | #--re-formatting the input file |
---|
82 | #--summing over sectors |
---|
83 | rm -f sumsectors.jnl |
---|
84 | cat << eod > sumsectors.jnl |
---|
85 | set memory/size=100 |
---|
86 | use "${filename}" |
---|
87 | save/clobber/file="${filesum}" ${species}_EM_ANTHRO[k=@sum] |
---|
88 | eod |
---|
89 | #--run ferret script |
---|
90 | ferret << eod |
---|
91 | go sumsectors.jnl |
---|
92 | exit |
---|
93 | eod |
---|
94 | |
---|
95 | #--reformatting input file for IDL to be able to read |
---|
96 | ncks -3 ${filesum} ${filetmp} |
---|
97 | #--cleaning up |
---|
98 | rm -f ${filesum} |
---|
99 | |
---|
100 | #--IDL code for time interpolation, to fill in 9-year gaps in input file |
---|
101 | rm -f time_interp_over_gaps.pro |
---|
102 | cat << eod >> time_interp_over_gaps.pro |
---|
103 | pro time_interp_over_gaps |
---|
104 | |
---|
105 | ; Les dimensions des fichiers |
---|
106 | nlon=720 |
---|
107 | nlat=360 |
---|
108 | nt=1032 |
---|
109 | |
---|
110 | une_annee=[31,30,29,31,30,31,30,31,31,30,31,30] |
---|
111 | les_mois = [31,28,31,30,31,30,31,31,30,31,30,31] |
---|
112 | |
---|
113 | jours_in = [15, 45, 74, 105, 135, 166, 196, 227, 258, 288, 319, 349, 1840, 1870, $ |
---|
114 | 1899, 1930, 1960, 1991, 2021, 2052, 2083, 2113, 2144, 2174, 5490, 5520, $ |
---|
115 | 5549, 5580, 5610, 5641, 5671, 5702, 5733, 5763, 5794, 5824, 9140, 9170, $ |
---|
116 | 9199, 9230, 9260, 9291, 9321, 9352, 9383, 9413, 9444, 9474, 12790, 12820, $ |
---|
117 | 12849, 12880, 12910, 12941, 12971, 13002, 13033, 13063, 13094, 13124, $ |
---|
118 | 16440, 16470, 16499, 16530, 16560, 16591, 16621, 16652, 16683, 16713, $ |
---|
119 | 16744, 16774, 20090, 20120, 20149, 20180, 20210, 20241, 20271, 20302, $ |
---|
120 | 20333, 20363, 20394, 20424, 23740, 23770, 23799, 23830, 23860, 23891, $ |
---|
121 | 23921, 23952, 23983, 24013, 24044, 24074, 27390, 27420, 27449, 27480, $ |
---|
122 | 27510, 27541, 27571, 27602, 27633, 27663, 27694, 27724, 31040, 31070, $ |
---|
123 | 31099, 31130, 31160, 31191, 31221, 31252, 31283, 31313, 31344, 31374] |
---|
124 | |
---|
125 | jours_out=make_array(1032) |
---|
126 | jours_out(0) = 15 |
---|
127 | for cpt=1,1031 do jours_out(cpt) = jours_out(cpt-1) + une_annee(cpt mod 12) |
---|
128 | |
---|
129 | idin = ncdf_open('${filetmp}') |
---|
130 | varid = ncdf_varid(idin,'${speciesUp}_EM_ANTHRO') |
---|
131 | lonid = ncdf_varid(idin,'LON') |
---|
132 | latid = ncdf_varid(idin,'LAT') |
---|
133 | ;lonbndid = ncdf_varid(idin,'LON_bnds') |
---|
134 | ;latbndid = ncdf_varid(idin,'LAT_bnds') |
---|
135 | timbndid = ncdf_varid(idin,'TIME_bnds') |
---|
136 | ncdf_varget, idin, varid, emiss_init |
---|
137 | ncdf_attget, idin, varid, "units", emiss_unit |
---|
138 | ncdf_attget, idin, varid, "long_name", emiss_longname |
---|
139 | ncdf_varget, idin, lonid, lon |
---|
140 | ncdf_varget, idin, latid, lat |
---|
141 | ;ncdf_varget, idin, lonbndid, lonbnds |
---|
142 | ;ncdf_varget, idin, latbndid, latbnds |
---|
143 | ncdf_varget, idin, timbndid, timbnds_in |
---|
144 | ncdf_close, idin |
---|
145 | |
---|
146 | timbnds_out = make_array(2,1032) |
---|
147 | timbnds_out(*,0) = [0,31] |
---|
148 | timbnds_out(*,1) = [31,59] |
---|
149 | for cpt=2,1031 do timbnds_out(0,cpt) = timbnds_out(0,cpt-1) + les_mois((cpt-1) mod 12) |
---|
150 | for cpt=1,1030 do timbnds_out(1,cpt) = timbnds_out(0,cpt+1) |
---|
151 | timbnds_out(1,1031) = 31390 |
---|
152 | |
---|
153 | emiss_interpol=make_array(nlon,nlat,1032,value=0.) |
---|
154 | |
---|
155 | indices_out_mois = make_array(86,12,value=0) |
---|
156 | for m=0,11 do begin |
---|
157 | for n=0,85 do indices_out_mois(n,m) = 12*n + m |
---|
158 | endfor |
---|
159 | |
---|
160 | jours_out_mois = make_array(86,12,value=0) |
---|
161 | for n=0,85 do begin |
---|
162 | for m=0,11 do jours_out_mois(n,m) = jours_out(indices_out_mois(n,m)) |
---|
163 | endfor |
---|
164 | |
---|
165 | jours_in_mois = make_array(n_elements(jours_in)/12,12,value=0) |
---|
166 | for m=0,11 do begin |
---|
167 | for n=0,n_elements(jours_in)/12-1 do jours_in_mois(n,m) = jours_in(n*12 + m) |
---|
168 | endfor |
---|
169 | |
---|
170 | indices_in_mois = make_array(n_elements(jours_in)/12,12,value=0) |
---|
171 | for m=0,11 do begin |
---|
172 | for n=0,n_elements(jours_in)/12-1 do indices_in_mois(n,m) = where(jours_in eq jours_in_mois(n,m)) |
---|
173 | endfor |
---|
174 | |
---|
175 | ; Interpolation mois par mois... |
---|
176 | for i=0,nlon-1 do begin |
---|
177 | for j=0,nlat-1 do begin |
---|
178 | for m=0,11 do begin |
---|
179 | emiss_interpol(i,j,indices_out_mois(*,m)) = interpol(emiss_init(i,j,indices_in_mois(*,m)),jours_in_mois(*,m),jours_out_mois(*,m)) |
---|
180 | endfor |
---|
181 | endfor |
---|
182 | endfor |
---|
183 | |
---|
184 | idout = ncdf_create('${fileintanthro}', /clobber) |
---|
185 | dimlonid = ncdf_dimdef(idout,'lon',nlon) |
---|
186 | dimlatid = ncdf_dimdef(idout,'lat',nlat) |
---|
187 | dimtimid = ncdf_dimdef(idout,'time',1032) |
---|
188 | dimbndid = ncdf_dimdef(idout,'bound',2) |
---|
189 | varlonid = ncdf_vardef(idout, 'lon', [dimlonid], /double) |
---|
190 | varlatid = ncdf_vardef(idout, 'lat', [dimlatid], /double) |
---|
191 | vartimid = ncdf_vardef(idout, 'time', [dimtimid], /double) |
---|
192 | ;varlonbndsid = ncdf_vardef(idout, 'lon_bnds', [dimbndid,dimlonid], /double) |
---|
193 | ;varlatbndsid = ncdf_vardef(idout, 'lat_bnds', [dimbndid,dimlatid], /double) |
---|
194 | vartimbndsid = ncdf_vardef(idout, 'time_bnds', [dimbndid,dimtimid], /double) |
---|
195 | varemissid = ncdf_vardef(idout, '${species}_em_anthro', [dimlonid,dimlatid,dimtimid], /float) |
---|
196 | ncdf_control, idout, /endef |
---|
197 | ncdf_varput, idout, varlonid, lon |
---|
198 | ncdf_varput, idout, varlatid, lat |
---|
199 | ;ncdf_varput, idout, varlonbndsid, lonbnds |
---|
200 | ;ncdf_varput, idout, varlatbndsid, latbnds |
---|
201 | ncdf_varput, idout, vartimbndsid, timbnds_out |
---|
202 | ncdf_varput, idout, varemissid, emiss_interpol |
---|
203 | ncdf_varput, idout, vartimid, jours_out |
---|
204 | ncdf_control, idout, /redef |
---|
205 | ncdf_attput, idout, varlonid, "units", "degrees_east" |
---|
206 | ncdf_attput, idout, varlonid, "long_name", "longitude" |
---|
207 | ncdf_attput, idout, varlonid, "axis", "X" |
---|
208 | ncdf_attput, idout, varlonid, "bounds", "lon_bnds" |
---|
209 | ncdf_attput, idout, varlonid, "modulo", 360. |
---|
210 | ncdf_attput, idout, varlonid, "realtopology", "circular" |
---|
211 | ncdf_attput, idout, varlonid, "standard_name", "longitude" |
---|
212 | ncdf_attput, idout, varlonid, "topology", "circular" |
---|
213 | ncdf_attput, idout, varlatid, "units", "degrees_north" |
---|
214 | ncdf_attput, idout, varlatid, "long_name", "latitude" |
---|
215 | ncdf_attput, idout, varlatid, "axis", "Y" |
---|
216 | ncdf_attput, idout, varlatid, "bounds", "lat_bnds" |
---|
217 | ncdf_attput, idout, varlatid, "realtopology", "linear" |
---|
218 | ncdf_attput, idout, varlatid, "standard_name", "latitude" |
---|
219 | ncdf_attput, idout, varemissid, "units", string(emiss_unit) |
---|
220 | ncdf_attput, idout, varemissid, "_FillValue", 1.e+20 |
---|
221 | ncdf_attput, idout, varemissid, "cell_methods", "time: mean" |
---|
222 | ncdf_attput, idout, varemissid, "long_name", string(emiss_longname) |
---|
223 | ncdf_attput, idout, varemissid, "missing_value", 1.e+20 |
---|
224 | ncdf_attput, idout, vartimid, "units", "days since 2015-01-01 0:0:0" |
---|
225 | ncdf_attput, idout, vartimid, "long_name", "time" |
---|
226 | ncdf_attput, idout, vartimid, "calendar", '365_day' |
---|
227 | ncdf_attput, idout, vartimid, "axis", "T" |
---|
228 | ncdf_attput, idout, vartimid, "bounds", "time_bnds" |
---|
229 | ncdf_attput, idout, vartimid, "realtopology", "linear" |
---|
230 | ncdf_attput, idout, vartimid, "standard_name", "time" |
---|
231 | ncdf_close, idout |
---|
232 | end |
---|
233 | eod |
---|
234 | # |
---|
235 | #--calling IDL |
---|
236 | # |
---|
237 | /opt/idl-6.4/idl/bin/idl << eod |
---|
238 | .r time_interp_over_gaps.pro |
---|
239 | time_interp_over_gaps |
---|
240 | exit |
---|
241 | eod |
---|
242 | # |
---|
243 | |
---|
244 | #--adding lat_bnds and lon_bnds variables |
---|
245 | ncks -A -v lat_bnds,lon_bnds ${filename} ${fileintanthro} |
---|
246 | |
---|
247 | #--cleaning up |
---|
248 | rm -f ${filetmp} |
---|
249 | |
---|
250 | #--end test whether file tmp already exists |
---|
251 | fi |
---|
252 | |
---|
253 | |
---|
254 | |
---|
255 | #--now dealing with the BB input file |
---|
256 | |
---|
257 | echo "... "${year}" : Dealing with "${species}" openburning input file..." |
---|
258 | |
---|
259 | #--input file BB |
---|
260 | filename=${dirin}IAMC-${prefix}-${scen}-1-1/atmos/mon/${species}_em_openburning/gn/v20180628/${species}-em-openburning_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12.nc |
---|
261 | #--reworked input file |
---|
262 | filetmp=${dirout}${species}-em-openburning_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_tmp.nc |
---|
263 | #--time-interpolated input file |
---|
264 | fileintbb=${dirout}${species}-em-openburning_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_interp.nc |
---|
265 | |
---|
266 | if [ -f ${fileintbb} ] |
---|
267 | then |
---|
268 | echo "...Nothing to do!" |
---|
269 | else |
---|
270 | |
---|
271 | rm -f ${filetmp} ${fileintbb} |
---|
272 | |
---|
273 | #--no need to sum over sectors, as none in BB files |
---|
274 | |
---|
275 | #--reformatting input file for IDL to be able to read |
---|
276 | ncks -3 ${filename} ${filetmp} |
---|
277 | |
---|
278 | #--IDL code for time interpolation, to fill in 9-year gaps in input file |
---|
279 | rm -f time_interp_over_gaps.pro |
---|
280 | cat << eod >> time_interp_over_gaps.pro |
---|
281 | pro time_interp_over_gaps |
---|
282 | |
---|
283 | ; Les dimensions des fichiers |
---|
284 | nlon=720 |
---|
285 | nlat=360 |
---|
286 | nt=1032 |
---|
287 | |
---|
288 | une_annee=[31,30,29,31,30,31,30,31,31,30,31,30] |
---|
289 | les_mois = [31,28,31,30,31,30,31,31,30,31,30,31] |
---|
290 | |
---|
291 | jours_in = [15, 45, 74, 105, 135, 166, 196, 227, 258, 288, 319, 349, 1840, 1870, $ |
---|
292 | 1899, 1930, 1960, 1991, 2021, 2052, 2083, 2113, 2144, 2174, 5490, 5520, $ |
---|
293 | 5549, 5580, 5610, 5641, 5671, 5702, 5733, 5763, 5794, 5824, 9140, 9170, $ |
---|
294 | 9199, 9230, 9260, 9291, 9321, 9352, 9383, 9413, 9444, 9474, 12790, 12820, $ |
---|
295 | 12849, 12880, 12910, 12941, 12971, 13002, 13033, 13063, 13094, 13124, $ |
---|
296 | 16440, 16470, 16499, 16530, 16560, 16591, 16621, 16652, 16683, 16713, $ |
---|
297 | 16744, 16774, 20090, 20120, 20149, 20180, 20210, 20241, 20271, 20302, $ |
---|
298 | 20333, 20363, 20394, 20424, 23740, 23770, 23799, 23830, 23860, 23891, $ |
---|
299 | 23921, 23952, 23983, 24013, 24044, 24074, 27390, 27420, 27449, 27480, $ |
---|
300 | 27510, 27541, 27571, 27602, 27633, 27663, 27694, 27724, 31040, 31070, $ |
---|
301 | 31099, 31130, 31160, 31191, 31221, 31252, 31283, 31313, 31344, 31374] |
---|
302 | |
---|
303 | jours_out=make_array(1032) |
---|
304 | jours_out(0) = 15 |
---|
305 | for cpt=1,1031 do jours_out(cpt) = jours_out(cpt-1) + une_annee(cpt mod 12) |
---|
306 | |
---|
307 | idin = ncdf_open('${filetmp}') |
---|
308 | varid = ncdf_varid(idin,'${species}_em_openburning') ; Here, small caps |
---|
309 | lonid = ncdf_varid(idin,'lon') |
---|
310 | latid = ncdf_varid(idin,'lat') |
---|
311 | ;lonbndid = ncdf_varid(idin,'lon_bnds') |
---|
312 | ;latbndid = ncdf_varid(idin,'lat_bnds') |
---|
313 | timbndid = ncdf_varid(idin,'time_bnds') |
---|
314 | ncdf_varget, idin, varid, emiss_init |
---|
315 | ncdf_attget, idin, varid, "units", emiss_unit |
---|
316 | ncdf_attget, idin, varid, "long_name", emiss_longname |
---|
317 | ncdf_varget, idin, lonid, lon |
---|
318 | ncdf_varget, idin, latid, lat |
---|
319 | ;ncdf_varget, idin, lonbndid, lonbnds |
---|
320 | ;ncdf_varget, idin, latbndid, latbnds |
---|
321 | ncdf_varget, idin, timbndid, timbnds_in |
---|
322 | ncdf_close, idin |
---|
323 | |
---|
324 | timbnds_out = make_array(2,1032) |
---|
325 | timbnds_out(*,0) = [0,31] |
---|
326 | timbnds_out(*,1) = [31,59] |
---|
327 | for cpt=2,1031 do timbnds_out(0,cpt) = timbnds_out(0,cpt-1) + une_annee((cpt-1) mod 12) |
---|
328 | for cpt=1,1030 do timbnds_out(1,cpt) = timbnds_out(0,cpt+1) |
---|
329 | timbnds_out(1,1031) = 31390 |
---|
330 | |
---|
331 | emiss_interpol=make_array(nlon,nlat,1032,value=0.) |
---|
332 | |
---|
333 | indices_out_mois = make_array(86,12,value=0) |
---|
334 | for m=0,11 do begin |
---|
335 | for n=0,85 do indices_out_mois(n,m) = 12*n + m |
---|
336 | endfor |
---|
337 | |
---|
338 | jours_out_mois = make_array(86,12,value=0) |
---|
339 | for n=0,85 do begin |
---|
340 | for m=0,11 do jours_out_mois(n,m) = jours_out(indices_out_mois(n,m)) |
---|
341 | endfor |
---|
342 | |
---|
343 | jours_in_mois = make_array(n_elements(jours_in)/12,12,value=0) |
---|
344 | for m=0,11 do begin |
---|
345 | for n=0,n_elements(jours_in)/12-1 do jours_in_mois(n,m) = jours_in(n*12 + m) |
---|
346 | endfor |
---|
347 | |
---|
348 | indices_in_mois = make_array(n_elements(jours_in)/12,12,value=0) |
---|
349 | for m=0,11 do begin |
---|
350 | for n=0,n_elements(jours_in)/12-1 do indices_in_mois(n,m) = where(jours_in eq jours_in_mois(n,m)) |
---|
351 | endfor |
---|
352 | |
---|
353 | ; Interpolation mois par mois... |
---|
354 | for i=0,nlon-1 do begin |
---|
355 | for j=0,nlat-1 do begin |
---|
356 | for m=0,11 do begin |
---|
357 | emiss_interpol(i,j,indices_out_mois(*,m)) = interpol(emiss_init(i,j,indices_in_mois(*,m)),jours_in_mois(*,m),jours_out_mois(*,m)) |
---|
358 | endfor |
---|
359 | endfor |
---|
360 | endfor |
---|
361 | |
---|
362 | idout = ncdf_create('${fileintbb}', /clobber) |
---|
363 | dimlonid = ncdf_dimdef(idout,'lon',nlon) |
---|
364 | dimlatid = ncdf_dimdef(idout,'lat',nlat) |
---|
365 | dimtimid = ncdf_dimdef(idout,'time',1032) |
---|
366 | dimbndid = ncdf_dimdef(idout,'bound',2) |
---|
367 | varlonid = ncdf_vardef(idout, 'lon', [dimlonid], /double) |
---|
368 | varlatid = ncdf_vardef(idout, 'lat', [dimlatid], /double) |
---|
369 | vartimid = ncdf_vardef(idout, 'time', [dimtimid], /double) |
---|
370 | ;varlonbndsid = ncdf_vardef(idout, 'lon_bnds', [dimbndid,dimlonid], /double) |
---|
371 | ;varlatbndsid = ncdf_vardef(idout, 'lat_bnds', [dimbndid,dimlatid], /double) |
---|
372 | vartimbndsid = ncdf_vardef(idout, 'time_bnds', [dimbndid,dimtimid], /double) |
---|
373 | varemissid = ncdf_vardef(idout, '${species}_em_openburning', [dimlonid,dimlatid,dimtimid], /float) |
---|
374 | ncdf_control, idout, /endef |
---|
375 | ncdf_varput, idout, varlonid, lon |
---|
376 | ncdf_varput, idout, varlatid, lat |
---|
377 | ;ncdf_varput, idout, varlonbndsid, lonbnds |
---|
378 | ;ncdf_varput, idout, varlatbndsid, latbnds |
---|
379 | ncdf_varput, idout, vartimbndsid, timbnds_out |
---|
380 | ncdf_varput, idout, varemissid, emiss_interpol |
---|
381 | ncdf_varput, idout, vartimid, jours_out |
---|
382 | ncdf_control, idout, /redef |
---|
383 | ncdf_attput, idout, varlonid, "units", "degrees_east" |
---|
384 | ncdf_attput, idout, varlonid, "long_name", "longitude" |
---|
385 | ncdf_attput, idout, varlonid, "axis", "X" |
---|
386 | ncdf_attput, idout, varlonid, "bounds", "lon_bnds" |
---|
387 | ncdf_attput, idout, varlonid, "modulo", 360. |
---|
388 | ncdf_attput, idout, varlonid, "realtopology", "circular" |
---|
389 | ncdf_attput, idout, varlonid, "standard_name", "longitude" |
---|
390 | ncdf_attput, idout, varlonid, "topology", "circular" |
---|
391 | ncdf_attput, idout, varlatid, "units", "degrees_north" |
---|
392 | ncdf_attput, idout, varlatid, "long_name", "latitude" |
---|
393 | ncdf_attput, idout, varlatid, "axis", "Y" |
---|
394 | ncdf_attput, idout, varlatid, "bounds", "lat_bnds" |
---|
395 | ncdf_attput, idout, varlatid, "realtopology", "linear" |
---|
396 | ncdf_attput, idout, varlatid, "standard_name", "latitude" |
---|
397 | ncdf_attput, idout, varemissid, "units", string(emiss_unit) |
---|
398 | ncdf_attput, idout, varemissid, "_FillValue", 1.e+20 |
---|
399 | ncdf_attput, idout, varemissid, "cell_methods", "time: mean" |
---|
400 | ncdf_attput, idout, varemissid, "long_name", string(emiss_longname) |
---|
401 | ncdf_attput, idout, varemissid, "missing_value", 1.e+20 |
---|
402 | ncdf_attput, idout, vartimid, "units", "days since 2015-01-01 0:0:0" |
---|
403 | ncdf_attput, idout, vartimid, "long_name", "time" |
---|
404 | ncdf_attput, idout, vartimid, "calendar", '365_day' |
---|
405 | ncdf_attput, idout, vartimid, "axis", "T" |
---|
406 | ncdf_attput, idout, vartimid, "bounds", "time_bnds" |
---|
407 | ncdf_attput, idout, vartimid, "realtopology", "linear" |
---|
408 | ncdf_attput, idout, vartimid, "standard_name", "time" |
---|
409 | ncdf_close, idout |
---|
410 | end |
---|
411 | eod |
---|
412 | # |
---|
413 | #--calling IDL |
---|
414 | # |
---|
415 | /opt/idl-6.4/idl/bin/idl << eod |
---|
416 | .r time_interp_over_gaps.pro |
---|
417 | time_interp_over_gaps |
---|
418 | exit |
---|
419 | eod |
---|
420 | # |
---|
421 | |
---|
422 | #--adding lat_bnds and lon_bnds variables |
---|
423 | ncks -A -v lat_bnds,lon_bnds ${filename} ${fileintbb} |
---|
424 | |
---|
425 | #--cleaning up |
---|
426 | rm -f ${filetmp} |
---|
427 | |
---|
428 | #--end test if interpolated file already exists |
---|
429 | fi |
---|
430 | |
---|
431 | #--end loop on species |
---|
432 | done |
---|
433 | |
---|
434 | |
---|
435 | |
---|
436 | #--anthro and BB input files fileintanthro and fileintbb are now ready, for the whole period and for the current scenario |
---|
437 | #--new double loop on species and years |
---|
438 | |
---|
439 | #--loop on years |
---|
440 | for year in {2015..2100} |
---|
441 | do |
---|
442 | |
---|
443 | #--loop on species |
---|
444 | for species in "BC" "NOx" "OC" "SO2" "NH3" |
---|
445 | do |
---|
446 | |
---|
447 | if [ ${species} = "BC" ] ; then speciesinca="bc" ; fi |
---|
448 | if [ ${species} = "NOx" ] ; then speciesinca="nox" ; fi |
---|
449 | if [ ${species} = "OC" ] ; then speciesinca="pom" ; fi |
---|
450 | if [ ${species} = "SO2" ] ; then speciesinca="so2" ; fi |
---|
451 | if [ ${species} = "NH3" ] ; then speciesinca="nh3" ; fi |
---|
452 | |
---|
453 | #--dealing with anthro |
---|
454 | |
---|
455 | #--input file |
---|
456 | fileintanthro=${dirout}${species}-em-anthro_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_interp.nc |
---|
457 | #--output files |
---|
458 | filenameout1=${dirout}flux_${speciesinca}_${year}.nc |
---|
459 | filenameout1b=${dirout}flux_0_${speciesinca}_${year}.nc |
---|
460 | filenameout2=${dirout}flux_lmdz_${speciesinca}_${year}.nc |
---|
461 | filenameout3=${dirout}flux_vector_${speciesinca}_${year}.nc |
---|
462 | |
---|
463 | echo ${fileintanthro} ${filenameout1} ${filenameout2} ${filenameout3} |
---|
464 | rm -f ${filenameout1} ${filenameout2} ${filenameout3} |
---|
465 | |
---|
466 | #--extracting the correct year |
---|
467 | rm -f select_yr.jnl |
---|
468 | cat << eod > select_yr.jnl |
---|
469 | set memory/size=100 |
---|
470 | use "${fileintanthro}" |
---|
471 | set region/t=16-jan-${year}:16-dec-${year} |
---|
472 | save/clobber/file="${filenameout1}" ${species}_EM_ANTHRO |
---|
473 | eod |
---|
474 | #--run ferret script |
---|
475 | ferret << eod |
---|
476 | go select_yr.jnl |
---|
477 | exit |
---|
478 | eod |
---|
479 | |
---|
480 | #--replace undef with 0 |
---|
481 | cdo setmisstoc,0.0 ${filenameout1} ${filenameout1b} |
---|
482 | |
---|
483 | #--remap to LMDz grid |
---|
484 | #--OC to POM conversion factor |
---|
485 | #--otherwise change to capital letters if not (eg NOx) |
---|
486 | if [ ${species} == "OC" ] ; then |
---|
487 | echo cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux -mulc,1.4 ${filenameout1b} ${filenameout2} |
---|
488 | cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux -mulc,1.4 ${filenameout1b} ${filenameout2} |
---|
489 | else |
---|
490 | echo cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2} |
---|
491 | cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2} |
---|
492 | fi |
---|
493 | |
---|
494 | #--Improved Sheng & Zwiers algorithm + transform into vector |
---|
495 | rm -f regrid.pro |
---|
496 | cat << eod >> regrid.pro |
---|
497 | pro regrid |
---|
498 | filename='${filenameout2}' |
---|
499 | print, filename |
---|
500 | NETCDFREAD,filename,'flux',flux,dimflux |
---|
501 | NETCDFREAD,filename,'lat',lat,dimlat0 |
---|
502 | NETCDFREAD,filename,'lon',lon,dimlon0 |
---|
503 | NETCDFREAD,filename,'TIME',time,dimtime0 |
---|
504 | dimlat=dimlat0(0) |
---|
505 | dimlon=dimlon0(0) |
---|
506 | dimtime=dimtime0(0) |
---|
507 | print, 'dim flux=', dimflux |
---|
508 | A = float([ [3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8.],$ |
---|
509 | [1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$ |
---|
510 | [0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0.],$ |
---|
511 | [0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0.],$ |
---|
512 | [0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0.],$ |
---|
513 | [0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0.],$ |
---|
514 | [0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0.],$ |
---|
515 | [0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0.],$ |
---|
516 | [0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0.],$ |
---|
517 | [0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0.],$ |
---|
518 | [0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8.],$ |
---|
519 | [1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4.] ]) |
---|
520 | fluxinit=flux |
---|
521 | flux_check=flux |
---|
522 | for lo=0,dimlon-1 do begin |
---|
523 | for la=0,dimlat-1 do begin |
---|
524 | flux_check(lo,la,*) = invert(A) ## transpose(fluxinit(lo,la,*)) |
---|
525 | endfor |
---|
526 | endfor |
---|
527 | m_bloq = make_array(dimlon,dimlat,12,value=0) ; Matrice booléenne "mois à bloquer ou non" |
---|
528 | if total(where(flux_check lt 0)) ne -1 then m_bloq(where(flux_check lt 0)) = 1 |
---|
529 | ; Correction/adaptation de la matrice S&Z en fonction du masque booléen m_bloq |
---|
530 | for lo=0,dimlon-1 do begin |
---|
531 | for la=0,dimlat-1 do begin |
---|
532 | whereneg = where(flux_check(lo,la,*) lt 0) ; (12 pts max) Identification de potentiels points à problÚmes, corrigés négativement |
---|
533 | nbannul=n_elements(whereneg)*(total(whereneg) ne -1) |
---|
534 | flux_corr=flux_check(lo,la,*) ; Création d'un vecteur pour recevoir les valeurs corrigées, initialisé à flux_check au cas où on n'ait rien à faire d'autre qu'une seule itération |
---|
535 | A2 = A ; Je repars de la matrice A initiale, ce pour chaque point de grille |
---|
536 | ; ; Potentiellement plusieurs passages pour éliminer toutes les valeurs négatives |
---|
537 | while nbannul ne 0 do begin ; Si l'on a effectivement des émissions corrigées négativement... |
---|
538 | m_bloq(lo,la,whereneg) = 1 ; Update de la matrice m_bloq |
---|
539 | for m=0,11 do begin |
---|
540 | if m eq 11 then begin ; Pour plus de facilité, mois précédents et suivants codés ici |
---|
541 | p=10 |
---|
542 | s=0 |
---|
543 | endif else if m eq 0 then begin |
---|
544 | p=11 |
---|
545 | s=1 |
---|
546 | endif else begin |
---|
547 | p = m-1 |
---|
548 | s = m+1 |
---|
549 | endelse |
---|
550 | if m_bloq(lo,la,m) then begin ; Je traite les mois bloqués en eux-mêmes |
---|
551 | A2(p,m) = 0. |
---|
552 | A2(m,m) = 1. |
---|
553 | A2(s,m) = 0. |
---|
554 | endif ; Fin du cas si l'on est sur un mois bloqué |
---|
555 | if ~m_bloq(lo,la,m) then begin ; Je traite les mois non bloqués, pour ceux adjacents à un mois bloqué |
---|
556 | if m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois encadré de deux mois bloqués |
---|
557 | A2(p,m) = 1./4. |
---|
558 | A2(m,m) = 1./2. |
---|
559 | A2(s,m) = 1./4. |
---|
560 | endif else if m_bloq(lo,la,p) and ~m_bloq(lo,la,s) then begin ; Mois précédent bloqué (uniquement) |
---|
561 | A2(p,m) = 2./8. |
---|
562 | A2(m,m) = 5./8. |
---|
563 | A2(s,m) = 1./8. |
---|
564 | endif else if ~m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois suivant bloqué (uniquement) |
---|
565 | A2(p,m) = 1./8. |
---|
566 | A2(m,m) = 5./8. |
---|
567 | A2(s,m) = 2./8. |
---|
568 | endif |
---|
569 | endif ; Fin du cas mois non bloqué |
---|
570 | endfor ; Fin de la boucle sur les mois, balayage de la matrice |
---|
571 | flux_corr = invert(A2) ## transpose(fluxinit(lo,la,*)) ; Ré-itération de la multiplication matricielle avec la matrice A modifiée (A2) |
---|
572 | whereneg = where(flux_corr lt 0) ; (12 pts max) Ré-identification de potentiels nouveaux points à problÚmes, corrigés négativement |
---|
573 | nbannul=n_elements(whereneg)*(total(whereneg) ne -1) |
---|
574 | endwhile ; Fin du cas où l'on avait des problÚmes d'émissions corrigées négativement |
---|
575 | ; *** IMPORTANT ! *** Pour signaler les mois bloqués, on prend la convention suivante : |
---|
576 | ; valeur négative ou nulle <=> mois bloqué |
---|
577 | ; valeur positive <=> mois à interpolation classique |
---|
578 | flux(lo,la,*) = flux_corr ; En sortie de la boucle while, normalement flux_corr est complÚtement positif |
---|
579 | endfor ; Fin boucle lat |
---|
580 | endfor ; Fin boucle lon |
---|
581 | nbnegtotal = n_elements(where(m_bloq eq 1)) * (total(where(m_bloq eq 1)) ne -1) |
---|
582 | if nbnegtotal ne 0 then flux(where(m_bloq eq 1)) = -flux(where(m_bloq eq 1)) ; Je force à des valeurs négatives |
---|
583 | ; |
---|
584 | month_in_year=12 |
---|
585 | nbpoint=${nbpoint} |
---|
586 | flux2=fltarr(nbpoint,month_in_year) |
---|
587 | flux2(*,*)=0.0 |
---|
588 | ; |
---|
589 | for l=0,month_in_year-1 do begin |
---|
590 | flux2(0,l)=TOTAL(flux(*,0,l))/float(dimlon) |
---|
591 | flux2(nbpoint-1,l)=TOTAL(flux(*,dimlat-1,l))/float(dimlon) |
---|
592 | endfor |
---|
593 | ; |
---|
594 | pt=1 |
---|
595 | for j=1,dimlat-2 do begin |
---|
596 | for i=0,dimlon-1 do begin |
---|
597 | for l=0,month_in_year-1 do begin |
---|
598 | flux2(pt,l)=flux(i,j,l) |
---|
599 | endfor |
---|
600 | pt=pt+1 |
---|
601 | endfor |
---|
602 | endfor |
---|
603 | ; |
---|
604 | ;saving netcdf file |
---|
605 | ; |
---|
606 | fluxstruct={vector:fltarr(nbpoint),time:fltarr(month_in_year), $ |
---|
607 | flx_${speciesinca}:fltarr(nbpoint,month_in_year) } |
---|
608 | ; |
---|
609 | fluxstruct.vector=float(indgen(nbpoint)+1) |
---|
610 | ;;fluxstruct.time=float(indgen(month_in_year)+1) |
---|
611 | fluxstruct.time=[15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345] |
---|
612 | fluxstruct.flx_${speciesinca}=flux2 |
---|
613 | ; |
---|
614 | attributes = {units:strarr(3),long_name:strarr(3)} |
---|
615 | attributes.units = ['vector','days since 1960-01-01','flux'] |
---|
616 | attributes.long_name = ['vector', 'time', 'flux'] |
---|
617 | ; |
---|
618 | dimensions = {isdim:intarr(3), links:intarr(2,3)} |
---|
619 | dimensions.isdim = [1,1,0] ; (1=dimension, 0=variable) |
---|
620 | dimensions.links = [ [-1,-1],[-1,-1],[0,1] ] |
---|
621 | ; |
---|
622 | netcdfwrite,'${filenameout3}',fluxstruct,clobber=1, attributes=attributes, dimensions=dimensions |
---|
623 | ; |
---|
624 | end |
---|
625 | eod |
---|
626 | # |
---|
627 | #--calling IDL |
---|
628 | # |
---|
629 | /opt/idl-6.4/idl/bin/idl << eod |
---|
630 | .r netcdf |
---|
631 | .r netcdfwrite |
---|
632 | .r struct_dims |
---|
633 | .r regrid |
---|
634 | regrid |
---|
635 | exit |
---|
636 | eod |
---|
637 | # |
---|
638 | |
---|
639 | #--cleaning the mess |
---|
640 | rm -f ferret* |
---|
641 | rm -f regrid.pro |
---|
642 | |
---|
643 | |
---|
644 | #--now dealing with BB |
---|
645 | |
---|
646 | #--input file |
---|
647 | fileintbb=${dirout}${species}-em-openburning_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_interp.nc |
---|
648 | #--output files |
---|
649 | filenameout1=${dirout}flux_${speciesinca}bb_${year}.nc |
---|
650 | filenameout1b=${dirout}flux_0_${speciesinca}bb_${year}.nc |
---|
651 | filenameout2=${dirout}flux_lmdz0_${speciesinca}bb_${year}.nc |
---|
652 | filenameout3=${dirout}flux_vector_${speciesinca}bb_${year}.nc |
---|
653 | |
---|
654 | echo ${fileintbb} ${filenameout1} ${filenameout1b} ${filenameout2} ${filenameout3} |
---|
655 | rm -f ${filenameout1} ${filenameout1b} ${filenameout2} ${filenameout3} |
---|
656 | |
---|
657 | #--unfortunately idl not happy with input netcdf files so need to ferretize files |
---|
658 | #--I extract the correct year as well; no need to sum up sectors, as none in BB files |
---|
659 | rm -f rewrite.jnl |
---|
660 | cat << eod > rewrite.jnl |
---|
661 | set memory/size=100 |
---|
662 | use "${fileintbb}" |
---|
663 | set region/t=16-jan-${year}:16-dec-${year} |
---|
664 | save/clobber/file="${filenameout1}" ${species}_EM_OPENBURNING |
---|
665 | eod |
---|
666 | #--run ferret script |
---|
667 | ferret << eod |
---|
668 | go rewrite.jnl |
---|
669 | exit |
---|
670 | eod |
---|
671 | |
---|
672 | #--replace undef with 0 |
---|
673 | cdo setmisstoc,0.0 ${filenameout1} ${filenameout1b} |
---|
674 | |
---|
675 | #--remap to LMDz grid |
---|
676 | #--OC to POM conversion factor |
---|
677 | #--as ferret returns NOX, treat NOx NOX inconsistency in names by converting to upper case |
---|
678 | if [ ${species} != "OC" ] ; then |
---|
679 | echo cdo remapcon,${gridfile} -chname,`echo ${species}_EM_OPENBURNING | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2} |
---|
680 | cdo remapcon,${gridfile} -chname,`echo ${species}_EM_OPENBURNING | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2} |
---|
681 | else |
---|
682 | echo cdo remapcon,${gridfile} -chname,${species}_EM_OPENBURNING,flux -mulc,1.4 ${filenameout1b} ${filenameout2} |
---|
683 | cdo remapcon,${gridfile} -chname,${species}_EM_OPENBURNING,flux -mulc,1.4 ${filenameout1b} ${filenameout2} |
---|
684 | fi |
---|
685 | |
---|
686 | #--Improved Sheng & Zwiers algorithm + transform into vector |
---|
687 | rm -f regrid.pro |
---|
688 | cat << eod >> regrid.pro |
---|
689 | pro regrid |
---|
690 | filename='${filenameout2}' |
---|
691 | print, filename |
---|
692 | NETCDFREAD,filename,'flux',flux,dimflux |
---|
693 | NETCDFREAD,filename,'lat',lat,dimlat0 |
---|
694 | NETCDFREAD,filename,'lon',lon,dimlon0 |
---|
695 | NETCDFREAD,filename,'TIME',time,dimtime0 |
---|
696 | dimlat=dimlat0(0) |
---|
697 | dimlon=dimlon0(0) |
---|
698 | dimtime=dimtime0(0) |
---|
699 | print, 'dim flux=', dimflux |
---|
700 | A = float([ [3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8.],$ |
---|
701 | [1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$ |
---|
702 | [0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0.],$ |
---|
703 | [0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0.],$ |
---|
704 | [0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0.],$ |
---|
705 | [0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0.],$ |
---|
706 | [0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0.],$ |
---|
707 | [0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0.],$ |
---|
708 | [0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0.],$ |
---|
709 | [0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0.],$ |
---|
710 | [0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8.],$ |
---|
711 | [1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4.] ]) |
---|
712 | fluxinit=flux |
---|
713 | flux_check=flux |
---|
714 | for lo=0,dimlon-1 do begin |
---|
715 | for la=0,dimlat-1 do begin |
---|
716 | flux_check(lo,la,*) = invert(A) ## transpose(fluxinit(lo,la,*)) |
---|
717 | endfor |
---|
718 | endfor |
---|
719 | m_bloq = make_array(dimlon,dimlat,12,value=0) ; Matrice booléenne "mois à bloquer ou non" |
---|
720 | if total(where(flux_check lt 0)) ne -1 then m_bloq(where(flux_check lt 0)) = 1 |
---|
721 | ; Correction/adaptation de la matrice S&Z en fonction du masque booléen m_bloq |
---|
722 | for lo=0,dimlon-1 do begin |
---|
723 | for la=0,dimlat-1 do begin |
---|
724 | whereneg = where(flux_check(lo,la,*) lt 0) ; (12 pts max) Identification de potentiels points à problÚmes, corrigés négativement |
---|
725 | nbannul=n_elements(whereneg)*(total(whereneg) ne -1) |
---|
726 | flux_corr=flux_check(lo,la,*) ; Création d'un vecteur pour recevoir les valeurs corrigées, initialisé à flux_check au cas où on n'ait rien à faire (à part 1 seule correction matricielle) |
---|
727 | A2 = A ; Je repars de la matrice A initiale, ce pour chaque point de grille |
---|
728 | ; ; Potentiellement plusieurs passages pour éliminer toutes les valeurs négatives |
---|
729 | while nbannul ne 0 do begin ; Si l'on a effectivement des émissions corrigées négativement... |
---|
730 | m_bloq(lo,la,whereneg) = 1 ; Update de la matrice m_bloq |
---|
731 | for m=0,11 do begin |
---|
732 | if m eq 11 then begin ; Pour plus de facilité, mois précédents et suivants codés ici |
---|
733 | p=10 |
---|
734 | s=0 |
---|
735 | endif else if m eq 0 then begin |
---|
736 | p=11 |
---|
737 | s=1 |
---|
738 | endif else begin |
---|
739 | p = m-1 |
---|
740 | s = m+1 |
---|
741 | endelse |
---|
742 | if m_bloq(lo,la,m) then begin ; Je traite les mois bloqués en eux-mêmes |
---|
743 | A2(p,m) = 0. |
---|
744 | A2(m,m) = 1. |
---|
745 | A2(s,m) = 0. |
---|
746 | endif ; Fin du cas si l'on est sur un mois bloqué |
---|
747 | if ~m_bloq(lo,la,m) then begin ; Je traite les mois non bloqués, pour ceux adjacents à un mois bloqué |
---|
748 | if m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois encadré de deux mois bloqués |
---|
749 | A2(p,m) = 1./4. |
---|
750 | A2(m,m) = 1./2. |
---|
751 | A2(s,m) = 1./4. |
---|
752 | endif else if m_bloq(lo,la,p) and ~m_bloq(lo,la,s) then begin ; Mois précédent bloqué (uniquement) |
---|
753 | A2(p,m) = 2./8. |
---|
754 | A2(m,m) = 5./8. |
---|
755 | A2(s,m) = 1./8. |
---|
756 | endif else if ~m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois suivant bloqué (uniquement) |
---|
757 | A2(p,m) = 1./8. |
---|
758 | A2(m,m) = 5./8. |
---|
759 | A2(s,m) = 2./8. |
---|
760 | endif |
---|
761 | endif ; Fin du cas mois non bloqué |
---|
762 | endfor ; Fin de la boucle sur les mois, balayage de la matrice |
---|
763 | flux_corr = invert(A2) ## transpose(fluxinit(lo,la,*)) ; Ré-itération de la multiplication matricielle avec la matrice A modifiée (A2) |
---|
764 | whereneg = where(flux_corr lt 0) ; (12 pts max) Ré-identification de potentiels nouveaux points à problÚmes, corrigés négativement |
---|
765 | nbannul=n_elements(whereneg)*(total(whereneg) ne -1) |
---|
766 | endwhile ; Fin du cas où l'on avait des problÚmes d'émissions corrigées négativement |
---|
767 | ; *** IMPORTANT ! *** Pour signaler les mois bloqués, on prend la convention suivante : |
---|
768 | ; valeur négative ou nulle <=> mois bloqué |
---|
769 | ; valeur positive <=> mois à interpolation classique |
---|
770 | flux(lo,la,*) = flux_corr ; En sortie de la boucle while, normalement flux_corr est complÚtement positif |
---|
771 | endfor ; Fin boucle lat |
---|
772 | endfor ; Fin boucle lon |
---|
773 | nbnegtotal = n_elements(where(m_bloq eq 1)) * (total(where(m_bloq eq 1)) ne -1) |
---|
774 | if nbnegtotal ne 0 then flux(where(m_bloq eq 1)) = -flux(where(m_bloq eq 1)) ; Je force à des valeurs négatives |
---|
775 | ; |
---|
776 | month_in_year=12 |
---|
777 | nbpoint=${nbpoint} |
---|
778 | flux2=fltarr(nbpoint,month_in_year) |
---|
779 | flux2(*,*)=0.0 |
---|
780 | ; |
---|
781 | for l=0,month_in_year-1 do begin |
---|
782 | flux2(0,l)=TOTAL(flux(*,0,l))/float(dimlon) |
---|
783 | flux2(nbpoint-1,l)=TOTAL(flux(*,dimlat-1,l))/float(dimlon) |
---|
784 | endfor |
---|
785 | ; |
---|
786 | pt=1 |
---|
787 | for j=1,dimlat-2 do begin |
---|
788 | for i=0,dimlon-1 do begin |
---|
789 | for l=0,month_in_year-1 do begin |
---|
790 | flux2(pt,l)=flux(i,j,l) |
---|
791 | endfor |
---|
792 | pt=pt+1 |
---|
793 | endfor |
---|
794 | endfor |
---|
795 | ; |
---|
796 | ;saving netcdf file |
---|
797 | ; |
---|
798 | fluxstruct={vector:fltarr(nbpoint),time:fltarr(month_in_year), $ |
---|
799 | flx_bb${speciesinca}:fltarr(nbpoint,month_in_year) } |
---|
800 | ; |
---|
801 | fluxstruct.vector=float(indgen(nbpoint)+1) |
---|
802 | ;;fluxstruct.time=float(indgen(month_in_year)+1) |
---|
803 | fluxstruct.time=[15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345] |
---|
804 | fluxstruct.flx_bb${speciesinca}=flux2 |
---|
805 | ; |
---|
806 | attributes = {units:strarr(3),long_name:strarr(3)} |
---|
807 | attributes.units = ['vector','days since 1960-01-01','flux'] |
---|
808 | attributes.long_name = ['vector', 'time', 'flux'] |
---|
809 | ; |
---|
810 | dimensions = {isdim:intarr(3), links:intarr(2,3)} |
---|
811 | dimensions.isdim = [1,1,0] ; (1=dimension, 0=variable) |
---|
812 | dimensions.links = [ [-1,-1],[-1,-1],[0,1] ] |
---|
813 | ; |
---|
814 | netcdfwrite,'${filenameout3}',fluxstruct,clobber=1, attributes=attributes, dimensions=dimensions |
---|
815 | ; |
---|
816 | end |
---|
817 | eod |
---|
818 | # |
---|
819 | #--calling IDL |
---|
820 | # |
---|
821 | /opt/idl-6.4/idl/bin/idl << eod |
---|
822 | .r netcdf |
---|
823 | .r netcdfwrite |
---|
824 | .r struct_dims |
---|
825 | .r regrid |
---|
826 | regrid |
---|
827 | exit |
---|
828 | eod |
---|
829 | # |
---|
830 | |
---|
831 | #--end loop on species |
---|
832 | done |
---|
833 | |
---|
834 | #--unfortunately idl use capital letters for variable names so need to change to small letters for now |
---|
835 | rm -f ${dirout}flux_vector_h2s_${year}.nc ${dirout}flux_vector_so4_${year}.nc |
---|
836 | cdo expr,'flx_h2s=0.*FLX_SO2' ${dirout}flux_vector_so2_${year}.nc ${dirout}flux_vector_h2s_${year}.nc |
---|
837 | cdo expr,'flx_so4=0.*FLX_SO2' ${dirout}flux_vector_so2_${year}.nc ${dirout}flux_vector_so4_${year}.nc |
---|
838 | |
---|
839 | rm -f ${dirout}flux_vector_${year}.nc |
---|
840 | |
---|
841 | #--combining everything into a single file with some final preprocessing |
---|
842 | rm -f ${dirout}flux_vector_noxtot_${year}.nc ${dirout}flux_vector_so2tot_${year}.nc ${dirout}flux_vector_nh3tot_${year}.nc |
---|
843 | |
---|
844 | #--deleting output file if already there |
---|
845 | rm -f ${dirout}sflx_lmdz_cmip6_${year}.nc |
---|
846 | #--merging all files into a single one |
---|
847 | #--anthro NOx is NO2 so 30/46 scaling factor to change to NO |
---|
848 | #--openburning NOx is NO so no change in unit |
---|
849 | cdo merge -expr,'flx_bc=FLX_BC' ${dirout}flux_vector_bc_${year}.nc -expr,'flx_bbbc=FLX_BBBC' ${dirout}flux_vector_bcbb_${year}.nc -expr,'flx_pom=FLX_POM' ${dirout}flux_vector_pom_${year}.nc -expr,'flx_bbpom=FLX_BBPOM' ${dirout}flux_vector_pombb_${year}.nc -expr,'flx_nox=30.*FLX_NOX/46.' ${dirout}flux_vector_nox_${year}.nc -expr,'flx_bbnox=FLX_BBNOX;' ${dirout}flux_vector_noxbb_${year}.nc -expr,'flx_so2=FLX_SO2' ${dirout}flux_vector_so2_${year}.nc -expr,'flx_bbso2=FLX_BBSO2' ${dirout}flux_vector_so2bb_${year}.nc -expr,'flx_nh3=FLX_NH3' ${dirout}flux_vector_nh3_${year}.nc -expr,'flx_bbnh3=FLX_BBNH3' ${dirout}flux_vector_nh3bb_${year}.nc ${dirout}flux_vector_h2s_${year}.nc ${dirout}flux_vector_so4_${year}.nc -selname,conc_dms ${fileINCAex} ${dirout}sflx_lmdz_cmip6_${year}.nc |
---|
850 | |
---|
851 | ncrename -d VECTOR,vector -v VECTOR,vector ${dirout}sflx_lmdz_cmip6_${year}.nc |
---|
852 | ncrename -d TIME,time -v TIME,time ${dirout}sflx_lmdz_cmip6_${year}.nc |
---|
853 | |
---|
854 | #--cleaning up |
---|
855 | #rm -f ${dirout}flux*_${year}.nc |
---|
856 | #--to be uncommented in final version |
---|
857 | |
---|
858 | #--end loop on years |
---|
859 | done |
---|
860 | |
---|
861 | rm -f ${fileintanthro} ${fileintbb} |
---|
862 | |
---|
863 | #--end loop on scenarios |
---|
864 | done |
---|
865 | |
---|
866 | #--cleaning the mess |
---|
867 | rm -f ferret* |
---|
868 | rm -f regrid.pro |
---|
869 | rm -f time_interp_over_gaps.pro sumsectors.jnl select_yr.jnl rewrite.jnl |
---|