#!/bin/bash
# use -x option for debug

function usage() {
	echo
	echo
	echo "Usage: perl $TkPerlDir/Crystal/CalculateDistance.pl --MaximumDistance=maxR --MaximumNumber=maxN --DoSort=do_sort cif_path"
	echo '            maxR: Max distance to search (Default: 3.5)'
	echo '            maxN: Max number of distances to search (Default: 1000)'
	echo '            do_sort: [0|1] Flag to sort the result by distance'
	echo "   ex: perl $TkPerlDir/Crystal/CalculateDistance.pl --MaximumDistance=$maxR --MaximumNumber=$maxN --DoSort=$do_sort $cif"
	echo
	echo
	exit 1
}

#=======================
# Set arguments
#=======================
if [ "$1" != "" ]; then
	cif=$1
fi
if [ "$2" != "" ]; then
	maxR=$2
else
	maxR=3.5
fi
if [ "$3" != "" ]; then
	maxN=$3
else
	maxN=1000
fi
if [ "$4" != "" ]; then
	do_sort=$4
else
	do_sort=0
fi

#=======================
# Show usage and terminate if $1 is not given
#=======================
if [ "$cif" == "" ]; then
	usage
fi

#=======================
# Execute
#=======================
echo
echo execute [perl $TkPerlDir/Crystal/CalculateDistance.pl --MaximumDistance=$maxR --MaximumNumber=$maxN --DoSort=$do_sort $cif]
perl $TkPerlDir/Crystal/CalculateDistance.pl --MaximumDistance=$maxR --MaximumNumber=$maxN --DoSort=$do_sort $cif

#=======================
# Script end
#=======================
echo
usage
