:

USR=`pwd`
bin=`echo $0_A_E_P |sed s/name_cycle_A_E_P//`; cd $bin; bin=`pwd`
cd $USR
LANG=
#============================
if(test $# -ne 4) then
 echo Error, $0 needs 4 parameters
 echo 1: Name of parameter 
 echo 2: Initial value 
 echo 3: Step
 echo 4: Number of steps
 exit 200
fi

 
val=$2
nstep=$4
first=1


while(test 0 -ne $nstep)
do
  $bin/set_param $1 $val
  err=$?; if(test $err -ne 0) then exit $err; fi
  if(test $first -eq 1) then
    Sep=`grep \#Subprocess  session.dat |cut -f5 -d" "`
    if(test "$Sep" = "->" ) then
       Units="Width [GeV]"
    else 
       Units="Cross section [pb]"
    fi
    n1=`grep Session_number session.dat|cut -f2 -d" "`
    n2=`expr  $n1 - 1 + $4`
    file=$1_tab_"$n1"_"$n2" 
    lastval=`$bin/calc "$2+($4-1)*($3)"`
#    date > $file
    echo "#type 0 %curve"  > $file
    echo "#x-axis: \"$1\"" >> $file
    echo "#xMin $2"        >> $file
    echo "#xMax $lastval"  >> $file
    echo "#xDim $4"        >> $file
    echo "#yName  " $UNITS >> $file
    first=0
  fi
  res=`$bin/run_vegas`
  err=$?; if(test $err -ne 0) then exit $err; fi
  echo $1=$val  sigma=$res[pb] 
  echo $res >>$file

  val=`$bin/calc "$val + ($3)"`
  nstep=`expr $nstep - 1`
done   
echo See $file file.
