#!/bin/sh
#
FE_Id=414
while [ ${FE_Id} -le 440 ] ; do
      data_in=/data/bfys/otroper/FE-Tester/FE_${FE_Id}_2000
      dir=/www/pub/experiments/bfys/lhcb/outerTracker/Electronics/Production/FE-Plots/FE_${FE_Id}
      #------------------------------
      # Check if the FE was tested:
      #------------------------------
      test -d ${data_in}
      FE_exist=`echo $?`
      if [ ${FE_exist} -eq 0 ] ; then
        # Last test:                 
        Test_Id=`ls ${data_in} | sed -n 's/^'"test"'\([0-9][0-9]*\)/\1/p' | sort -n | tail -1`
        #------------------------------
        # Check if the test was tested:
        #------------------------------
	test -d ${data_in}/test${Test_Id}
	Test_exist=`echo $?`
        if [ ${Test_exist} -eq 0 ] ; then
            #-------------------------------------
            # Check if the test is already copied:
            #-------------------------------------
	    test -d ${dir}/test${Test_Id}
	    Test_copied=`echo $?`
            if [ ${Test_copied} -eq 1 ] ; then
		mkdir ${dir}
		echo '-------------------------------------------------'
		echo 'Moving files, please be patient... FE' ${FE_Id} 'Test' ${Test_Id}
                echo '-------------------------------------------------'
		mv ${data_in}/test${Test_Id} ${dir}/
		ln -s ${dir}/test${Test_Id} ${data_in}
                mkbrows.sh ${FE_Id} ${Test_Id}
		echo ' Zip Drift_Spectra... '
		gzip ${dir}/test${Test_Id}/ps/Drift_Spectra/*ps
	    else
                echo '------------------------------------'
		echo 'Plots already present: FE' ${FE_Id} 'Test' ${Test_Id}
                echo '------------------------------------'
		echo ${dir}/test${Test_Id}/ps
                ls ${dir}/test${Test_Id}/ps
	    fi
	fi
      fi
      FE_Id=`expr ${FE_Id} + 1`
done


