3 ##########################################################################
5 # Script Name: met_point_verf_sfc.ksh
7 # Authors: J.Wolff and M.Harrold
13 # This script runs the MET/Point-Stat tool to verify gridded output
14 # from the WRF PostProcessor using point observations. The MET/PB2NC
15 # tool is run on the PREPBUFR observation files within this script.
17 # START_TIME = The cycle time to use for the initial time.
18 # FCST_TIME = The three-digit forecast that is to be verified.
19 # DOMAIN_LIST = A list of domains to be verified.
20 # MET_EXE_ROOT = The full path of the MET executables.
21 # MET_CONFIG = The full path of the MET configuration files.
22 # UTIL_EXEC = The full path of the ndate executable.
23 # MOAD_DATAROOT = Top-level data directory of WRF output.
24 # RAW_OBS = Directory containing observations to be used.
25 # MODEL = The model being evaluated.
27 ##########################################################################
30 SCRIPT=met_point_verf_sfc.ksh
32 # Set path for manual testing of script
33 #export CONSTANT=/scratch4/BMC/gmtb/harrold/gmtb-tierIII/bin/constants.ksh
35 # Make sure ${CONSTANT} exists
36 if [ ! -x "${CONSTANT}" ]; then
37 ${ECHO} "ERROR: ${CONSTANT} does not exist or is not executable"
41 # Read constants into the current shell
44 # Vars used for manual testing of the script
45 #export START_TIME=2016012200
46 #export FCST_TIME="006"
47 #export RES_LIST="0p25"
48 #export GRID_VX_LIST="G218"
49 #export MET_EXE_ROOT=/scratch4/BMC/dtc/MET/met-5.1/bin
50 #export MET_CONFIG=/scratch4/BMC/gmtb/harrold/gmtb-tierIII/parm/met_config
51 #export UTIL_EXEC=/scratch4/BMC/gmtb/gmtb-tierIII/util
52 #export MOAD_DATAROOT=/scratch4/BMC/gmtb/mid_tier/OUTPUT/prtutornems_0p25/DOMAINS/2016012200
53 #export PNT_OBS_DIR=/scratch4/NCEPDEV/global/noscrub/stat/prepbufr
56 # Print run parameters/masks
58 ${ECHO} "${SCRIPT} started at `${DATE}`"
60 ${ECHO} " START_TIME = ${START_TIME}"
61 ${ECHO} " FCST_TIME = ${FCST_TIME}"
62 ${ECHO} " RES_LIST = ${RES_LIST}"
63 ${ECHO} " GRID_VX_LIST = ${GRID_VX_LIST}"
64 ${ECHO} " MET_EXE_ROOT = ${MET_EXE_ROOT}"
65 ${ECHO} " MET_CONFIG = ${MET_CONFIG}"
66 ${ECHO} " UTIL_EXEC = ${UTIL_EXEC}"
67 ${ECHO} " MOAD_DATAROOT = ${MOAD_DATAROOT}"
68 ${ECHO} " ROTDIR = ${ROTDIR}"
69 ${ECHO} " PNT_OBS_DIR = ${PNT_OBS_DIR}"
70 ${ECHO} " MODEL = ${MODEL}"
72 # Make sure $MOAD_DATAROOT exists
73 if [ ! -d "${MOAD_DATAROOT}" ]; then
74 ${ECHO} "MOAD_DATAROOT, ${MOAD_DATAROOT} does not exist; will create it now!"
75 ${MKDIR} -p ${MOAD_DATAROOT}
78 # Make sure ROTDIR exists
79 if [ ! -d "${ROTDIR}" ]; then
80 ${ECHO} "ERROR: ROTDIR, ${ROTDIR} does not exist"
84 # Make sure PNT_OBS_DIR directory exists
85 if [ ! -d ${PNT_OBS_DIR} ]; then
86 ${ECHO} "ERROR: PNT_OBS_DIR, ${PNT_OBS_DIR}, does not exist!"
90 # Go to working directory
91 workdir=${MOAD_DATAROOT}/metprd
92 ${MKDIR} -p ${workdir}
98 ${ECHO} "MODEL=${MODEL}"
99 ${ECHO} "VERSION=${VERSION}"
100 ${ECHO} "FCST_TIME=${FCST_TIME}"
102 ########################################################################
103 # Compute VX date - only need to run once
104 ########################################################################
106 # Compute the verification date
107 VDATE=`${UTIL_EXEC}/ndate +${FCST_TIME} ${START_TIME}`
108 VYYYYMMDD=`${ECHO} ${VDATE} | ${CUT} -c1-8`
109 VHH=`${ECHO} ${VDATE} | ${CUT} -c9-10`
110 ${ECHO} 'valid time for ' ${FCST_TIME} 'h forecast = ' ${VDATE}
112 ########################################################################
113 # Run pb2nc on prepbufr obs file - only need to run once
114 ########################################################################
116 # Specify the MET PB2NC configuration file to be used
117 export CONFIG_PB2NC="${MET_CONFIG}/PB2NCConfig_GMTB"
119 # Make sure the MET configuration files exists
120 if [ ! -e ${CONFIG_PB2NC} ]; then
121 echo "ERROR: ${CONFIG_PB2NC} does not exist!"
125 # Process time information -- NDAS specific
126 # For retro NDAS vx, use "late" files, which are tm09 and tm12.
127 if [[ ${VHH} == "00" || ${VHH} == "06" || ${VHH} == "12" || ${VHH} == "18" ]]; then
129 elif [[ ${VHH} == "03" || ${VHH} == "09" || ${VHH} == "15" || ${VHH} == "21" ]]; then
132 echo "ERROR: Valid hour is not compatible with using NDAS data."
136 # For finding NDAS files in traditional naming convention and placements, uncomment.
137 # For GMTB, we organized the data by valid time.
138 #TM_HR=`echo ${TMMARK} | cut -c3-4`
140 #VYYYY=`echo ${VYYYYMMDD} | cut -c1-4`
141 #VMM=`echo ${VYYYYMMDD} | cut -c5-6`
142 #VDD=`echo ${VYYYYMMDD} | cut -c7-8`
143 #SEC_OFF=`expr ${TM_HR} \* 3600`
144 #REF_UT=`date -ud ''${VYYYY}-${VMM}-${VDD}' UTC '${VHH}:00:00'' +%s`
145 #NDAS_UT=`expr ${REF_UT} + ${SEC_OFF}`
146 #NDAS_YMD=`date -ud '1970-01-01 UTC '${NDAS_UT}' seconds' +%Y%m%d`
147 #NDAS_HR=`date -ud '1970-01-01 UTC '${NDAS_UT}' seconds' +%H`
148 #BEG_UT=`expr ${REF_UT} - 2700`
149 #END_UT=`expr ${REF_UT} + 2700`
150 #BEG_STR=`date -ud '1970-01-01 UTC '${BEG_UT}' seconds' +%Y%m%d_%H%M%S`
151 #END_STR=`date -ud '1970-01-01 UTC '${END_UT}' seconds' +%Y%m%d_%H%M%S`
153 TM_HR=`echo ${TMMARK} | cut -c3-4`
155 VYYYY=`echo ${VYYYYMMDD} | cut -c1-4`
156 VMM=`echo ${VYYYYMMDD} | cut -c5-6`
157 VDD=`echo ${VYYYYMMDD} | cut -c7-8`
158 REF_UT=`date -ud ''${VYYYY}-${VMM}-${VDD}' UTC '${VHH}:00:00'' +%s`
159 BEG_UT=`expr ${REF_UT} - 2700`
160 END_UT=`expr ${REF_UT} + 2700`
161 BEG_STR=`date -ud '1970-01-01 UTC '${BEG_UT}' seconds' +%Y%m%d_%H%M%S`
162 END_STR=`date -ud '1970-01-01 UTC '${END_UT}' seconds' +%Y%m%d_%H%M%S`
165 # List observation file to be run through pb2nc
166 #PB_FILE=`${LS} ${PNT_OBS_DIR}/ndas/ndas.${NDAS_YMD}/ndas.t${NDAS_HR}z.prepbufr.${TMMARK} | head -1`
167 PB_FILE=`${LS} ${PNT_OBS_DIR}/${VYYYYMMDD}/prepbufr.ndas.${VYYYYMMDD}.t${VHH}z.${TMMARK} | head -1`
168 if [ ! -e ${PB_FILE} ]; then
169 echo "ERROR: Could not find observation file: ${PB_FILE}"
174 pb2nc=${workdir}/pb2nc
177 # Create a PB2NC output file name
178 OBS_FILE="${pb2nc}/prepbufr.ndas.${VYYYYMMDD}.t${VHH}z.nc"
181 echo "CALLING: ${MET_EXE_ROOT}/pb2nc ${PB_FILE} ${OBS_FILE} ${CONFIG_PB2NC} -v 2"
183 ${MET_EXE_ROOT}/pb2nc ${PB_FILE} ${OBS_FILE} ${CONFIG_PB2NC} -valid_beg ${BEG_STR} -valid_end ${END_STR} -v 2
185 ########################################################################
186 # Run point stat for each grid resolution and verification grid
187 ########################################################################
189 # Loop through the domain list
190 for RES in ${RES_LIST}; do
195 for GRID_VX in ${GRID_VX_LIST}; do
196 GRID_VX_NUM=`${ECHO} ${GRID_VX} | cut -c2-`
197 typeset -Z3 GRID_VX_NUM
198 GRID_VX_FORMAT="G${GRID_VX_NUM}"
201 export GRID_VX_FORMAT
203 ${ECHO} "FCST_TIME=${FCST_TIME}"
205 # Specify new mask directory structure
206 MASKS=${MET_CONFIG}/masks
209 # Specify the MET Point-Stat configuration files to be used
210 CONFIG_ADPSFC="${MET_CONFIG}/PointStatConfig_ADPSFC_NDAS_REGRID"
211 CONFIG_ADPSFC_MPR="${MET_CONFIG}/PointStatConfig_ADPSFC_MPR_NDAS_REGRID"
213 # Make sure the Point-Stat configuration files exists
214 if [ ! -e ${CONFIG_ADPSFC} ]; then
215 ${ECHO} "ERROR: ${CONFIG_ADPSFC} does not exist!"
218 if [ ! -e ${CONFIG_ADPSFC_MPR} ]; then
219 ${ECHO} "ERROR: ${CONFIG_ADPSFC_MPR} does not exist!"
223 # Check the NDAS observation file (created from previous command to run pb2nc)
224 ${ECHO} "OBS_FILE: ${OBS_FILE}"
226 if [ ! -e ${OBS_FILE} ]; then
227 ${ECHO} "ERROR: Could not find observation file: ${OBS_FILE}"
231 # Get the forecast to verify
232 FCST_FILE=${ROTDIR}/pgrbq${FCST_TIME}.gfs.${START_TIME}.grib2
233 ${ECHO} "FCST_FILE: ${FCST_FILE}"
235 if [ ! -e ${FCST_FILE} ]; then
236 ${ECHO} "ERROR: Could not find UPP output file: ${FCST_FILE}"
240 #######################################################################
242 #######################################################################
244 # Verify surface variables for each forecast hour
245 CONFIG_FILE=${CONFIG_ADPSFC}
247 ${ECHO} "CALLING: ${MET_EXE_ROOT}/point_stat ${FCST_FILE} ${OBS_FILE} ${CONFIG_FILE} -outdir . -v 2"
249 /usr/bin/time ${MET_EXE_ROOT}/point_stat ${FCST_FILE} ${OBS_FILE} ${CONFIG_FILE} \
253 if [ ${error} -ne 0 ]; then
254 ${ECHO} "ERROR: For ${MODEL}, ${MET_EXE_ROOT}/point_stat ${CONFIG_FILE} crashed Exit status: ${error}"
258 # Verify surface variables for each forecast hour - MPR output
259 CONFIG_FILE=${CONFIG_ADPSFC_MPR}
261 ${ECHO} "CALLING: ${MET_EXE_ROOT}/point_stat ${FCST_FILE} ${OBS_FILE} ${CONFIG_FILE} -outdir . -v 2"
263 /usr/bin/time ${MET_EXE_ROOT}/point_stat ${FCST_FILE} ${OBS_FILE} ${CONFIG_FILE} \
267 if [ ${error} -ne 0 ]; then
268 ${ECHO} "ERROR: For ${MODEL}, ${MET_EXE_ROOT}/point_stat ${CONFIG_FILE} crashed Exit status: ${error}"
275 ##########################################################################
277 ${ECHO} "${SCRIPT} completed at `${DATE}`"