-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget_files.sh
executable file
·211 lines (175 loc) · 4.73 KB
/
get_files.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
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
function usage {
echo " "
echo " USAGE: $0 [options] [VARDEFNS]"
echo " "
echo " PURPOSE: Stage raw initial and lateral boundary conditions by calling wrapper scripts in <regional_workflow/ush/wrappers/>."
echo " "
echo " VARDEFNS - var_defns.sh file generated by FV3LAM regional workflow"
echo " default: \"../var_defns.sh\""
echo " "
echo " OPTIONS:"
echo " -h Display this message"
echo " -n Show command to be run only"
echo " -v Verbose mode"
echo " -m odin Machine (odin, stampede or macos)"
echo " default, determine automatically based on hostname."
echo " "
echo " -- By Y. Wang (2020.10.21)"
echo " "
exit $1
}
#-----------------------------------------------------------------------
#
# Default values
#
#-----------------------------------------------------------------------
show=0
verb=0
VARDEFNS="../var_defns.sh"
host_name=$(hostname)
if [[ $host_name =~ "stampede2" ]]; then
machine="stampede"
elif [[ $host_name =~ "odin" ]]; then
machine="odin"
elif [[ $host_name =~ "4373-Wang-mbp" ]]; then
machine="macos"
else
machine="UNKOWN"
fi
#-----------------------------------------------------------------------
#
# Handle command line arguments
#
#-----------------------------------------------------------------------
while [[ $# > 0 ]]
do
key="$1"
case $key in
-h)
usage 0
;;
-n)
show=1
;;
-v)
verb=1
;;
-m)
machine=$2
shift
;;
-*)
echo "Unknown option: $key"
exit
;;
*)
if [[ -f $key ]]; then
VARDEFNS=$key
else
echo ""
echo "ERROR: unknown option, get [$key]."
usage -2
fi
;;
esac
shift # past argument or value
done
if [[ -f $VARDEFNS ]]; then
echo "VARDEFNS = $VARDEFNS"
else
echo ""
echo "ERROR: cannot find var_defns.sh - <$VARDEFNS>."
usage -2
fi
#-----------------------------------------------------------------------
#
# Definitions
#
#-----------------------------------------------------------------------
VARDEFNS="$(realpath ${VARDEFNS})"
source ${VARDEFNS}
##---------------- Prepare Python environment --------------------------
case $machine in
odin)
read -r -d '' pythonstring <<- EOM
source /scratch/software/Odin/python/anaconda2/etc/profile.d/conda.sh
conda activate regional_workflow
EOM
;;
stampede)
pythonstring="module load python3/3.7.0"
;;
macos)
read -r -d '' pythonstring <<- EOM
source ~/.python
conda activate regional_workflow
EOM
;;
*)
echo "ERROR: unsupported machine - $machine"
usage 0
;;
esac
##@@@@@@@@@@@@@@@@@@@@@ Run shell script @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
CODEBASE="${HOMErrfs}"
WRKDIR="${LOGDIR}"
if [[ ! -d $WRKDIR ]]; then
mkdir $WRKDIR
fi
cd $WRKDIR
#
# Step 1. Get files for IC
#
jobscript="get_ics_files.sh"
read -r -d '' taskheader <<EOF
#!/bin/bash
${pythonstring}
export EXPTDIR=${EXPTDIR}
EOF
sed "1d" ${CODEBASE}/ush/wrappers/run_get_ics.sh > ${jobscript}
echo "$taskheader" | cat - ${jobscript} > temp && mv temp ${jobscript}
if [[ $verb -eq 1 ]]; then
echo "jobscript: $WRKDIR/$jobscript is created."
fi
chmod +x ${jobscript}
if [[ $show -eq 1 ]]; then
echo "Execute \"$WRKDIR/$jobscript\" manually to stage initial conditions."
else
${jobscript} >& out.get_files_ics
RC=$?
if [ $RC = 0 ]; then
echo "ICs downloaded successfully (see ${LOGDIR}/out.get_files_ics)"
else
echo "An error occured while downloading ICs, check logfile ${LOGDIR}/out.get_files_ics"
exit 1
fi
fi
#
# Step 2. Get files for LBCs
#
jobscript="get_lbc_files.sh"
read -r -d '' taskheader <<EOF
#!/bin/bash
${pythonstring}
export EXPTDIR=${EXPTDIR}
EOF
sed "1d" ${CODEBASE}/ush/wrappers/run_get_lbcs.sh > ${jobscript}
echo "$taskheader" | cat - ${jobscript} > temp && mv temp ${jobscript}
if [[ $verb -eq 1 ]]; then
echo "jobscript: $WRKDIR/$jobscript is created."
fi
chmod +x ${jobscript}
if [[ $show -eq 1 ]]; then
echo "Execute \"$WRKDIR/$jobscript\" manually to stage LBCs."
else
${jobscript} >& out.get_files_lbcs
RC=$?
if [ $RC = 0 ]; then
echo "LBCs downloaded successfully (see ${LOGDIR}/out.get_files_lbcs)"
exit 0
else
echo "An error occured while downloading LBCs, check logfile ${LOGDIR}/out.get_files_lbcs"
exit 1
fi
fi