-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_SST_forcing.sh
executable file
·163 lines (121 loc) · 4.14 KB
/
generate_SST_forcing.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#! /bin/bash
if [ "$0" = "$BASH_SOURCE" ]; then
echo "script is meant to be sourced by create_SST_forcing_*.sh"
exit 1
fi
########################################################
######### Create SST and Sea Ice forcing files #########
########################################################
# AFTER
# http://www.cesm.ucar.edu/models/cesm1.2/cesm/doc/usersguide/x2306.html
# and the script from Jan Sedlacek
# ----------------------------------------------------------------------
# we need ncl
module load ncl
root_ocn=${root}ocn/hist/
root_ice=${root}ice/hist/
file_root_ocn=${casename}.pop.h.
file_root_ice=${casename}.cice.h.
year=$first; monthi=01
# create weight for interpolation (is faster)
if [ ! -f weight_ocn.nc ]; then
file_ocn=${file_root_ocn}${year}-${monthi}.nc
ifile=${root_ocn}${file_ocn}
cdo genbil,griddes_1x1.txt -selvar,TEMP ${ifile} weight_ocn.nc
fi
# ice can not be bilinearly interpolated
if [ ! -f weight_ice.nc ]; then
file_ice=${file_root_ice}${year}-${monthi}.nc
ifile=${root_ice}${file_ice}
cdo gencon,griddes_1x1.txt ${ifile} weight_ice.nc
fi
for year in $(seq $first $last)
do
for month in {1..12}
do
monthi=`printf "%02d" $month`
echo =======
echo ${monthi}.${year}
echo =======
# =====================================================================
# PREPARE OCEAN
# =====================================================================
file_ocn=${file_root_ocn}${year}-${monthi}.nc
ifile=${root_ocn}${file_ocn}
ofile=${dest}reggrid_${file_ocn}
if [ ! -f ${ofile} ]; then
# if file does not exist try to unzip ocean file
if [ ! -f ${ifile} ]; then
echo unzipping ocean file
zcat $ifile > ${dest}${file_ocn}
ifile=${dest}${file_ocn}
fi
cdo remap,griddes_1x1.txt,weight_ocn.nc `# regrid to 1x1 deg`\
-chname,TEMP,SST_cpl `# rename`\
-sellevel,500 `# sel topmost level`\
-selname,TEMP `# we need TEMP`\
${ifile} ${ofile}
fi
# remove unzipped ocean file
if [ -f ${dest}${file_ocn} ]; then
rm -f ${dest}${file_ocn}
fi
ifile=${ofile}
ofile=${dest}gridfill_${file_ocn}
if [ ! -f ${ofile} ]; then
# fill the continents
s1=ifile=\"${ifile}\"
s2=ofile=\"${ofile}\"
s3=varname=\"SST_cpl\"
# rm ${ofile}
ncl $s1 $s2 $s3 grid_fill.ncl >&/dev/null
fi
# =====================================================================
# PREPARE SEA ICE
# =====================================================================
file_ice=${file_root_ice}${year}-${monthi}.nc
ifile=${root_ice}${file_ice}
ofile=${dest}reggrid_${file_ice}
if [ ! -f ${ofile} ]; then
cdo remap,griddes_1x1.txt,weight_ice.nc `# regrid to 1x1 deg`\
-chname,aice,ice_cov `# rename`\
-divc,100 `# convert from percent to fraction`\
-selname,aice `# we need aice`\
${ifile} ${ofile}
fi
ifile=${ofile}
ofile=${dest}gridfill_${file_ice}
# fill the continents
if [ ! -f ${ofile} ]; then
s1=ifile=\"${ifile}\"
s2=ofile=\"${ofile}\"
s3=varname=\"ice_cov\"
ncl $s1 $s2 $s3 grid_fill.ncl >&/dev/null
fi
done
done
year=????
monthi=??
# =====================================================================
# Concatenate OCEAN
# =====================================================================
rm ${dest}SST_cpl.nc
file_ocn=${file_root_ocn}${year}-${monthi}.nc
ifiles=${dest}gridfill_${file_ocn}
cdo cat ${ifiles} ${dest}SST_cpl.nc
# =====================================================================
# Concatenate Sea Ice
# =====================================================================
rm ${dest}ice_cov.nc
file_ice=${file_root_ice}${year}-${monthi}.nc
ifiles=${dest}gridfill_${file_ice}
cdo cat ${ifiles} ${dest}ice_cov.nc
# =====================================================================
# Merge Ocean and Sea Ice
# =====================================================================
rm ${dest}SST_ICE_${casename}.nc
cdo merge ${dest}SST_cpl.nc ${dest}ice_cov.nc ${dest}SST_ICE_${casename}.nc
# =====================================================================
# Change Time
# =====================================================================
python change_time.py ${dest}SST_ICE_${casename}.nc