source: TOOLS/CMIP6_FORCING/AER_TROP_EMISSIONS/REGRID/regrid.sh @ 3567

Last change on this file since 3567 was 3567, checked in by tlurton, 6 years ago

Update Th. Lurton
7 Feb. 2018
Changed input file paths to fetch new versions of the files.
For SOLAR, AER_TROP_EMISSIONS, GHG, NITROGEN and OZONE.

  • Property svn:executable set to *
File size: 19.0 KB
Line 
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
15fileINCAex="/home/oboucher/CMIP6/AER_EMISSIONS/INCAfile/sflx_lmdz_phy_1997.nc"
16
17#--input directory for anthropogenic (non-BB) emissions
18dirinPNNL="/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
22dirinVUA="/prodigfs/esgf/mirror/input4MIPs/CMIP6/CMIP/VUA/VUA-CMIP-BB4CMIP6-1-2/atmos/mon/"
23
24#--LMDz grid information
25grid="144x143"
26gridfile="../GRID/grid-lmdz-lonlat_"${grid}
27nbpoint=$((144*141+2))
28
29#--output directory
30dirout="/data/"${USER}"/CMIP6/AEROSOL/"
31if [ ! -d ${dirout} ] ; then mkdir -p ${dirout} ; fi
32
33#--year
34for year in {1850..2014}
35do
36
37#--species
38for species in "BC" "NOx" "OC" "SO2" "NH3"
39do
40
41if [ ${species} = "BC"  ] ; then speciesinca="bc"  ; fi
42if [ ${species} = "NOx" ] ; then speciesinca="nox" ; fi
43if [ ${species} = "OC"  ] ; then speciesinca="pom" ; fi
44if [ ${species} = "SO2" ] ; then speciesinca="so2" ; fi
45if [ ${species} = "NH3" ] ; then speciesinca="nh3" ; fi
46
47#--finding correct file for PNNL data
48if [ $year -ge 1750 -a $year -lt 1800 ]; then
49year1=1750
50year2=1799
51elif [ $year -ge 1800 -a $year -lt 1850 ]; then
52year1=1800
53year2=1849
54elif [ $year == 1850 ]; then
55year1=1850
56year2=1850
57elif [ $year -ge 1851 -a $year -lt 1900 ]; then
58year1=1851
59year2=1899
60elif [ $year -ge 1900 -a $year -lt 1950 ]; then
61year1=1900
62year2=1949
63elif [ $year -ge 1950 -a $year -lt 2000 ]; then
64year1=1950
65year2=1999
66elif [ $year -ge 2000 -a $year -lt 2015 ]; then
67year1=2000
68year2=2014
69else
70echo 'Houston we have a problem for the PNNL data'
71exit 1
72fi
73
74#--input file PNNL (fossil fuel emissions)       Underscores in the old species-directory are now hyphens.
75filename=${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
78filenameout1=${dirout}flux_${speciesinca}_${year}.nc
79filenameout2=${dirout}flux_lmdz_${speciesinca}_${year}.nc
80filenameout3=${dirout}flux_vector_${speciesinca}_${year}.nc
81
82echo ${filename} ${filenameout1} ${filenameout2} ${filenameout3}
83rm -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
87rm -f rewrite.jnl
88cat << eod > rewrite.jnl
89use "${filename}"
90set region/t=16-jan-${year}:16-dec-${year}
91save/clobber/file="${filenameout1}" ${species}_EM_ANTHRO[k=@sum]
92eod
93
94#--run ferret script
95ferret << eod
96go rewrite.jnl
97exit
98eod
99
100#--remap to LMDz grid
101#--OC to POM conversion factor
102#--otherwise change to capital letters if not (eg NOx)
103if [ ${species} == "OC"  ] ; then
104echo cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux -mulc,1.4 ${filenameout1} ${filenameout2}
105cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux -mulc,1.4 ${filenameout1} ${filenameout2}
106else
107echo cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux  ${filenameout1} ${filenameout2}
108cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux ${filenameout1} ${filenameout2}
109fi
110
111#--Improved Sheng & Zwiers algorithm + transform into vector
112rm -f regrid.pro
113cat << eod >> regrid.pro
114pro regrid
115filename='${filenameout2}'
116print, filename
117NETCDFREAD,filename,'flux',flux,dimflux
118NETCDFREAD,filename,'lat',lat,dimlat0
119NETCDFREAD,filename,'lon',lon,dimlon0
120NETCDFREAD,filename,'TIME',time,dimtime0
121dimlat=dimlat0(0)
122dimlon=dimlon0(0)
123dimtime=dimtime0(0)
124print, 'dim flux=', dimflux
125A = 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.]   ])
137fluxinit=flux
138flux_check=flux
139for lo=0,dimlon-1 do begin
140for la=0,dimlat-1 do begin
141flux_check(lo,la,*) = invert(A) ## transpose(fluxinit(lo,la,*))
142endfor
143endfor                 
144m_bloq = make_array(dimlon,dimlat,12,value=0)           ; Matrice booléenne "mois à bloquer ou non"
145if 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
147for lo=0,dimlon-1 do begin
148for la=0,dimlat-1 do begin
149whereneg = where(flux_check(lo,la,*) lt 0)              ; (12 pts max) Identification de potentiels points à problÚmes, corrigés négativement
150nbannul=n_elements(whereneg)*(total(whereneg) ne -1)
151flux_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
152A2 = 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
154while nbannul ne 0 do begin                             ; Si l'on a effectivement des émissions corrigées négativement...
155m_bloq(lo,la,whereneg) = 1                              ; Update de la matrice m_bloq
156for m=0,11 do begin
157if m eq 11 then begin                                   ; Pour plus de facilité, mois précédents et suivants codés ici
158p=10
159s=0
160endif else if m eq 0 then begin
161p=11
162s=1
163endif else begin
164p = m-1
165s = m+1
166endelse
167if m_bloq(lo,la,m) then begin                           ; Je traite les mois bloqués en eux-mêmes
168A2(p,m) = 0.
169A2(m,m) = 1.
170A2(s,m) = 0.
171endif                                                   ; Fin du cas si l'on est sur un mois bloqué
172if ~m_bloq(lo,la,m) then begin                          ; Je traite les mois non bloqués, pour ceux adjacents à un mois bloqué
173if m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin               ; Mois encadré de deux mois bloqués
174A2(p,m) = 1./4.
175A2(m,m) = 1./2.
176A2(s,m) = 1./4.
177endif else if m_bloq(lo,la,p) and ~m_bloq(lo,la,s) then begin   ; Mois précédent bloqué (uniquement)
178A2(p,m) = 2./8.
179A2(m,m) = 5./8.
180A2(s,m) = 1./8.
181endif else if ~m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin   ; Mois suivant bloqué (uniquement)
182A2(p,m) = 1./8.
183A2(m,m) = 5./8.
184A2(s,m) = 2./8.
185endif
186endif                                                           ; Fin du cas mois non bloqué
187endfor                                                          ; Fin de la boucle sur les mois, balayage de la matrice
188flux_corr = invert(A2) ## transpose(fluxinit(lo,la,*))          ; Ré-itération de la multiplication matricielle avec la matrice A modifiée (A2)
189whereneg = where(flux_corr lt 0)                                ; (12 pts max) Ré-identification de potentiels nouveaux points à problÚmes, corrigés négativement
190nbannul=n_elements(whereneg)*(total(whereneg) ne -1)
191endwhile                                                        ; 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
195flux(lo,la,*) = flux_corr                                       ; En sortie de la boucle while, normalement flux_corr est complÚtement positif
196endfor                                                          ; Fin boucle lat
197endfor                                                          ; Fin boucle lon
198nbnegtotal = n_elements(where(m_bloq eq 1)) * (total(where(m_bloq eq 1)) ne -1)
199if nbnegtotal ne 0 then flux(where(m_bloq eq 1)) = -flux(where(m_bloq eq 1))            ; Je force à des valeurs négatives
200;
201month_in_year=12
202nbpoint=${nbpoint}
203flux2=fltarr(nbpoint,month_in_year)
204flux2(*,*)=0.0
205;
206for l=0,month_in_year-1 do begin
207flux2(0,l)=TOTAL(flux(*,0,l))/float(dimlon)
208flux2(nbpoint-1,l)=TOTAL(flux(*,dimlat-1,l))/float(dimlon)
209endfor
210;
211pt=1
212for j=1,dimlat-2  do begin
213for i=0,dimlon-1  do begin
214for l=0,month_in_year-1 do begin
215  flux2(pt,l)=flux(i,j,l)
216endfor
217pt=pt+1
218endfor
219endfor
220;
221;saving netcdf file
222;
223fluxstruct={vector:fltarr(nbpoint),time:fltarr(month_in_year), $
224            flx_${speciesinca}:fltarr(nbpoint,month_in_year) }
225;
226fluxstruct.vector=float(indgen(nbpoint)+1)
227;;fluxstruct.time=float(indgen(month_in_year)+1)
228fluxstruct.time=[15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345]
229fluxstruct.flx_${speciesinca}=flux2
230;
231attributes = {units:strarr(3),long_name:strarr(3)}
232attributes.units = ['vector','days since 1960-01-01','flux']
233attributes.long_name = ['vector', 'time', 'flux']
234;
235dimensions = {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;
239netcdfwrite,'${filenameout3}',fluxstruct,clobber=1, attributes=attributes, dimensions=dimensions
240;
241end
242eod
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
252regrid
253exit
254eod
255#
256
257#--finding correct file for VUA data
258if [ $year -ge 1750 -a $year -lt 1850 ]; then
259year1=1750
260year2=1849
261elif [ $year -ge 1850 -a $year -lt 2016 ]; then
262year1=1850
263year2=2015
264else
265echo 'Houston we have a problem for the VUA data'
266exit 1
267fi
268
269#--now dealing with BB sources               Species-directory was previously of the form "CO-em-biomassburning", it is now just "CO"
270filename=${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
273filenameout1=${dirout}flux_${speciesinca}bb_${year}.nc
274filenameout1b=${dirout}flux_0_${speciesinca}bb_${year}.nc
275filenameout2=${dirout}flux_lmdz0_${speciesinca}bb_${year}.nc
276filenameout3=${dirout}flux_vector_${speciesinca}bb_${year}.nc
277
278echo ${filename} ${filenameout1} ${filenameout1b} ${filenameout2} ${filenameout3}
279rm -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
283rm -f rewrite.jnl
284cat << eod > rewrite.jnl
285set memory/size=100
286use "${filename}"
287set region/t=16-jan-${year}:16-dec-${year}
288save/clobber/file="${filenameout1}" ${species}
289eod
290
291#--run ferret script
292ferret << eod
293go rewrite.jnl
294exit
295eod
296
297#--replace undef with 0               --------------------------- Moved here (before remap) by ThL 22/06/2017
298cdo 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
303if [ ${species} != "OC"  ] ; then
304echo cdo remapcon,${gridfile} -chname,`echo ${species} | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2}
305cdo remapcon,${gridfile} -chname,`echo ${species} | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2}
306else
307echo cdo remapcon,${gridfile} -chname,${species},flux -mulc,1.4 ${filenameout1b} ${filenameout2}
308cdo remapcon,${gridfile} -chname,${species},flux -mulc,1.4 ${filenameout1b} ${filenameout2}
309fi
310
311#--Improved Sheng & Zwiers algorithm + transform into vector
312rm -f regrid.pro
313cat << eod >> regrid.pro
314pro regrid
315filename='${filenameout2}'
316print, filename
317NETCDFREAD,filename,'flux',flux,dimflux
318NETCDFREAD,filename,'lat',lat,dimlat0
319NETCDFREAD,filename,'lon',lon,dimlon0
320NETCDFREAD,filename,'TIME',time,dimtime0
321dimlat=dimlat0(0)
322dimlon=dimlon0(0)
323dimtime=dimtime0(0)
324print, 'dim flux=', dimflux
325A = 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.]   ])
337fluxinit=flux
338flux_check=flux
339for lo=0,dimlon-1 do begin
340for la=0,dimlat-1 do begin
341flux_check(lo,la,*) = invert(A) ## transpose(fluxinit(lo,la,*))
342endfor
343endfor                 
344m_bloq = make_array(dimlon,dimlat,12,value=0)           ; Matrice booléenne "mois à bloquer ou non"
345if 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
347for lo=0,dimlon-1 do begin
348for la=0,dimlat-1 do begin
349whereneg = where(flux_check(lo,la,*) lt 0)              ; (12 pts max) Identification de potentiels points à problÚmes, corrigés négativement
350nbannul=n_elements(whereneg)*(total(whereneg) ne -1)
351flux_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)
352A2 = 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
354while nbannul ne 0 do begin                             ; Si l'on a effectivement des émissions corrigées négativement...
355m_bloq(lo,la,whereneg) = 1                              ; Update de la matrice m_bloq
356for m=0,11 do begin
357if m eq 11 then begin                                   ; Pour plus de facilité, mois précédents et suivants codés ici
358p=10
359s=0
360endif else if m eq 0 then begin
361p=11
362s=1
363endif else begin
364p = m-1
365s = m+1
366endelse
367if m_bloq(lo,la,m) then begin                           ; Je traite les mois bloqués en eux-mêmes
368A2(p,m) = 0.
369A2(m,m) = 1.
370A2(s,m) = 0.
371endif                                                   ; Fin du cas si l'on est sur un mois bloqué
372if ~m_bloq(lo,la,m) then begin                          ; Je traite les mois non bloqués, pour ceux adjacents à un mois bloqué
373if m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin               ; Mois encadré de deux mois bloqués
374A2(p,m) = 1./4.
375A2(m,m) = 1./2.
376A2(s,m) = 1./4.
377endif else if m_bloq(lo,la,p) and ~m_bloq(lo,la,s) then begin   ; Mois précédent bloqué (uniquement)
378A2(p,m) = 2./8.
379A2(m,m) = 5./8.
380A2(s,m) = 1./8.
381endif else if ~m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin   ; Mois suivant bloqué (uniquement)
382A2(p,m) = 1./8.
383A2(m,m) = 5./8.
384A2(s,m) = 2./8.
385endif
386endif                                                           ; Fin du cas mois non bloqué
387endfor                                                          ; Fin de la boucle sur les mois, balayage de la matrice
388flux_corr = invert(A2) ## transpose(fluxinit(lo,la,*))          ; Ré-itération de la multiplication matricielle avec la matrice A modifiée (A2)
389whereneg = where(flux_corr lt 0)                                ; (12 pts max) Ré-identification de potentiels nouveaux points à problÚmes, corrigés négativement
390nbannul=n_elements(whereneg)*(total(whereneg) ne -1)
391endwhile                                                        ; 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
395flux(lo,la,*) = flux_corr                                       ; En sortie de la boucle while, normalement flux_corr est complÚtement positif
396endfor                                                          ; Fin boucle lat
397endfor                                                          ; Fin boucle lon
398nbnegtotal = n_elements(where(m_bloq eq 1)) * (total(where(m_bloq eq 1)) ne -1)
399if nbnegtotal ne 0 then flux(where(m_bloq eq 1)) = -flux(where(m_bloq eq 1))            ; Je force à des valeurs négatives
400;
401month_in_year=12
402nbpoint=${nbpoint}
403flux2=fltarr(nbpoint,month_in_year)
404flux2(*,*)=0.0
405;
406for l=0,month_in_year-1 do begin
407flux2(0,l)=TOTAL(flux(*,0,l))/float(dimlon)
408flux2(nbpoint-1,l)=TOTAL(flux(*,dimlat-1,l))/float(dimlon)
409endfor
410;
411pt=1
412for j=1,dimlat-2  do begin
413for i=0,dimlon-1  do begin
414for l=0,month_in_year-1 do begin
415  flux2(pt,l)=flux(i,j,l)
416endfor
417pt=pt+1
418endfor
419endfor
420;
421;saving netcdf file
422;
423fluxstruct={vector:fltarr(nbpoint),time:fltarr(month_in_year), $
424            flx_bb${speciesinca}:fltarr(nbpoint,month_in_year) }
425;
426fluxstruct.vector=float(indgen(nbpoint)+1)
427;;fluxstruct.time=float(indgen(month_in_year)+1)
428fluxstruct.time=[15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345]
429fluxstruct.flx_bb${speciesinca}=flux2
430;
431attributes = {units:strarr(3),long_name:strarr(3)}
432attributes.units = ['vector','days since 1960-01-01','flux']
433attributes.long_name = ['vector', 'time', 'flux']
434;
435dimensions = {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;
439netcdfwrite,'${filenameout3}',fluxstruct,clobber=1, attributes=attributes, dimensions=dimensions
440;
441end
442eod
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
452regrid
453exit
454eod
455#
456
457#--end loop on species
458done
459
460#--unfortunately idl use capital letters for variable names so need to change to small letters for now
461rm -f ${dirout}flux_vector_h2s_${year}.nc ${dirout}flux_vector_so4_${year}.nc
462cdo expr,'flx_h2s=0.*FLX_SO2' ${dirout}flux_vector_so2_${year}.nc ${dirout}flux_vector_h2s_${year}.nc
463cdo expr,'flx_so4=0.*FLX_SO2' ${dirout}flux_vector_so2_${year}.nc ${dirout}flux_vector_so4_${year}.nc
464
465rm -f ${dirout}flux_vector_${year}.nc
466
467#--combining everything into a single file with some final preprocessing
468rm -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
471rm -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
475cdo 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
477ncrename -d VECTOR,vector -v VECTOR,vector ${dirout}sflx_lmdz_cmip6_${year}.nc
478ncrename -d TIME,time     -v TIME,time     ${dirout}sflx_lmdz_cmip6_${year}.nc
479
480#--cleaning up
481rm -f ${dirout}flux*_${year}.nc
482
483#--end loop on years
484done
485
486#--cleaning the mess
487rm -f ferret*
488rm -f regrid.pro
Note: See TracBrowser for help on using the repository browser.