source: TOOLS/CMIP6_FORCING/SCENARIOS/interp_time_OXY.sh @ 5920

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

A few scripts to generate oxidant files and SST/SIC files for the scenarios.

  • Property svn:executable set to *
File size: 8.1 KB
Line 
1#--Script performing a linear time interpolation
2#--in order to yield every year between decade-years
3#--for oxidant files.
4#--Th. Lurton, IPSL, 07/2018
5
6dirinOXY=/ccc/work/cont003/gencmip6/lurtont/CMIP6_OXIDANTS/
7diroutOXY=${GENCMIP6_CCCWORKDIR}/CMIP6_OXIDANTS/yearly_interp/
8
9if [ ! -d ${diroutOXY} ] ; then mkdir -p ${diroutOXY} ; fi
10
11#--historical
12hist=$false
13if [ $hist ] ; then
14for year in {1850..1999}  #--note that the whole hist period is not covered
15do
16
17echo "Historical period, interpolation for year "${year}"..."
18
19if [ ${year} -ge 1850 -a ${year} -lt 1860 ]
20then
21year1=1850
22year2=1860
23fi
24if [ ${year} -ge 1860 -a ${year} -lt 1870 ]
25then
26year1=1860
27year2=1870
28fi
29if [ ${year} -ge 1870 -a ${year} -lt 1880 ]
30then
31year1=1870
32year2=1880
33fi
34if [ ${year} -ge 1880 -a ${year} -lt 1890 ]
35then
36year1=1880
37year2=1890
38fi
39if [ ${year} -ge 1890 -a ${year} -lt 1900 ]
40then
41year1=1890
42year2=1900
43fi
44if [ ${year} -ge 1900 -a ${year} -lt 1910 ]
45then
46year1=1900
47year2=1910
48fi
49if [ ${year} -ge 1910 -a ${year} -lt 1920 ]
50then
51year1=1910
52year2=1920
53fi
54if [ ${year} -ge 1920 -a ${year} -lt 1930 ]
55then
56year1=1920
57year2=1930
58fi
59if [ ${year} -ge 1930 -a ${year} -lt 1940 ]
60then
61year1=1930
62year2=1940
63fi
64if [ ${year} -ge 1940 -a ${year} -lt 1950 ]
65then
66year1=1940
67year2=1950
68fi
69if [ ${year} -ge 1950 -a ${year} -lt 1960 ]
70then
71year1=1950
72year2=1960
73fi
74if [ ${year} -ge 1960 -a ${year} -lt 1970 ]
75then
76year1=1960
77year2=1970
78fi
79if [ ${year} -ge 1970 -a ${year} -lt 1980 ]
80then
81year1=1970
82year2=1980
83fi
84if [ ${year} -ge 1980 -a ${year} -lt 1990 ]
85then
86year1=1980
87year2=1990
88fi
89if [ ${year} -ge 1990 -a ${year} -lt 2000 ]
90then
91year1=1990
92year2=2000
93fi
94
95file1=${dirinOXY}LOI_AR6_${year1}.nc
96file2=${dirinOXY}LOI_AR6_${year2}.nc
97filetmp=${diroutOXY}tmp.nc
98fileout=${diroutOXY}LOI_AR6_${year}.nc
99
100#--using separate file with time_counter and time_bnds
101#--to yield correct time_counter and time_bnds
102echo "... Creating time pattern for year "${year}", scenario "${scen}"..."
103filetimes=${diroutOXY}times_${year}.nc
104cdo addc,$(((${year}-1850)*365*24*3600)) -selname,time_counter,time_bnds ${dirinOXY}LOI_AR6_1850.nc ${filetmp}
105#--something weird happens, as time_counter is declared not found, and is not shifted as should be (time_bnds is). I am here forcing the shift by hand.
106cdo shifttime,$(((${year}-1850)*365))days ${filetmp} ${filetimes}
107ncrename -d x,bnds ${filetimes}
108
109if [ ${year:3:1} == 1 ]
110then
111cdo add -mulc,0.9 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.1 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
112fi
113if [ ${year:3:1} == 2 ]
114then
115cdo add -mulc,0.8 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.2 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
116fi
117if [ ${year:3:1} == 3 ]
118then
119cdo add -mulc,0.7 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.3 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
120fi
121if [ ${year:3:1} == 4 ]
122then
123cdo add -mulc,0.6 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.4 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
124fi
125if [ ${year:3:1} == 5 ]
126then
127cdo add -mulc,0.5 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.5 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
128fi
129if [ ${year:3:1} == 6 ]
130then
131cdo add -mulc,0.4 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.6 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
132fi
133if [ ${year:3:1} == 7 ]
134then
135cdo add -mulc,0.3 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.7 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
136fi
137if [ ${year:3:1} == 8 ]
138then
139cdo add -mulc,0.2 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.8 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
140fi
141if [ ${year:3:1} == 9 ]
142then
143cdo add -mulc,0.1 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.9 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
144fi
145#--nothing to be done if we are on a decade-year.
146if [ ${year:3:1} == 0 ]
147then
148ncks -v H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
149fi
150
151#--fixing presnivs, presnivs_bnds, time_counter and time_bnds
152echo "... Fixing presnivs, presnivs_bnds, time_counter and time_bnds for year "${year}", scenario "${scen}"..."
153ncks -A -v time_counter,time_bnds ${filetimes} ${filetmp}
154ncks -A -v presnivs,presnivs_bnds ${dirinOXY}LOI_AR6_1850.nc ${filetmp}
155cp ${filetmp} ${fileout}
156rm -f ${filetmp}
157
158#--end loop on historical years
159done
160
161#--skip historical
162fi 
163
164#--Scenarios
165
166for scen in "RCP26" "RCP45" "RCP60" "RCP85sstA2"
167do
168
169for year in {2000..2100}
170do
171
172echo "Scenario "${scen}", interpolation for year "${year}"..."
173
174if [ ${year} -ge 2000 -a ${year} -lt 2010 ]
175then
176year1=2000
177year2=2010
178fi
179if [ ${year} -ge 2010 -a ${year} -lt 2020 ]
180then
181year1=2010
182year2=2020
183fi
184if [ ${year} -ge 2020 -a ${year} -lt 2030 ]
185then
186year1=2020
187year2=2030
188fi
189if [ ${year} -ge 2030 -a ${year} -lt 2040 ]
190then
191year1=2030
192year2=2040
193fi
194if [ ${year} -ge 2040 -a ${year} -lt 2050 ]
195then
196year1=2040
197year2=2050
198fi
199if [ ${year} -ge 2050 -a ${year} -lt 2060 ]
200then
201year1=2050
202year2=2060
203fi
204if [ ${year} -ge 2060 -a ${year} -lt 2070 ]
205then
206year1=2060
207year2=2070
208fi
209if [ ${year} -ge 2070 -a ${year} -lt 2080 ]
210then
211year1=2070
212year2=2080
213fi
214if [ ${year} -ge 2080 -a ${year} -lt 2090 ]
215then
216year1=2080
217year2=2090
218fi
219if [ ${year} -ge 2090 -a ${year} -lt 2100 ]
220then
221year1=2090
222year2=2100
223fi
224if [ ${year} == 2100 ]
225then
226year1=2100
227year2=2100
228fi
229
230file1=${dirinOXY}LOI_AR6_${scen}_${year1}.nc
231file2=${dirinOXY}LOI_AR6_${scen}_${year2}.nc
232filetmp=${diroutOXY}tmp.nc
233fileout=${diroutOXY}LOI_AR6_${scen}_${year}.nc
234
235#--specific case for junction with historical -- year2=2010 is correct, but year1=2000 does not exist for scenarios. Let's override that...
236if [ ${year} -lt 2010 ]
237then
238file1=${dirinOXY}LOI_AR6_2000.nc
239fi
240
241rm -f ${diroutOXY}tmp.nc
242
243#--using separate file with time_counter and time_bnds
244#--to yield correct time_counter and time_bnds
245echo "... Creating time pattern for year "${year}", scenario "${scen}"..."
246filetimes=${diroutOXY}times_${year}.nc
247cdo addc,$(((${year}-2000)*365*24*3600)) -selname,time_counter,time_bnds ${dirinOXY}LOI_AR6_2000.nc ${filetmp}
248#--something weird happens, as time_counter is declared not found, and is not shifted as should be (time_bnds is). I am here forcing the shift by hand.
249cdo shifttime,$(((${year}-2000)*365))days ${filetmp} ${filetimes}
250ncrename -d x,bnds ${filetimes}
251
252rm -f ${filetmp}
253
254if [ ${year:3:1} == 1 ]
255then
256cdo add -mulc,0.9 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.1 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
257fi
258if [ ${year:3:1} == 2 ]
259then
260cdo add -mulc,0.8 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.2 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
261fi
262if [ ${year:3:1} == 3 ]
263then
264cdo add -mulc,0.7 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.3 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
265fi
266if [ ${year:3:1} == 4 ]
267then
268cdo add -mulc,0.6 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.4 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
269fi
270if [ ${year:3:1} == 5 ]
271then
272cdo add -mulc,0.5 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.5 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
273fi
274if [ ${year:3:1} == 6 ]
275then
276cdo add -mulc,0.4 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.6 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
277fi
278if [ ${year:3:1} == 7 ]
279then
280cdo add -mulc,0.3 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.7 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
281fi
282if [ ${year:3:1} == 8 ]
283then
284cdo add -mulc,0.2 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.8 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
285fi
286if [ ${year:3:1} == 9 ]
287then
288cdo add -mulc,0.1 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file1} -mulc,0.9 -selname,H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
289fi
290if [ ${year:3:1} == 0 ]
291then
292ncks -v H2O2,HNO3,NO2,NO3,O1D,O3,OH ${file2} ${filetmp}
293fi
294
295#--fixing presnivs, presnivs_bnds, time_counter and time_bnds
296echo "... Fixing presnivs, presnivs_bnds, time_counter and time_bnds for year "${year}", scenario "${scen}"..."
297ncks -A -v time_counter,time_bnds ${filetimes} ${filetmp}
298ncks -A -v presnivs,presnivs_bnds ${dirinOXY}LOI_AR6_RCP26_2010.nc ${filetmp}
299cp ${filetmp} ${fileout}
300rm -f ${filetmp}
301
302#--end loop on years
303done
304
305rm -f ${diroutOXY}times*.nc
306
307#--end loop on scenario names
308done
Note: See TracBrowser for help on using the repository browser.