#! /bin/tcsh -f
# "@(#) $Id: ferosCheckByLog,v 1.2 2004/02/28 01:06:28 jpritcha Exp $"
#
set exstat=0

while ( $#argv )
  switch ( $1 )
  case -h:
    goto usage
  case --CDLogRep:
    set CDLogRep="${2}"; shift; shift; breaksw
  default:
    set logfile=$1; shift; breaksw
  endsw
end

if ( ! $?logfile ) then
  echo "Error\!\!\! Must at least supply <logfile>"
  set exstat=1
  goto usage
endif

set feroList=`grep fero $logfile | cut -b204-214`
set  VLTList=`grep fero $logfile | cut -b169-202`

set i=1
while ( $i <= $#feroList )
 if ( ! -e ${feroList[${i}]} ) then
   echo "${feroList[${i}]} --> ${VLTList[${i}]} missing..."
   if ( $?CDLogRep ) then
     grep -l ${VLTList[${i}]} $CDLogRep/*.log
   endif
 endif
 @ i++
end

exit

usage:
echo "Usage: ferosCheckByLog [-h] <logfile> [--CDLogRep <dir>]"
echo " "
echo "<logfile>"
echo "   Check fero<nnnn>.mt files are present in the current directory."
echo "--CDLogRep <dir>"
echo "   If file fero<nnnn>.mt is not present, search for it in .log files in the <dir> directory."
exit $exstat
