#--corrected 2080 bug 9/2018, ThL #--reworked 7/2018 for scenario emissions, ThL #--updated on 5/2/2018 with new paths, ThL #--updated on 4/5/2017 with improved Sheng & Zwiers algorithm, ThL #--corrected some interpolation preprocessing (compared to v4) #--updated on 5/5/2017 with correction factor (30/46) on NOx vs. NO #--updated on 9/5/2017 with output separation BB/anthro for SO2, NOx and NH3 #--corrected on 22/6/2017 for BB: undef values zeroed before remapping #--corrected on 26/09/2017 for NOx units: PNNL dataset is kg NO2, VUA is kg NO. # INCA expects NO in its AER version. # #INCA conc_dms flx_nox flx_bc flx_pom flx_bbbc flx_bbpom flx_so2 flx_so4 flx_h2s flx_nh3 #CMIP6 species NOx BC OC SO2 NH3 # + NMVOC CO #--INCA example file where dms_conc can be reused fileINCAex="/home/oboucher/CMIP6/AER_EMISSIONS/INCAfile/sflx_lmdz_phy_1997.nc" #--input directory for anthropogenic (non-BB) emissions dirin="/prodigfs/project/input4MIPs/CMIP6/ScenarioMIP/IAMC/" #--LMDz grid information grid="144x143" gridfile="../GRID/grid-lmdz-lonlat_"${grid} nbpoint=$((144*141+2)) for scen in "ssp119" "ssp126" "ssp245" "ssp370" "ssp434" "ssp460" "ssp534-over" "ssp585" do #--output directory dirout="/data/"${USER}"/CMIP6/AEROSOL/ScenarioMIP/${scen}/v2_correcte/" if [ ! -d ${dirout} ] ; then mkdir -p ${dirout} ; fi if [ ${scen} == "ssp119" ] ; then prefix="IMAGE" ; fi if [ ${scen} == "ssp126" ] ; then prefix="IMAGE" ; fi if [ ${scen} == "ssp245" ] ; then prefix="MESSAGE-GLOBIOM" ; fi if [ ${scen} == "ssp370" ] ; then prefix="AIM" ; fi if [ ${scen} == "ssp434" ] ; then prefix="GCAM4" ; fi if [ ${scen} == "ssp460" ] ; then prefix="GCAM4" ; fi if [ ${scen} == "ssp534-over" ] ; then prefix="REMIND-MAGPIE" ; fi if [ ${scen} == "ssp585" ] ; then prefix="REMIND-MAGPIE" ; fi #--loop on years for year in {2015..2100} do if [ ${year} -ge "2015" -a ${year} -lt "2020" ] then year1=2015 year2=2020 fi if [ ${year} -ge "2020" -a ${year} -lt "2030" ] then year1=2020 year2=2030 fi if [ ${year} -ge "2030" -a ${year} -lt "2040" ] then year1=2030 year2=2040 fi if [ ${year} -ge "2040" -a ${year} -lt "2050" ] then year1=2040 year2=2050 fi if [ ${year} -ge "2050" -a ${year} -lt "2060" ] then year1=2050 year2=2060 fi if [ ${year} -ge "2060" -a ${year} -lt "2070" ] then year1=2060 year2=2070 fi if [ ${year} -ge "2070" -a ${year} -lt "2080" ] then year1=2070 year2=2080 fi if [ ${year} -ge "2080" -a ${year} -lt "2090" ] then year1=2080 year2=2090 fi if [ ${year} -ge "2090" -a ${year} -lt "2100" ] then year1=2090 year2=2100 fi if [ ${year} == 2100 ] then year1=2100 year2=2100 fi #--weights for linear interpolation if [ ${year} == 2015 ] then pond1="1" pond2="0" fi if [ ${year} == 2016 ] then pond1="0.8" pond2="0.2" fi if [ ${year} == 2017 ] then pond1="0.6" pond2="0.4" fi if [ ${year} == 2018 ] then pond1="0.4" pond2="0.6" fi if [ ${year} == 2019 ] then pond1="0.2" pond2="0.8" fi if [ ${year} == 2020 -o ${year} == 2030 -o ${year} == 2040 -o ${year} == 2050 -o ${year} == 2060 -o ${year} == 2070 -o ${year} == 2080 -o ${year} == 2090 ] then pond1="1" pond2="0" fi if [ ${year} == 2021 -o ${year} == 2031 -o ${year} == 2041 -o ${year} == 2051 -o ${year} == 2061 -o ${year} == 2071 -o ${year} == 2081 -o ${year} == 2091 ] then pond1="0.9" pond2="0.1" fi if [ ${year} == 2022 -o ${year} == 2032 -o ${year} == 2042 -o ${year} == 2052 -o ${year} == 2062 -o ${year} == 2072 -o ${year} == 2082 -o ${year} == 2092 ] then pond1="0.8" pond2="0.2" fi if [ ${year} == 2023 -o ${year} == 2033 -o ${year} == 2043 -o ${year} == 2053 -o ${year} == 2063 -o ${year} == 2073 -o ${year} == 2083 -o ${year} == 2093 ] then pond1="0.7" pond2="0.3" fi if [ ${year} == 2024 -o ${year} == 2034 -o ${year} == 2044 -o ${year} == 2054 -o ${year} == 2064 -o ${year} == 2074 -o ${year} == 2084 -o ${year} == 2094 ] then pond1="0.6" pond2="0.4" fi if [ ${year} == 2025 -o ${year} == 2035 -o ${year} == 2045 -o ${year} == 2055 -o ${year} == 2065 -o ${year} == 2075 -o ${year} == 2085 -o ${year} == 2095 ] then pond1="0.5" pond2="0.5" fi if [ ${year} == 2026 -o ${year} == 2036 -o ${year} == 2046 -o ${year} == 2056 -o ${year} == 2066 -o ${year} == 2076 -o ${year} == 2086 -o ${year} == 2096 ] then pond1="0.4" pond2="0.6" fi if [ ${year} == 2027 -o ${year} == 2037 -o ${year} == 2047 -o ${year} == 2057 -o ${year} == 2067 -o ${year} == 2077 -o ${year} == 2087 -o ${year} == 2097 ] then pond1="0.3" pond2="0.7" fi if [ ${year} == 2028 -o ${year} == 2038 -o ${year} == 2048 -o ${year} == 2058 -o ${year} == 2068 -o ${year} == 2078 -o ${year} == 2088 -o ${year} == 2098 ] then pond1="0.2" pond2="0.8" fi if [ ${year} == 2029 -o ${year} == 2039 -o ${year} == 2049 -o ${year} == 2059 -o ${year} == 2069 -o ${year} == 2079 -o ${year} == 2089 -o ${year} == 2099 ] then pond1="0.1" pond2="0.9" fi if [ ${year} == 2100 ] then pond1="0" pond2="1" fi #--species for species in "BC" "NOx" "OC" "SO2" "NH3" do if [ ${species} = "BC" ] ; then speciesinca="bc" ; fi if [ ${species} = "NOx" ] ; then speciesinca="nox" ; fi if [ ${species} = "OC" ] ; then speciesinca="pom" ; fi if [ ${species} = "SO2" ] ; then speciesinca="so2" ; fi if [ ${species} = "NH3" ] ; then speciesinca="nh3" ; fi if [ ${species} = "BC" ] ; then speciesUp="BC" ; fi if [ ${species} = "NOx" ] ; then speciesUp="NOX" ; fi if [ ${species} = "OC" ] ; then speciesUp="OC" ; fi if [ ${species} = "SO2" ] ; then speciesUp="SO2" ; fi if [ ${species} = "NH3" ] ; then speciesUp="NH3" ; fi #--Dealing with anthro emissions file... echo "... "${year}" : Dealing with "${species}" anthro input file..." #--input file anthro (fossil fuel emissions) 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_201501-210012.nc #--two temporary files for interpolation filetmp1=${dirout}tmp1.nc filetmp2=${dirout}tmp2.nc #--output files filenameout1=${dirout}flux_${speciesinca}_${year}.nc filenameout1b=${dirout}flux_0_${speciesinca}_${year}.nc filenameout2=${dirout}flux_lmdz_${speciesinca}_${year}.nc filenameout3=${dirout}flux_vector_${speciesinca}_${year}.nc echo ${filename} ${filenameout1} ${filenameout2} ${filenameout3} rm -f ${filetmp1} ${filetmp2} ${filenameout1} ${filenameout2} ${filenameout3} #--unfortunately idl not happy with input netcdf files so need to ferretize files #--I also sum over sectors and I extract the correct years as well #--first year (start of 5-Y or 10-Y period, for later interpolation) rm -f rewrite.jnl cat << eod > rewrite.jnl use "${filename}" set region/t=16-jan-${year1}:16-dec-${year1} save/clobber/file="${filetmp1}" ${speciesUp}_EM_ANTHRO[k=@sum] eod #--run ferret script ferret << eod go rewrite.jnl exit eod #--second year (end of 5-Y or 10-Y period, for later interpolation) rm -f rewrite.jnl cat << eod > rewrite.jnl use "${filename}" set region/t=16-jan-${year2}:16-dec-${year2} save/clobber/file="${filetmp2}" ${speciesUp}_EM_ANTHRO[k=@sum] eod #--run ferret script ferret << eod go rewrite.jnl exit eod #--performing time interpolation cdo add -mulc,${pond1} -selname,${speciesUp}_EM_ANTHRO ${filetmp1} -mulc,${pond2} -selname,${speciesUp}_EM_ANTHRO ${filetmp2} ${filenameout1} cdo setmisstoc,0.0 ${filenameout1} ${filenameout1b} #--remap to LMDz grid #--OC to POM conversion factor #--otherwise change to capital letters if not (eg NOx) if [ ${species} == "OC" ] ; then echo cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux -mulc,1.4 ${filenameout1b} ${filenameout2} cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux -mulc,1.4 ${filenameout1b} ${filenameout2} else echo cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2} cdo remapcon,${gridfile} -chname,`echo ${species}_EM_ANTHRO | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2} fi #--Improved Sheng & Zwiers algorithm + transform into vector rm -f regrid.pro cat << eod >> regrid.pro pro regrid filename='${filenameout2}' print, filename NETCDFREAD,filename,'flux',flux,dimflux NETCDFREAD,filename,'lat',lat,dimlat0 NETCDFREAD,filename,'lon',lon,dimlon0 NETCDFREAD,filename,'TIME',time,dimtime0 dimlat=dimlat0(0) dimlon=dimlon0(0) dimtime=dimtime0(0) print, 'dim flux=', dimflux A = float([ [3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8.],$ [1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$ [0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0.],$ [0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0.],$ [0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0.],$ [0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0.],$ [0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0.],$ [0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0.],$ [0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0.],$ [0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0.],$ [0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8.],$ [1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4.] ]) fluxinit=flux flux_check=flux for lo=0,dimlon-1 do begin for la=0,dimlat-1 do begin flux_check(lo,la,*) = invert(A) ## transpose(fluxinit(lo,la,*)) endfor endfor m_bloq = make_array(dimlon,dimlat,12,value=0) ; Matrice booléenne "mois à bloquer ou non" if total(where(flux_check lt 0)) ne -1 then m_bloq(where(flux_check lt 0)) = 1 ; Correction/adaptation de la matrice S&Z en fonction du masque booléen m_bloq for lo=0,dimlon-1 do begin for la=0,dimlat-1 do begin whereneg = where(flux_check(lo,la,*) lt 0) ; (12 pts max) Identification de potentiels points à problèmes, corrigés négativement nbannul=n_elements(whereneg)*(total(whereneg) ne -1) 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 A2 = A ; Je repars de la matrice A initiale, ce pour chaque point de grille ; ; Potentiellement plusieurs passages pour éliminer toutes les valeurs négatives while nbannul ne 0 do begin ; Si l'on a effectivement des émissions corrigées négativement... m_bloq(lo,la,whereneg) = 1 ; Update de la matrice m_bloq for m=0,11 do begin if m eq 11 then begin ; Pour plus de facilité, mois précédents et suivants codés ici p=10 s=0 endif else if m eq 0 then begin p=11 s=1 endif else begin p = m-1 s = m+1 endelse if m_bloq(lo,la,m) then begin ; Je traite les mois bloqués en eux-mêmes A2(p,m) = 0. A2(m,m) = 1. A2(s,m) = 0. endif ; Fin du cas si l'on est sur un mois bloqué if ~m_bloq(lo,la,m) then begin ; Je traite les mois non bloqués, pour ceux adjacents à un mois bloqué if m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois encadré de deux mois bloqués A2(p,m) = 1./4. A2(m,m) = 1./2. A2(s,m) = 1./4. endif else if m_bloq(lo,la,p) and ~m_bloq(lo,la,s) then begin ; Mois précédent bloqué (uniquement) A2(p,m) = 2./8. A2(m,m) = 5./8. A2(s,m) = 1./8. endif else if ~m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois suivant bloqué (uniquement) A2(p,m) = 1./8. A2(m,m) = 5./8. A2(s,m) = 2./8. endif endif ; Fin du cas mois non bloqué endfor ; Fin de la boucle sur les mois, balayage de la matrice flux_corr = invert(A2) ## transpose(fluxinit(lo,la,*)) ; Ré-itération de la multiplication matricielle avec la matrice A modifiée (A2) whereneg = where(flux_corr lt 0) ; (12 pts max) Ré-identification de potentiels nouveaux points à problèmes, corrigés négativement nbannul=n_elements(whereneg)*(total(whereneg) ne -1) endwhile ; Fin du cas où l'on avait des problèmes d'émissions corrigées négativement ; *** IMPORTANT ! *** Pour signaler les mois bloqués, on prend la convention suivante : ; valeur négative ou nulle <=> mois bloqué ; valeur positive <=> mois à interpolation classique flux(lo,la,*) = flux_corr ; En sortie de la boucle while, normalement flux_corr est complètement positif endfor ; Fin boucle lat endfor ; Fin boucle lon nbnegtotal = n_elements(where(m_bloq eq 1)) * (total(where(m_bloq eq 1)) ne -1) if nbnegtotal ne 0 then flux(where(m_bloq eq 1)) = -flux(where(m_bloq eq 1)) ; Je force à des valeurs négatives ; month_in_year=12 nbpoint=${nbpoint} flux2=fltarr(nbpoint,month_in_year) flux2(*,*)=0.0 ; for l=0,month_in_year-1 do begin flux2(0,l)=TOTAL(flux(*,0,l))/float(dimlon) flux2(nbpoint-1,l)=TOTAL(flux(*,dimlat-1,l))/float(dimlon) endfor ; pt=1 for j=1,dimlat-2 do begin for i=0,dimlon-1 do begin for l=0,month_in_year-1 do begin flux2(pt,l)=flux(i,j,l) endfor pt=pt+1 endfor endfor ; ;saving netcdf file ; fluxstruct={vector:fltarr(nbpoint),time:fltarr(month_in_year), $ flx_${speciesinca}:fltarr(nbpoint,month_in_year) } ; fluxstruct.vector=float(indgen(nbpoint)+1) ;;fluxstruct.time=float(indgen(month_in_year)+1) fluxstruct.time=[15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345] fluxstruct.flx_${speciesinca}=flux2 ; attributes = {units:strarr(3),long_name:strarr(3)} attributes.units = ['vector','days since 1960-01-01','flux'] attributes.long_name = ['vector', 'time', 'flux'] ; dimensions = {isdim:intarr(3), links:intarr(2,3)} dimensions.isdim = [1,1,0] ; (1=dimension, 0=variable) dimensions.links = [ [-1,-1],[-1,-1],[0,1] ] ; netcdfwrite,'${filenameout3}',fluxstruct,clobber=1, attributes=attributes, dimensions=dimensions ; end eod # #--calling IDL # /opt/idl-6.4/idl/bin/idl << eod .r netcdf .r netcdfwrite .r struct_dims .r regrid regrid exit eod # #--now dealing with BB sources echo "... "${year}" : Dealing with "${species}" openburning input file..." 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_201501-210012.nc if [ ${species} = "BC" ] ; then speciesinca="bc" ; fi if [ ${species} = "NOx" ] ; then speciesinca="nox" ; fi if [ ${species} = "OC" ] ; then speciesinca="pom" ; fi if [ ${species} = "SO2" ] ; then speciesinca="so2" ; fi if [ ${species} = "NH3" ] ; then speciesinca="nh3" ; fi #--two temporary files for interpolation filetmp1=${dirout}tmp1.nc filetmp2=${dirout}tmp2.nc #--output files filenameout1=${dirout}flux_${speciesinca}bb_${year}.nc filenameout1b=${dirout}flux_0_${speciesinca}bb_${year}.nc filenameout2=${dirout}flux_lmdz0_${speciesinca}bb_${year}.nc filenameout3=${dirout}flux_vector_${speciesinca}bb_${year}.nc echo ${filename} ${filenameout1} ${filenameout1b} ${filenameout2} ${filenameout3} rm -f ${filetmp1} ${filetmp2} ${filenameout1} ${filenameout1b} ${filenameout2} ${filenameout3} #--unfortunately idl not happy with input netcdf files so need to ferretize files #--I also sum over sectors and I extract the correct years as well #--first year (start of 5-Y or 10-Y period, for later interpolation) rm -f rewrite.jnl cat << eod > rewrite.jnl use "${filename}" set region/t=16-jan-${year1}:16-dec-${year1} save/clobber/file="${filetmp1}" ${speciesUp}_EM_OPENBURNING[k=@sum] eod #--run ferret script ferret << eod go rewrite.jnl exit eod #--second year (end of 5-Y or 10-Y period, for later interpolation) rm -f rewrite.jnl cat << eod > rewrite.jnl use "${filename}" set region/t=16-jan-${year2}:16-dec-${year2} save/clobber/file="${filetmp2}" ${speciesUp}_EM_OPENBURNING[k=@sum] eod #--run ferret script ferret << eod go rewrite.jnl exit eod #--performing time interpolation cdo add -mulc,${pond1} -selname,${speciesUp}_EM_OPENBURNING ${filetmp1} -mulc,${pond2} -selname,${speciesUp}_EM_OPENBURNING ${filetmp2} ${filenameout1} #--replace undef with 0 cdo setmisstoc,0.0 ${filenameout1} ${filenameout1b} #--remap to LMDz grid #--OC to POM conversion factor #--as ferret returns NOX, treat NOx NOX inconsistency in names by converting to upper case if [ ${species} != "OC" ] ; then echo cdo remapcon,${gridfile} -chname,`echo ${species}_EM_OPENBURNING | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2} cdo remapcon,${gridfile} -chname,`echo ${species}_EM_OPENBURNING | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2} else echo cdo remapcon,${gridfile} -chname,${species}_EM_OPENBURNING,flux -mulc,1.4 ${filenameout1b} ${filenameout2} cdo remapcon,${gridfile} -chname,${species}_EM_OPENBURNING,flux -mulc,1.4 ${filenameout1b} ${filenameout2} fi #--Improved Sheng & Zwiers algorithm + transform into vector rm -f regrid.pro cat << eod >> regrid.pro pro regrid filename='${filenameout2}' print, filename NETCDFREAD,filename,'flux',flux,dimflux NETCDFREAD,filename,'lat',lat,dimlat0 NETCDFREAD,filename,'lon',lon,dimlon0 NETCDFREAD,filename,'TIME',time,dimtime0 dimlat=dimlat0(0) dimlon=dimlon0(0) dimtime=dimtime0(0) print, 'dim flux=', dimflux A = float([ [3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8.],$ [1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$ [0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0.],$ [0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0.],$ [0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0.],$ [0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0.],$ [0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0.],$ [0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0.],$ [0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0.],$ [0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0.],$ [0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8.],$ [1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4.] ]) fluxinit=flux flux_check=flux for lo=0,dimlon-1 do begin for la=0,dimlat-1 do begin flux_check(lo,la,*) = invert(A) ## transpose(fluxinit(lo,la,*)) endfor endfor m_bloq = make_array(dimlon,dimlat,12,value=0) ; Matrice booléenne "mois à bloquer ou non" if total(where(flux_check lt 0)) ne -1 then m_bloq(where(flux_check lt 0)) = 1 ; Correction/adaptation de la matrice S&Z en fonction du masque booléen m_bloq for lo=0,dimlon-1 do begin for la=0,dimlat-1 do begin whereneg = where(flux_check(lo,la,*) lt 0) ; (12 pts max) Identification de potentiels points à problèmes, corrigés négativement nbannul=n_elements(whereneg)*(total(whereneg) ne -1) 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) A2 = A ; Je repars de la matrice A initiale, ce pour chaque point de grille ; ; Potentiellement plusieurs passages pour éliminer toutes les valeurs négatives while nbannul ne 0 do begin ; Si l'on a effectivement des émissions corrigées négativement... m_bloq(lo,la,whereneg) = 1 ; Update de la matrice m_bloq for m=0,11 do begin if m eq 11 then begin ; Pour plus de facilité, mois précédents et suivants codés ici p=10 s=0 endif else if m eq 0 then begin p=11 s=1 endif else begin p = m-1 s = m+1 endelse if m_bloq(lo,la,m) then begin ; Je traite les mois bloqués en eux-mêmes A2(p,m) = 0. A2(m,m) = 1. A2(s,m) = 0. endif ; Fin du cas si l'on est sur un mois bloqué if ~m_bloq(lo,la,m) then begin ; Je traite les mois non bloqués, pour ceux adjacents à un mois bloqué if m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois encadré de deux mois bloqués A2(p,m) = 1./4. A2(m,m) = 1./2. A2(s,m) = 1./4. endif else if m_bloq(lo,la,p) and ~m_bloq(lo,la,s) then begin ; Mois précédent bloqué (uniquement) A2(p,m) = 2./8. A2(m,m) = 5./8. A2(s,m) = 1./8. endif else if ~m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois suivant bloqué (uniquement) A2(p,m) = 1./8. A2(m,m) = 5./8. A2(s,m) = 2./8. endif endif ; Fin du cas mois non bloqué endfor ; Fin de la boucle sur les mois, balayage de la matrice flux_corr = invert(A2) ## transpose(fluxinit(lo,la,*)) ; Ré-itération de la multiplication matricielle avec la matrice A modifiée (A2) whereneg = where(flux_corr lt 0) ; (12 pts max) Ré-identification de potentiels nouveaux points à problèmes, corrigés négativement nbannul=n_elements(whereneg)*(total(whereneg) ne -1) endwhile ; Fin du cas où l'on avait des problèmes d'émissions corrigées négativement ; *** IMPORTANT ! *** Pour signaler les mois bloqués, on prend la convention suivante : ; valeur négative ou nulle <=> mois bloqué ; valeur positive <=> mois à interpolation classique flux(lo,la,*) = flux_corr ; En sortie de la boucle while, normalement flux_corr est complètement positif endfor ; Fin boucle lat endfor ; Fin boucle lon nbnegtotal = n_elements(where(m_bloq eq 1)) * (total(where(m_bloq eq 1)) ne -1) if nbnegtotal ne 0 then flux(where(m_bloq eq 1)) = -flux(where(m_bloq eq 1)) ; Je force à des valeurs négatives ; month_in_year=12 nbpoint=${nbpoint} flux2=fltarr(nbpoint,month_in_year) flux2(*,*)=0.0 ; for l=0,month_in_year-1 do begin flux2(0,l)=TOTAL(flux(*,0,l))/float(dimlon) flux2(nbpoint-1,l)=TOTAL(flux(*,dimlat-1,l))/float(dimlon) endfor ; pt=1 for j=1,dimlat-2 do begin for i=0,dimlon-1 do begin for l=0,month_in_year-1 do begin flux2(pt,l)=flux(i,j,l) endfor pt=pt+1 endfor endfor ; ;saving netcdf file ; fluxstruct={vector:fltarr(nbpoint),time:fltarr(month_in_year), $ flx_bb${speciesinca}:fltarr(nbpoint,month_in_year) } ; fluxstruct.vector=float(indgen(nbpoint)+1) ;;fluxstruct.time=float(indgen(month_in_year)+1) fluxstruct.time=[15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345] fluxstruct.flx_bb${speciesinca}=flux2 ; attributes = {units:strarr(3),long_name:strarr(3)} attributes.units = ['vector','days since 1960-01-01','flux'] attributes.long_name = ['vector', 'time', 'flux'] ; dimensions = {isdim:intarr(3), links:intarr(2,3)} dimensions.isdim = [1,1,0] ; (1=dimension, 0=variable) dimensions.links = [ [-1,-1],[-1,-1],[0,1] ] ; netcdfwrite,'${filenameout3}',fluxstruct,clobber=1, attributes=attributes, dimensions=dimensions ; end eod # #--calling IDL # /opt/idl-6.4/idl/bin/idl << eod .r netcdf .r netcdfwrite .r struct_dims .r regrid regrid exit eod # #--end loop on species done #--cleaning up rm -f ferret* #--unfortunately idl use capital letters for variable names so need to change to small letters for now rm -f ${dirout}flux_vector_h2s_${year}.nc ${dirout}flux_vector_so4_${year}.nc cdo expr,'flx_h2s=0.*FLX_SO2' ${dirout}flux_vector_so2_${year}.nc ${dirout}flux_vector_h2s_${year}.nc cdo expr,'flx_so4=0.*FLX_SO2' ${dirout}flux_vector_so2_${year}.nc ${dirout}flux_vector_so4_${year}.nc rm -f ${dirout}flux_vector_${year}.nc #--combining everything into a single file with some final preprocessing rm -f ${dirout}flux_vector_noxtot_${year}.nc ${dirout}flux_vector_so2tot_${year}.nc ${dirout}flux_vector_nh3tot_${year}.nc #--deleting output file if already there rm -f ${dirout}sflx_lmdz_cmip6_${year}.nc #--merging all files into a single one #--PNNL NOx is NO2 so 30/46 scaling factor to change to NO #--VUA NOx is NO so no change in unit 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 ncrename -d VECTOR,vector -v VECTOR,vector ${dirout}sflx_lmdz_cmip6_${year}.nc ncrename -d TIME,time -v TIME,time ${dirout}sflx_lmdz_cmip6_${year}.nc #--cleaning up rm -f ${dirout}flux*_${year}.nc #--to be uncommented in final script #--end loop on years done #--end loop on scenarios done #--cleaning the mess rm -f ferret* rm -f regrid.pro rm -f rewrite.jnl