-
Notifications
You must be signed in to change notification settings - Fork 29
/
module_wrf_ens.sh
executable file
·197 lines (171 loc) · 5.57 KB
/
module_wrf_ens.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
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
#!/bin/bash
. $CONFIG_FILE
rundir=$WORK_DIR/run/$DATE/wrf_ens
if [[ ! -d $rundir ]]; then mkdir -p $rundir; echo waiting > $rundir/stat; fi
cd $rundir
if [[ `cat stat` == "complete" ]]; then exit; fi
#Check dependency
wait_for_module ../icbc
if [ $DATE == $DATE_START ]; then wait_for_module ../perturb_ic; fi
if [ $DATE -gt $DATE_START ]; then wait_for_module ../enkf; fi
echo running > stat
export start_date=$DATE
export run_minutes=$run_minutes_cycle
if $RUN_4DVAR; then
export inputout_interval=`abs $OBS_WIN_MIN`
export inputout_begin=`echo "$run_minutes + $OBS_WIN_MIN" |bc`
export inputout_end=$run_minutes
export wrfout_interval=`gcd $inputout_begin $inputout_end`
else
export inputout_interval=$run_minutes
export inputout_begin=0
export inputout_end=$run_minutes
fi
#1 Perturb BCs with random_samples
echo " Perturbing ensemble BCs..."
dd=`diff_time $DATE_START $LBDATE`
n_1=$((dd/$LBC_INTERVAL+1))
tid=0
nt=$total_ntasks
for NE in `seq 1 $NUM_ENS`; do
id=`expr $NE + 1000 |cut -c2-`
if [[ ! -d $id ]]; then mkdir $id; fi
touch $id/update_wrf_bc.log
if [[ `tail -n5 $id/update_wrf_bc.log |grep successfully` ]]; then continue; fi
cd $id
cat > parame.in << EOF
&control_param
wrf_3dvar_output_file = 'wrfinput_d01_update'
wrf_bdy_file = 'wrfbdy_d01_update'
wrf_bdy_file_real = 'wrfbdy_d01_real'
wrf_input_from_si = 'wrfinput_d01_real'
wrf_input_from_si_randmean = 'random_mean'
wrf_3dvar_random_draw = 'random_draw'
cycling = .true.
debug = .true.
low_bdy_only = .false.
perturb_bdy = .true.
n_1 = $n_1
/
EOF
ln -fs $WRF_BC_DIR/update_wrf_bc.exe .
if [ $DATE == $DATE_START ]; then
ln -fs ../../../../fc/wrfbdy_d01 wrfbdy_d01_real
else
ln -fs ../../../../fc/wrfbdy_d01_$id wrfbdy_d01_real
fi
cp -L wrfbdy_d01_real wrfbdy_d01_update
ln -fs ../../../../rc/$LBDATE/wrfinput_d01 wrfinput_d01_real
rm -f wrfinput_d01_update
ln -fs ../../../../fc/$DATE/wrfinput_d01_$id wrfinput_d01_update
ln -fs ../../../../fc/$DATE_START/wrfinput_d01_`expr $((RANDOM%($NUM_ENS-1)+1)) + 1000 |cut -c2-` random_draw
ln -fs ../../../../rc/$DATE_START/wrfinput_d01 random_mean
$SCRIPT_DIR/job_submit.sh 1 $tid $HOSTPPN ./update_wrf_bc.exe >& update_wrf_bc.log &
# ./update_wrf_bc.exe >& update_wrf_bc.log
tid=$((tid+1))
if [[ $tid == $nt ]]; then
tid=0
wait
fi
cd ..
done
wait
for NE in `seq 1 $NUM_ENS`; do
id=`expr $NE + 1000 |cut -c2-`
watch_log $id/update_wrf_bc.log successfully 1 $rundir
mv $id/wrfbdy_d01_update $WORK_DIR/fc/wrfbdy_d01_$id
done
#Run wrf forecast for each member
echo " Running WRF ensemble forecast..."
tid=0
nt=$((total_ntasks/$wrf_ntasks))
for r in 1 3; do
export time_step_ratio=$r
for NE in `seq 1 $NUM_ENS`; do
id=`expr $NE + 1000 |cut -c2-`
if [[ ! -d $id ]]; then mkdir $id; fi
touch $id/rsl.error.0000
if [[ `tail -n5 $id/rsl.error.0000 |grep SUCCESS` ]]; then continue; fi
cd $id
ln -fs $WRF_DIR/run/* .
rm -f namelist.*
for n in `seq 1 $MAX_DOM`; do
dm=d`expr $n + 100 |cut -c2-`
ln -fs ../../../../fc/$DATE/wrfinput_${dm}_$id wrfinput_$dm
done
ln -fs ../../../../fc/wrfbdy_d01_$id wrfbdy_d01
# ln -fs ../../../../rc/$DATE_START/wrfbdy_d01 wrfbdy_d01
if [ $DATE -gt $DATE_START ]; then
$SCRIPT_DIR/multi_physics_set.sh $id >& multi_physics_set.log
fi
if [[ $SST_UPDATE == 1 ]]; then
ln -fs ../../../../rc/$DATE_START/wrflowinp_d?? .
fi
if $FOLLOW_STORM; then
cp $WORK_DIR/rc/$DATE/ij_parent_start .
cp $WORK_DIR/rc/$DATE/domain_moves .
fi
$SCRIPT_DIR/namelist_wrf.sh wrf > namelist.input
$SCRIPT_DIR/job_submit.sh $wrf_ntasks $((tid*$wrf_ntasks)) $HOSTPPN ./wrf.exe >& wrf.log &
tid=$((tid+1))
if [[ $tid == $nt ]]; then
tid=0
wait
fi
cd ..
done
wait
done
#Check outputs
for NE in `seq 1 $NUM_ENS`; do
id=`expr $NE + 1000 |cut -c2-`
watch_log $id/rsl.error.0000 SUCCESS 1 $rundir
if $RUN_4DVAR; then
e_offset="$OBS_WIN_MIN 0"
else
e_offset="0"
fi
for i in $e_offset; do
outdate=`advance_time $NEXTDATE $i`
outfile=$id/wrfinput_d01_`wrf_time_string $outdate`
mv $outfile $WORK_DIR/fc/$DATE/wrfinput_d01_`wrf_time_string $outdate`_$id
if [ $MAX_DOM -gt 1 ]; then
for n in `seq 1 $MAX_DOM`; do
dm=d`expr $n + 100 |cut -c2-`
outfile=$id/wrfout_${dm}_`wrf_time_string $outdate`
mv $outfile $WORK_DIR/fc/$DATE/wrfinput_${dm}_`wrf_time_string $outdate`_$id
done
fi
done
done
#Calculate ensemble mean for 4DVar fg (next cycle)
if $RUN_4DVAR; then
echo " Calculating ensemble mean..."
cd $rundir
for i in $OBS_WIN_MIN; do
outdate=`advance_time $NEXTDATE $i`
for n in `seq 1 $MAX_DOM`; do
dm=d`expr $n + 100 |cut -c2-`
if [[ ! -d mean_${dm}_$outdate ]]; then mkdir -p mean_${dm}_$outdate; fi
cd mean_${dm}_$outdate
for NE in `seq 1 $NUM_ENS`; do
id=`expr $NE + 1000 |cut -c2-`
ln -fs ../../../../fc/$DATE/wrfinput_${dm}_`wrf_time_string $outdate`_$id fort.`expr 80010 + $NE`
done
cp -L fort.80011 fort.`expr 80011 + $NUM_ENS`
$SCRIPT_DIR/namelist_enkf.sh $n > namelist.enkf
ln -fs $ENKF_DIR/ensemble_mean.exe .
$SCRIPT_DIR/job_submit.sh $enkf_ntasks 0 $enkf_ppn ./ensemble_mean.exe >& ensemble_mean.log
watch_log ensemble_mean.log Successful 1 $rundir
mv fort.`expr 80011 + $NUM_ENS` $WORK_DIR/fc/$DATE/wrfinput_${dm}_`wrf_time_string $outdate`_mean
cd ..
done
done
fi
if $CLEAN; then
for NE in `seq 1 $NUM_ENS`; do
id=`expr $NE + 1000 |cut -c2-`
rm -f $rundir/$id/wrfout*
done
fi
echo complete > stat