-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathjob_preamble.sh
171 lines (164 loc) · 4.88 KB
/
job_preamble.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
#!/bin/bash
#
#-----------------------------------------------------------------------
#
# If requested to share data with next task, override jobid
#
#-----------------------------------------------------------------------
#
export share_pid=${WORKFLOW_ID}_${PDY}${cyc}
if [ $# -ne 0 ]; then
export pid=$share_pid
export jobid=${job}.${pid}
fi
#
#-----------------------------------------------------------------------
#
# Set cycle and ensemble member names in file/diectory names
#
#-----------------------------------------------------------------------
#
if [ $subcyc -eq 0 ]; then
export cycle="t${cyc}z"
else
export cycle="t${cyc}${subcyc}z"
fi
if [ "${RUN_ENVIR}" = "nco" ] && [ "${DO_ENSEMBLE}" = "TRUE" ] && [ ! -z $ENSMEM_INDX ]; then
export dot_ensmem=".mem${ENSMEM_INDX}"
else
export dot_ensmem=
fi
#
#-----------------------------------------------------------------------
#
# Create a temp working directory (DATA) and cd into it.
#
#-----------------------------------------------------------------------
#
export DATA=
if [ "${RUN_ENVIR}" = "nco" ]; then
export DATA=${DATAROOT}/${jobid}
mkdir -p $DATA
cd $DATA
fi
#
#-----------------------------------------------------------------------
#
# Run setpdy to initialize PDYm and PDYp variables
#
#-----------------------------------------------------------------------
#
if [ "${RUN_ENVIR}" = "nco" ]; then
if [ ! -z $(command -v setpdy.sh) ]; then
COMROOT=$COMROOT setpdy.sh
. ./PDY
fi
else
export PDYm1=$( $DATE_UTIL --date "${PDY} -1 day" "+%Y%m%d" )
export PDYm2=$( $DATE_UTIL --date "${PDY} -2 day" "+%Y%m%d" )
export PDYm3=$( $DATE_UTIL --date "${PDY} -3 day" "+%Y%m%d" )
fi
export CDATE=${PDY}${cyc}
#
#-----------------------------------------------------------------------
#
# Set pgmout and pgmerr files
#
#-----------------------------------------------------------------------
#
if [ "${RUN_ENVIR}" = "nco" ]; then
export pgmout="${DATA}/OUTPUT.$$"
export pgmerr="${DATA}/errfile"
export REDIRECT_OUT_ERR=">>${pgmout} 2>${pgmerr}"
export pgmout_lines=1
function PREP_STEP() {
export pgm="$(basename ${0})"
if [ ! -z $(command -v prep_step) ]; then
. prep_step
else
# Append header
if [ -n "$pgm" ] && [ -n "$pgmout" ]; then
echo "$pgm" >> $pgmout
fi
# Remove error file
if [ -f $pgmerr ]; then
rm $pgmerr
fi
fi
}
function POST_STEP() {
if [ -f $pgmout ]; then
tail -n +${pgmout_lines} $pgmout
pgmout_line=$( wc -l $pgmout )
pgmout_lines=$((pgmout_lines + 1))
fi
}
else
export pgmout=
export pgmerr=
export REDIRECT_OUT_ERR=
function PREP_STEP() {
:
}
function POST_STEP() {
:
}
fi
export -f PREP_STEP
export -f POST_STEP
#
#-----------------------------------------------------------------------
#
# Set COMIN / COMOUT
#
#-----------------------------------------------------------------------
#
if [ "${RUN_ENVIR}" = "nco" ]; then
export COMROOT=$COMROOT
export COMIN="${COMIN:-$(compath.py -o ${NET}/${model_ver}/${RUN}.${PDY}/${cyc})}"
export COMOUT="${COMOUT:-$(compath.py -o ${NET}/${model_ver}/${RUN}.${PDY}/${cyc})}"
export COMINm1="${COMINm1:-$(compath.py -o ${NET}/${model_ver}/${RUN}.${PDYm1})}"
export COMINgfs="${COMINgfs:-$(compath.py ${envir}/gfs/${gfs_ver})}"
export COMINgefs="${COMINgefs:-$(compath.py ${envir}/gefs/${gefs_ver})}"
else
export COMIN="${COMIN_BASEDIR}/${PDY}${cyc}"
export COMOUT="${COMOUT_BASEDIR}/${PDY}${cyc}"
export COMINm1="${COMIN_BASEDIR}/${RUN}.${PDYm1}"
fi
export COMOUTwmo="${COMOUT}/wmo"
#
#-----------------------------------------------------------------------
#
# Create symlinks to log files in the experiment directory. Makes viewing
# log files easier in NCO mode, as well as make CIs work
#
#-----------------------------------------------------------------------
#
if [ "${RUN_ENVIR}" = "nco" ] && [ "${DEBUG}" = "TRUE" ]; then
__EXPTLOG=${EXPTDIR}/log
mkdir -p ${__EXPTLOG}
for i in ${LOGDIR}/*.${WORKFLOW_ID}.log; do
__LOGB=$(basename $i .${WORKFLOW_ID}.log)
ln -sf $i ${__EXPTLOG}/${__LOGB}.log
done
fi
#
#-----------------------------------------------------------------------
#
# Add a postamble function
#
#-----------------------------------------------------------------------
#
function job_postamble() {
# Remove temp directory
if [ "${RUN_ENVIR}" = "nco" ] && [ $# -eq 0 ]; then
cd ${DATAROOT}
[[ $KEEPDATA = "FALSE" ]] && rm -rf $DATA
fi
# Print exit message
print_info_msg "
========================================================================
Exiting script: \"${scrfunc_fn}\"
In directory: \"${scrfunc_dir}\"
========================================================================"
}