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