1 | #--updated on 5/2/2018 with new paths, ThL |
---|
2 | #--updated on 4/5/2017 with improved Sheng & Zwiers algorithm, ThL |
---|
3 | #--corrected some interpolation preprocessing (compared to v4) |
---|
4 | #--updated on 5/5/2017 with correction factor (30/46) on NOx vs. NO |
---|
5 | #--updated on 9/5/2017 with output separation BB/anthro for SO2, NOx and NH3 |
---|
6 | #--corrected on 22/6/2017 for BB: undef values zeroed before remapping |
---|
7 | #--corrected on 26/09/2017 for NOx units: PNNL dataset is kg NO2, VUA is kg NO. |
---|
8 | # INCA expects NO in its AER version. |
---|
9 | # |
---|
10 | #INCA conc_dms flx_nox flx_bc flx_pom flx_bbbc flx_bbpom flx_so2 flx_so4 flx_h2s flx_nh3 |
---|
11 | #CMIP6 species NOx BC OC SO2 NH3 |
---|
12 | # + NMVOC CO |
---|
13 | |
---|
14 | #--INCA example file where dms_conc can be reused |
---|
15 | fileINCAex="/home/oboucher/CMIP6/AER_EMISSIONS/INCAfile/sflx_lmdz_phy_1997.nc" |
---|
16 | |
---|
17 | #--input directory for anthropogenic (non-BB) emissions |
---|
18 | dirinPNNL="/prodigfs/esgf/mirror/input4MIPs/CMIP6/CMIP/PNNL-JGCRI/CEDS-2017-05-18/atmos/mon/" |
---|
19 | ##--Be careful if ever one needs the 3D (=AIR) data, the latest are in the different directory |
---|
20 | ## /prodigfs/esgf/mirror/input4MIPs/CMIP6/CMIP/PNNL-JGCRI/CEDS-2017-08-30/atmos/mon/ |
---|
21 | #--input directory for anthropogenic (BB) emissions |
---|
22 | dirinVUA="/prodigfs/esgf/mirror/input4MIPs/CMIP6/CMIP/VUA/VUA-CMIP-BB4CMIP6-1-2/atmos/mon/" |
---|
23 | |
---|
24 | #--LMDz grid information |
---|
25 | grid="144x143" |
---|
26 | gridfile="../GRID/grid-lmdz-lonlat_"${grid} |
---|
27 | nbpoint=$((144*141+2)) |
---|
28 | |
---|
29 | #--output directory |
---|
30 | dirout="/data/"${USER}"/CMIP6/AEROSOL/" |
---|
31 | if [ ! -d ${dirout} ] ; then mkdir -p ${dirout} ; fi |
---|
32 | |
---|
33 | #--year |
---|
34 | for year in {1850..2014} |
---|
35 | do |
---|
36 | |
---|
37 | #--species |
---|
38 | for species in "BC" "NOx" "OC" "SO2" "NH3" |
---|
39 | do |
---|
40 | |
---|
41 | if [ ${species} = "BC" ] ; then speciesinca="bc" ; fi |
---|
42 | if [ ${species} = "NOx" ] ; then speciesinca="nox" ; fi |
---|
43 | if [ ${species} = "OC" ] ; then speciesinca="pom" ; fi |
---|
44 | if [ ${species} = "SO2" ] ; then speciesinca="so2" ; fi |
---|
45 | if [ ${species} = "NH3" ] ; then speciesinca="nh3" ; fi |
---|
46 | |
---|
47 | #--finding correct file for PNNL data |
---|
48 | if [ $year -ge 1750 -a $year -lt 1800 ]; then |
---|
49 | year1=1750 |
---|
50 | year2=1799 |
---|
51 | elif [ $year -ge 1800 -a $year -lt 1850 ]; then |
---|
52 | year1=1800 |
---|
53 | year2=1849 |
---|
54 | elif [ $year == 1850 ]; then |
---|
55 | year1=1850 |
---|
56 | year2=1850 |
---|
57 | elif [ $year -ge 1851 -a $year -lt 1900 ]; then |
---|
58 | year1=1851 |
---|
59 | year2=1899 |
---|
60 | elif [ $year -ge 1900 -a $year -lt 1950 ]; then |
---|
61 | year1=1900 |
---|
62 | year2=1949 |
---|
63 | elif [ $year -ge 1950 -a $year -lt 2000 ]; then |
---|
64 | year1=1950 |
---|
65 | year2=1999 |
---|
66 | elif [ $year -ge 2000 -a $year -lt 2015 ]; then |
---|
67 | year1=2000 |
---|
68 | year2=2014 |
---|
69 | else |
---|
70 | echo 'Houston we have a problem for the PNNL data' |
---|
71 | exit 1 |
---|
72 | fi |
---|
73 | |
---|
74 | #--input file PNNL (fossil fuel emissions) Underscores in the old species-directory are now hyphens. |
---|
75 | filename=${dirinPNNL}${species}-em-anthro/gn/v20170519/${species}-em-anthro_input4MIPs_emissions_CMIP_CEDS-2017-05-18_gn_${year1}01-${year2}12.nc |
---|
76 | |
---|
77 | #--output files |
---|
78 | filenameout1=${dirout}flux_${speciesinca}_${year}.nc |
---|
79 | filenameout2=${dirout}flux_lmdz_${speciesinca}_${year}.nc |
---|
80 | filenameout3=${dirout}flux_vector_${speciesinca}_${year}.nc |
---|
81 | |
---|
82 | echo ${filename} ${filenameout1} ${filenameout2} ${filenameout3} |
---|
83 | rm -f ${filenameout1} ${filenameout2} ${filenameout3} |
---|
84 | |
---|
85 | #--unfortunately idl not happy with PNNL netcdf files so need to ferretize files |
---|
86 | #--I also sum over sectors and I extract the correct year as well |
---|
87 | rm -f rewrite.jnl |
---|
88 | cat << eod > rewrite.jnl |
---|
89 | use "${filename}" |
---|
90 | set region/t=16-jan-${year}:16-dec-${year} |
---|
91 | save/clobber/file="${filenameout1}" ${species}_EM_ANTHRO[k=@sum] |
---|
92 | eod |
---|
93 | |
---|
94 | #--run ferret script |
---|
95 | ferret << eod |
---|
96 | go rewrite.jnl |
---|
97 | exit |
---|
98 | eod |
---|
99 | |
---|
100 | #--remap to LMDz grid |
---|
101 | #--OC to POM conversion factor |
---|
102 | #--otherwise change to capital letters if not (eg NOx) |
---|
103 | if [ ${species} == "OC" ] ; then |
---|
104 | echo cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux -mulc,1.4 ${filenameout1} ${filenameout2} |
---|
105 | cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux -mulc,1.4 ${filenameout1} ${filenameout2} |
---|
106 | else |
---|
107 | echo cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux ${filenameout1} ${filenameout2} |
---|
108 | cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux ${filenameout1} ${filenameout2} |
---|
109 | fi |
---|
110 | |
---|
111 | #--Improved Sheng & Zwiers algorithm + transform into vector |
---|
112 | rm -f regrid.pro |
---|
113 | cat << eod >> regrid.pro |
---|
114 | pro regrid |
---|
115 | filename='${filenameout2}' |
---|
116 | print, filename |
---|
117 | NETCDFREAD,filename,'flux',flux,dimflux |
---|
118 | NETCDFREAD,filename,'lat',lat,dimlat0 |
---|
119 | NETCDFREAD,filename,'lon',lon,dimlon0 |
---|
120 | NETCDFREAD,filename,'TIME',time,dimtime0 |
---|
121 | dimlat=dimlat0(0) |
---|
122 | dimlon=dimlon0(0) |
---|
123 | dimtime=dimtime0(0) |
---|
124 | print, 'dim flux=', dimflux |
---|
125 | A = float([ [3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8.],$ |
---|
126 | [1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$ |
---|
127 | [0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0.],$ |
---|
128 | [0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0.],$ |
---|
129 | [0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0.],$ |
---|
130 | [0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0.],$ |
---|
131 | [0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0.],$ |
---|
132 | [0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0.],$ |
---|
133 | [0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0.],$ |
---|
134 | [0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0.],$ |
---|
135 | [0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8.],$ |
---|
136 | [1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4.] ]) |
---|
137 | fluxinit=flux |
---|
138 | flux_check=flux |
---|
139 | for lo=0,dimlon-1 do begin |
---|
140 | for la=0,dimlat-1 do begin |
---|
141 | flux_check(lo,la,*) = invert(A) ## transpose(fluxinit(lo,la,*)) |
---|
142 | endfor |
---|
143 | endfor |
---|
144 | m_bloq = make_array(dimlon,dimlat,12,value=0) ; Matrice booléenne "mois à bloquer ou non" |
---|
145 | if total(where(flux_check lt 0)) ne -1 then m_bloq(where(flux_check lt 0)) = 1 |
---|
146 | ; Correction/adaptation de la matrice S&Z en fonction du masque booléen m_bloq |
---|
147 | for lo=0,dimlon-1 do begin |
---|
148 | for la=0,dimlat-1 do begin |
---|
149 | whereneg = where(flux_check(lo,la,*) lt 0) ; (12 pts max) Identification de potentiels points à problÚmes, corrigés négativement |
---|
150 | nbannul=n_elements(whereneg)*(total(whereneg) ne -1) |
---|
151 | 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 |
---|
152 | A2 = A ; Je repars de la matrice A initiale, ce pour chaque point de grille |
---|
153 | ; ; Potentiellement plusieurs passages pour éliminer toutes les valeurs négatives |
---|
154 | while nbannul ne 0 do begin ; Si l'on a effectivement des émissions corrigées négativement... |
---|
155 | m_bloq(lo,la,whereneg) = 1 ; Update de la matrice m_bloq |
---|
156 | for m=0,11 do begin |
---|
157 | if m eq 11 then begin ; Pour plus de facilité, mois précédents et suivants codés ici |
---|
158 | p=10 |
---|
159 | s=0 |
---|
160 | endif else if m eq 0 then begin |
---|
161 | p=11 |
---|
162 | s=1 |
---|
163 | endif else begin |
---|
164 | p = m-1 |
---|
165 | s = m+1 |
---|
166 | endelse |
---|
167 | if m_bloq(lo,la,m) then begin ; Je traite les mois bloqués en eux-mêmes |
---|
168 | A2(p,m) = 0. |
---|
169 | A2(m,m) = 1. |
---|
170 | A2(s,m) = 0. |
---|
171 | endif ; Fin du cas si l'on est sur un mois bloqué |
---|
172 | if ~m_bloq(lo,la,m) then begin ; Je traite les mois non bloqués, pour ceux adjacents à un mois bloqué |
---|
173 | if m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois encadré de deux mois bloqués |
---|
174 | A2(p,m) = 1./4. |
---|
175 | A2(m,m) = 1./2. |
---|
176 | A2(s,m) = 1./4. |
---|
177 | endif else if m_bloq(lo,la,p) and ~m_bloq(lo,la,s) then begin ; Mois précédent bloqué (uniquement) |
---|
178 | A2(p,m) = 2./8. |
---|
179 | A2(m,m) = 5./8. |
---|
180 | A2(s,m) = 1./8. |
---|
181 | endif else if ~m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois suivant bloqué (uniquement) |
---|
182 | A2(p,m) = 1./8. |
---|
183 | A2(m,m) = 5./8. |
---|
184 | A2(s,m) = 2./8. |
---|
185 | endif |
---|
186 | endif ; Fin du cas mois non bloqué |
---|
187 | endfor ; Fin de la boucle sur les mois, balayage de la matrice |
---|
188 | flux_corr = invert(A2) ## transpose(fluxinit(lo,la,*)) ; Ré-itération de la multiplication matricielle avec la matrice A modifiée (A2) |
---|
189 | whereneg = where(flux_corr lt 0) ; (12 pts max) Ré-identification de potentiels nouveaux points à problÚmes, corrigés négativement |
---|
190 | nbannul=n_elements(whereneg)*(total(whereneg) ne -1) |
---|
191 | endwhile ; Fin du cas où l'on avait des problÚmes d'émissions corrigées négativement |
---|
192 | ; *** IMPORTANT ! *** Pour signaler les mois bloqués, on prend la convention suivante : |
---|
193 | ; valeur négative ou nulle <=> mois bloqué |
---|
194 | ; valeur positive <=> mois à interpolation classique |
---|
195 | flux(lo,la,*) = flux_corr ; En sortie de la boucle while, normalement flux_corr est complÚtement positif |
---|
196 | endfor ; Fin boucle lat |
---|
197 | endfor ; Fin boucle lon |
---|
198 | nbnegtotal = n_elements(where(m_bloq eq 1)) * (total(where(m_bloq eq 1)) ne -1) |
---|
199 | if nbnegtotal ne 0 then flux(where(m_bloq eq 1)) = -flux(where(m_bloq eq 1)) ; Je force à des valeurs négatives |
---|
200 | ; |
---|
201 | month_in_year=12 |
---|
202 | nbpoint=${nbpoint} |
---|
203 | flux2=fltarr(nbpoint,month_in_year) |
---|
204 | flux2(*,*)=0.0 |
---|
205 | ; |
---|
206 | for l=0,month_in_year-1 do begin |
---|
207 | flux2(0,l)=TOTAL(flux(*,0,l))/float(dimlon) |
---|
208 | flux2(nbpoint-1,l)=TOTAL(flux(*,dimlat-1,l))/float(dimlon) |
---|
209 | endfor |
---|
210 | ; |
---|
211 | pt=1 |
---|
212 | for j=1,dimlat-2 do begin |
---|
213 | for i=0,dimlon-1 do begin |
---|
214 | for l=0,month_in_year-1 do begin |
---|
215 | flux2(pt,l)=flux(i,j,l) |
---|
216 | endfor |
---|
217 | pt=pt+1 |
---|
218 | endfor |
---|
219 | endfor |
---|
220 | ; |
---|
221 | ;saving netcdf file |
---|
222 | ; |
---|
223 | fluxstruct={vector:fltarr(nbpoint),time:fltarr(month_in_year), $ |
---|
224 | flx_${speciesinca}:fltarr(nbpoint,month_in_year) } |
---|
225 | ; |
---|
226 | fluxstruct.vector=float(indgen(nbpoint)+1) |
---|
227 | ;;fluxstruct.time=float(indgen(month_in_year)+1) |
---|
228 | fluxstruct.time=[15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345] |
---|
229 | fluxstruct.flx_${speciesinca}=flux2 |
---|
230 | ; |
---|
231 | attributes = {units:strarr(3),long_name:strarr(3)} |
---|
232 | attributes.units = ['vector','days since 1960-01-01','flux'] |
---|
233 | attributes.long_name = ['vector', 'time', 'flux'] |
---|
234 | ; |
---|
235 | dimensions = {isdim:intarr(3), links:intarr(2,3)} |
---|
236 | dimensions.isdim = [1,1,0] ; (1=dimension, 0=variable) |
---|
237 | dimensions.links = [ [-1,-1],[-1,-1],[0,1] ] |
---|
238 | ; |
---|
239 | netcdfwrite,'${filenameout3}',fluxstruct,clobber=1, attributes=attributes, dimensions=dimensions |
---|
240 | ; |
---|
241 | end |
---|
242 | eod |
---|
243 | |
---|
244 | # |
---|
245 | #--calling IDL |
---|
246 | # |
---|
247 | /opt/idl-6.4/idl/bin/idl << eod |
---|
248 | .r netcdf |
---|
249 | .r netcdfwrite |
---|
250 | .r struct_dims |
---|
251 | .r regrid |
---|
252 | regrid |
---|
253 | exit |
---|
254 | eod |
---|
255 | # |
---|
256 | |
---|
257 | #--finding correct file for VUA data |
---|
258 | if [ $year -ge 1750 -a $year -lt 1850 ]; then |
---|
259 | year1=1750 |
---|
260 | year2=1849 |
---|
261 | elif [ $year -ge 1850 -a $year -lt 2016 ]; then |
---|
262 | year1=1850 |
---|
263 | year2=2015 |
---|
264 | else |
---|
265 | echo 'Houston we have a problem for the VUA data' |
---|
266 | exit 1 |
---|
267 | fi |
---|
268 | |
---|
269 | #--now dealing with BB sources Species-directory was previously of the form "CO-em-biomassburning", it is now just "CO" |
---|
270 | filename=${dirinVUA}${species}"/gn/v20161213/"${species}"-em-biomassburning_input4MIPs_emissions_CMIP_VUA-CMIP-BB4CMIP6-1-2_gn_${year1}01-${year2}12.nc" |
---|
271 | |
---|
272 | #--output files |
---|
273 | filenameout1=${dirout}flux_${speciesinca}bb_${year}.nc |
---|
274 | filenameout1b=${dirout}flux_0_${speciesinca}bb_${year}.nc |
---|
275 | filenameout2=${dirout}flux_lmdz0_${speciesinca}bb_${year}.nc |
---|
276 | filenameout3=${dirout}flux_vector_${speciesinca}bb_${year}.nc |
---|
277 | |
---|
278 | echo ${filename} ${filenameout1} ${filenameout1b} ${filenameout2} ${filenameout3} |
---|
279 | rm -f ${filenameout1} ${filenameout1b} ${filenameout2} ${filenameout3} |
---|
280 | |
---|
281 | #--unfortunately idl not happy with VUA netcdf files so need to ferretize files |
---|
282 | #--I extract the correct year as well |
---|
283 | rm -f rewrite.jnl |
---|
284 | cat << eod > rewrite.jnl |
---|
285 | set memory/size=100 |
---|
286 | use "${filename}" |
---|
287 | set region/t=16-jan-${year}:16-dec-${year} |
---|
288 | save/clobber/file="${filenameout1}" ${species} |
---|
289 | eod |
---|
290 | |
---|
291 | #--run ferret script |
---|
292 | ferret << eod |
---|
293 | go rewrite.jnl |
---|
294 | exit |
---|
295 | eod |
---|
296 | |
---|
297 | #--replace undef with 0 --------------------------- Moved here (before remap) by ThL 22/06/2017 |
---|
298 | cdo setmisstoc,0.0 ${filenameout1} ${filenameout1b} |
---|
299 | |
---|
300 | #--remap to LMDz grid |
---|
301 | #--OC to POM conversion factor |
---|
302 | #--as ferret returns NOX, treat NOx NOX inconsistency in names by converting to upper case |
---|
303 | if [ ${species} != "OC" ] ; then |
---|
304 | echo cdo remapcon,${gridfile} -chname,`echo ${species} | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2} |
---|
305 | cdo remapcon,${gridfile} -chname,`echo ${species} | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2} |
---|
306 | else |
---|
307 | echo cdo remapcon,${gridfile} -chname,${species},flux -mulc,1.4 ${filenameout1b} ${filenameout2} |
---|
308 | cdo remapcon,${gridfile} -chname,${species},flux -mulc,1.4 ${filenameout1b} ${filenameout2} |
---|
309 | fi |
---|
310 | |
---|
311 | #--Improved Sheng & Zwiers algorithm + transform into vector |
---|
312 | rm -f regrid.pro |
---|
313 | cat << eod >> regrid.pro |
---|
314 | pro regrid |
---|
315 | filename='${filenameout2}' |
---|
316 | print, filename |
---|
317 | NETCDFREAD,filename,'flux',flux,dimflux |
---|
318 | NETCDFREAD,filename,'lat',lat,dimlat0 |
---|
319 | NETCDFREAD,filename,'lon',lon,dimlon0 |
---|
320 | NETCDFREAD,filename,'TIME',time,dimtime0 |
---|
321 | dimlat=dimlat0(0) |
---|
322 | dimlon=dimlon0(0) |
---|
323 | dimtime=dimtime0(0) |
---|
324 | print, 'dim flux=', dimflux |
---|
325 | A = float([ [3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8.],$ |
---|
326 | [1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$ |
---|
327 | [0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0.],$ |
---|
328 | [0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0.],$ |
---|
329 | [0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0.],$ |
---|
330 | [0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0.],$ |
---|
331 | [0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0.],$ |
---|
332 | [0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0.],$ |
---|
333 | [0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0.],$ |
---|
334 | [0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0.],$ |
---|
335 | [0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8.],$ |
---|
336 | [1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4.] ]) |
---|
337 | fluxinit=flux |
---|
338 | flux_check=flux |
---|
339 | for lo=0,dimlon-1 do begin |
---|
340 | for la=0,dimlat-1 do begin |
---|
341 | flux_check(lo,la,*) = invert(A) ## transpose(fluxinit(lo,la,*)) |
---|
342 | endfor |
---|
343 | endfor |
---|
344 | m_bloq = make_array(dimlon,dimlat,12,value=0) ; Matrice booléenne "mois à bloquer ou non" |
---|
345 | if total(where(flux_check lt 0)) ne -1 then m_bloq(where(flux_check lt 0)) = 1 |
---|
346 | ; Correction/adaptation de la matrice S&Z en fonction du masque booléen m_bloq |
---|
347 | for lo=0,dimlon-1 do begin |
---|
348 | for la=0,dimlat-1 do begin |
---|
349 | whereneg = where(flux_check(lo,la,*) lt 0) ; (12 pts max) Identification de potentiels points à problÚmes, corrigés négativement |
---|
350 | nbannul=n_elements(whereneg)*(total(whereneg) ne -1) |
---|
351 | 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) |
---|
352 | A2 = A ; Je repars de la matrice A initiale, ce pour chaque point de grille |
---|
353 | ; ; Potentiellement plusieurs passages pour éliminer toutes les valeurs négatives |
---|
354 | while nbannul ne 0 do begin ; Si l'on a effectivement des émissions corrigées négativement... |
---|
355 | m_bloq(lo,la,whereneg) = 1 ; Update de la matrice m_bloq |
---|
356 | for m=0,11 do begin |
---|
357 | if m eq 11 then begin ; Pour plus de facilité, mois précédents et suivants codés ici |
---|
358 | p=10 |
---|
359 | s=0 |
---|
360 | endif else if m eq 0 then begin |
---|
361 | p=11 |
---|
362 | s=1 |
---|
363 | endif else begin |
---|
364 | p = m-1 |
---|
365 | s = m+1 |
---|
366 | endelse |
---|
367 | if m_bloq(lo,la,m) then begin ; Je traite les mois bloqués en eux-mêmes |
---|
368 | A2(p,m) = 0. |
---|
369 | A2(m,m) = 1. |
---|
370 | A2(s,m) = 0. |
---|
371 | endif ; Fin du cas si l'on est sur un mois bloqué |
---|
372 | if ~m_bloq(lo,la,m) then begin ; Je traite les mois non bloqués, pour ceux adjacents à un mois bloqué |
---|
373 | if m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois encadré de deux mois bloqués |
---|
374 | A2(p,m) = 1./4. |
---|
375 | A2(m,m) = 1./2. |
---|
376 | A2(s,m) = 1./4. |
---|
377 | endif else if m_bloq(lo,la,p) and ~m_bloq(lo,la,s) then begin ; Mois précédent bloqué (uniquement) |
---|
378 | A2(p,m) = 2./8. |
---|
379 | A2(m,m) = 5./8. |
---|
380 | A2(s,m) = 1./8. |
---|
381 | endif else if ~m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois suivant bloqué (uniquement) |
---|
382 | A2(p,m) = 1./8. |
---|
383 | A2(m,m) = 5./8. |
---|
384 | A2(s,m) = 2./8. |
---|
385 | endif |
---|
386 | endif ; Fin du cas mois non bloqué |
---|
387 | endfor ; Fin de la boucle sur les mois, balayage de la matrice |
---|
388 | flux_corr = invert(A2) ## transpose(fluxinit(lo,la,*)) ; Ré-itération de la multiplication matricielle avec la matrice A modifiée (A2) |
---|
389 | whereneg = where(flux_corr lt 0) ; (12 pts max) Ré-identification de potentiels nouveaux points à problÚmes, corrigés négativement |
---|
390 | nbannul=n_elements(whereneg)*(total(whereneg) ne -1) |
---|
391 | endwhile ; Fin du cas où l'on avait des problÚmes d'émissions corrigées négativement |
---|
392 | ; *** IMPORTANT ! *** Pour signaler les mois bloqués, on prend la convention suivante : |
---|
393 | ; valeur négative ou nulle <=> mois bloqué |
---|
394 | ; valeur positive <=> mois à interpolation classique |
---|
395 | flux(lo,la,*) = flux_corr ; En sortie de la boucle while, normalement flux_corr est complÚtement positif |
---|
396 | endfor ; Fin boucle lat |
---|
397 | endfor ; Fin boucle lon |
---|
398 | nbnegtotal = n_elements(where(m_bloq eq 1)) * (total(where(m_bloq eq 1)) ne -1) |
---|
399 | if nbnegtotal ne 0 then flux(where(m_bloq eq 1)) = -flux(where(m_bloq eq 1)) ; Je force à des valeurs négatives |
---|
400 | ; |
---|
401 | month_in_year=12 |
---|
402 | nbpoint=${nbpoint} |
---|
403 | flux2=fltarr(nbpoint,month_in_year) |
---|
404 | flux2(*,*)=0.0 |
---|
405 | ; |
---|
406 | for l=0,month_in_year-1 do begin |
---|
407 | flux2(0,l)=TOTAL(flux(*,0,l))/float(dimlon) |
---|
408 | flux2(nbpoint-1,l)=TOTAL(flux(*,dimlat-1,l))/float(dimlon) |
---|
409 | endfor |
---|
410 | ; |
---|
411 | pt=1 |
---|
412 | for j=1,dimlat-2 do begin |
---|
413 | for i=0,dimlon-1 do begin |
---|
414 | for l=0,month_in_year-1 do begin |
---|
415 | flux2(pt,l)=flux(i,j,l) |
---|
416 | endfor |
---|
417 | pt=pt+1 |
---|
418 | endfor |
---|
419 | endfor |
---|
420 | ; |
---|
421 | ;saving netcdf file |
---|
422 | ; |
---|
423 | fluxstruct={vector:fltarr(nbpoint),time:fltarr(month_in_year), $ |
---|
424 | flx_bb${speciesinca}:fltarr(nbpoint,month_in_year) } |
---|
425 | ; |
---|
426 | fluxstruct.vector=float(indgen(nbpoint)+1) |
---|
427 | ;;fluxstruct.time=float(indgen(month_in_year)+1) |
---|
428 | fluxstruct.time=[15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345] |
---|
429 | fluxstruct.flx_bb${speciesinca}=flux2 |
---|
430 | ; |
---|
431 | attributes = {units:strarr(3),long_name:strarr(3)} |
---|
432 | attributes.units = ['vector','days since 1960-01-01','flux'] |
---|
433 | attributes.long_name = ['vector', 'time', 'flux'] |
---|
434 | ; |
---|
435 | dimensions = {isdim:intarr(3), links:intarr(2,3)} |
---|
436 | dimensions.isdim = [1,1,0] ; (1=dimension, 0=variable) |
---|
437 | dimensions.links = [ [-1,-1],[-1,-1],[0,1] ] |
---|
438 | ; |
---|
439 | netcdfwrite,'${filenameout3}',fluxstruct,clobber=1, attributes=attributes, dimensions=dimensions |
---|
440 | ; |
---|
441 | end |
---|
442 | eod |
---|
443 | |
---|
444 | # |
---|
445 | #--calling IDL |
---|
446 | # |
---|
447 | /opt/idl-6.4/idl/bin/idl << eod |
---|
448 | .r netcdf |
---|
449 | .r netcdfwrite |
---|
450 | .r struct_dims |
---|
451 | .r regrid |
---|
452 | regrid |
---|
453 | exit |
---|
454 | eod |
---|
455 | # |
---|
456 | |
---|
457 | #--end loop on species |
---|
458 | done |
---|
459 | |
---|
460 | #--unfortunately idl use capital letters for variable names so need to change to small letters for now |
---|
461 | rm -f ${dirout}flux_vector_h2s_${year}.nc ${dirout}flux_vector_so4_${year}.nc |
---|
462 | cdo expr,'flx_h2s=0.*FLX_SO2' ${dirout}flux_vector_so2_${year}.nc ${dirout}flux_vector_h2s_${year}.nc |
---|
463 | cdo expr,'flx_so4=0.*FLX_SO2' ${dirout}flux_vector_so2_${year}.nc ${dirout}flux_vector_so4_${year}.nc |
---|
464 | |
---|
465 | rm -f ${dirout}flux_vector_${year}.nc |
---|
466 | |
---|
467 | #--combining everything into a single file with some final preprocessing |
---|
468 | rm -f ${dirout}flux_vector_noxtot_${year}.nc ${dirout}flux_vector_so2tot_${year}.nc ${dirout}flux_vector_nh3tot_${year}.nc |
---|
469 | |
---|
470 | #--deleting output file if already there |
---|
471 | rm -f ${dirout}sflx_lmdz_cmip6_${year}.nc |
---|
472 | #--merging all files into a single one |
---|
473 | #--PNNL NOx is NO2 so 30/46 scaling factor to change to NO |
---|
474 | #--VUA NOx is NO so no change in unit |
---|
475 | 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 |
---|
476 | |
---|
477 | ncrename -d VECTOR,vector -v VECTOR,vector ${dirout}sflx_lmdz_cmip6_${year}.nc |
---|
478 | ncrename -d TIME,time -v TIME,time ${dirout}sflx_lmdz_cmip6_${year}.nc |
---|
479 | |
---|
480 | #--cleaning up |
---|
481 | rm -f ${dirout}flux*_${year}.nc |
---|
482 | |
---|
483 | #--end loop on years |
---|
484 | done |
---|
485 | |
---|
486 | #--cleaning the mess |
---|
487 | rm -f ferret* |
---|
488 | rm -f regrid.pro |
---|