#!/bin/bash

# -------------------------------------------------------
# RPC Project :
# Run RPC_check_rff of all RFF files of a given directory
# P. Robert, LPP, 2011-08-17
# -------------------------------------------------------

appli=`basename $0`
appli36=`echo "$appli                                 " | cut -c1-36`
Narg=1

if( (test $# = 1 ) && (test $1 = -h ) ) ; then hh=1 ; else hh=0 ; fi

if test $# != $Narg || test $hh = 1
   then
   echo "$appli : check of all RFF files of a given directory"
   echo "$appli   require $Narg argument(s), ex:"
   echo "$appli   toto"
   echo "    toto : name of a directory containing RFF files"
   echo ""
   if test $hh = 1 ; then exit 0 ; fi
   echo " $appli36 : *** ERROR ! Command aborted." >&2
   exit 1
fi

echo " -------------------------------------------------------------------"

# test if given dir is existing

if test -d $1
   then 
       ls -1 $1/*.rff > toto1_$$.tmp
       echo "check RFF files of $1"
       echo "please wait..."
       echo
       else echo "$1 is not an existing directory"
       echo ""
       echo " $appli36 : *** ERROR ! Command aborted." >&2
       exit 2
fi

# make batch file

echo "nb of RFF files : ",`wc -l toto1_$$.tmp`
echo "--------------------------------"
echo
sed "s%.*%RPC_check_rff &%" toto1_$$.tmp > toto2_$$.tmp

# run batch file

sh toto2_$$.tmp
echo
echo "Done !"

# end of command
# --------------

datim2=`date +%F'  '%H':'%M':'%S `
julsec2=`date +%s`
diff=`expr $julsec2 - $julsec1`

echo ""
echo " Starting time $appli : $datim1"
echo " Ending   time $appli : $datim2"
echo " Duration      $appli : $diff sec."
echo    
echo " $appli36 : NORMAL TERMINATION - time exe= $diff s." >&2 

echo " ==================================================================="
