########################################################################
##
## SCRIPT: listac.sh            NCO/PMB/SDM
##
## Syntax:  listac $1 $2
##          $1 = model hour (00 06 12 18)
##          $2 = aircraft ID (from column 1 of file listac.yyyymmddZZ)
##
## CHANGE LOG:
##
##   04/2010   MALONE      Changed working directory from local
##                         /nco/pmb/$LOGNAME/sdmedit to /nco/ops/sdm[2]
##
########################################################################

set -xa

## DEFINE THE MACHINE AND ASSOCIATED VARIABLES.
machi=`hostname | cut -c1`
user=`whoami`
## If machi=c, then machine is cirrus.  If machi=s, then machine is stratus.

hour=$1
ac=$2

## DEFINE THE WORKING DIRECTORY.
if [ $LOGNAME = 'wx12sd' ]; then
   DATA=/nco/ops/sdm   # operational wx12sd
else
   DATA=/nco/ops/sdm2   # operational wx12ss
fi
mkdir -p $DATA
cd $DATA

## ERROR CHECK  
## Exit if 2 valid arguments are not entered.
## $1 = model hour... 00 06 12 18
## $2 = aircraft ID... found in column 1 of listac.yyyymmddzz
if [ $# -ne 2 ]; then
   echo Specify model hour and aircraft ID.
   exit
fi

## PRESENT AIRCRAFT DATA
ls -t /nco/ops/sdm/listac*$1 /nco/ops/sdm2/listac*$1 > filesel
file=`head -1 filesel`
echo "Looking for acft ID $ac in $file"
if test -s $file
then
   head -2 $file > outfile 
   grep "^$ac" $file >> outfile
   more outfile
else
   echo "$file does not exist."
fi

## END OF SCRIPT
