forked from ufs-community/ufs-srweather-app
-
Notifications
You must be signed in to change notification settings - Fork 5
/
exregional_nexus_gfs_sfc.sh
executable file
·169 lines (157 loc) · 5.68 KB
/
exregional_nexus_gfs_sfc.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
#
#-----------------------------------------------------------------------
#
# Source the variable definitions file and the bash utility functions.
#
#-----------------------------------------------------------------------
#
. $USHdir/source_util_funcs.sh
source_config_for_task "cpl_aqm_parm|task_nexus_gfs_sfc" ${GLOBAL_VAR_DEFNS_FP}
#
#-----------------------------------------------------------------------
#
# Save current shell options (in a global array). Then set new options
# for this script/function.
#
#-----------------------------------------------------------------------
#
{ save_shell_opts; . $USHdir/preamble.sh; } > /dev/null 2>&1
#
#-----------------------------------------------------------------------
#
# Get the full path to the file in which this script/function is located
# (scrfunc_fp), the name of that file (scrfunc_fn), and the directory in
# which the file is located (scrfunc_dir).
#
#-----------------------------------------------------------------------
#
scrfunc_fp=$( $READLINK -f "${BASH_SOURCE[0]}" )
scrfunc_fn=$( basename "${scrfunc_fp}" )
scrfunc_dir=$( dirname "${scrfunc_fp}" )
#
#-----------------------------------------------------------------------
#
# Print message indicating entry into script.
#
#-----------------------------------------------------------------------
#
print_info_msg "
========================================================================
Entering script: \"${scrfunc_fn}\"
In directory: \"${scrfunc_dir}\"
This is the ex-script for the task that copies or fetches GFS surface
data files from disk or HPSS.
========================================================================"
#
#-----------------------------------------------------------------------
#
set -x
DATA="${DATA}/tmp_GFS_SFC"
mkdir_vrfy -p "$DATA"
cd_vrfy $DATA
#
#-----------------------------------------------------------------------
#
# Set up variables for call to retrieve_data.py
#
#-----------------------------------------------------------------------
#
yyyymmdd=${GFS_SFC_CDATE:0:8}
yyyymm=${GFS_SFC_CDATE:0:6}
yyyy=${GFS_SFC_CDATE:0:4}
hh=${GFS_SFC_CDATE:8:2}
if [ "${NUM_FCST_LEN_CYCL}" -gt "1" ]; then
cyc_mod=$(( ${cyc} - ${DATE_FIRST_CYCL:8:2} ))
CYCLE_IDX=$(( ${cyc_mod} / ${INCR_CYCL_FREQ} ))
FCST_LEN_HRS=${FCST_LEN_CYCL[$CYCLE_IDX]}
fi
#
#-----------------------------------------------------------------------
#
# Retrieve GFS surface files to GFS_SFC_STAGING_DIR
#
#-----------------------------------------------------------------------
#
GFS_SFC_TAR_DIR="${NEXUS_GFS_SFC_ARCHV_DIR}/rh${yyyy}/${yyyymm}/${yyyymmdd}"
GFS_SFC_TAR_SUB_DIR="gfs.${yyyymmdd}/${hh}/atmos"
if [ "${DO_REAL_TIME}" = "TRUE" ]; then
GFS_SFC_LOCAL_DIR="${COMINgfs}/${GFS_SFC_TAR_SUB_DIR}"
else
GFS_SFC_LOCAL_DIR="${NEXUS_GFS_SFC_DIR}/${GFS_SFC_TAR_SUB_DIR}"
fi
GFS_SFC_DATA_INTVL="3"
# copy files from local directory
if [ -d ${GFS_SFC_LOCAL_DIR} ]; then
gfs_sfc_fn="gfs.t${hh}z.sfcanl.nc"
cp_vrfy "${GFS_SFC_LOCAL_DIR}/${gfs_sfc_fn}" ${GFS_SFC_STAGING_DIR}
for fhr in $(seq -f "%03g" 0 ${GFS_SFC_DATA_INTVL} ${FCST_LEN_HRS}); do
gfs_sfc_fn="gfs.t${hh}z.sfcf${fhr}.nc"
if [ -e "${GFS_SFC_LOCAL_DIR}/${gfs_sfc_fn}" ]; then
cp_vrfy "${GFS_SFC_LOCAL_DIR}/${gfs_sfc_fn}" ${GFS_SFC_STAGING_DIR}
else
print_err_msg_exit "\
sfc file does not exist in the directory:
GFS_SFC_LOCAL_DIR = \"${GFS_SFC_LOCAL_DIR}\"
gfs_sfc_fn = \"${gfs_sfc_fn}\""
fi
done
# retrieve files from HPSS
else
if [ "${yyyymmdd}" -lt "20220627" ]; then
GFS_SFC_TAR_FN_VER="prod"
elif [ "${yyyymmdd}" -lt "20221129" ]; then
GFS_SFC_TAR_FN_VER="v16.2"
else
GFS_SFC_TAR_FN_VER="v16.3"
fi
GFS_SFC_TAR_FN_PREFIX="com_gfs_${GFS_SFC_TAR_FN_VER}_gfs"
GFS_SFC_TAR_FN_SUFFIX_A="gfs_nca.tar"
GFS_SFC_TAR_FN_SUFFIX_B="gfs_ncb.tar"
# Check if the sfcanl file exists in the staging directory
gfs_sfc_tar_fn="${GFS_SFC_TAR_FN_PREFIX}.${yyyymmdd}_${hh}.${GFS_SFC_TAR_FN_SUFFIX_A}"
gfs_sfc_tar_fp="${GFS_SFC_TAR_DIR}/${gfs_sfc_tar_fn}"
gfs_sfc_fns=("gfs.t${hh}z.sfcanl.nc")
gfs_sfc_fps="./${GFS_SFC_TAR_SUB_DIR}/gfs.t${hh}z.sfcanl.nc"
if [ "${FCST_LEN_HRS}" -lt "40" ]; then
ARCHV_LEN_HRS="${FCST_LEN_HRS}"
else
ARCHV_LEN_HRS="39"
fi
for fhr in $(seq -f "%03g" 0 ${GFS_SFC_DATA_INTVL} ${ARCHV_LEN_HRS}); do
gfs_sfc_fns+="gfs.t${hh}z.sfcf${fhr}.nc"
gfs_sfc_fps+=" ./${GFS_SFC_TAR_SUB_DIR}/gfs.t${hh}z.sfcf${fhr}.nc"
done
# Retrieve data from A file up to FCST_LEN_HRS=39
htar -tvf ${gfs_sfc_tar_fp}
PREP_STEP
htar -xvf ${gfs_sfc_tar_fp} ${gfs_sfc_fps} ${REDIRECT_OUT_ERR} || \
print_err_msg_exit "htar file reading operation (\"htar -xvf ...\") failed."
POST_STEP
# Retireve data from B file when FCST_LEN_HRS>=40
if [ "${FCST_LEN_HRS}" -ge "40" ]; then
gfs_sfc_tar_fn="${GFS_SFC_TAR_FN_PREFIX}.${yyyymmdd}_${hh}.${GFS_SFC_TAR_FN_SUFFIX_B}"
gfs_sfc_tar_fp="${GFS_SFC_TAR_DIR}/${gfs_sfc_tar_fn}"
gfs_sfc_fns=()
gfs_sfc_fps=""
for fhr in $(seq -f "%03g" 42 ${GFS_SFC_DATA_INTVL} ${FCST_LEN_HRS}); do
gfs_sfc_fns+="gfs.t${hh}z.sfcf${fhr}.nc"
gfs_sfc_fps+=" ./${GFS_SFC_TAR_SUB_DIR}/gfs.t${hh}z.sfcf${fhr}.nc"
done
htar -tvf ${gfs_sfc_tar_fp}
PREP_STEP
htar -xvf ${gfs_sfc_tar_fp} ${gfs_sfc_fps} ${REDIRECT_OUT_ERR} || \
print_err_msg_exit "htar file reading operation (\"htar -xvf ...\") failed."
POST_STEP
fi
# Move retrieved files to staging directory
mv_vrfy ${DATA}/${GFS_SFC_TAR_SUB_DIR}/gfs.*.nc ${GFS_SFC_STAGING_DIR}
fi
#
#-----------------------------------------------------------------------
#
# Restore the shell options saved at the beginning of this script/function.
#
#-----------------------------------------------------------------------
#
{ restore_shell_opts; } > /dev/null 2>&1