#!/bin/bash
FOLDER='kspectrum1.3'
ARCHIVE='kspectrum1.3.tgz'

LOCAL=$('pwd')

minimum_version=2
# Since Chet Ramey is constantly adding features to Bash,
# you may set $minimum_version to 2.XX, 3.XX, or whatever is appropriate.
E_BAD_VERSION=80

if [ "$BASH_VERSION" \< "$minimum_version" ]
then
  echo "This script works only with Bash, version $minimum or greater."
  echo "Upgrade strongly recommended."
  exit $E_BAD_VERSION
fi

if [ -e $FOLDER ]
then
	echo "Directory already exists:"
	echo $FOLDER
	echo "Please erase it and try again"
	exit 0
else
	if [ ! -f $ARCHIVE ]
	then
		echo "$ARCHIVE does not exists in the current directory"
		echo "installation failed"
		exit 0
	else
		echo "+ Uncompressing file $ARCHIVE..."
		tar -zxvf ${ARCHIVE} > /dev/null
		echo "...done"
		echo "The archive was extracted in: ./"$FOLDER
		cd $FOLDER/data
		#ln -s ../includes/formats.inc .
		#ln -s ../includes/max.inc .

		echo ""
		echo "+ Compiling program make_composition.exe"
		./f0

		if [ ! -f make_composition.exe ]
		then
			echo 'Error: make_composition.exe could not be compiled'
		else
			echo ""
			echo "+ Running program make_composition.exe"
			./make_composition.exe
		fi
		echo ""
		echo "+ linking files"
#		ln -s composition_venus.in composition.in
#		ln -s nu_venus.txt narrowbands.in
		./linkLBL.bash

		cd $LOCAL
#		rm -f ${ARCHIVE}
#		rm -f install_kspectrum*.bash

	fi
fi

echo ""
echo "Use documentation file ./$FOLDER/Doc/manual.pdf if needed"
if [ -e $FOLDER/data/HITRAN2004 ]; then
echo "LBL databases have been linked"
else
echo "Do not forget to install LBL databases in the ./$FOLDER/data directory !"
fi

exit 0
