-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtlauto_run.bash
executable file
·235 lines (191 loc) · 6.88 KB
/
tlauto_run.bash
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
# Script by Tyge Løvset, NORCE Reginal Climate, 2024
if [ -z "$2" ]; then
echo "Usage: $0 <year-imonth-iday> <run_months> [download]"
echo " e.g.: $0 1991-02-10 6"
echo ""
exit
fi
run_months=$2
dry_run=0
year=$(date "+%Y" -d "$1")
imon=$(date "+%m" -d "$1")
iday=$(date "+%d" -d "$1")
year2=$(date "+%Y" -d "$year-$imon-01 +$run_months months -1 day")
imon2=$(date "+%m" -d "$year-$imon-01 +$run_months months -1 day")
iday2=$(date "+%d" -d "$year-$imon-01 +$run_months months -1 day")
echo $year, $imon, $iday
echo $year2, $imon2, $iday2
######################################################
## Setting variables and prepare runtime environment:
##----------------------------------------------------
## Recommended safety settings:
set -o errexit # Make bash exit on any error
#set -o nounset # Treat unset variables as errors
########################################################################
# set directory to copy important scripts and files and creat working
#########################################################################
#startdir="/cluster/projects/nn9853k/tylo/start"
startdir=$(cd $(dirname $0) ; pwd)
#start=021000 # month, date, hour
start=${imon}${iday}00
#outdir="/nird/projects/NS9853K/users/tylo/CFSv2_downscaled_wrfout/MAM-WRFOUT"
outdir="/datalake/NS9853K/CFSv2_downscaled_wrfout/MAM-WRFOUT"
rundir="/cluster/work/users/${USER}/MAM_CFSv2_downscaling/MAM_${year}${start}"
#rundir="/cluster/projects/nn9853k/${USER}/MAM_CFSv2_downscaling/MAM_${year}${start}"
echo --------------------------------------------------------------------------------------------------
echo YEAR: $year.$start
echo RUNDIR: $rundir
# Predownload all years...
if [ "$3" == "download" ]; then
for (( ; year <= 2023; year++ )); do
hindcast=/cluster/projects/nn9853k/WRF_Hindcast_input/CFS2V_Reforecast_MAM/$year/${year}${start}
echo "Hindcast: $hindcast"
mkdir -p $hindcast
pushd $hindcast
cp $startdir/cfs2v_reforecast_download.bash .
echo "bash cfs2v_reforecast_download.bash $year-$imon-$iday $run_months" | tee download.bash
bash download.bash >& my_download.log
popd
done # all years
exit # stop after download all
else
# Only download given input year - if needed
hindcast=/cluster/projects/nn9853k/WRF_Hindcast_input/CFS2V_Reforecast_MAM/$year/${year}${start}
echo "Hindcast: $hindcast"
mkdir -p $hindcast
pushd $hindcast
cp $startdir/cfs2v_reforecast_download.bash .
echo "bash cfs2v_reforecast_download.bash $year-$imon-$iday $run_months" | tee download.bash
bash download.bash >& my_download.log
popd
fi
# Enter rundir:
if [ -d $rundir ]; then
echo "Rundir already exists, canceling..."
echo " $rundir"
exit
fi
echo Rundir: $rundir
mkdir -p $rundir
cd $rundir
cp $startdir/tlauto_run.bash .
cp $startdir/sbatch_wrapper.sh .
rm -rf ANALYSIS
mkdir ANALYSIS
echo "CFS: link grb2 files..."
rm -rf CFS
mkdir CFS
pushd CFS
ln -s $hindcast/*01.${year}${start}.grb2* .
popd
###############################################
# Loading Software modules
###############################################
# Allways be explicit on loading modules and setting run time environment!!!
# Type "module avail MySoftware" to find available modules and versions
# It is also recommended to to list loaded modules, for easier debugging:
#module list
#module purge
#module load WPS/4.4-foss-2022a-dmpar
#module load WRF/4.4-foss-2022a-dmpar
#module list
echo "WPS: copy script files..."
#rm -rf WPS
mkdir WPS
pushd WPS
cp $startdir/WPS/linkWPS.csh .
cp $startdir/WPS/namelist.wps .
#cp $startdir/WPS/run_geogrid.sh .
#cp $startdir/WPS/run_ungrib.sh .
cp $startdir/WPS/run_wps.sh .
cp $startdir/WPS/run_metgrid.sh .
cp -r $startdir/WPS/ungrib/Variable_Tables .
sed -i -e "s|@YYYY2|$year2|g" -e "s|@MM2|$imon2|g" -e "s|@DD2|$iday2|g" \
-e "s|@YYYY|$year|g" -e "s|@MM|$imon|g" -e "s|@DD|$iday|g" namelist.wps
sed -i -e "s|@YYYY|$year|g" -e "s|@DD|$iday|g" run_wps.sh
sed -i -e "s|@YYYY|$year|g" -e "s|@DD|$iday|g" run_metgrid.sh
echo "Link WPS files."
./linkWPS.csh
###############################################
# Run WPS geogrid, ungrib and avg_tsfc
###############################################
echo "Run all WPS: geogrid.exe, ungrib.exe and avg_tsfc.exe"
if [ "$dry_run" != "1" ]; then
wps_job=$(../sbatch_wrapper.sh run_wps.sh)
fi
echo "wps_job: $wps_job"
## sed -i "48s|SFLX|SST|" namelist.wps
## ./link_grib.csh $sstdir/oiss*grb
## ln -sf ./ungrib/Variable_Tables/Vtable.SST Vtable
## mpirun ./ungrib.exe >& my_ungrib3.log
##
## echo "interpolate SFC temperature over lake"
## ./util/avg_tsfc.exe >& my_avg_tsfc.log
###############################################
# running metgrid
###############################################
echo "Run metgrid.exe"
if [ "$dry_run" != "1" ]; then
metg_job=$(../sbatch_wrapper.sh --dependency=afterok:$wps_job run_metgrid.sh)
fi
echo "metg_job: $metg_job"
popd # WPS
#exit
###############################################
# preparing to run WRF
###############################################
#rm -rf WRFRUN
mkdir -p WRFRUN
pushd WRFRUN
cp $startdir/WRF/linkWRF.csh .
cp $startdir/WRF/run_real.sh .
cp $startdir/WRF/run_wrf.sh .
cp $startdir/WRF/tkb_hydro_d0?.txt .
cp $startdir/WRF/namelist.input .
cp $startdir/WRF/copy_output.sh .
cp $startdir/WRF/clean_data.sh .
target=$outdir/$(basename $rundir) # on NIRD via ssh
sed -i -e "s|@YYYY2|$year2|g" -e "s|@MM2|$imon2|g" -e "s|@DD2|$iday2|g" \
-e "s|@YYYY|$year|g" -e "s|@MM|$imon|g" -e "s|@DD|$iday|g" namelist.input
sed -i -e "s|@YYYY|$year|g" -e "s|@DD|$iday|g" run_real.sh
sed -i -e "s|@YYYY|$year|g" -e "s|@DD|$iday|g" run_wrf.sh
sed -i -e "s|@YYYY|$year|g" -e "s|@DD|$iday|g" \
-e "s|@TARGET|$target|g" copy_output.sh
echo "Link WRF program files."
./linkWRF.csh
###############################################
# run real.exe
###############################################
echo "Run real.exe"
if [ "$dry_run" != "1" ]; then
real_job=$(../sbatch_wrapper.sh --dependency=afterok:$metg_job run_real.sh)
fi
echo "real_job: $real_job"
###############################################
# run wrf.exe
###############################################
echo "Run wrf.exe"
if [ "$dry_run" != "1" ]; then
wrf_job=$(../sbatch_wrapper.sh --dependency=afterok:$real_job run_wrf.sh)
fi
echo "wrf_job: $wrf_job"
###############################################
# copy wrf.exe output
###############################################
#echo "Wait for copy of output until WRF is successfully done"
#while [ 1 == 1 ]; do
# sleep 30
# if [ -f "wrfhydro_hourly_d01_${year}-${imon2}-${iday2}_00:00:00" ] &&
# [ -f "wrfhydro_hourly_d02_${year}-${imon2}-${iday2}_00:00:00" ]; then
# break
# fi
#done
#sleep 720
#echo "copying..."
#if [ "$dry_run" != "1" ]; then
# bash ./copy_output.sh
#fi
popd # WRFRUN
echo "SUCCESS!"
exit 0