-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmip2pism
executable file
·75 lines (59 loc) · 2.02 KB
/
cmip2pism
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
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
set -evx
tas=$1
pr=$2
orog=$3
tho=$4
sao=$5
target=$6
outfile=$7
faulty=$8
if [ -z "${outfile}" -o -n "${faulty}" ] ; then
echo "WRONG NUMBER OF ARGUMENTS! NEED SEVEN ARGUMENTS"
echo TAS file ${tas}
echo PR file ${pr}
echo OROG file ${orog}
echo THO file ${tho}
echo SAO file ${sao}
echo REMAPPING TARGET ${target}
echo OUTPUT file ${outfile}
if [ -n "${faulty}" ] ; then
echo "Got additional argument ${faulty} (and maybe even more)"
fi
exit 2
fi
tempdir=$(mktemp -d -p . -t cmip2pism.XXXX)
COMMON=' -seltimestep,1/60 '
cdo -P 6 -remapbil,${target} -setname,air_temp -selvar,tas ${COMMON} ${tas} ${tempdir}/tas.nc &
cdo -P 6 -remapbil,${target} -setname,precipitation -setunit,'m s-1' -divc,910 -selvar,pr ${COMMON} ${pr} ${tempdir}/pr.nc &
cdo -remapbil,${target} ${orog} ${tempdir}/orog.nc
cdo -P 6 -setname,theta_ocean -remapnn,${target} -selvar,thetao ${COMMON} ${tho} ${tempdir}/tho.nc &
cdo -P 6 -setname,salinity_ocean -setunit,'g kg-1' -remapnn,${target} -selvar,so ${COMMON} ${sao} ${tempdir}/sao.nc
wait
diffuse ${tempdir}/tho.nc theta_ocean &
diffuse ${tempdir}/sao.nc salinity_ocean &
wait
outfile_atm=${outfile/.nc/_atm.nc}
outfile_oce=${outfile/.nc/_oce.nc}
for outfile in ${outfile_oce} ${outfile_atm} ; do
if [ -f ${outfile} ] ; then
mv ${outfile} ${outfile}.bak
fi
done
cp ${tempdir}/orog.nc ${outfile_atm}
for x in ${tempdir}/tas.nc ${tempdir}/pr.nc ; do
ncks -A $x ${outfile_atm}
done
rm -f temp_merge.nc
cp ${tempdir}/tho.nc ${outfile_oce}
ncks -A ${tempdir}/tho_filled.nc ${outfile_oce}
ncks -A ${tempdir}/sao_filled.nc ${outfile_oce}
#cdo -merge ${tempdir}/tas.nc ${tempdir}/pr.nc ${tempdir}/orog.nc ${outfile_atm}
#cdo -merge ${tempdir}/tho.nc ${tempdir}/sao.nc ${outfile_oce}
ncks -Av x,y ${target} ${outfile_atm}
ncks -Av x,y ${target} ${outfile_oce}
ncpdq -a time,x,y ${outfile_atm} temp_ncpdq.nc
mv temp_ncpdq.nc ${outfile_atm}
ncpdq -a time,x,y ${outfile_oce} temp_ncpdq.nc
mv temp_ncpdq.nc ${outfile_oce}
# rm -r ${tempdir}