-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractandmerge.sh
64 lines (49 loc) · 1.88 KB
/
extractandmerge.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
module load daint-mc
module load CDO
module load NCO
#input arguments
simulation=$1
year=$2
for streamno in 01 03 04 05; do
if [ $streamno -eq 01 ]; then
vars="W_SO,W_SO_ICE,W_I,W_SNOW"
elif [ $streamno -eq 03 ]; then
vars="RAIN_CON,RAIN_GSP,TOT_PREC"
elif [ $streamno -eq 04 ]; then
vars="ALHFL_S,ALHFL_BS,ALHFL_PL,T_2M"
elif [ $streamno -eq 05 ]; then
vars="RUNOFF_S,RUNOFF_G,SNOW_MELT"
else
echo "Stream not valid."
fi
outstream=out$streamno
#set directory
directory=/scratch/snx3000/regenass/cosmo5_validation/$simulation/output/$outstream/$year
cd $directory
# loop outputfiles
for filename in lffd*.nc; do
echo "Extracting soil variables from $filename"
cdo selname,$vars $filename ${filename}_extracted.nc
done
echo "Mergetime"
# split to 4 parts first to avoid opening of too many files.
cdo mergetime lffd${year}01*_extracted.nc lffd${year}02*_extracted.nc lffd${year}03*_extracted.nc ${outstream}_1.nc
cdo mergetime lffd${year}04*_extracted.nc lffd${year}05*_extracted.nc lffd${year}06*_extracted.nc ${outstream}_2.nc
cdo mergetime lffd${year}07*_extracted.nc lffd${year}08*_extracted.nc lffd${year}09*_extracted.nc ${outstream}_3.nc
cdo mergetime lffd${year}10*_extracted.nc lffd${year}11*_extracted.nc lffd${year}12*_extracted.nc ${outstream}_4.nc
cdo mergetime ${outstream}_*.nc ${outstream}s.nc
rm *extracted*
rm ${outstream}_*
if [ $streamno -eq 03 ]; then
# sum up to 6hr values
cdo timselmean,6,1 ${outstream}s.nc tmp1
# reintroduce first timestep
cdo seltimestep,1 ${outstream}s.nc tmp2
cdo mergetime tmp1 tmp2 tmp3
# cut out last (incomplete) timestep
cdo seldate,${year}-01-01T00:00:00,${year}-12-31T18:00:00 tmp3 ${outstream}s_summed.nc
fi
vars=""
echo "DONE Stream ${outstream}."
done