#!/usr/bin/ksh

#  Script to distribute atcf track files to NHC atcf file library

trakfile=attk126

export syy=`echo ${PDY} | cut -c3-4`

if test -r $trakfile
then

# Determine the number of forecast records in the ATCF file, then
# loop through for each forecast record.

  nfcst=` cat ${trakfile} | wc -l`
  echo "nfcst=$nfcst"

  nstm=1
  while test $nstm -le $nfcst
  do

    sed -n ${nstm}p ${trakfile} > tmptrk
    basin=` cut -c71-72 tmptrk`
    stmnum=`cut -c73-74 tmptrk`
    echo "Extracted storm basin is: $basin    Extracted storm number is: $stmnum"
    ID=${basin}${stmnum}${syy}
    outfile=$TPCATdir/$ID/A$ID.DAT
    echo "outfile is $outfile"

    if [ ${basin} = 'AL' -o ${basin} = 'EP' -o ${basin} = 'CP' ]; then

      cat tmptrk >> $outfile

      echo "Following forecast sent to ${outfile}:"
      cat tmptrk
 
    fi

    nstm=` expr $nstm + 1 `

  done

else
  echo "track file not found. ABORT"
  exit 1
fi
