#!/bin/ksh set -ax #------------------------------------------------------------------------------ # # NAME: enupdate.ksh # # LANGUAGE: K-shell # # PURPOSE: Performs update of grib files and processes those files # into Packed files. This version is for the ECMWF grib files. # # DESCRIPTION: Queries for new updates to ECMWF model grib fields and in # turn processes those Grib files into packed file format for # inclusion into SHIPS model runs. # # INFORMATION: # National Hurricane Center / Tropical Prediction Center # Department of Commerce - NOAA / NWS # # CATEGORY: Grib unpacking # # CALLING SEQUENCE: enupdate.ksh # # INPUTS: # # OUTPUTS: # # EXTERNAL: # # SIDE EFFECTS: Unknown # # RESTRICTIONS: # # EXAMPLE or USAGE: enupdate.ksh # # OTHER NOTES: None # # MODIFICATION HISTORY: # Written by: M. DeMaria and F. Horsfall, 15-MAY-2001 (NOAA-NWS) # Revised by: C. Sisko, 24-MAR-2003 (NOAA-NWS) # Revised by: M. DeMaria, 13-MAY-2003 (Mods for frost/snow) # Revised by: C. Sisko, 20-DEC-2006 (NOAA-NWS) # Revised by: M. Sardi, 22-JUL-2014 (NOAA-NWS) # Revised by: M. DeMaria and K. Musgrave, 18-AUG-2015 (ECMWF fields) # Revised by: K. Musgrave, 22-MAR-2016 (ECMWF filename change) # Revised by: M. Sardi, 03-AUG-2016 (Revised PACK file handling at end) # Revised by: S. Stevenson 16-APR-2020 (Revised for Cray delivery & for 7day) # # REVISION INFORMATION (RCS Keyword): # Modified for use on the IBM CCS (Frost/Snow) by C. Sisko, 24-MAR-2003 # Ported to IBM CCS (BLUE/WHITE) by C. Sisko, 20-JAN-2005 # # Major re-write for WCOSS transition by M.DeMaria, May 2013 # Uses wgrib utilities instead of FORTRAN code for grib exraction # New pressure levels added, sfc variables added # Domain of packed ASCII files extended to 160 E # Resolution increased from 2 to 1 deg lat/lon # Forecast length increased from 126 to 174 h # $Id$ #------------------------------------------------------------------------------ # # common root path #commonp="/nhc/save/guidance/prgms" commonp=${HOMEnhcg} # Define wgrib utility name with full path # Now loaded in module #WGRIB="/nwprod/util/exec/wgrib" # # Specify the directory containing the grib files gdir=${ECMDIR} #gdir=${commonp}"/test/ecmwf/egrib/" # # Specify the directory to put the packed ASCII analysis files #pdir="/nhc/noscrub/data/guidance/ships/ecm/" #pdir=${commonp}"/test/ecmwf/epack/" pdir="${COM_STORM_DATA}/ships/ecm/" mkdir -p ${pdir} # # Specify the directory containing the executables #xdir=${commonp}"/test/ecmwf/exec/" #xdir="/nhc/save/guidance/prgms/src/ships/ops/src/bin2packe/" xdir=${commonp}"/exec/" # # Specify the directory containing required scripts sdir=${commonp}"/scripts/" # # Initialize the grib file date directory variable gddir="19550930" # logf="enupdate.log" rm -f $logf # # Find most recent EC grib file directory #tday="${storm_tday}" #ttim="${storm_ttim}" #tyr4="${storm_year}" #tdate="${storm_tdate}" tday=`date -u +%m%d` ttim=`date -u +%H` tyr4=`date -u +%Y` tdate=`date -u +%Y%m%d` echo " -- checking "$gdir" for new ECMWF files for SHIPS" > $logf echo " -- current date/time: " $tday " " $tyr4 " " $ttim " UTC" >> $logf for line0 in `ls $gdir | grep "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$" | sort` do echo line0 = $line0 echo gdir = $gdir echo tdate = $tdate echo gddir = $gddir echo ttim = $ttim if [ $ttim -ge 6 ] then if [ $line0 -le $tdate ] && [ $line0 -gt $gddir ] then gddir=$line0 fi fi if [ $ttim -lt 6 ] then if [ $line0 -lt $tdate ] && [ $line0 -gt $gddir ] then gddir=$line0 fi fi done fullgdir=${gdir}/${gddir}"/wgrbbul/ecmwf/" # # Find the most current 180 hour forecast # (will check back one additional day as needed, if none found in two days will exit) rm -f ecm_intimes for line0 in `ls $fullgdir | grep "DCD"` #for line0 in `ls $fullgdir | grep "ecens_DCD"` do basename $line0 | cut -c4-9 >> ecm_intimes # basename $line0 | cut -c10-15 >> ecm_intimes done gtime="99" inityr=`echo $gddir | cut -c1-4` initmm=`echo $gddir | cut -c5-6` initdd=`echo $gddir | cut -c7-8` for line0 in `sort ecm_intimes | uniq` do inithh=`echo $line0 | cut -c5-6` fcstdg=`date -d "${inityr}-${initmm}-${initdd} ${inithh} 180 hours" +%m%d%H` fcstfile=${fullgdir}"DCD"${line0}"00"${fcstdg}"001" # fcstfile=${fullgdir}"ecens_DCD"${line0}"00"${fcstdg}"001" if [ -f ${fcstfile} ] then gtime=${inithh} fi done #go back to previous day if no runs found with 180hr forecast for gddir if [ ${gtime} = "99" ] then gddir=`date -d "${inityr}-${initmm}-${initdd} 1 day ago" +%Y%m%d` fullgdir=${gdir}/${gddir}"/wgrbbul/ecmwf/" inityr=`echo $gddir | cut -c1-4` initmm=`echo $gddir | cut -c5-6` initdd=`echo $gddir | cut -c7-8` rm -f ecm_intimes for line0 in `ls $fullgdir | grep "DCD"` # for line0 in `ls $fullgdir | grep "ecens_DCD"` do basename $line0 | cut -c4-9 >> ecm_intimes # basename $line0 | cut -c10-15 >> ecm_intimes done for line0 in `sort ecm_intimes | uniq` do inithh=`echo $line0 | cut -c5-6` fcstdg=`date -d "${inityr}-${initmm}-${initdd} ${inithh} 180 hours" +%m%d%H` fcstfile=${fullgdir}"DCD"${line0}"00"${fcstdg}"001" # fcstfile=${fullgdir}"ecens_DCD"${line0}"00"${fcstdg}"001" if [ -f ${fcstfile} ] then gtime=${inithh} fi done fi rm -f ecm_intimes #no runs found with 120hr fcst in current or previous day - exit program if [ ${gtime} = "99" ] then echo "" >> $logf echo "*** Grib unpack *not* run as 180hr forecast not found, enupdate completed" >> $logf exit 1 fi # Only use cyc for NCO version #gtime=$CYC gmax=${gddir}${gtime} echo "The most recent ECMWF run available is "$gmax >> $logf # # Find the most recent processed 180hr ECMWF PACK file dmax="0000000000" # naming convention: Efffyy_[XY]mmdd_PACK.DAT # where fff is 3-digit forecast hour, yy is 2-digit year, # [XY] is X if 00 or 12z runs and Y if 06 or 18z runs # mm is 2-digit month, and # dd is 2-digit day (or 50+day if 12 or 18z runs) # for line0 in `ls $pdir | grep E180` do ayr=`echo $line0 | cut -c5-6` axy=`echo $line0 | cut -c8-8` amon=`echo $line0 | cut -c9-10` aday=`echo $line0 | cut -c11-12` # # Adjust year ayr="20${ayr}" # # Adjust day and calculate time atime="00" if [ $aday -ge 51 ] then aday=$(($aday - 50)) typeset -Z2 aday=$aday atime="12" fi # if [ $axy == 'Y' ] then atime=$(($atime + 6)) typeset -Z2 atime=$atime fi # dtem="${ayr}${amon}${aday}${atime}" # if [ $dtem -ge $dmax ] then dmax=$dtem fi done echo "The most recent ECMWF run processed is "$dmax >> $logf if [ $dmax -ge $gmax ] then echo "" >> $logf echo "*** Grib unpack *not* needed, enupdate completed" >> $logf exit 0 fi rm -f E*_PACK.DAT rm -f *.bin rm -f ecm_indate #Specify date, initialization time and forecast end (hr) YMD=${gddir} HH=${gtime} IFEND="180" # #***Testing Block*** set to one of the testcases in egrib #inityr="2015" #initmm="08" #initdd="23" #gtime="12" #YMD=${inityr}${initmm}${initdd} #HH=${gtime} #gddir="${inityr}${initmm}${initdd}" #fullgdir=${gdir}${gddir}"/wgrbbul/ecmwf/" #***End Testing Block*** fhour="0" finc="6" while [ $fhour -le $IFEND ] do typeset -Z3 IFHR=${fhour} fcstdg=`date -d "${inityr}-${initmm}-${initdd} ${gtime} ${fhour} hours" +%m%d%H` gribfil=${fullgdir}"DCD${initmm}${initdd}${gtime}00${fcstdg}001" # gribfil=${fullgdir}"ecens_DCD${initmm}${initdd}${gtime}00${fcstdg}001" fhour=$(($fhour + $finc)) if [ ! -f ${gribfil} ] then echo "ECMWF grib file for forecast hour $(($fhour - $finc)) not found, skipping." >> $logf continue fi echo $YMD > ecm_indate echo $HH >> ecm_indate echo $IFHR >> ecm_indate # Pull desired fields # $WGRIB -s $gribfil |grep 'U:50 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_u50.bin" $WGRIB -s $gribfil |grep 'U:100 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_u100.bin" $WGRIB -s $gribfil |grep 'U:150 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_u150.bin" $WGRIB -s $gribfil |grep 'U:200 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_u200.bin" $WGRIB -s $gribfil |grep 'U:250 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_u250.bin" $WGRIB -s $gribfil |grep 'U:300 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_u300.bin" $WGRIB -s $gribfil |grep 'U:400 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_u400.bin" $WGRIB -s $gribfil |grep 'U:500 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_u500.bin" $WGRIB -s $gribfil |grep 'U:700 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_u700.bin" $WGRIB -s $gribfil |grep 'U:850 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_u850.bin" $WGRIB -s $gribfil |grep 'U:925 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_u925.bin" $WGRIB -s $gribfil |grep 'U:1000 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_u1000.bin" $WGRIB -s $gribfil |grep 'V:50 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_v50.bin" $WGRIB -s $gribfil |grep 'V:100 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_v100.bin" $WGRIB -s $gribfil |grep 'V:150 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_v150.bin" $WGRIB -s $gribfil |grep 'V:200 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_v200.bin" $WGRIB -s $gribfil |grep 'V:250 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_v250.bin" $WGRIB -s $gribfil |grep 'V:300 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_v300.bin" $WGRIB -s $gribfil |grep 'V:400 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_v400.bin" $WGRIB -s $gribfil |grep 'V:500 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_v500.bin" $WGRIB -s $gribfil |grep 'V:700 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_v700.bin" $WGRIB -s $gribfil |grep 'V:850 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_v850.bin" $WGRIB -s $gribfil |grep 'V:925 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_v925.bin" $WGRIB -s $gribfil |grep 'V:1000 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_v1000.bin" $WGRIB -s $gribfil |grep 'GH:50 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_height50.bin" $WGRIB -s $gribfil |grep 'GH:100 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_height100.bin" $WGRIB -s $gribfil |grep 'GH:150 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_height150.bin" $WGRIB -s $gribfil |grep 'GH:200 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_height200.bin" $WGRIB -s $gribfil |grep 'GH:250 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_height250.bin" $WGRIB -s $gribfil |grep 'GH:300 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_height300.bin" $WGRIB -s $gribfil |grep 'GH:400 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_height400.bin" $WGRIB -s $gribfil |grep 'GH:500 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_height500.bin" $WGRIB -s $gribfil |grep 'GH:700 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_height700.bin" $WGRIB -s $gribfil |grep 'GH:850 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_height850.bin" $WGRIB -s $gribfil |grep 'GH:925 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_height925.bin" $WGRIB -s $gribfil |grep 'GH:1000 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_height1000.bin" $WGRIB -s $gribfil |grep 'T:50 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_temp50.bin" $WGRIB -s $gribfil |grep 'T:100 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_temp100.bin" $WGRIB -s $gribfil |grep 'T:150 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_temp150.bin" $WGRIB -s $gribfil |grep 'T:200 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_temp200.bin" $WGRIB -s $gribfil |grep 'T:250 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_temp250.bin" $WGRIB -s $gribfil |grep 'T:300 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_temp300.bin" $WGRIB -s $gribfil |grep 'T:400 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_temp400.bin" $WGRIB -s $gribfil |grep 'T:500 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_temp500.bin" $WGRIB -s $gribfil |grep 'T:700 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_temp700.bin" $WGRIB -s $gribfil |grep 'T:850 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_temp850.bin" $WGRIB -s $gribfil |grep 'T:925 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_temp925.bin" $WGRIB -s $gribfil |grep 'T:1000 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_temp1000.bin" $WGRIB -s $gribfil |grep 'R:50 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_relh50.bin" $WGRIB -s $gribfil |grep 'R:100 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_relh100.bin" $WGRIB -s $gribfil |grep 'R:150 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_relh150.bin" $WGRIB -s $gribfil |grep 'R:200 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_relh200.bin" $WGRIB -s $gribfil |grep 'R:250 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_relh250.bin" $WGRIB -s $gribfil |grep 'R:300 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_relh300.bin" $WGRIB -s $gribfil |grep 'R:400 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_relh400.bin" $WGRIB -s $gribfil |grep 'R:500 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_relh500.bin" $WGRIB -s $gribfil |grep 'R:700 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_relh700.bin" $WGRIB -s $gribfil |grep 'R:850 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_relh850.bin" $WGRIB -s $gribfil |grep 'R:925 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_relh925.bin" $WGRIB -s $gribfil |grep 'R:1000 mb:' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_relh1000.bin" $WGRIB -s $gribfil |grep ':10U:sfc' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_u1070.bin" $WGRIB -s $gribfil |grep ':10V:sfc' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_v1070.bin" $WGRIB -s $gribfil |grep ':2T:sfc' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_temp1070.bin" $WGRIB -s $gribfil |grep ':SP:sfc' | $WGRIB -s -i -nh $gribfil -bin -o $YMD$HH"_F"$IFHR"_p1070.bin" # Convert binary files to packed ASCII $xdir"bin2packe.x" rm *.bin done # Remove any incomplete (< 2.8 MB) PACK files first. pfiles=`find . -name "E*_PACK.DAT" -size -2700k` rm -f $pfiles # Next, check remaining files through forecast hour 180. If any are missing, set complete (set) flag to false. complete="true" fhours="000 006 012 018 024 030 036 042 048 054 060 066 072 078 084 090 096 102 108 114 120 126 132 138 144 150 156 162 168 174 180" for fhour in $fhours; do ls E${fhour}*_PACK.DAT > /dev/null 2>&1 if [[ $? != 0 ]]; then complete="false" fi done #ECM_PACK_DIR copy only needed for NCO version export ECM_PACK_DIR=${COM_STORM_DATA}/ecm_PACK.${gddir}/${gtime} mkdir -p ${ECM_PACK_DIR} cp -p E*_PACK.DAT ${ECM_PACK_DIR} ##DBNET ALERTS dcount=0 if [ $SENDDBN = YES ]; then for file in `find $ECM_PACK_DIR/*.DAT -type f` do ${DBNROOT}/bin/dbn_alert MODEL NHC_ATCF_PACK $job $file ls $file dcount=$((dcount+1)) echo $file done echo "Totall number of alerted files is $dcount" fi #####END ALERT # If the PACK files are complete through 180 hours, move to the ECMWF SHIPS input location ($pdir). Otherwise, # remove 'em all and try again at the next cron run time. if [[ $complete == "true" ]]; then mv E*_PACK.DAT $pdir else rm E*_PACK.DAT fi # echo "" >> $logf echo "*** ECMWF grib unpack update completed." >> $logf exit 0 #------------------------------------------------------------------------------ # # EXPANDED REVISION INFORMATION (RCS Keywords): # # $Id$ # $Author$ # $Log$ # $Locker$ # #------------------------------------------------------------------------------