Changeset 4051


Ignore:
Timestamp:
10/11/18 13:52:39 (6 years ago)
Author:
tlurton
Message:

Corrected script to generate sflx files for scenarios (bug on 2080's decade).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/CMIP6_FORCING/SCENARIOS/AER_TROP_EMISSIONS/REGRID/regrid_scen.sh

    r4007 r4051  
     1#--corrected 2080 bug 9/2018, ThL 
    12#--reworked 7/2018 for scenario emissions, ThL 
    23#--updated on 5/2/2018 with new paths, ThL 
     
    1617fileINCAex="/home/oboucher/CMIP6/AER_EMISSIONS/INCAfile/sflx_lmdz_phy_1997.nc" 
    1718 
    18 #--input directory for emissions 
     19#--input directory for anthropogenic (non-BB) emissions 
    1920dirin="/prodigfs/project/input4MIPs/CMIP6/ScenarioMIP/IAMC/" 
    2021 
     
    2829 
    2930#--output directory 
    30 dirout="/data/"${USER}"/CMIP6/AEROSOL/ScenarioMIP/${scen}/v1/" 
     31dirout="/data/"${USER}"/CMIP6/AEROSOL/ScenarioMIP/${scen}/v2_correcte/" 
    3132if [ ! -d ${dirout} ] ; then mkdir -p ${dirout} ; fi 
    3233 
     
    4041if [ ${scen} == "ssp585" ] ; then prefix="REMIND-MAGPIE" ; fi 
    4142 
    42 #--Unique file for the whole period, so fixed variables: 
     43#--loop on years 
     44for year in {2015..2100} 
     45do 
     46 
     47if [ ${year} -ge "2015" -a ${year} -lt "2020" ] 
     48then 
    4349year1=2015 
     50year2=2020 
     51fi 
     52if [ ${year} -ge "2020" -a ${year} -lt "2030" ] 
     53then 
     54year1=2020 
     55year2=2030 
     56fi 
     57if [ ${year} -ge "2030" -a ${year} -lt "2040" ] 
     58then 
     59year1=2030 
     60year2=2040 
     61fi 
     62if [ ${year} -ge "2040" -a ${year} -lt "2050" ] 
     63then 
     64year1=2040 
     65year2=2050 
     66fi 
     67if [ ${year} -ge "2050" -a ${year} -lt "2060" ] 
     68then 
     69year1=2050 
     70year2=2060 
     71fi 
     72if [ ${year} -ge "2060" -a ${year} -lt "2070" ] 
     73then 
     74year1=2060 
     75year2=2070 
     76fi 
     77if [ ${year} -ge "2070" -a ${year} -lt "2080" ] 
     78then 
     79year1=2070 
     80year2=2080 
     81fi 
     82if [ ${year} -ge "2080" -a ${year} -lt "2090" ] 
     83then 
     84year1=2080 
     85year2=2090 
     86fi 
     87if [ ${year} -ge "2090" -a ${year} -lt "2100" ] 
     88then 
     89year1=2090 
    4490year2=2100 
    45  
    46 #--Loop on species (anthro) 
     91fi 
     92if [ ${year} == 2100 ] 
     93then 
     94year1=2100 
     95year2=2100 
     96fi 
     97#--weights for linear interpolation 
     98if [ ${year} == 2015 ] 
     99then 
     100pond1="1" 
     101pond2="0" 
     102fi 
     103if [ ${year} == 2016 ] 
     104then 
     105pond1="0.8" 
     106pond2="0.2" 
     107fi 
     108if [ ${year} == 2017 ] 
     109then 
     110pond1="0.6" 
     111pond2="0.4" 
     112fi 
     113if [ ${year} == 2018 ] 
     114then 
     115pond1="0.4" 
     116pond2="0.6" 
     117fi 
     118if [ ${year} == 2019 ] 
     119then 
     120pond1="0.2" 
     121pond2="0.8" 
     122fi 
     123if [ ${year} == 2020 -o ${year} == 2030 -o ${year} == 2040 -o ${year} == 2050 -o ${year} == 2060 -o ${year} == 2070 -o ${year} == 2080 -o ${year} == 2090 ] 
     124then 
     125pond1="1" 
     126pond2="0" 
     127fi 
     128if [ ${year} == 2021 -o ${year} == 2031 -o ${year} == 2041 -o ${year} == 2051 -o ${year} == 2061 -o ${year} == 2071 -o ${year} == 2081 -o ${year} == 2091 ] 
     129then 
     130pond1="0.9" 
     131pond2="0.1" 
     132fi 
     133if [ ${year} == 2022 -o ${year} == 2032 -o ${year} == 2042 -o ${year} == 2052 -o ${year} == 2062 -o ${year} == 2072 -o ${year} == 2082 -o ${year} == 2092 ] 
     134then 
     135pond1="0.8" 
     136pond2="0.2" 
     137fi 
     138if [ ${year} == 2023 -o ${year} == 2033 -o ${year} == 2043 -o ${year} == 2053 -o ${year} == 2063 -o ${year} == 2073 -o ${year} == 2083 -o ${year} == 2093 ] 
     139then 
     140pond1="0.7" 
     141pond2="0.3" 
     142fi 
     143if [ ${year} == 2024 -o ${year} == 2034 -o ${year} == 2044 -o ${year} == 2054 -o ${year} == 2064 -o ${year} == 2074 -o ${year} == 2084 -o ${year} == 2094 ] 
     144then 
     145pond1="0.6" 
     146pond2="0.4" 
     147fi 
     148if [ ${year} == 2025 -o ${year} == 2035 -o ${year} == 2045 -o ${year} == 2055 -o ${year} == 2065 -o ${year} == 2075 -o ${year} == 2085 -o ${year} == 2095 ] 
     149then 
     150pond1="0.5" 
     151pond2="0.5" 
     152fi 
     153if [ ${year} == 2026 -o ${year} == 2036 -o ${year} == 2046 -o ${year} == 2056 -o ${year} == 2066 -o ${year} == 2076 -o ${year} == 2086 -o ${year} == 2096 ] 
     154then 
     155pond1="0.4" 
     156pond2="0.6" 
     157fi 
     158if [ ${year} == 2027 -o ${year} == 2037 -o ${year} == 2047 -o ${year} == 2057 -o ${year} == 2067 -o ${year} == 2077 -o ${year} == 2087 -o ${year} == 2097 ] 
     159then 
     160pond1="0.3" 
     161pond2="0.7" 
     162fi 
     163if [ ${year} == 2028 -o ${year} == 2038 -o ${year} == 2048 -o ${year} == 2058 -o ${year} == 2068 -o ${year} == 2078 -o ${year} == 2088 -o ${year} == 2098 ] 
     164then 
     165pond1="0.2" 
     166pond2="0.8" 
     167fi 
     168if [ ${year} == 2029 -o ${year} == 2039 -o ${year} == 2049 -o ${year} == 2059 -o ${year} == 2069 -o ${year} == 2079 -o ${year} == 2089 -o ${year} == 2099 ] 
     169then 
     170pond1="0.1" 
     171pond2="0.9" 
     172fi 
     173if [ ${year} == 2100 ] 
     174then 
     175pond1="0" 
     176pond2="1" 
     177fi 
     178 
     179#--species  
    47180for species in "BC" "NOx" "OC" "SO2" "NH3" 
    48181do 
    49  
    50 echo "... "${year}" : Dealing with "${species}" anthro input file..." 
    51182 
    52183if [ ${species} = "BC"  ] ; then speciesinca="bc"  ; fi 
     
    62193if [ ${species} = "NH3" ] ; then speciesUp="NH3" ; fi 
    63194 
    64 #--input file anthro 
    65 filename=${dirin}IAMC-${prefix}-${scen}-1-1/atmos/mon/${species}_em_anthro/gn/v20180628/${species}-em-anthro_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12.nc 
    66  
    67 #--input file summed over sectors 
    68 filesum=${dirout}${species}-em-anthro_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_sum.nc 
    69 #--reworked input file 
    70 filetmp=${dirout}${species}-em-anthro_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_tmp.nc 
    71 #--time-interpolated input file 
    72 fileintanthro=${dirout}${species}-em-anthro_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_interp.nc 
    73  
    74 if [ -f ${fileintanthro} ] 
    75 then 
    76    echo "...Nothing to do!" 
    77 else 
    78  
    79 rm -f ${filesum} ${filetmp} ${fileintanthro} 
    80  
    81 #--re-formatting the input file 
    82 #--summing over sectors 
    83 rm -f sumsectors.jnl 
    84 cat << eod > sumsectors.jnl 
    85 set memory/size=100 
    86 use "${filename}" 
    87 save/clobber/file="${filesum}" ${species}_EM_ANTHRO[k=@sum] 
    88 eod 
    89 #--run ferret script 
    90 ferret << eod  
    91 go sumsectors.jnl 
    92 exit 
    93 eod 
    94  
    95 #--reformatting input file for IDL to be able to read 
    96 ncks -3 ${filesum} ${filetmp} 
    97 #--cleaning up 
    98 rm -f ${filesum} 
    99  
    100 #--IDL code for time interpolation, to fill in 9-year gaps in input file 
    101 rm -f time_interp_over_gaps.pro 
    102 cat << eod >> time_interp_over_gaps.pro 
    103 pro time_interp_over_gaps 
    104  
    105 ; Les dimensions des fichiers 
    106 nlon=720 
    107 nlat=360 
    108 nt=1032 
    109  
    110 une_annee=[31,30,29,31,30,31,30,31,31,30,31,30] 
    111 les_mois = [31,28,31,30,31,30,31,31,30,31,30,31] 
    112  
    113 jours_in = [15, 45, 74, 105, 135, 166, 196, 227, 258, 288, 319, 349, 1840, 1870, $ 
    114     1899, 1930, 1960, 1991, 2021, 2052, 2083, 2113, 2144, 2174, 5490, 5520, $ 
    115     5549, 5580, 5610, 5641, 5671, 5702, 5733, 5763, 5794, 5824, 9140, 9170, $ 
    116     9199, 9230, 9260, 9291, 9321, 9352, 9383, 9413, 9444, 9474, 12790, 12820, $ 
    117     12849, 12880, 12910, 12941, 12971, 13002, 13033, 13063, 13094, 13124, $ 
    118     16440, 16470, 16499, 16530, 16560, 16591, 16621, 16652, 16683, 16713, $ 
    119     16744, 16774, 20090, 20120, 20149, 20180, 20210, 20241, 20271, 20302, $ 
    120     20333, 20363, 20394, 20424, 23740, 23770, 23799, 23830, 23860, 23891, $ 
    121     23921, 23952, 23983, 24013, 24044, 24074, 27390, 27420, 27449, 27480, $  
    122     27510, 27541, 27571, 27602, 27633, 27663, 27694, 27724, 31040, 31070, $  
    123     31099, 31130, 31160, 31191, 31221, 31252, 31283, 31313, 31344, 31374] 
    124  
    125 jours_out=make_array(1032) 
    126 jours_out(0) = 15 
    127 for cpt=1,1031 do jours_out(cpt) = jours_out(cpt-1) + une_annee(cpt mod 12) 
    128  
    129 idin = ncdf_open('${filetmp}') 
    130 varid = ncdf_varid(idin,'${speciesUp}_EM_ANTHRO') 
    131 lonid = ncdf_varid(idin,'LON') 
    132 latid = ncdf_varid(idin,'LAT') 
    133 ;lonbndid = ncdf_varid(idin,'LON_bnds') 
    134 ;latbndid = ncdf_varid(idin,'LAT_bnds') 
    135 timbndid = ncdf_varid(idin,'TIME_bnds') 
    136 ncdf_varget, idin, varid, emiss_init 
    137 ncdf_attget, idin, varid, "units", emiss_unit 
    138 ncdf_attget, idin, varid, "long_name", emiss_longname 
    139 ncdf_varget, idin, lonid, lon 
    140 ncdf_varget, idin, latid, lat 
    141 ;ncdf_varget, idin, lonbndid, lonbnds 
    142 ;ncdf_varget, idin, latbndid, latbnds 
    143 ncdf_varget, idin, timbndid, timbnds_in 
    144 ncdf_close, idin 
    145  
    146 timbnds_out = make_array(2,1032) 
    147 timbnds_out(*,0) = [0,31] 
    148 timbnds_out(*,1) = [31,59] 
    149 for cpt=2,1031 do timbnds_out(0,cpt) = timbnds_out(0,cpt-1) + les_mois((cpt-1) mod 12) 
    150 for cpt=1,1030 do timbnds_out(1,cpt) = timbnds_out(0,cpt+1) 
    151 timbnds_out(1,1031) = 31390 
    152  
    153 emiss_interpol=make_array(nlon,nlat,1032,value=0.) 
    154  
    155 indices_out_mois = make_array(86,12,value=0) 
    156 for m=0,11 do begin 
    157    for n=0,85 do indices_out_mois(n,m) = 12*n + m 
    158 endfor 
    159  
    160 jours_out_mois = make_array(86,12,value=0) 
    161 for n=0,85 do begin 
    162    for m=0,11 do jours_out_mois(n,m) = jours_out(indices_out_mois(n,m)) 
    163 endfor 
    164  
    165 jours_in_mois = make_array(n_elements(jours_in)/12,12,value=0) 
    166 for m=0,11 do begin 
    167    for n=0,n_elements(jours_in)/12-1 do jours_in_mois(n,m) = jours_in(n*12 + m) 
    168 endfor 
    169  
    170 indices_in_mois = make_array(n_elements(jours_in)/12,12,value=0) 
    171 for m=0,11 do begin 
    172    for n=0,n_elements(jours_in)/12-1 do indices_in_mois(n,m) = where(jours_in eq jours_in_mois(n,m)) 
    173 endfor 
    174  
    175 ; Interpolation mois par mois... 
    176 for i=0,nlon-1 do begin 
    177    for j=0,nlat-1 do begin 
    178       for m=0,11 do begin 
    179          emiss_interpol(i,j,indices_out_mois(*,m)) = interpol(emiss_init(i,j,indices_in_mois(*,m)),jours_in_mois(*,m),jours_out_mois(*,m)) 
    180       endfor 
    181    endfor 
    182 endfor 
    183  
    184 idout = ncdf_create('${fileintanthro}', /clobber) 
    185 dimlonid = ncdf_dimdef(idout,'lon',nlon) 
    186 dimlatid = ncdf_dimdef(idout,'lat',nlat) 
    187 dimtimid = ncdf_dimdef(idout,'time',1032) 
    188 dimbndid = ncdf_dimdef(idout,'bound',2) 
    189 varlonid = ncdf_vardef(idout, 'lon', [dimlonid], /double) 
    190 varlatid = ncdf_vardef(idout, 'lat', [dimlatid], /double) 
    191 vartimid = ncdf_vardef(idout, 'time', [dimtimid], /double) 
    192 ;varlonbndsid = ncdf_vardef(idout, 'lon_bnds', [dimbndid,dimlonid], /double) 
    193 ;varlatbndsid = ncdf_vardef(idout, 'lat_bnds', [dimbndid,dimlatid], /double) 
    194 vartimbndsid = ncdf_vardef(idout, 'time_bnds', [dimbndid,dimtimid], /double) 
    195 varemissid = ncdf_vardef(idout, '${species}_em_anthro', [dimlonid,dimlatid,dimtimid], /float) 
    196 ncdf_control, idout, /endef 
    197 ncdf_varput, idout, varlonid, lon 
    198 ncdf_varput, idout, varlatid, lat 
    199 ;ncdf_varput, idout, varlonbndsid, lonbnds 
    200 ;ncdf_varput, idout, varlatbndsid, latbnds 
    201 ncdf_varput, idout, vartimbndsid, timbnds_out 
    202 ncdf_varput, idout, varemissid, emiss_interpol 
    203 ncdf_varput, idout, vartimid, jours_out 
    204 ncdf_control, idout, /redef 
    205 ncdf_attput, idout, varlonid, "units", "degrees_east" 
    206 ncdf_attput, idout, varlonid, "long_name", "longitude" 
    207 ncdf_attput, idout, varlonid, "axis", "X" 
    208 ncdf_attput, idout, varlonid, "bounds", "lon_bnds" 
    209 ncdf_attput, idout, varlonid, "modulo", 360. 
    210 ncdf_attput, idout, varlonid, "realtopology", "circular" 
    211 ncdf_attput, idout, varlonid, "standard_name", "longitude" 
    212 ncdf_attput, idout, varlonid, "topology", "circular" 
    213 ncdf_attput, idout, varlatid, "units", "degrees_north" 
    214 ncdf_attput, idout, varlatid, "long_name", "latitude" 
    215 ncdf_attput, idout, varlatid, "axis", "Y" 
    216 ncdf_attput, idout, varlatid, "bounds", "lat_bnds" 
    217 ncdf_attput, idout, varlatid, "realtopology", "linear" 
    218 ncdf_attput, idout, varlatid, "standard_name", "latitude" 
    219 ncdf_attput, idout, varemissid, "units", string(emiss_unit) 
    220 ncdf_attput, idout, varemissid, "_FillValue", 1.e+20 
    221 ncdf_attput, idout, varemissid, "cell_methods", "time: mean" 
    222 ncdf_attput, idout, varemissid, "long_name", string(emiss_longname) 
    223 ncdf_attput, idout, varemissid, "missing_value", 1.e+20 
    224 ncdf_attput, idout, vartimid, "units", "days since 2015-01-01 0:0:0" 
    225 ncdf_attput, idout, vartimid, "long_name", "time" 
    226 ncdf_attput, idout, vartimid, "calendar", '365_day' 
    227 ncdf_attput, idout, vartimid, "axis", "T" 
    228 ncdf_attput, idout, vartimid, "bounds", "time_bnds" 
    229 ncdf_attput, idout, vartimid, "realtopology", "linear" 
    230 ncdf_attput, idout, vartimid, "standard_name", "time" 
    231 ncdf_close, idout 
    232 end 
    233 eod 
    234 # 
    235 #--calling IDL 
    236 # 
    237 /opt/idl-6.4/idl/bin/idl << eod 
    238 .r time_interp_over_gaps.pro 
    239 time_interp_over_gaps 
    240 exit 
    241 eod 
    242 # 
    243  
    244 #--adding lat_bnds and lon_bnds variables 
    245 ncks -A -v lat_bnds,lon_bnds ${filename} ${fileintanthro} 
    246  
    247 #--cleaning up 
    248 rm -f ${filetmp} 
    249  
    250 #--end test whether file tmp already exists 
    251 fi 
    252  
    253  
    254  
    255 #--now dealing with the BB input file 
    256  
    257 echo "... "${year}" : Dealing with "${species}" openburning input file..." 
    258  
    259 #--input file BB 
    260 filename=${dirin}IAMC-${prefix}-${scen}-1-1/atmos/mon/${species}_em_openburning/gn/v20180628/${species}-em-openburning_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12.nc 
    261 #--reworked input file 
    262 filetmp=${dirout}${species}-em-openburning_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_tmp.nc 
    263 #--time-interpolated input file 
    264 fileintbb=${dirout}${species}-em-openburning_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_interp.nc 
    265  
    266 if [ -f ${fileintbb} ] 
    267 then 
    268    echo "...Nothing to do!" 
    269 else 
    270  
    271 rm -f ${filetmp} ${fileintbb} 
    272  
    273 #--no need to sum over sectors, as none in BB files 
    274  
    275 #--reformatting input file for IDL to be able to read 
    276 ncks -3 ${filename} ${filetmp} 
    277  
    278 #--IDL code for time interpolation, to fill in 9-year gaps in input file 
    279 rm -f time_interp_over_gaps.pro 
    280 cat << eod >> time_interp_over_gaps.pro 
    281 pro time_interp_over_gaps 
    282  
    283 ; Les dimensions des fichiers 
    284 nlon=720 
    285 nlat=360 
    286 nt=1032 
    287  
    288 une_annee=[31,30,29,31,30,31,30,31,31,30,31,30] 
    289 les_mois = [31,28,31,30,31,30,31,31,30,31,30,31] 
    290  
    291 jours_in = [15, 45, 74, 105, 135, 166, 196, 227, 258, 288, 319, 349, 1840, 1870, $ 
    292     1899, 1930, 1960, 1991, 2021, 2052, 2083, 2113, 2144, 2174, 5490, 5520, $ 
    293     5549, 5580, 5610, 5641, 5671, 5702, 5733, 5763, 5794, 5824, 9140, 9170, $ 
    294     9199, 9230, 9260, 9291, 9321, 9352, 9383, 9413, 9444, 9474, 12790, 12820, $ 
    295     12849, 12880, 12910, 12941, 12971, 13002, 13033, 13063, 13094, 13124, $ 
    296     16440, 16470, 16499, 16530, 16560, 16591, 16621, 16652, 16683, 16713, $ 
    297     16744, 16774, 20090, 20120, 20149, 20180, 20210, 20241, 20271, 20302, $ 
    298     20333, 20363, 20394, 20424, 23740, 23770, 23799, 23830, 23860, 23891, $ 
    299     23921, 23952, 23983, 24013, 24044, 24074, 27390, 27420, 27449, 27480, $  
    300     27510, 27541, 27571, 27602, 27633, 27663, 27694, 27724, 31040, 31070, $  
    301     31099, 31130, 31160, 31191, 31221, 31252, 31283, 31313, 31344, 31374] 
    302  
    303 jours_out=make_array(1032) 
    304 jours_out(0) = 15 
    305 for cpt=1,1031 do jours_out(cpt) = jours_out(cpt-1) + une_annee(cpt mod 12) 
    306  
    307 idin = ncdf_open('${filetmp}') 
    308 varid = ncdf_varid(idin,'${species}_em_openburning')      ; Here, small caps 
    309 lonid = ncdf_varid(idin,'lon') 
    310 latid = ncdf_varid(idin,'lat') 
    311 ;lonbndid = ncdf_varid(idin,'lon_bnds') 
    312 ;latbndid = ncdf_varid(idin,'lat_bnds') 
    313 timbndid = ncdf_varid(idin,'time_bnds') 
    314 ncdf_varget, idin, varid, emiss_init 
    315 ncdf_attget, idin, varid, "units", emiss_unit 
    316 ncdf_attget, idin, varid, "long_name", emiss_longname 
    317 ncdf_varget, idin, lonid, lon 
    318 ncdf_varget, idin, latid, lat 
    319 ;ncdf_varget, idin, lonbndid, lonbnds 
    320 ;ncdf_varget, idin, latbndid, latbnds 
    321 ncdf_varget, idin, timbndid, timbnds_in 
    322 ncdf_close, idin 
    323  
    324 timbnds_out = make_array(2,1032) 
    325 timbnds_out(*,0) = [0,31] 
    326 timbnds_out(*,1) = [31,59] 
    327 for cpt=2,1031 do timbnds_out(0,cpt) = timbnds_out(0,cpt-1) + une_annee((cpt-1) mod 12) 
    328 for cpt=1,1030 do timbnds_out(1,cpt) = timbnds_out(0,cpt+1) 
    329 timbnds_out(1,1031) = 31390 
    330  
    331 emiss_interpol=make_array(nlon,nlat,1032,value=0.) 
    332  
    333 indices_out_mois = make_array(86,12,value=0) 
    334 for m=0,11 do begin 
    335    for n=0,85 do indices_out_mois(n,m) = 12*n + m 
    336 endfor 
    337  
    338 jours_out_mois = make_array(86,12,value=0) 
    339 for n=0,85 do begin 
    340    for m=0,11 do jours_out_mois(n,m) = jours_out(indices_out_mois(n,m)) 
    341 endfor 
    342  
    343 jours_in_mois = make_array(n_elements(jours_in)/12,12,value=0) 
    344 for m=0,11 do begin 
    345    for n=0,n_elements(jours_in)/12-1 do jours_in_mois(n,m) = jours_in(n*12 + m) 
    346 endfor 
    347  
    348 indices_in_mois = make_array(n_elements(jours_in)/12,12,value=0) 
    349 for m=0,11 do begin 
    350    for n=0,n_elements(jours_in)/12-1 do indices_in_mois(n,m) = where(jours_in eq jours_in_mois(n,m)) 
    351 endfor 
    352  
    353 ; Interpolation mois par mois... 
    354 for i=0,nlon-1 do begin 
    355    for j=0,nlat-1 do begin 
    356       for m=0,11 do begin 
    357          emiss_interpol(i,j,indices_out_mois(*,m)) = interpol(emiss_init(i,j,indices_in_mois(*,m)),jours_in_mois(*,m),jours_out_mois(*,m)) 
    358       endfor 
    359    endfor 
    360 endfor 
    361  
    362 idout = ncdf_create('${fileintbb}', /clobber) 
    363 dimlonid = ncdf_dimdef(idout,'lon',nlon) 
    364 dimlatid = ncdf_dimdef(idout,'lat',nlat) 
    365 dimtimid = ncdf_dimdef(idout,'time',1032) 
    366 dimbndid = ncdf_dimdef(idout,'bound',2) 
    367 varlonid = ncdf_vardef(idout, 'lon', [dimlonid], /double) 
    368 varlatid = ncdf_vardef(idout, 'lat', [dimlatid], /double) 
    369 vartimid = ncdf_vardef(idout, 'time', [dimtimid], /double) 
    370 ;varlonbndsid = ncdf_vardef(idout, 'lon_bnds', [dimbndid,dimlonid], /double) 
    371 ;varlatbndsid = ncdf_vardef(idout, 'lat_bnds', [dimbndid,dimlatid], /double) 
    372 vartimbndsid = ncdf_vardef(idout, 'time_bnds', [dimbndid,dimtimid], /double) 
    373 varemissid = ncdf_vardef(idout, '${species}_em_openburning', [dimlonid,dimlatid,dimtimid], /float) 
    374 ncdf_control, idout, /endef 
    375 ncdf_varput, idout, varlonid, lon 
    376 ncdf_varput, idout, varlatid, lat 
    377 ;ncdf_varput, idout, varlonbndsid, lonbnds 
    378 ;ncdf_varput, idout, varlatbndsid, latbnds 
    379 ncdf_varput, idout, vartimbndsid, timbnds_out 
    380 ncdf_varput, idout, varemissid, emiss_interpol 
    381 ncdf_varput, idout, vartimid, jours_out 
    382 ncdf_control, idout, /redef 
    383 ncdf_attput, idout, varlonid, "units", "degrees_east" 
    384 ncdf_attput, idout, varlonid, "long_name", "longitude" 
    385 ncdf_attput, idout, varlonid, "axis", "X" 
    386 ncdf_attput, idout, varlonid, "bounds", "lon_bnds" 
    387 ncdf_attput, idout, varlonid, "modulo", 360. 
    388 ncdf_attput, idout, varlonid, "realtopology", "circular" 
    389 ncdf_attput, idout, varlonid, "standard_name", "longitude" 
    390 ncdf_attput, idout, varlonid, "topology", "circular" 
    391 ncdf_attput, idout, varlatid, "units", "degrees_north" 
    392 ncdf_attput, idout, varlatid, "long_name", "latitude" 
    393 ncdf_attput, idout, varlatid, "axis", "Y" 
    394 ncdf_attput, idout, varlatid, "bounds", "lat_bnds" 
    395 ncdf_attput, idout, varlatid, "realtopology", "linear" 
    396 ncdf_attput, idout, varlatid, "standard_name", "latitude" 
    397 ncdf_attput, idout, varemissid, "units", string(emiss_unit) 
    398 ncdf_attput, idout, varemissid, "_FillValue", 1.e+20 
    399 ncdf_attput, idout, varemissid, "cell_methods", "time: mean" 
    400 ncdf_attput, idout, varemissid, "long_name", string(emiss_longname) 
    401 ncdf_attput, idout, varemissid, "missing_value", 1.e+20 
    402 ncdf_attput, idout, vartimid, "units", "days since 2015-01-01 0:0:0" 
    403 ncdf_attput, idout, vartimid, "long_name", "time" 
    404 ncdf_attput, idout, vartimid, "calendar", '365_day' 
    405 ncdf_attput, idout, vartimid, "axis", "T" 
    406 ncdf_attput, idout, vartimid, "bounds", "time_bnds" 
    407 ncdf_attput, idout, vartimid, "realtopology", "linear" 
    408 ncdf_attput, idout, vartimid, "standard_name", "time" 
    409 ncdf_close, idout 
    410 end 
    411 eod 
    412 # 
    413 #--calling IDL 
    414 # 
    415 /opt/idl-6.4/idl/bin/idl << eod 
    416 .r time_interp_over_gaps.pro 
    417 time_interp_over_gaps 
    418 exit 
    419 eod 
    420 # 
    421  
    422 #--adding lat_bnds and lon_bnds variables 
    423 ncks -A -v lat_bnds,lon_bnds ${filename} ${fileintbb} 
    424  
    425 #--cleaning up 
    426 rm -f ${filetmp} 
    427  
    428 #--end test if interpolated file already exists 
    429 fi 
    430  
    431 #--end loop on species 
    432 done 
    433  
    434  
    435  
    436 #--anthro and BB input files fileintanthro and fileintbb are now ready, for the whole period and for the current scenario 
    437 #--new double loop on species and years 
    438  
    439 #--loop on years 
    440 for year in {2015..2100} 
    441 do 
    442  
    443 #--loop on species 
    444 for species in "BC" "NOx" "OC" "SO2" "NH3" 
    445 do 
    446  
    447 if [ ${species} = "BC"  ] ; then speciesinca="bc"  ; fi 
    448 if [ ${species} = "NOx" ] ; then speciesinca="nox" ; fi 
    449 if [ ${species} = "OC"  ] ; then speciesinca="pom" ; fi 
    450 if [ ${species} = "SO2" ] ; then speciesinca="so2" ; fi 
    451 if [ ${species} = "NH3" ] ; then speciesinca="nh3" ; fi 
    452  
    453 #--dealing with anthro 
    454  
    455 #--input file 
    456 fileintanthro=${dirout}${species}-em-anthro_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_interp.nc 
     195#--Dealing with anthro emissions file... 
     196 
     197echo "... "${year}" : Dealing with "${species}" anthro input file..." 
     198 
     199#--input file anthro (fossil fuel emissions) 
     200filename=${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 
     201 
     202#--two temporary files for interpolation 
     203filetmp1=${dirout}tmp1.nc 
     204filetmp2=${dirout}tmp2.nc 
     205 
    457206#--output files 
    458207filenameout1=${dirout}flux_${speciesinca}_${year}.nc 
     
    461210filenameout3=${dirout}flux_vector_${speciesinca}_${year}.nc 
    462211 
    463 echo ${fileintanthro} ${filenameout1} ${filenameout2} ${filenameout3} 
    464 rm -f ${filenameout1} ${filenameout2} ${filenameout3} 
    465  
    466 #--extracting the correct year 
    467 rm -f select_yr.jnl 
    468 cat << eod > select_yr.jnl 
    469 set memory/size=100 
    470 use "${fileintanthro}" 
    471 set region/t=16-jan-${year}:16-dec-${year} 
    472 save/clobber/file="${filenameout1}" ${species}_EM_ANTHRO 
     212echo ${filename} ${filenameout1} ${filenameout2} ${filenameout3} 
     213rm -f ${filetmp1} ${filetmp2} ${filenameout1} ${filenameout2} ${filenameout3} 
     214 
     215#--unfortunately idl not happy with input netcdf files so need to ferretize files 
     216#--I also sum over sectors and I extract the correct years as well 
     217#--first year (start of 5-Y or 10-Y period, for later interpolation) 
     218rm -f rewrite.jnl 
     219cat << eod > rewrite.jnl 
     220use "${filename}" 
     221set region/t=16-jan-${year1}:16-dec-${year1} 
     222save/clobber/file="${filetmp1}" ${speciesUp}_EM_ANTHRO[k=@sum] 
     223eod 
     224#--run ferret script 
     225ferret << eod 
     226go rewrite.jnl 
     227exit 
     228eod 
     229#--second year (end of 5-Y or 10-Y period, for later interpolation) 
     230rm -f rewrite.jnl 
     231cat << eod > rewrite.jnl 
     232use "${filename}" 
     233set region/t=16-jan-${year2}:16-dec-${year2} 
     234save/clobber/file="${filetmp2}" ${speciesUp}_EM_ANTHRO[k=@sum] 
    473235eod 
    474236#--run ferret script 
    475237ferret << eod  
    476 go select_yr.jnl 
     238go rewrite.jnl 
    477239exit 
    478240eod 
    479241 
    480 #--replace undef with 0 
     242#--performing time interpolation 
     243cdo add -mulc,${pond1} -selname,${speciesUp}_EM_ANTHRO ${filetmp1} -mulc,${pond2} -selname,${speciesUp}_EM_ANTHRO ${filetmp2} ${filenameout1} 
     244 
    481245cdo setmisstoc,0.0 ${filenameout1} ${filenameout1b} 
    482246 
     
    624388end 
    625389eod 
     390 
    626391# 
    627392#--calling IDL 
     
    637402# 
    638403 
    639 #--cleaning the mess 
    640 rm -f ferret* 
    641 rm -f regrid.pro 
    642  
    643  
    644 #--now dealing with BB 
    645  
    646 #--input file 
    647 fileintbb=${dirout}${species}-em-openburning_input4MIPs_emissions_ScenarioMIP_IAMC-${prefix}-${scen}-1-1_gn_${year1}01-${year2}12_interp.nc 
     404 
     405#--now dealing with BB sources 
     406echo "... "${year}" : Dealing with "${species}" openburning input file..." 
     407 
     408filename=${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 
     409 
     410if [ ${species} = "BC"  ] ; then speciesinca="bc"  ; fi 
     411if [ ${species} = "NOx" ] ; then speciesinca="nox" ; fi 
     412if [ ${species} = "OC"  ] ; then speciesinca="pom" ; fi 
     413if [ ${species} = "SO2" ] ; then speciesinca="so2" ; fi 
     414if [ ${species} = "NH3" ] ; then speciesinca="nh3" ; fi 
     415 
     416#--two temporary files for interpolation 
     417filetmp1=${dirout}tmp1.nc 
     418filetmp2=${dirout}tmp2.nc 
     419 
    648420#--output files 
    649421filenameout1=${dirout}flux_${speciesinca}bb_${year}.nc 
     
    652424filenameout3=${dirout}flux_vector_${speciesinca}bb_${year}.nc 
    653425 
    654 echo ${fileintbb} ${filenameout1} ${filenameout1b} ${filenameout2} ${filenameout3} 
    655 rm -f ${filenameout1} ${filenameout1b} ${filenameout2} ${filenameout3} 
     426echo ${filename} ${filenameout1} ${filenameout1b} ${filenameout2} ${filenameout3} 
     427rm -f ${filetmp1} ${filetmp2} ${filenameout1} ${filenameout1b} ${filenameout2} ${filenameout3} 
    656428 
    657429#--unfortunately idl not happy with input netcdf files so need to ferretize files 
    658 #--I extract the correct year as well; no need to sum up sectors, as none in BB files 
     430#--I also sum over sectors and I extract the correct years as well 
     431#--first year (start of 5-Y or 10-Y period, for later interpolation) 
    659432rm -f rewrite.jnl 
    660433cat << eod > rewrite.jnl 
    661 set memory/size=100 
    662 use "${fileintbb}" 
    663 set region/t=16-jan-${year}:16-dec-${year} 
    664 save/clobber/file="${filenameout1}" ${species}_EM_OPENBURNING 
     434use "${filename}" 
     435set region/t=16-jan-${year1}:16-dec-${year1} 
     436save/clobber/file="${filetmp1}" ${speciesUp}_EM_OPENBURNING[k=@sum] 
    665437eod 
    666438#--run ferret script 
     
    669441exit 
    670442eod 
    671  
    672 #--replace undef with 0  
     443#--second year (end of 5-Y or 10-Y period, for later interpolation) 
     444rm -f rewrite.jnl 
     445cat << eod > rewrite.jnl 
     446use "${filename}" 
     447set region/t=16-jan-${year2}:16-dec-${year2} 
     448save/clobber/file="${filetmp2}" ${speciesUp}_EM_OPENBURNING[k=@sum] 
     449eod 
     450#--run ferret script 
     451ferret << eod  
     452go rewrite.jnl 
     453exit 
     454eod 
     455 
     456#--performing time interpolation 
     457cdo add -mulc,${pond1} -selname,${speciesUp}_EM_OPENBURNING ${filetmp1} -mulc,${pond2} -selname,${speciesUp}_EM_OPENBURNING ${filetmp2} ${filenameout1} 
     458 
     459#--replace undef with 0 
    673460cdo setmisstoc,0.0 ${filenameout1} ${filenameout1b} 
    674461 
     
    676463#--OC to POM conversion factor 
    677464#--as ferret returns NOX, treat NOx NOX inconsistency in names by converting to upper case 
    678 if [ ${species} != "OC" ] ; then 
     465if [ ${species} != "OC"  ] ; then 
    679466echo cdo remapcon,${gridfile} -chname,`echo ${species}_EM_OPENBURNING | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2} 
    680467cdo remapcon,${gridfile} -chname,`echo ${species}_EM_OPENBURNING | awk '{print toupper($0)}'`,flux ${filenameout1b} ${filenameout2} 
     
    816603end 
    817604eod 
     605 
    818606# 
    819607#--calling IDL 
     
    832620done 
    833621 
     622#--cleaning up 
     623rm -f ferret* 
     624 
    834625#--unfortunately idl use capital letters for variable names so need to change to small letters for now  
    835626rm -f ${dirout}flux_vector_h2s_${year}.nc ${dirout}flux_vector_so4_${year}.nc 
     
    845636rm -f ${dirout}sflx_lmdz_cmip6_${year}.nc 
    846637#--merging all files into a single one 
    847 #--anthro NOx is NO2 so 30/46 scaling factor to change to NO  
    848 #--openburning NOx is NO so no change in unit 
     638#--PNNL NOx is NO2 so 30/46 scaling factor to change to NO  
     639#--VUA NOx is NO so no change in unit 
    849640cdo 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 
    850641 
     
    853644 
    854645#--cleaning up  
    855 #rm -f ${dirout}flux*_${year}.nc 
    856 #--to be uncommented in final version 
     646rm -f ${dirout}flux*_${year}.nc 
     647#--to be uncommented in final script 
    857648 
    858649#--end loop on years 
    859650done 
    860  
    861 rm -f ${fileintanthro} ${fileintbb} 
    862651 
    863652#--end loop on scenarios 
     
    867656rm -f ferret* 
    868657rm -f regrid.pro 
    869 rm -f time_interp_over_gaps.pro sumsectors.jnl select_yr.jnl rewrite.jnl 
     658rm -f rewrite.jnl 
Note: See TracChangeset for help on using the changeset viewer.