#!/bin/ksh # set -x #-------------------------------------------------------- # Updates: # # August 2005: Hui-Ya Chuang, NCEP: This script uses # NCEP's Unipost to post processes WRF native model # output, and uses copygb to horizontally interpolate posted # output from native A-E to a regular projection grid. # # July 2006: Meral Demirtas, NCAR/DTC: Added new "copygb" # options and revised some parts for clarity. # # April 2015: Modified to run NMM-B/NEMS, KRF(DTC) # # January 2019: Modified to remove NMMB/NMM and add FV3, TH (DTC) # # October 2019: Modified for new unified build system; # ndate.exe and copygb.exe have been removed # #-------------------------------------------------------- # # This script performs 2 jobs: # # 1. Run the community version of UPP, unipost.exe # 2. Run GEMPAK to plot results # #-------------------------------------------------------- #---------------------------------------------------------------------------------- #--- USER EDIT DESCIPTIONS -------------------------------------------------------- # See UPP User's Guide for more information # http://www.dtcenter.org/upp/users/docs/user_guide/V4/upp_users_guide.pdf #---------------------------------------------------------------------------------- # TOP_DIR : Top level directory for source codes (UPPV4.0) # DOMAINPATH : Working directory for this run. # UNIPOST_HOME : Where the UPP build directory located # POSTEXEC : Where the UPP executables are located # SCRIPTS : Where the UPP scripts directory is (i.e. UPPV4.0/scripts/) # modelDataPath : Where are the model data files to be processed located # : e.g. "wrfprd/" for WRF-based runs # FV3 model filename examples (may need to alter in script) # inFileName=dynf012.nemsio (default) or gfs.t00z.atmf012.nemsio # flxFileName=phyf012.nemsio (default) or gfs.t00z.sfcf012.nemsio # paramFile : Name and location of cntrl.parm file (wrf_cntrl.parm) # Text file lists desired fields for grib1 output. Template in UPPV4.0/parm/ # txtCntrlFile : Name and location of post flat file (postxconfig-NT.txt) for grib2 # Text file listing desired fields to be generated by the user before running UPP. # Step 1: Edit postcntrl.xml to include desired fields (template in UPPV4.0/parm) # Step 2: Validate postcntrl.xml and post_avblflds.xml # Step 3: Type 'make' in parm directory to generate the post flat file # dyncore : What model is used ARW (WRF) or FV3 (GFS) # inFormat : Format of the model data # arw - "netcdf" # fv3 - "binarynemsiompiio" or "netcdf" # outFormat : Format of output from UPP # grib (WRF only) # grib2 # startdate : Forecast start date (YYYYMMDDHH) # fhr : First forecast hour to be post-processed # lastfhr : Last forecast hour to be post-processed # incrementhr : Increment (in hours) between forecast files # * Do not set to 0 or the script will loop continuously * # domain_list : List of domains for run # RUN_COMMAND : System run command for serial or parallel runs, examples below. # #---------------------------------------------------------------------------------- #--- BEGIN USER EDIT HERE --------------------------------------------------------- #---------------------------------------------------------------------------------- # Set relevant paths and data information # This script assumes you created a directory $DOMAINPATH/postprd # and that your model output is in $DOMAINPATH/wrfprd # as recommended in the users guide where UPP will output. export TOP_DIR=/home/username export DOMAINPATH=${TOP_DIR}/DOMAINS/test_case export UNIPOST_HOME=${TOP_DIR}/UPPV4.0 export POSTEXEC=${UNIPOST_HOME}/exec export SCRIPTS=${UNIPOST_HOME}/scripts export modelDataPath=${DOMAINPATH}/wrfprd export paramFile=${DOMAINPATH}/parm/wrf_cntrl.parm # grib1 (WRF only) export txtCntrlFile=${DOMAINPATH}/parm/postxconfig-NT-WRF.txt # grib2 (or postxconfig-NT-GFS.txt) # Specify Dyn Core (ARW or FV3 in upper case) export dyncore="ARW" # Set input format from model and ouput format from unipost export inFormat="netcdf" export outFormat="grib2" # Set date/time information export startdate=2014020412 export fhr=00 export lastfhr=06 export incrementhr=03 # Set domain lists export domain_list="d01" # Set run command: # Serial command example export RUN_COMMAND="${POSTEXEC}/unipost.exe " # Parallel command examples: #export RUN_COMMAND="mpirun -np 1 ${POSTEXEC}/unipost.exe " #export RUN_COMMAND="mpirun.lsf ${POSTEXEC}/unipost.exe " #export RUN_COMMAND="mpiexec_mpt ${POSTEXEC}/unipost.exe " # DEBUG command example found further below, search "DEBUG" # Shouldn't need to edit these. # tmmark is an variable used as the file extention of the output # filename .GrbF is used if this variable is not set # COMSP is a variable used as the initial string of the output filename export tmmark=tm00 export MP_SHARED_MEMORY=yes export MP_LABELIO=yes #---------------------------------------------------------------------- #--- END USER EDIT ---------------------------------------------------- #---------------------------------------------------------------------- #---------------------------------------------------------------------- # Shouldn't need to edit below unless something goes wrong or debugging #---------------------------------------------------------------------- #---------------------------------------------------------------------- # Do some checks for directory/executable existence, user input, etc. #---------------------------------------------------------------------- if [ ! -d ${POSTEXEC} ]; then echo "ERROR: POSTEXEC, '${POSTEXEC}', does not exist" exit 1 fi if [ ! -x ${POSTEXEC}/unipost.exe ]; then echo "ERROR: unipost.exe, '${POSTEXEC}/unipost.exe', does not exist or is not executable." exit 1 fi # Set tag based on user defined $dyncore (ARW or FV3 in upper case) if [ $dyncore = "ARW" ]; then export tag=NCAR elif [ $dyncore = "FV3" ]; then export tag=GFS else echo "${dyncore} is not supported. Edit script to choose ARW or FV3 dyncore." exit fi if [[ ${dyncore} == "ARW" ]]; then if [[ ${inFormat} != "netcdf" ]]; then echo "ERROR: 'inFormat' must be 'netcdf' for ARW model output. Exiting... " exit 1 fi elif [ ${dyncore} == "FV3" ]; then if [[ ${inFormat} == "binarynemsiompiio" ]]; then echo "Check: You are using 'dyncore' 'inFormat'!" elif [[ ${inFormat} == "netcdf" ]]; then echo "Check: You are using 'dyncore' 'inFormat'!" else echo "ERROR: 'inFormat' must be 'binarynemsiompiio' or 'netcdf' for FV3 model output. Exiting... " exit 1 fi fi if [[ ${outFormat} == "grib" ]]; then if [ ! -e ${paramFile} ]; then echo "ERROR: 'paramFile' not found in '${paramFile}'. Exiting... " exit 1 fi elif [[ ${outFormat} == "grib2" ]]; then if [ ! -e ${txtCntrlFile} ]; then echo "ERROR: 'txtCntrlFile' not found in '${txtCntrlFile}'. Exiting... " exit 1 fi fi if [ ! -d ${DOMAINPATH}/postprd ]; then echo "ERROR: DOMAINPATH/postprd, '${DOMAINPATH}/postprd', does not exist. Exiting..." exit 1 fi if [ ${incrementhr} -eq 0 ]; then echo "ERROR: increment hour (incrementhr) cannot be zero. Inifinite loop will result. Please modify. Exiting..." exit 1 fi #---------------------------------------------------------------------- # End checks of user input #---------------------------------------------------------------------- #---------------------------------------------------------------------- # Begin work #---------------------------------------------------------------------- # cd to working directory cd ${DOMAINPATH}/postprd err1=$? if test "$err1" -ne 0; then echo "ERROR: Could not 'cd' to working directory. Did you create directory: '${DOMAINPATH}/postprd'? \ Does '${DOMAINPATH}' exist? Exiting... " exit 1 fi # Get local copy of parm file # For GRIB1 the code uses wrf_cntrl.parm to select variables for output # the available fields are set at compilation if [[ ${outFormat} == "grib" ]]; then if [[ ${dyncore} == "ARW" ]]; then ln -fs ${paramFile} wrf_cntrl.parm elif [[ ${dyncore} == "FV3" ]]; then echo "ERROR: FV3 not available for grib1 output. Use GRIB2 output. Exiting..." exit 1 fi elif [[ ${outFormat} == "grib2" ]]; then # For GRIB2 the code reads postxconfig-NT.txt to select variables for output # the available fields are defined in post_avlbflds.xml -- while we # set a link to this file for reading during runtime it is not typical # for one to update this file, therefore the link goes back to the # program directory - this is true for params_grib2_tbl_new also - a # file which defines the GRIB2 table values ln -fs ${txtCntrlFile} postxconfig-NT.txt ln -fs ${UNIPOST_HOME}/parm/post_avblflds.xml post_avblflds.xml ln -fs ${UNIPOST_HOME}/parm/params_grib2_tbl_new params_grib2_tbl_new fi # Link microphysics tables - code will use based on mp_physics option # found in data ln -fs ${UNIPOST_HOME}/parm/nam_micro_lookup.dat . ln -fs ${UNIPOST_HOME}/parm/hires_micro_lookup.dat . # link coefficients for crtm2 (simulated synthetic satellites) CRTMDIR=${UNIPOST_HOME}/sorc/comlibs/crtm2/src/fix ln -fs $CRTMDIR/EmisCoeff/IR_Water/Big_Endian/Nalli.IRwater.EmisCoeff.bin ./ ln -fs $CRTMDIR/EmisCoeff/MW_Water/Big_Endian/FASTEM4.MWwater.EmisCoeff.bin ./ ln -fs $CRTMDIR/EmisCoeff/MW_Water/Big_Endian/FASTEM5.MWwater.EmisCoeff.bin ./ ln -fs $CRTMDIR/EmisCoeff/MW_Water/Big_Endian/FASTEM6.MWwater.EmisCoeff.bin ./ ln -fs $CRTMDIR/EmisCoeff/IR_Land/SEcategory/Big_Endian/NPOESS.IRland.EmisCoeff.bin ./ ln -fs $CRTMDIR/EmisCoeff/IR_Snow/SEcategory/Big_Endian/NPOESS.IRsnow.EmisCoeff.bin ./ ln -fs $CRTMDIR/EmisCoeff/IR_Ice/SEcategory/Big_Endian/NPOESS.IRice.EmisCoeff.bin ./ ln -fs $CRTMDIR/AerosolCoeff/Big_Endian/AerosolCoeff.bin ./ ln -fs $CRTMDIR/CloudCoeff/Big_Endian/CloudCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/imgr_g11.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/imgr_g11.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/imgr_g12.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/imgr_g12.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/imgr_g13.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/imgr_g13.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/imgr_g15.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/imgr_g15.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/imgr_mt1r.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/imgr_mt1r.TauCoeff.bin ln -fs $CRTMDIR/SpcCoeff/Big_Endian/imgr_mt2.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/imgr_mt2.TauCoeff.bin ln -fs $CRTMDIR/SpcCoeff/Big_Endian/imgr_insat3d.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/imgr_insat3d.TauCoeff.bin ln -fs $CRTMDIR/SpcCoeff/Big_Endian/amsre_aqua.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/amsre_aqua.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/tmi_trmm.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/tmi_trmm.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/ssmi_f13.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/ssmi_f13.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/ssmi_f14.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/ssmi_f14.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/ssmi_f15.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/ssmi_f15.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/ssmis_f16.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/ssmis_f16.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/ssmis_f17.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/ssmis_f17.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/ssmis_f18.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/ssmis_f18.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/ssmis_f19.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/ssmis_f19.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/ssmis_f20.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/ssmis_f20.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/seviri_m10.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/seviri_m10.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/v.seviri_m10.SpcCoeff.bin ./ ln -fs $CRTMDIR/TauCoeff/ODPS/Big_Endian/abi_gr.TauCoeff.bin ./ ln -fs $CRTMDIR/SpcCoeff/Big_Endian/abi_gr.SpcCoeff.bin ./ ####################################################### # 1. Run Unipost # # The Unipost is used to read native WRF model # output and put out isobaric state fields and derived fields. ####################################################### export NEWDATE=$startdate YYY=`echo $startdate | cut -c1-4` MMM=`echo $startdate | cut -c5-6` DDD=`echo $startdate | cut -c7-8` HHH=`echo $startdate | cut -c9-10` while [ $((10#${fhr})) -le $((10#${lastfhr})) ]; do # Formatted fhr for filenames fhr=`printf "%02i" ${fhr}` fhour=`printf "%03i" ${fhr}` NEWDATE=`${POSTEXEC}/ndate.exe +$((10#${fhr})) $startdate` YY=`echo $NEWDATE | cut -c1-4` MM=`echo $NEWDATE | cut -c5-6` DD=`echo $NEWDATE | cut -c7-8` HH=`echo $NEWDATE | cut -c9-10` iHH=`echo $startdate | cut -c9-10` echo 'NEWDATE' $NEWDATE echo 'YY' $YY # Begin looping through domains list for domain in ${domain_list}; do # Create model file name (inFileName) dom_id=`echo "${domain}" | cut -d 'd' -f 2` if [[ ${dyncore} == "ARW" ]]; then inFileName=${modelDataPath}/wrfout_d${dom_id}_${YY}-${MM}-${DD}_${HH}:00:00 elif [ ${dyncore} == "FV3" ]; then if [[ ${inFormat} == "binarynemsiompiio" ]]; then inFileName=${modelDataPath}/dynf${fhour}.nemsio flxFileName=${modelDataPath}/phyf${fhour}.nemsio elif [ ${inFormat} == "netcdf" ]; then inFileName=${modelDataPath}/gfs.t${fhr}z.atmf006.nc flxFileName=${modelDataPath}/gfs.t${fhr}z.sfcf006.nc fi fi # Check if the files exist if [[ ! -e ${inFileName} ]]; then echo "ERROR: Can't find 'inFileName': ${inFileName}. Directory or file does not exist. Exiting..." echo "ERROR: Check if 'modelDataPath': ${modelDataPath} exists." if [[ ${dyncore} == "ARW" ]]; then echo "ERROR: Check if file: 'wrfout_d${dom_id}_${YY}-${MM}-${DD}_${HH}:00:00' exists in modelDataPath." elif [ ${dyncore} == "FV3" ]; then echo "ERROR: Check if file: 'dynf${fhour}.nemsio' exists in modelDataPath." # echo "ERROR: Check if file: 'gfs.t${iHH}z.sfcf${fhour}.nemsio' exists in modelDataPath." fi exit 1 fi # Check if that flux file exists for FV3 if [ ${dyncore} == "FV3" ]; then if [[ ! -e ${flxFileName} ]]; then echo "ERROR: Can't find 'flxFileName': ${flxFileName}. Directory or file does not exist. Exiting..." echo "ERROR: Check if 'modelDataPath': ${modelDataPath} exists." echo "ERROR: Check if file: 'phyf${fhour}.nemsio' exists in modelDataPath." # echo "ERROR: Check if file: 'gfs.t${iHH}z.sfcf${fhour}.nemsio' exists in modelDataPath." exit 1 fi fi # Create itag based on user provided info. # Output format now set by user so if-block below uses this # to generate the correct itag. if [[ ${outFormat} == "grib" ]]; then cat > itag < itag < itag < unipost_${domain}.${fhr}.out 2>&1 elif [ ${dyncore} == "FV3" ]; then ${RUN_COMMAND} > unipost.${fhr}.out 2>&1 fi #---------------------------------------------------------------------- # DEBUG Example, uncomment below and comment ${RUN_COMMAND} line above. # debugger runs - enter your debugger and hour of error #if [[ $((10#${fhr})) -eq 3 ]]; then # mpirun.dbg.totalview -progname ${POSTEXEC}/unipost.exe > unipost_${domain}.${fhr}.out 2>&1 #else # mpirun -np 1 ${POSTEXEC}/unipost.exe > unipost_${domain}.${fhr}.out 2>&1 #fi #---------------------------------------------------------------------- # This prefix was given in the wrf_cntl.parm file (GRIB1) # or postcntrl.xml(GRIB2) if [[ ${dyncore} == "ARW" ]]; then mv WRFPRS${fhr}.${tmmark} WRFPRS_${domain}.${fhr} elif [ ${dyncore} == "FV3" ]; then mv GFSPRS.GrbF${fhr} GFSPRS.${fhr} fi # #---------------------------------------------------------------------- # End of unipost job #---------------------------------------------------------------------- # check to make sure UPP was successful and script linked the file if [[ ${dyncore} == "ARW" ]]; then ls -l WRFPRS_${domain}.${fhr} err1=$? elif [ ${dyncore} == "FV3" ]; then ls -l GFSPRS.${fhr} err1=$? fi if test "$err1" -ne 0; then echo 'UNIPOST FAILED, EXITTING' exit fi ####################################################### # 2. Run GEMPAK to plot results. # Use gempak to first convert Grib to GEMPAK binary and # then plot various fields ####################################################### if [[ $dyncore = "ARW" ]]; then fname=WRFPRS_${domain}.${fhr} cntlfname=WRFPRS_${domain}_${fhr} elif [[ $dyncore = "FV3" ]]; then fname=GFSPRS.${fhr} cntlfname=GFSPRS_${fhr} fi rm -f ${cntlfname}.grd nagrib<< EOF GBFILE=${fname} GDOUTF=${cntlfname}.grd MAXGRD=3000 CPYFIL=gds OUTPUT=t GBTBLS= GAREA=dset PROJ= KXKY= run GBFILE=${fname} GDOUTF=${cntlfname}.grd r exit EOF # plot difference fields gdplot<< EOF GDFILE = ${cntlfname}.grd GDATTIM = LAST GLEVEL = 0 GVCORD = none PANEL = 0 SCALE = 0 GFUNC = p${incrementhr}m CTYPE = f FINT = 0.01;1;3;6;9;12;15;18;21 FLINE = 32;3;22;26;25;24;17;16;15;14 fline = 32;21-29;14-18 CLRBAR = 1 GVECT = CLEAR = YES MAP = 1 TITLE = 1//^ Mean SLP and ${incrementhr} hourly Precip DEVICE = GIF|Sfcmap_${domain}_${fhr}.gif run GDFILE = ${cntlfname}.grd CLEAR = N CTYPE = C CINT = 4 SCALE = 0 GFUNC = EMSL LINE = 7 TITLE = 0 run CLEAR = YES GFUNC = WXTS FINT = 0.5;0.99 FLINE = 0;0;4 CTYPE = F TITLE = 1//^ Precip Type: Green for Rain and Blue for Snow CLRBAR = 0 DEVICE = GIF|PrecipType_${domain}_${fhr}.gif run CLEAR = N GFUNC = WXTR FINT = 0.5;0.99 FLINE = 0;0;3 CTYPE = F TITLE = 0 DEVICE = GIF|PrecipType_${domain}_${fhr}.gif run CLEAR = YES GFUNC = RELH GLEVEL = 850 GVCORD = pres FINT = 70;75;80;85;90;92;94;96;98;99 FLINE = 32;3;22;26;25;24;17;16;15;14;8 CTYPE = F TITLE = 1//^ 850 mb RH CLRBAR = 1 DEVICE = GIF|850mbRH_${domain}_${fhr}.gif run CLEAR = YES GFUNC = tmpc GLEVEL = 850 GVCORD = pres SKIP = /15;15 FINT = -20;-15;-10;-5;0;5;10;15;20 FLINE = 32;24;25;26;22;17;16;15;14;8 CTYPE = F TITLE = 1//^ 850 mb Temperature and Wind CLRBAR = 1 GVECT = wnd WIND = BM1 DEVICE = GIF|850mbTempandWind_${domain}_${fhr}.gif run CLEAR = YES GFUNC = AVOR GLEVEL = 500 GVCORD = pres FINT = 16;20;24;28;32;36;40 FLINE = 32;3;22;26;25;24;17;16 CTYPE = F TITLE = 1//^ 500 mb Height and Vorticity CLRBAR = 1 SCALE = 5 GVECT = DEVICE = GIF|500mbHandVort_${domain}_${fhr}.gif run CLEAR = N SCALE = 0 GFUNC = HGHT CTYPE = C cint = 60 LINE = 5 TITLE = 0 run CLEAR = YES GFUNC = sqrt(dot(wnd,wnd)) GLEVEL = 250 GVCORD = pres FINT = 50;60;70;90;110;130;150 FLINE = 32;3;22;26;25;24;17;16 CTYPE = F TITLE = 1//^ 250 mb Height and Wind Speed CLRBAR = 1 DEVICE = GIF|250mbWindandH_${domain}_${fhr}.gif run CLEAR = N SCALE = 0 GFUNC = HGHT CTYPE = C LINE = 5 cint = 120 TITLE = 0 run exit EOF gpend #---------------------------------------------------------------------- # End of GEMPAK job #---------------------------------------------------------------------- done fhr=$((10#${fhr}+$((${incrementhr})))) NEWDATE=`date '+%Y%m%d%H' --date="$YYY$MMM$DDD $HHH $((10#${fhr})) hour"` done date echo "End of Output Job" exit