#!/bin/csh -f 

### run $aout < $data > $output and append time to $output
### usage: runn $aout $data [$output]	(run in foreground only)

echo " "
set aout  = $1
set datfn = $2
set outfn = $3

if( "$3" == "" ) then
  echo    ' ---  Usage: runn $1 $2 [out_file] ---'
  echo -n ' ---  Enter out_file  _OR_  <ENTER>(to screen) : '
  set outfn = $<
endif

if( "$outfn" == "" ) then
	echo "   runn --- executing  $1 < $2 ---"
	( time $1 < $2 ) &
	exit
else
	echo "--- executing  $1 < $2 > $outfn --- timing to $outfn"
	(time $1 < $2 > $outfn ) | ( cat > ./tmp."$outfn" )
	cat ./tmp."$outfn" >> $outfn 
	sleep 1
	/bin/rm -f ./tmp."$outfn"
	exit
endif

### replaces
### alias  run     '(time \!^ <"\!:2" >"\!:3") | (cat > ./tmp."\!:3"); \
#	cat ./tmp."\!:3" >>"\!:3"; sleep 2; /bin/rm -f ./tmp."\!:3" &'
