#!/bin/bash
echo ' '
echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo %% Try to translate ODV contours into DIVA format %%%
echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if [ -f ./input/coast.coa ]
then
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
echo $xori > ./divawork/fort.13
echo $yori >> ./divawork/fort.13
echo $dx >> ./divawork/fort.13
echo $dy >> ./divawork/fort.13
echo $nx >> ./divawork/fort.13
echo $ny >> ./divawork/fort.13
cp ./input/coast.coa ./divawork/fort.10
cd ./divawork
if [ -f ../output/diva.log ] ; then
 cp  -f ../output/diva.log .
fi
../../bin/coatocont.a >> diva.log
 cp -f diva.log ../output/.
cp -v fort.99 ../output/coast.cont
cp -v fort.67 ../output/coast.cont.odv
rm -f fort13
rm -f fort.10
rm -f fort.99
rm -f fort.66
if [ "$1" == "-r" ] 
then
echo Placing new contour file as input
cp -v ../output/coast.cont ../input/coast.cont
fi
cd ..
else
echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo %%% Sorry, need an ODV coast.coa  file %%%%%%%%%%%%
echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fi