#!/bin/bash
echo //////////////////////////////////////////////////
echo             Looking for outliers
echo //////////////////////////////////////////////////
echo ' '
if [ -f ./input/data.dat ]
then 
cp ./input/data.dat ./divawork/fort.44
else
echo Need to provide data.dat in ./input
fi
Filepar=./input/param.par
{
read linecomment
read lc
read linecomment
read icoordchange
read linecomment
read ispec
read linecomment
read ireg
read linecomment
read xori
read linecomment
read yori
read linecomment
read dx
read linecomment
read dy
read linecomment
read nx
read linecomment
read ny
read linecomment
read valex
read linecomment
read snr
read linecomment
read varbak
} < $Filepar
cd divawork
nbccol=$(head -n 1 ./fort.44 | wc -w)
GGGGG=../output/gcvval.dat
{
read GCVVAL BBBBBB TRACEA tutu
}<$GGGGG
if [ -f ../output/diva.log ] ; then
 cp -f ../output/diva.log .
fi
echo $TRACEA 
echo $lc $snr $nbccol $GCVVAL $TRACEA  | ../../bin/calcest.a >> diva.log
if [ $? -ne 0 ];then
echo ' '
echo --------------------------------------------
echo A problem was encountered during execution !
echo          divaqcter      calcest.a
echo Check execution track
echo --------------------------------------------
echo ' ' >> diva.log
echo -------------------------------------------- >> diva.log
echo A problem was encountered during execution ! >> diva.log
echo          divaqcter      calcest.a  >> diva.log
echo Check execution track >> diva.log
echo -------------------------------------------- >> diva.log
fi
#output of results to user
cp -v fort.76 ../output/expectederroratdatapointter.anl
echo ' '
echo Looking for outliers
echo ' '
if [ -f fort.71 ] 
then
echo Using fort.71 found in divawork
else
Try using fieldatdatapoint.anl
if [ -f ./output/fieldatdatapoint.anl ]
then
cp ../output/fieldatdatapoint.anl fort.71
else
Need to execute divacalc before
fi
fi
echo $valex | ../../bin/lookforoutliers.a >> diva.log
if [ $? -ne 0 ];then
echo ' '
echo --------------------------------------------
echo A problem was encountered during execution !
echo          divaqcter      lookforoutliers.a
echo Check execution track
echo --------------------------------------------
echo ' ' >> diva.log
echo -------------------------------------------- >> diva.log
echo A problem was encountered during execution ! >> diva.log
echo          divaqcter      lookforoutliers.a  >> diva.log
echo Check execution track >> diva.log
echo -------------------------------------------- >> diva.log
fi
echo ' '
echo Copying outlier lists
echo ' '
if [ -f fort.66 ]
then
mv -v fort.66 ../output/outlierster.dat
mv -v fort.67 ../output/outlierster.normalized.dat
else
echo ' '
echo --------------------------------------------
echo A problem was encountered during execution !
echo Check execution track
echo --------------------------------------------
fi
 cp -f diva.log ../output/.
cd ..
dvvariance 3
echo ' '
echo --------------------------
echo Outlier detection finished
echo --------------------------