#/bin/sh
####################################################################
#
# sdmedit - upper air qc tool for SDM use 
# Script to prompt for SDM_Edit parameters
#
#
# Modified to run this script for frost/snow/blue/white IBM systems
# By                    V. Krishna Kumar NCO/Date: December 27, 2004
#
# F.Achorn/NCO	08/14/06	modified existing script to work in 
#				nwpara/nwprod
#

# set current environment (nwpara/nwtest/nwprod)
export envir=prod 

# Script to prompt for SDM_Edit parameters
set -ea 

bufrlist1='adpupa'
bufrlist2='adpupa aircft'
bufrlist3='adpupa aircft acars' 
bufrlist4='adpupa aircft acars adpsfc'  
  type=x
if [ $# -eq 1  -o   $# -eq 2 ]
then
  hour=$1
  if [ "$hour" = "00" -o "$hour" = "06" -o "$hour" = "12" -o "$hour" = "18" ]
  then
    date=`cat /com/date/t${hour}z  | cut -c7-14`
    echo date=$date
  else
    echo sdmedit only works for UTC hours 00, 06, 12, and 18. 
    echo you entered ${hour}.  Try again.
    exit
  fi
  if [ $# -eq 2 ]
  then
    type=$2
    if [ "$type" = "1" -o "$type" = "2" -o "$type" = "3" -o "$type" = "4" ]
    then
      bufrlist="bufrlist${type}"
    else
      echo sdmedit only works for for types - 1, 2, 3, 4
      echo you entered ${type}.  Try again.
      exit
    fi
  fi
# Script to prompt for CARDINAL parameters

else
  while [ -z "$date" ]
  do
     echo "Enter date (yyyymmdd) Please note 4 digit year is required:"
     read date
     yc=`echo $date | cut -c1-2`
     if test $yc != "19" -a $yc != "20"
     then
       echo "You entered date $date.  This is incorrect."
       exit
     fi
     echo "Date entered: $date"
     echo
  done

  tz='00'
  while [ "$tz" != "00z" -a "$tz" != "06z" -a "$tz" != "12z" -a "$tz" != "18z" ]
  do
     echo "Enter time (00z, 06z, 12z or 18z):"
     read tz
     echo "Time entered: $tz"
     hour=`echo $tz|cut -c 1-2`
     echo
  done
fi

if [ $type = x ]
then
  echo "Enter data types to be dumped (1, 2, 3, or 4)"
  echo "Enter 1 for adpupa only"
  echo "Enter 2 for adpupa and aircft"
  echo "Enter 3 for adpupa, aircft, and acars."
  echo "Enter 4 for adpupa, aircft, acars, and adpsfc."
  read type
  bufrlist="bufrlist${type}"
fi
echo bufrlist=$bufrlist

echo "type=$type"
echo "sdmedit will dump: $bufrlist"
echo "Starting SDM_Edit for $date $hour"

sh /nw${envir}/ush/sdmedit_gempak_2.sh $date $hour $type

