#!/bin/bash
# create files sgx, sgy in $resultDir 
# {print NR,"0", $2} adding 0 column just to be compatible with Guillermo
# If first argument is test number then plot just this one othrewise all
# Jaroslav Vazny, summer student 2010

# inicialization
. ~/sigmaOpt/bin/var
rm -f $resultDir/sgx $resultDir/sgy


function readSigma {
    for file in sgx sgy
    	do
	     grep sigma${file:(-1)} $1/sigmatemp.madx | awk '{print NR,"0", $2}' >> $resultDir/$file 
    	     printf "\n\n" >> $resultDir/$file
	done
}

#
if [ "$#" -eq 1 ]
then 
    echo "Creating plot of test #$1"
    readSigma $testDir/$1
else
    echo "Creating plot of all tests"
    nOfTests=0
    for dir in $testDir/[[:digit:]]*; do
	nOfTests=$(($nOfTests+1))
	readSigma $dir
    done
fi
export nOfTests



. $binDir/plotPs
