#!/bin/bash
chipnumber=0
if [ $# == 0 ]; then
    chipnumber=0
elif [ $# == 1 ]; then
    chipnumber=$1
else
    echo "Wrong number of arguments: " $#
    exit
fi
#
# General settings
#===================
datadir=/home/jum/wdir/ilcdaq/data
#
# SRU and MCM general settings
#=============================
dcladdress=0
chipaddress=7
myfile=`printf 'chip%d/saltro%d-regtest-mcm%d-c%d' $chipnumber $chipnumber $dcladdress $chipaddress`
csvfile=${datadir}/${myfile}.csv


./saltroregtest --fec $dcladdress --chip $chipaddress --pattern FFFF --loop 100 --outfile ${csvfile}

if [ $chipnumber != 0 ]; then
    if [ -f "${csvfile}" ]; then
        mydate=`date +%Y%m%d%H%M%S`
        echo "$csvfile exist" $mydate
        destfile=${datadir}/${myfile}-${mydate}.csv
        mv $csvfile $destfile
    fi
else
    echo "TESTRUN - manage csvfile by hand"
fi

exit
