#!/bin/sh
# Script Name:  nos_ofs_create_forcing_met.sh
#
# Purpose:
#   This program is used to read NCEP atmospheric operational products of grib2 files
#   such as NAM,GFS, and RTMA,etc. to generated surface forcing file for ROMS. The most recent available
#   products for the given time are are searched and used to generate meteorological forcing files. The wind vectors are rotated to earth coordinates.
#   The missing variables are filled with a missing value of -99999.0.
#
# Location:   ~/scripts 
# Technical Contact:   	Aijun Zhang         Org:  NOS/CO-OPS
#                       Phone: 301-7132890 ext. 127  
#                       E-Mail: aijun.zhang@noaa.gov
#
#  Usage: ./nos_ofs_create_forcing_met.sh 
#
# Input Parameters:
#  RUNTYPE: "NOWCAST" or "FORECAST"
#  RUN:             Name of Operational Forecast System, e.g., cbofs, dbofs, tbofs
#  DBASE:           Name of NCEP operational meteological products such NAM, GFS, RTMA..
#  time_start:  start time to grab data, e.g., YYYYMMDDHH (2008101500)
#  time_end:    end time to grab data, e.g., YYYYMMDDHH (2008101600)
#  IGRD_MET: =0, The output is on the native AWIPS Grid 218 (coarse grid)
#        =1, The output is on the ocean model grid (ROMS), remesh routine (from Tom Gross and used by
#            Greg for GLOFS) is used for spatial interpolation. 
#        =2, The output is on the ocean model grid (ROMS), bicubic routine (from ROMS) 
#            is used for spatial interpolation. 
#        =3, The output is on the ocean model grid (ROMS), bilinear routine (from ROMS) 
#            is used for spatial interpolation. 
#        =4, on ocean model grid (rotated to local coordinates) interpolated using nature neighbors routine.
#
# Language:   Bourne Shell Script      
#
# Target Computer: IBM P757 Supter Computer at NCEP
#
# Estimated Execution Time: 1800s 
#
# Suboutines/Functions Called:
#     nos_ofs_create_forcing_met.f   
#
# Input Files:
#     ROMS ocean model grid netCDF file  
#
# Output Files:
##    ----  nowcast  ---- 
#     nos.${RUN}.met.nowcast.$yyyy$mm$dd.t${cyc}z.nc
#     nos.${RUN}.hflux.nowcast.$yyyy$mm$dd.t${cyc}z.nc
#     Fortran.${RUN}.nowcast.log
#     ----  forecast ----
#     nos.${RUN}.met.forecast.$yyyy$mm$dd.t${cyc}z.nc
#     nos.${RUN}.hflux.forecast.$yyyy$mm$dd.t${cyc}z.nc 
#     Fortran.${RUN}.forecast.log 
#
# Libraries Used: see the makefile
#  
# Error Conditions:
#
# Modification: 
#   (1).  Degui Cao       degui.cao@noaa.gov           /1/14/2010 
#         Implementing in the super computer
#
# -------------------------------------------------------------------------------
#seton='-xa'
#setoff='-xa'
#set $seton

set $setoff
set -xa

echo 'The script nos_ofs_create_forcing_met.sh starts at time: ' `date `
echo 'The script nos_ofs_create_forcing_met.sh starts at time: ' `date ` >> $jlogfile
RUNTYPE=$1
if [ $OCEAN_MODEL == 'ROMS' -o $OCEAN_MODEL == 'roms' ]
then
  export EXFILE='nos_ofs_create_forcing_met'
elif [ $OCEAN_MODEL == 'FVCOM' -o $OCEAN_MODEL == 'SELFE' ]
then
  export EXFILE='nos_ofs_create_forcing_met_fvcom'
fi  
if [ $RUNTYPE == "NOWCAST" -o $RUNTYPE == "nowcast" ]
then
  DBASE=$DBASE_MET_NOW
  TIME_START=${time_hotstart}
  TIME_END=$time_nowcastend
  OUTPUTFILE=$MET_NETCDF_1_NOWCAST
  OUTPUTFILE1=$MET_NETCDF_2_NOWCAST
elif [ $RUNTYPE == "FORECAST" -o $RUNTYPE == "forecast" ]
then
  DBASE=$DBASE_MET_FOR
  TIME_START=${time_nowcastend}
  TIME_END=$time_forecastend
  OUTPUTFILE=$MET_NETCDF_1_FORECAST
  OUTPUTFILE1=$MET_NETCDF_2_FORECAST
fi
rm -f *.$DBASE
rm -f *.$DBASE_MET_FOR
#cp -p $FIXnos/LAND.* $DATA
INPUTTIME=$TIME_START
typeset -Z2 HH HH3 CYCLE
YYYY=`echo $TIME_START | cut -c1-4 `
MM=`echo $TIME_START |cut -c5-6 `
DD=`echo $TIME_START |cut -c7-8 `
CYCLE=`echo $TIME_START |cut -c9-10 `

# make sure to get enough data, two additional hours will be acquired. 
#TIME_START=` $NDATE -3 $TIME_START `
#TIME_END=` $NDATE 3 $TIME_END `
LENGTH=` $NHOUR $TIME_END $TIME_START `
NPP=14
VARNAME[0]='TMP'
VARNAME[1]='DPT'
VARNAME[2]='UGRD'
VARNAME[3]='VGRD'
VARNAME[4]='RH'
VARNAME[5]='PRMSL'
VARNAME[6]='DLWRF'
VARNAME[7]='ULWRF'
VARNAME[8]='DSWRF'
VARNAME[9]='USWRF'
VARNAME[10]='LHTFL'
VARNAME[11]='SHTFL'
VARNAME[12]='SPFH'
VARNAME[13]='PRATE'
VARNAME[14]='PRES'
VARNAME[15]='WTMP'
VARNAME[16]='TCDC'
VARNAME[17]='APCP'
LEV[0]=':2 m above ground:'
LEV[1]=':2 m above ground:'
LEV[2]=':10 m above ground:'
LEV[3]=':10 m above ground:'
LEV[4]=':2 m above ground:'
LEV[5]=':mean sea level:'
LEV[6]=':surface:'
LEV[7]=':surface:'
LEV[8]=':surface:'
LEV[9]=':surface:'
LEV[10]=':surface:'
LEV[11]=':surface:'
LEV[12]=':2 m above ground:'
LEV[13]=':surface:'
LEV[14]=':surface:'
LEV[15]=':surface:'
LEV[16]=':NCEP level type 200'
LEV[17]=':surface:'
HH=00

##  find grib2 file at forecast project hour 00 of 
##  the most recently available cycle of NCEP atmospheric operational products
HH=00

if [ $DBASE == "RUC" ]; then 
     modelist="RUC NAM GFS"
elif [ $DBASE == "RTMA" ]; then
     modelist="RTMA NAM GFS"
elif [ $DBASE == "NAM" ]; then
     modelist="NAM GFS"
elif [ $DBASE == "GFS" ]; then
     modelist="GFS NAM"
elif [ $DBASE == "NAM4" ]; then
     modelist="NAM4 NAM GFS"
fi
 
totalcheck=`echo "$modelist"|wc -w`
numcheck=0
 
for modelcheck in $modelist
do
 
   if [ $modelcheck == "NAM" ] || [ $modelcheck == "GFS" ] || [ $modelcheck == "NAM4" ]; then 
      tlength=36
   else
      tlength=6
   fi 

   numcheck=`expr $numcheck + 1`

   CURRENTTIME=$INPUTTIME

   YYYY=`echo $CURRENTTIME | cut -c1-4 `
   MM=`echo $CURRENTTIME |cut -c5-6 `
   DD=`echo $CURRENTTIME |cut -c7-8 `
   CYCLE=`echo $CURRENTTIME |cut -c9-10 `

   if [ $modelcheck == "NAM" ]
   then
     NCEPPRODDIR=$COMNAM'/nam.'$YYYY$MM$DD
     GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.awip12${HH}.tm00.grib2"
   elif [ $modelcheck == "GFS" ]
   then
     NCEPPRODDIR=${COMGFS}'/gfs.'$YYYY$MM$DD
     GRB2FILE=$NCEPPRODDIR/"gfs.t${CYCLE}z.pgrb2f${HH}"
   elif [ $modelcheck == "RTMA" ]
   then
     NCEPPRODDIR=$COMRTMA'/rtma.'$YYYY$MM$DD
     GRB2FILE=$NCEPPRODDIR/"rtma.t${HH}z.2dvaranl_ndfd.grb2"
   elif [ $modelcheck == "RUC" ]
   then
    NCEPPRODDIR=${COMRUC}'/ruc2a.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"ruc2.t${CYCLE}z.bgrb13f${HH}.grib2"
    GRB2FILE1=$NCEPPRODDIR/"ruc2.t${CYCLE}z.pgrb13f${HH}.grib2"
   elif [ $modelcheck == "NAM4" ]
   then
     NCEPPRODDIR=$COMNAM'/nam.'$YYYY$MM$DD
     GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.conusnest.hiresf${HH}.tm00.grib2_nos"
   fi 

   while [ ! -s $GRB2FILE ]
   do
     echo 'grib2 file is ' $GRB2FILE 'not found'
  
     CURRENTTIME=`$NDATE -1 $CURRENTTIME `
     if [ $CURRENTTIME -le ` $NDATE -$tlength $INPUTTIME ` ]
     then
       if [ $numcheck -lt $totalcheck ]
       then
         echo 'no valid atmospheric $modelcheck products is available for the given time period'
         msg=" no valid atmospheric $modelcheck products is available for the given time period  "
         ./postmsg "$jlogfile" "$msg"
         msg="check the atmospheric operational products at the given time period"  
         ./postmsg "$jlogfile" "$msg"
         break
       fi
      
       if [ $numcheck -eq $totalcheck ]  
       then
         echo 'Abnormal exit: no any atmospheric operational products available for the given time period'
         msg="ABNORMAL EXIT: no any atmospheric operational products available for the given time period  "
         ./postmsg "$jlogfile" "$msg"
         msg="check the atmospheric operational products at the given time period"  
         ./postmsg "$jlogfile" "$msg"
         touch err.${RUN}.$PDY1.t${HH}z
         err=1;export err;err_chk     
         exit
       fi
     fi
     
     YYYY=`echo $CURRENTTIME | cut -c1-4 `
     MM=`echo $CURRENTTIME |cut -c5-6 `
     DD=`echo $CURRENTTIME |cut -c7-8 `
     CYCLE=`echo $CURRENTTIME |cut -c9-10 `

     if [ $modelcheck == "NAM" ]
     then
       NCEPPRODDIR=$COMNAM'/nam.'$YYYY$MM$DD
       GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.awip12${HH}.tm00.grib2"
     elif [ $modelcheck == "GFS" ]
     then
       NCEPPRODDIR=${COMGFS}'/gfs.'$YYYY$MM$DD
       GRB2FILE=$NCEPPRODDIR/"gfs.t${CYCLE}z.pgrb2f${HH}"
     elif [ $modelcheck == "RTMA" ]
     then
       NCEPPRODDIR=$COMRTMA'/rtma.'$YYYY$MM$DD
       GRB2FILE=$NCEPPRODDIR/"rtma.t${HH}z.2dvaranl_ndfd.grb2"
     elif [ $modelcheck == "RUC" ]
     then
       NCEPPRODDIR=${COMRUC}'/ruc2a.'$YYYY$MM$DD
       GRB2FILE=$NCEPPRODDIR/"ruc2.t${CYCLE}z.bgrb13f${HH}.grib2"
       GRB2FILE1=$NCEPPRODDIR/"ruc2.t${CYCLE}z.pgrb13f${HH}.grib2"
     elif [ $modelcheck == "NAM4" ]
     then
       NCEPPRODDIR=$COMNAM'/nam.'$YYYY$MM$DD
       GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.conusnest.hiresf${HH}.tm00.grib2_nos"
     fi

   done

   if [ -s $GRB2FILE ];   then 
      break  
   fi

done      # end of atmos prod check

export DBASE=$modelcheck     ## Assign the existing prod checked to the DBASE

echo "The current DBASE is $DBASE "
##  Begin reading land-sea mask
TMPGRB2=${RUN}_${DBASE}.grib2
if [ $DBASE == "NAM" ]
then
    NCEPPRODDIR=$COMNAM'/nam.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.awip12${HH}.tm00.grib2"
    $WGRIB2 $GRB2FILE -small_grib ${MINLON}:${MAXLON} ${MINLAT}:${MAXLAT} $TMPGRB2 
    $WGRIB2 $TMPGRB2 -s | grep "LAND:surface" | $WGRIB2 -i $TMPGRB2 -spread tmp.txt
    if [ -s tmp.txt ]
    then
       mv tmp.txt LAND.$DBASE
    fi	  
    
elif [ $DBASE == "GFS" ]
then
    NCEPPRODDIR=${COMGFS}'/gfs.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"gfs.t${CYCLE}z.pgrb2f${HH}"
    $WGRIB2 $GRB2FILE -small_grib ${MINLON}:${MAXLON} ${MINLAT}:${MAXLAT} $TMPGRB2 
    $WGRIB2 $TMPGRB2 -s | grep "LAND:surface" | $WGRIB2 -i $TMPGRB2 -spread tmp.txt
    if [ -s tmp.txt ]
    then
       mv tmp.txt LAND.$DBASE
    fi	  

elif [ $DBASE == "RTMA" ]
then
    NCEPPRODDIR=$COMRTMA'/rtma.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"rtma.t${HH}z.2dvaranl_ndfd.grb2"
    $WGRIB2 $GRB2FILE -small_grib ${MINLON}:${MAXLON} ${MINLAT}:${MAXLAT} $TMPGRB2 
    $WGRIB2 $TMPGRB2 -s | grep "LAND:surface" | $WGRIB2 -i $TMPGRB2 -spread tmp.txt
    if [ -s tmp.txt ]
    then
       mv tmp.txt LAND.$DBASE
    fi	

elif [ $DBASE == "RUC" ]
then
    NCEPPRODDIR=${COMRUC}'/ruc2a.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"ruc2.t${CYCLE}z.bgrb13f${HH}.grib2"
    GRB2FILE1=$NCEPPRODDIR/"ruc2.t${CYCLE}z.pgrb13f${HH}.grib2"
    $WGRIB2 $GRB2FILE -small_grib ${MINLON}:${MAXLON} ${MINLAT}:${MAXLAT} $TMPGRB2 
    $WGRIB2 $TMPGRB2 -s | grep "LAND:surface" | $WGRIB2 -i $TMPGRB2 -spread tmp.txt
    if [ -s tmp.txt ]
    then
       mv tmp.txt LAND.$DBASE
    fi	  
elif [ $DBASE == "NAM4" ]
then
    NCEPPRODDIR=$COMNAM'/nam.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.conusnest.hiresf${HH}.tm00.grib2"
    $WGRIB2 $GRB2FILE -small_grib ${MINLON}:${MAXLON} ${MINLAT}:${MAXLAT} $TMPGRB2 
    $WGRIB2 $TMPGRB2 -s | grep "LAND:surface" | $WGRIB2 -i $TMPGRB2 -spread tmp.txt
    if [ -s tmp.txt ]
    then
       mv tmp.txt LAND.$DBASE
    fi	  
fi  
##  END reading land-sea mask

if [ $DBASE == "NAM" ]
then
    NCEPPRODDIR=$COMNAM'/nam.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.awip12${HH}.tm00.grib2"
    
elif [ $DBASE == "NAM4" ]
then
    NCEPPRODDIR=$COMNAM'/nam.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.conusnest.hiresf${HH}.tm00.grib2_nos"

elif [ $DBASE == "GFS" ]
then
    NCEPPRODDIR=${COMGFS}'/gfs.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"gfs.t${CYCLE}z.pgrb2f${HH}"

elif [ $DBASE == "RTMA" ]
then
    NCEPPRODDIR=$COMRTMA'/rtma.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"rtma.t${HH}z.2dvaranl_ndfd.grb2"
    NPP=6
    VARNAME[0]='PRES'
    VARNAME[1]='TMP'
    VARNAME[2]='DPT'
    VARNAME[3]='UGRD'
    VARNAME[4]='VGRD'
    VARNAME[5]='SPFH'
    LEV[0]=':surface:'
    LEV[1]=':2 m above ground:'
    LEV[2]=':2 m above ground:'
    LEV[3]=':10 m above ground:'
    LEV[4]=':10 m above ground:'
    LEV[5]=':2 m above ground:'
 ##  echo ${VARNAME[0]}${LEV[0]}
elif [ $DBASE == "RUC" ]
then
    NCEPPRODDIR=${COMRUC}'/ruc2a.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"ruc2.t${CYCLE}z.bgrb13f${HH}.grib2"
    GRB2FILE1=$NCEPPRODDIR/"ruc2.t${CYCLE}z.pgrb13f${HH}.grib2"
    NPP=12
    VARNAME[0]='MSLMA'
    VARNAME[1]='TMP'
    VARNAME[2]='DPT'
    VARNAME[3]='UGRD'
    VARNAME[4]='VGRD'
    VARNAME[5]='RH'
    VARNAME[6]='NLWRS'
    VARNAME[7]='NSWRS'
    VARNAME[8]='LHTFL'
    VARNAME[9]='SHTFL'
    VARNAME[10]='SPFH'
    VARNAME[11]='PRATE'
    LEV[0]=':mean sea level:'
    LEV[1]=':2 m above ground:'
    LEV[2]=':2 m above ground:'
    LEV[3]=':10 m above ground:'
    LEV[4]=':10 m above ground:'
    LEV[5]=':2 m above ground:'
    LEV[6]=':surface:'
    LEV[7]=':surface:'
    LEV[8]=':surface:'
    LEV[9]=':surface:'
    LEV[10]=':2 m above ground:'
    LEV[11]=':surface:'
fi  

echo 'Time of the most recent available products is ' $DBASE 'at cycle' $YYYY $MM $DD $CYCLE
echo 'Time of the most recent available products is ' $DBASE 'at cycle' $YYYY $MM $DD $CYCLE >> $jlogfile

#  read in data from hour 00z to 60z of the most recent cycle
YYYY=`echo $CURRENTTIME | cut -c1-4 `
MM=`echo $CURRENTTIME |cut -c5-6 `
DD=`echo $CURRENTTIME |cut -c7-8 `
TMPDATE=$YYYY$MM$DD
YYYY=`echo $TIME_END | cut -c1-4 `
MM=`echo $TIME_END |cut -c5-6 `
DD=`echo $TIME_END |cut -c7-8 `
ENDDATE=$YYYY$MM$DD

rm -f tmp.out tmp1.out   
if [ $DBASE == "RTMA" -o $DBASE == "RUC" -o $DBASE == "RAP" ]; then
  while [ $TMPDATE -le $ENDDATE ]
  do 
    if [ $DBASE == "RTMA" ]; then
      ls -l ${COMRTMA}/rtma.${TMPDATE}/rtma.t*z.2dvaranl_ndfd.grb2 | awk '{print $9}' >> tmp.out
    elif [ $DBASE == "RUC" ]; then
      ls -l ${COMRUC}/ruc2a.${TMPDATE}/ruc2.t*.bgrb13f*.grib2 | awk '{print $9}' >> tmp.out
      ls -l ${COMRUC}/ruc2a.${TMPDATE}/ruc2.t*.pgrb13f*.grib2 | awk '{print $9}' >> tmp1.out
    elif [ $DBASE == "RAP" ]; then
      ls -l ${COMRAP}/rap.${TMPDATE}/rap.t*z.awp130bgrbf??.grib2 | awk '{print $9}' >> tmp.out
      ls -l ${COMRAP}/rap.${TMPDATE}/rap.t*z.awp130pgrbf??.grib2 | awk '{print $9}' >> tmp1.out
    fi

    CURRENTTIME=`$NDATE +24 $CURRENTTIME `
    YYYY=`echo $CURRENTTIME | cut -c1-4 `
    MM=`echo $CURRENTTIME |cut -c5-6 `
    DD=`echo $CURRENTTIME |cut -c7-8 `
    TMPDATE=$YYYY$MM$DD
  done
else
  if [ $DBASE == "NAM" ]
  then
    ls -l ${COMNAM}/nam.${TMPDATE}/nam.t${CYCLE}z.awip12*tm00.grib2 | awk '{print $9}' >> tmp.out

  elif [ $DBASE == "NAM4" ]
  then
    ls -l ${COMNAM}/nam.${TMPDATE}/nam.t${CYCLE}z.conusnest.hiresf*tm00.grib2_nos | awk '{print $9}' >> tmp.out
    
  elif [ $DBASE == "GFS" ]
  then
    ls -l ${COMGFS}/gfs.${TMPDATE}/gfs.t${CYCLE}z.pgrb2f?? | awk '{print $9}' >> tmp.out

  fi
fi


if [ -s tmp.out ]
then
   rm -f Fortran_file_search.ctl Fortran_file_search.log
   MET_FILE=${DBASE}_FILE_${RUNTYPE}.dat
   echo $TIME_START > Fortran_file_search.ctl
   echo $TIME_END >> Fortran_file_search.ctl
   echo tmp.out >> Fortran_file_search.ctl
   echo $MET_FILE >> Fortran_file_search.ctl
if [ ! -s $EXECnos/nos_ofs_met_file_search -a  ! -x  $EXECnos/nos_ofs_met_file_search ]
then
  echo "$EXECnos/nos_ofs_met_file_search does not exist" 
  msg="$EXECnos/nos_ofs_met_file_search does not exist  "
  ./postmsg "$jlogfile" "$msg"
  err=1;export err;err_chk
  exit
fi   

export pgm=nos_ofs_met_file_search
. ./prep_step

./startmsg

 $EXECnos/nos_ofs_met_file_search < Fortran_file_search.ctl > Fortran_file_search.log
 export err=$?

if [ $err -ne 0 ]
then
  echo "$pgm did not complete normally, critical failure!"
  msg="$pgm did not complete normally, critical failure!"
  ./postmsg "$jlogfile" "$msg"
  ./err_chk
else
  echo "$pgm completed normally"
  msg="$pgm completed normally"
  ./postmsg "$jlogfile" "$msg"

  if grep "COMPLETED SUCCESSFULLY" Fortran_file_search.log /dev/null 2>&1
  then
  echo "MET FILE SEARCH ${RUNTYPE} ${DBASE} COMPLETED SUCCESSFULLY 100" >> $CORMSLOG
  else
  echo "MET FILE SEARCH ${RUNTYPE} ${DBASE} COMPLETED SUCCESSFULLY 0" >> $CORMSLOG
  fi
fi

fi

if [ -s $MET_FILE ]
then
   exec 5<&0 < $MET_FILE
   while read GRB2FILE 
   do
     read YYYY MM DD CYC HH
     echo $GRB2FILE
     if [ $DBASE == "RUC" ]
     then
       GRB2FILE1=`echo $GRB2FILE | sed 's/bgrb13/pgrb13/' `
       echo $GRB2FILE1
     fi   
     TMPGRB2=${RUN}_${DBASE}.grib2
     TMP1GRB2=${RUN}_${DBASE}1.grib2
     if [ -s $TMPGRB2 ]
     then
        rm -f $TMPGRB2 $TMP1GRB2
     fi
     $WGRIB2 $GRB2FILE -small_grib ${MINLON}:${MAXLON} ${MINLAT}:${MAXLAT} $TMPGRB2 
     if [ $DBASE == "RUC" ]
     then
       $WGRIB2 $GRB2FILE1 -small_grib ${MINLON}:${MAXLON} ${MINLAT}:${MAXLAT} $TMP1GRB2 
     fi   
     N=0
#     if [ $DBASE == "NAM" -o  $DBASE == "NAM4" ]; then
#       N=1
#     fi 
     while (( N < $HH))
     do
       (( N = N + 1 ))
     done
     count=0
     (( N3 = $N - 3 ))
     if [ $N3 -lt 0 ]
     then
        N3=0
     fi   
     while (( count < $NPP))
     do
       if [ $N = 0 ]
       then
          FPSTG="anl"
       else 
          FPSTG="$N hour fcst"
       fi   
       if [ $count = 16 ]
       then
         FPSTG="${N3}-${N} hour fcst"
       fi   
       if [ $DBASE == 'GFS' ]
       then
          if [ $count -ge 6 -a $count -le 11 ]
	  then
             FPSTG=""
          fi   
          if [  $count = 14 -o $count = 15  ]
	  then
             FPSTG=""
          fi
       fi	     
       if [ $DBASE == 'RTMA' ]
       then
          FPSTG="anl"
       fi   
    
       echo decoding ${VARNAME[count]}
       if [ -s tmp.txt ]
       then
         rm -f tmp.txt
       fi	 
         $WGRIB2 $TMPGRB2 -s | grep "${VARNAME[count]}${LEV[count]}$FPSTG" | sed '2,$d' | $WGRIB2 -i $TMPGRB2 -spread tmp.txt
       if [ $DBASE == 'RUC' -a \( $count = 2 -o $count = 5 \) ]
       then
         $WGRIB2 $TMP1GRB2 -s | grep "${VARNAME[count]}${LEV[count]}$FPSTG" | sed '2,$d' | $WGRIB2 -i $TMP1GRB2 -spread tmp.txt
       fi   
       if [ -s tmp.txt ]
       then
          cat tmp.txt >> ${VARNAME[count]}.$DBASE
       fi	  
       (( count = count + 1 ))
     done
   done 3<&-  
else
  echo "no Meteorological product files are found in time period from $TIME_START to $TIME_END"
   msg=" no Meteorological product files are found in time period from $TIME_START to $TIME_END   "
   ./postmsg "$jlogfile" "$msg"
   err=1;export err;err_chk
fi   
count=0
while (( count < $NPP))
do
   if [ ! -s ${VARNAME[count]}.$DBASE ]
   then
      echo ${VARNAME[count]}.$DBASE
      rm -f ${VARNAME[count]}.$DBASE
   fi   
   (( count = count + 1 ))
   
done
if [ -s PRES.RTMA ]
then
   mv PRES.RTMA PRMSL.RTMA
fi
if [ -s MSLMA.RUC ]
then
   mv MSLMA.RUC PRMSL.RUC
fi
rm -f Fortran_met.ctl ${DBASE}_Fortran.log
echo ${RUN} > Fortran_met.ctl
echo $DBASE >> Fortran_met.ctl
echo $OCEAN_MODEL >> Fortran_met.ctl
echo $TIME_START >> Fortran_met.ctl
echo $TIME_END >> Fortran_met.ctl
echo $IGRD_MET >> Fortran_met.ctl
echo $TMPGRB2 >> Fortran_met.ctl
echo $GRIDFILE >> Fortran_met.ctl
echo $OUTPUTFILE >> Fortran_met.ctl
echo $BASE_DATE >> Fortran_met.ctl 
echo $MINLON  >> Fortran_met.ctl
echo $MINLAT >> Fortran_met.ctl 
echo $MAXLON >> Fortran_met.ctl 
echo $MAXLAT >> Fortran_met.ctl 
echo $SCALE_HFLUX >> Fortran_met.ctl 
if [ ! -s $EXECnos/$EXFILE -o  ! -x  $EXECnos/$EXFILE ]
then
  echo "$EXECnos/$EXFILE does not exist"
  msg="$EXECnos/$EXFILE does not exist  "
  ./postmsg "$jlogfile" "$msg"
  err=1;export err;err_chk
  exit
fi

export pgm=$EXFILE
. ./prep_step

./startmsg

$EXECnos/$EXFILE < Fortran_met.ctl > ${DBASE}_Fortran.log
 export err=$?

## output corms information
if [ -s ${DBASE}_Fortran.log ]
then
   cp -p ${DBASE}_Fortran.log $COMOUT/$DBASE.${RUNTYPE}_Fortran.t${cyc}z.log

else
   echo "NO $DBASE.${RUNTYPE}_Fortran.t${cyc}z.log Found"
fi

if grep "COMPLETED SUCCESSFULLY" ${DBASE}_Fortran.log /dev/null 2>&1
then
  echo "MET FORCING ${RUNTYPE} ${DBASE} COMPLETED SUCCESSFULLY 100" >> $CORMSLOG
  if [ $RUNTYPE == "NOWCAST" -o $RUNTYPE == "nowcast" ]
  then
     echo MET_NOWCAST DONE 100  >> $CORMSLOG
  else
     echo MET_FORECAST DONE 100  >> $CORMSLOG
  fi

else
   echo "MET FORCING ${RUNTYPE} ${DBASE} COMPLETED SUCCESSFULLY 0" >> $CORMSLOG
   if [ $RUNTYPE == "NOWCAST" -o $RUNTYPE == "nowcast" ]
   then
      echo MET_NOWCAST DONE 0  >> $CORMSLOG
   else
      echo MET_FORECAST DONE 0  >> $CORMSLOG
   fi
   err=1;export err;err_chk
fi

if [ $err -ne 0 ]
then
  echo "$pgm did not complete normally, critical failure!"
  msg="$pgm did not complete normally, critical failure!"
  ./postmsg "$jlogfile" "$msg"
  ./err_chk
else
  echo "$pgm completed normally"
  msg="$pgm completed normally"
  ./postmsg "$jlogfile" "$msg"
fi

if [ $OCEAN_MODEL == 'SELFE' -o $OCEAN_MODEL == 'selfe' ]
then
   if [ -s sflux_air.nc ]
   then 
      cp -p sflux_air.nc sflux_air_1.001.nc
      cp -p sflux_air.nc ${NET}.${RUN}.air.$RUNTYPE.$PDY1.t${cyc}z.nc
   fi
   if [ -s sflux_rad.nc ]
   then
      cp -p sflux_rad.nc sflux_rad_1.001.nc 
      cp -p sflux_rad.nc ${NET}.${RUN}.flux.$RUNTYPE.$PDY1.t${cyc}z.nc
   fi
   if [ -s sflux_prc.nc ]
   then
      cp -p sflux_prc.nc sflux_prc_1.001.nc
      cp -p sflux_prc.nc ${NET}.${RUN}.precip.$RUNTYPE.$PDY1.t${cyc}z.nc
   fi
elif [ $OCEAN_MODEL == 'FVCOM' -o  $OCEAN_MODEL == 'fvcom' ]
then
   if [ $DBASE == 'RTMA' ]
   then
     if [ -s met_fvcom.nc ]
     then
        mv met_fvcom.nc $OUTPUTFILE
     else
        echo 'surface forcing file ' $OUTPUTFILE 'is not generated'
     fi	  	
   else
     if [ -s met_fvcom.nc ]
     then
        mv met_fvcom.nc $OUTPUTFILE
     else
        echo 'surface forcing file ' $OUTPUTFILE 'is not generated'
     fi	  	
     if [ -s hflux_fvcom.nc ]
     then
        mv hflux_fvcom.nc $OUTPUTFILE1
     else
        echo 'surface forcing file ' $OUTPUTFILE1 'is not generate'
     fi	  	
   fi   
fi


## Radiation heat flux from NAM is used if DBASE=RTMA since RTMA does not have radiation heat flux
if [ $DBASE == 'RTMA' ]
then
# DBASE='NAM'   AJ 06/14/2011 
  DBASE=$DBASE_MET_FOR
##  rm -f *.$DBASE
  NPP=14
  VARNAME[0]='TMP'
  VARNAME[1]='DPT'
  VARNAME[2]='UGRD'
  VARNAME[3]='VGRD'
  VARNAME[4]='RH'
  VARNAME[5]='PRMSL'
  VARNAME[6]='DLWRF'
  VARNAME[7]='ULWRF'
  VARNAME[8]='DSWRF'
  VARNAME[9]='USWRF'
  VARNAME[10]='LHTFL'
  VARNAME[11]='SHTFL'
  VARNAME[12]='SPFH'
  VARNAME[13]='PRATE'
  VARNAME[14]='PRES'
  VARNAME[15]='WTMP'
  VARNAME[16]='TCDC'
  VARNAME[17]='APCP'
  LEV[0]=':2 m above ground:'
  LEV[1]=':2 m above ground:'
  LEV[2]=':10 m above ground:'
  LEV[3]=':10 m above ground:'
  LEV[4]=':2 m above ground:'
  LEV[5]=':mean sea level:'
  LEV[6]=':surface:'
  LEV[7]=':surface:'
  LEV[8]=':surface:'
  LEV[9]=':surface:'
  LEV[10]=':surface:'
  LEV[11]=':surface:'
  LEV[12]=':2 m above ground:'
  LEV[13]=':surface:'
  LEV[14]=':surface:'
  LEV[15]=':surface:'
  LEV[16]=':NCEP level type 200'
  LEV[17]=':surface:'
  HH=00
  YYYY=`echo $INPUTTIME | cut -c1-4 `
  MM=`echo $INPUTTIME |cut -c5-6 `
  DD=`echo $INPUTTIME |cut -c7-8 `
  CYCLE=`echo $INPUTTIME |cut -c9-10 `
## find first available GRIB2 file for the TIME_START
  NCEPPRODDIR=${COMNAM}/nam.$YYYY$MM$DD
  GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.awip12${HH}.tm00.grib2"
  if [ $DBASE == "NAM4" ]
  then
      NCEPPRODDIR=$COMNAM'/nam.'$YYYY$MM$DD
      GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.conusnest.hiresf${HH}.tm00.grib2_nos"
  fi  
  CURRENTTIME=$INPUTTIME
  while [ ! -s $GRB2FILE ]
  do
    echo 'grib2 file is ' $GRB2FILE 'not found'
    CURRENTTIME=`$NDATE -1 $CURRENTTIME `
    if [ $CURRENTTIME -le ` $NDATE -60 $INPUTTIME ` ]
    then
      echo 'no valid atmospheric operational products is available for the given time period'
      msg="ABNORMAL EXIT: no valid atmospheric operational products is available for the given time period    "
      ./postmsg "$jlogfile" "$msg"
      err=1;export err;err_chk
      touch err.${RUN}.$PDY1.t${HH}z
      exit
    fi
    YYYY=`echo $CURRENTTIME | cut -c1-4 `
    MM=`echo $CURRENTTIME |cut -c5-6 `
    DD=`echo $CURRENTTIME |cut -c7-8 `
    CYCLE=`echo $CURRENTTIME |cut -c9-10 `
    if [ $DBASE == "NAM" ]
    then
       NCEPPRODDIR=${COMNAM}/nam.$YYYY$MM$DD
       GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.awip12${HH}.tm00.grib2"
    elif [ $DBASE == "NAM4" ]
    then
       NCEPPRODDIR=$COMNAM'/nam.'$YYYY$MM$DD
       GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.conusnest.hiresf${HH}.tm00.grib2_nos"
    fi  
  done
  echo 'Time of the most recent available products is ' $DBASE 'at cycle' $YYYY $MM $DD $CYCLE
############
  TMPGRB2=${RUN}_${DBASE}.grib2
  if [ $DBASE == "NAM" ]
  then
    NCEPPRODDIR=$COMNAM'/nam.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.awip12${HH}.tm00.grib2"
    $WGRIB2 $GRB2FILE -small_grib ${MINLON}:${MAXLON} ${MINLAT}:${MAXLAT} $TMPGRB2 
    $WGRIB2 $TMPGRB2 -s | grep "LAND:surface" | $WGRIB2 -i $TMPGRB2 -spread tmp.txt
    if [ -s tmp.txt ]
    then
       mv tmp.txt LAND.$DBASE
    fi	  
    
  elif [ $DBASE == "GFS" ]
  then
    NCEPPRODDIR=${COMGFS}'/gfs.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"gfs.t${CYCLE}z.pgrb2f${HH}"
    $WGRIB2 $GRB2FILE -small_grib ${MINLON}:${MAXLON} ${MINLAT}:${MAXLAT} $TMPGRB2 
    $WGRIB2 $TMPGRB2 -s | grep "LAND:surface" | $WGRIB2 -i $TMPGRB2 -spread tmp.txt
    if [ -s tmp.txt ]
    then
       mv tmp.txt LAND.$DBASE
    fi	  
  elif [ $DBASE == "NAM4" ]
  then
    NCEPPRODDIR=$COMNAM'/nam.'$YYYY$MM$DD
    GRB2FILE=$NCEPPRODDIR/"nam.t${CYCLE}z.conusnest.hiresf${HH}.tm00.grib2"
    $WGRIB2 $GRB2FILE -small_grib ${MINLON}:${MAXLON} ${MINLAT}:${MAXLAT} $TMPGRB2 
    $WGRIB2 $TMPGRB2 -s | grep "LAND:surface" | $WGRIB2 -i $TMPGRB2 -spread tmp.txt
    if [ -s tmp.txt ]
    then
       mv tmp.txt LAND.$DBASE
    fi	  
  fi  

########
  YYYY=`echo $CURRENTTIME | cut -c1-4 `
  MM=`echo $CURRENTTIME |cut -c5-6 `
  DD=`echo $CURRENTTIME |cut -c7-8 `
  TMPDATE=$YYYY$MM$DD
  YYYY=`echo $TIME_END | cut -c1-4 `
  MM=`echo $TIME_END |cut -c5-6 `
  DD=`echo $TIME_END |cut -c7-8 `
  ENDDATE=$YYYY$MM$DD
  if [ -s tmp.out ]
  then
     rm -f tmp.out
  fi   
  if [ -s tmp1.out ]
  then
     rm -f tmp1.out
  fi   
#  while [ $TMPDATE -le $ENDDATE ]
#  do 
      if [ $DBASE == "NAM" ]
      then
         ls -l ${COMNAM}/nam.${TMPDATE}/nam.t${CYCLE}z.awip12*tm00.grib2 | awk '{print $9}' >> tmp.out
      elif [ $DBASE == "NAM4" ]
      then
         ls -l ${COMNAM}/nam.${TMPDATE}/nam.t${CYCLE}z.conusnest.hiresf*.tm00.grib2_nos | awk '{print $9}' >> tmp.out
      fi  
#
#      CURRENTTIME=`$NDATE +24 $CURRENTTIME `
#      YYYY=`echo $CURRENTTIME | cut -c1-4 `
#      MM=`echo $CURRENTTIME |cut -c5-6 `
#      DD=`echo $CURRENTTIME |cut -c7-8 `
#      TMPDATE=$YYYY$MM$DD
#  done
  if [ -s tmp.out ]
  then
     MET_FILE=${DBASE}_FILE_${RUNTYPE}.dat
     rm -f Fortran_file_search.ctl

     echo $TIME_START > Fortran_file_search.ctl
     echo $TIME_END >> Fortran_file_search.ctl
     echo tmp.out >> Fortran_file_search.ctl
     echo $MET_FILE >> Fortran_file_search.ctl
     $EXECnos/nos_ofs_met_file_search < Fortran_file_search.ctl
  fi   
  if [ -s $MET_FILE ]
  then
     exec 5<&0 < $MET_FILE
     while read GRB2FILE 
     do
        read YYYY MM DD CYC HH
        echo $GRB2FILE
        TMPGRB2=${RUN}_${DBASE}.grib2
        if [ -s $TMPGRB2 ]
        then
          rm -f $TMPGRB2
        fi
        $WGRIB2 $GRB2FILE -small_grib ${MINLON}:${MAXLON} ${MINLAT}:${MAXLAT} $TMPGRB2 
	N=0
        while (( N < $HH))
        do
           (( N = N + 1 ))
	done
        (( N3 = N - 3 ))
        if [ $N3 -lt 0 ]
        then
          N3=0
        fi   
        count=0    ## here only decode PRMSL, DLWRF, ULWRF, DSWRF, USWRF,LHTFL,SHTFL,SPFH from NAM grib2 file
        while (( count < 14))
        do
           if [ $N = 0 ]
           then
              FPSTG="anl"
           else 
              FPSTG="$N hour fcst"
           fi   
           if [ -s tmp.txt ]
           then
             rm -f tmp.txt
           fi	 
         $WGRIB2 $TMPGRB2 -s | grep "${VARNAME[count]}${LEV[count]}$FPSTG" | sed '2,$d' | $WGRIB2 -i $TMPGRB2 -spread tmp.txt
           if [ -s tmp.txt ]
           then
              cat tmp.txt >> ${VARNAME[count]}.$DBASE
           fi	  
           (( count = count + 1 ))
        done
     done 3<&-  
  else
     echo "no Meteorological product files are found in time period from $TIME_START to $TIME_END"
     msg="ABNORMAL EXIT: no Meteorological product files are found in time period from $TIME_START to $TIME_END   "
     ./postmsg "$jlogfile" "$msg"
  fi   
  count=0
  while (( count < $NPP))
  do
     if [ ! -s ${VARNAME[count]}.$DBASE ]
     then
        echo ${VARNAME[count]}.$DBASE
        rm -f ${VARNAME[count]}.$DBASE
     fi   
     (( count = count + 1 ))
   
  done
  rm -f Fortran.ctl ${DBASE}_Fortran.log
  echo ${RUN} > Fortran.ctl 
  echo $DBASE >> Fortran.ctl
  echo $OCEAN_MODEL >> Fortran.ctl
  echo $TIME_START >> Fortran.ctl
  echo $TIME_END >> Fortran.ctl
  echo $IGRD_MET >> Fortran.ctl
  echo $TMPGRB2 >> Fortran.ctl
  echo $GRIDFILE >> Fortran.ctl
  echo $OUTPUTFILE1 >> Fortran.ctl
  echo $BASE_DATE >> Fortran.ctl 
  echo $MINLON  >> Fortran.ctl
  echo $MINLAT >> Fortran.ctl 
  echo $MAXLON >> Fortran.ctl 
  echo $MAXLAT >> Fortran.ctl 
  echo $SCALE_HFLUX >> Fortran.ctl 
  if [ ! -s $EXECnos/$EXFILE -o  ! -x  $EXECnos/$EXFILE ]
  then
  echo "$EXECnos/$EXFILE does not exist"
  msg="$EXECnos/$EXFILE does not exist  "
  ./postmsg "$jlogfile" "$msg"
  err=1;export err;err_chk
  exit
  fi

  export pgm=$EXFILE
  . ./prep_step

  ./startmsg

  $EXECnos/$EXFILE < Fortran.ctl > ${DBASE}_Fortran.log
  export err=$?
  if [ $OCEAN_MODEL == 'SELFE' -o  $OCEAN_MODEL == 'selfe' ]
  then
    if [ -s sflux_rad.nc ]
    then 
      cp -p sflux_rad.nc sflux_rad_1.001.nc
      cp -p sflux_rad.nc ${NET}.${RUN}.flux.$RUNTYPE.$PDY1.t${cyc}z.nc
    fi
    if [ -s sflux_prc.nc ]
    then 
      cp -p sflux_prc.nc sflux_prc_1.001.nc
      cp -p sflux_prc.nc ${NET}.${RUN}.precip.$RUNTYPE.$PDY1.t${cyc}z.nc
    fi
  elif [ $OCEAN_MODEL == 'FVCOM' -o  $OCEAN_MODEL == 'fvcom' ]
  then
     if [ -s hflux_fvcom.nc ]
     then
        mv hflux_fvcom.nc $OUTPUTFILE1
     else
        echo 'surface forcing file ' $OUTPUTFILE1 'is not generate'
     fi	  	

  fi

  if [ $err -ne 0 ]
  then
    echo "$pgm did not complete normally, critical failure!"
    msg="$pgm did not complete normally, critical failure!"
    ./postmsg "$jlogfile" "$msg"
    ./err_chk
  else
    echo "$pgm completed normally"
    msg="$pgm completed normally"
    ./postmsg "$jlogfile" "$msg"
  fi

## output corms flag information
  if [ -s ${DBASE}_Fortran.log ]
  then
    cp -p ${DBASE}_Fortran.log $COMOUT/$DBASE.${RUNTYPE}_Fortran.t${cyc}z.log

  else
    echo "NO $DBASE.${RUNTYPE}_Fortran.t${cyc}z.log Found"
  fi
  if grep "COMPLETED SUCCESSFULLY" ${DBASE}_Fortran.log /dev/null 2>&1
  then
     echo "MET FORCING ${RUNTYPE} ${DBASE} COMPLETED SUCCESSFULLY 100" >> $CORMSLOG
     if [ $RUNTYPE == "NOWCAST" -o $RUNTYPE == "nowcast" ]
     then
        echo MET_NOWCAST DONE 100  >> $CORMSLOG
     else
        echo MET_FORECAST DONE 100  >> $CORMSLOG
     fi
  else
     echo "MET_FORCING ${RUNTYPE} ${DBASE} COMPLETED SUCCESSFULLY 0" >> $CORMSLOG
     if [ $RUNTYPE == "NOWCAST" -o $RUNTYPE == "nowcast" ]
     then
        echo MET_NOWCAST DONE 0  >> $CORMSLOG
     else
        echo MET_FORECAST DONE 0  >> $CORMSLOG
     fi

  fi
fi

if [ $OCEAN_MODEL == 'SELFE' -o  $OCEAN_MODEL == 'selfe' ]
then
  tar -cvf ${OUTPUTFILE} sflux_air_1.001.nc sflux_rad_1.001.nc sflux_prc_1.001.nc
fi

   
if [ $RUNTYPE == "NOWCAST" -o $RUNTYPE == "nowcast" ]
then

export pgm=$MET_NETCDF_1_NOWCAST"_copy"
. ./prep_step

  if [ -f $MET_NETCDF_1_NOWCAST ]
  then
    cp $MET_NETCDF_1_NOWCAST $COMOUT/$MET_NETCDF_1_NOWCAST
    export err=$?; ./err_chk
  else
    echo "NO $MET_NETCDF_1_NOWCAST File Found"
    echo "NO $MET_NETCDF_1_NOWCAST File Found" >> $jlogfile
  fi

export pgm=$MET_NETCDF_2_NOWCAST"_copy"
. ./prep_step

  if [ -f $MET_NETCDF_2_NOWCAST ]
  then
    cp $MET_NETCDF_2_NOWCAST $COMOUT/$MET_NETCDF_2_NOWCAST
#    export err=$?; ./err_chk
  else
    echo "NO $MET_NETCDF_2_NOWCAST File Found"
    echo "NO $MET_NETCDF_2_NOWCAST File Found" >> $jlogfile
  fi

  if [ $OCEAN_MODEL == 'ROMS' -o  $OCEAN_MODEL == 'roms' ]; then

    if [ -f $INI_FILE_ROMS_NOWCAST ]; then
      cp $INI_FILE_ROMS_NOWCAST $COMOUT/$INI_FILE_ROMS_NOWCAST
      export err=$?; ./err_chk
    else
      echo "NO $INI_FILE_ROMS_NOWCAST File Found"
      echo "NO $INI_FILE_ROMS_NOWCAST File Found" >> $jlogfile
    fi
  fi
elif [ $RUNTYPE == "FORECAST" -o $RUNTYPE == "forecast" ]
then

export pgm=$MET_NETCDF_1_FORECAST"_copy"
. ./prep_step

  if [ -f $MET_NETCDF_1_FORECAST ]
  then
    cp $MET_NETCDF_1_FORECAST $COMOUT/$MET_NETCDF_1_FORECAST
    export err=$?; ./err_chk

  else
    echo "NO $MET_NETCDF_1_FORECAST File Found"
    echo "NO $MET_NETCDF_1_FORECAST File Found" >> $jlogfile
  fi

  export pgm=$MET_NETCDF_2_FORECAST"_copy"
  . ./prep_step

  if [ -f $MET_NETCDF_2_FORECAST ]
  then
    cp $MET_NETCDF_2_FORECAST $COMOUT/$MET_NETCDF_2_FORECAST
  else
    echo "NO $MET_NETCDF_2_FORECAST File Found"
  fi


fi
#if [ $OCEAN_MODEL == 'SELFE' -o  $OCEAN_MODEL == 'selfe' ]
#then
#  tar -cvf ${OUTPUTFILE} sflux_air_1.001.nc sflux_rad_1.001.nc sflux_prc_1.001.nc
#  cp -p ${OUTPUTFILE} $COMOUT/. 
#fi
echo 'The script nos_ofs_create_forcing_met.sh completed at time: ' `date `
exit   
