#! /bin/bash

# script to convert lists between output formats using /home/bart/source/biquandle/biquandle-search

directory="."

if [[ $1 == "" ]]
then
    echo "usage: convert-lists -n <n> -d <directory> -S -o (T|PT)"
    echo "       -n convert lists of order <n>"
    echo "       -d read original lists from <directory> (defaults to .)"    
    echo "       -S use S-Yang-Baxter conditions"
    echo "       -o output format"
else

	while getopts ":n:o:d:Sf" opt; 
	do
		case $opt in
			n)
				n=$OPTARG
				;;
			o)
				output_options=$OPTARG
				;;
			d)
				directory=$OPTARG
				;;
			S)
				s_yang_baxter=$opt
				;;
			\?)
				echo "Invalid option: -$OPTARG" >&2
				exit 1
				;;
			:)
				echo "Option -$OPTARG requires an argument." >&2
				exit 1
				;;
		esac
	done

	echo "n = ${n}, s_yang_baxter = $s_yang_baxter, directory = $directory, output options = $output_options"
	
	if ((${n} < 5))
	then
		echo "biquandle-search -n=${n}bRX$s_yang_baxter$output_options $directory/birack-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}bRX$s_yang_baxter$output_options $directory/birack-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out birack-${n}-$output_options.txt
		else
			mv biquandle.out birack-${n}.txt
		fi
		echo "biquandle-search -n=${n}RX$s_yang_baxter$output_options $directory/biquandle-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}RX$s_yang_baxter$output_options $directory/biquandle-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out biquandle-${n}-$output_options.txt
		else
			mv biquandle.out biquandle-${n}.txt
		fi
		echo "biquandle-search -n=${n}bRX$s_yang_baxter$output_options $directory/birack-${n}-not-biquandle.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}bRX$s_yang_baxter$output_options $directory/birack-${n}-not-biquandle.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out birack-${n}-not-biquandle-$output_options.txt
		else
			mv biquandle.out birack-${n}-not-biquandle.txt
		fi
		echo "biquandle-search -n=${n}rRX$s_yang_baxter$output_options $directory/rack-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}rRX$s_yang_baxter$output_options $directory/rack-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out rack-${n}-$output_options.txt
		else
			mv biquandle.out rack-${n}.txt
		fi
		echo "biquandle-search -n=${n}bRX$s_yang_baxter$output_options $directory/birack-${n}-not-biquandle-not-rack.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}bRX$s_yang_baxter$output_options $directory/birack-${n}-not-biquandle-not-rack.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out birack-${n}-not-biquandle-not-rack-$output_options.txt
		else
			mv biquandle.out birack-${n}-not-biquandle-not-rack.txt
		fi
		echo "biquandle-search -n=${n}qRX$s_yang_baxter$output_options $directory/quandle-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}qRX$s_yang_baxter$output_options $directory/quandle-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out quandle-${n}-$output_options.txt
		else
			mv biquandle.out quandle-${n}.txt
		fi
		echo "biquandle-search -n=${n}RX$s_yang_baxter$output_options $directory/biquandle-${n}-not-quandle.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}RX$s_yang_baxter$output_options $directory/biquandle-${n}-not-quandle.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out biquandle-${n}-not-quandle-$output_options.txt
		else
			mv biquandle.out biquandle-${n}-not-quandle.txt
		fi
		echo "biquandle-search -n=${n}rRX$s_yang_baxter$output_options $directory/rack-${n}-not-quandle.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}rRX$s_yang_baxter$output_options $directory/rack-${n}-not-quandle.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out rack-${n}-not-quandle-$output_options.txt
		else
			mv biquandle.out rack-${n}-not-quandle.txt
		fi
		echo "biquandle-search -n=${n}bRXD$s_yang_baxter$output_options $directory/quandle-related-birack-${n}.txt $directory/quandle-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}bRXD$s_yang_baxter$output_options $directory/quandle-related-birack-${n}.txt $directory/quandle-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out quandle-related-birack-${n}-$output_options.txt
		else
			mv biquandle.out quandle-related-birack-${n}.txt
		fi
		echo "biquandle-search -n=${n}bRXD$s_yang_baxter$output_options $directory/quandle-related-birack-${n}-not-quandle.txt $directory/quandle-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}bRXD$s_yang_baxter$output_options $directory/quandle-related-birack-${n}-not-quandle.txt $directory/quandle-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out quandle-related-birack-${n}-not-quandle-$output_options.txt
		else
			mv biquandle.out quandle-related-birack-${n}-not-quandle.txt
		fi
		echo "biquandle-search -n=${n}XRD$s_yang_baxter$output_options $directory/quandle-related-biquandle-${n}-not-quandle.txt $directory/quandle-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}XRD$s_yang_baxter$output_options $directory/quandle-related-biquandle-${n}-not-quandle.txt $directory/quandle-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out quandle-related-biquandle-${n}-not-quandle-$output_options.txt
		else
			mv biquandle.out quandle-related-biquandle-${n}-not-quandle.txt
		fi
	else
		echo "biquandle-search -n=${n}qRX$s_yang_baxter$output_options $directory/quandle-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}qRX$s_yang_baxter$output_options $directory/quandle-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out quandle-${n}-$output_options.txt
		else
			mv biquandle.out quandle-${n}.txt
		fi
		echo "biquandle-search -n=${n}RXD$s_yang_baxter$output_options $directory/quandle-related-biquandle-${n}-not-quandle.txt $directory/quandle-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}RXD$s_yang_baxter$output_options $directory/quandle-related-biquandle-${n}-not-quandle.txt $directory/quandle-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out quandle-related-biquandle-${n}-not-quandle-$output_options.txt
		else
			mv biquandle.out quandle-related-biquandle-${n}-not-quandle.txt
		fi
		echo "biquandle-search -n=${n}RDX$s_yang_baxter$output_options $directory/quandle-related-biquandle-${n}.txt $directory/quandle-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}RDX$s_yang_baxter$output_options $directory/quandle-related-biquandle-${n}.txt $directory/quandle-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out quandle-related-biquandle-${n}-$output_options.txt
		else
			mv biquandle.out quandle-related-biquandle-${n}.txt
		fi
		echo "biquandle-search -n=${n}bRDX$s_yang_baxter$output_options $directory/quandle-related-birack-${n}-not-biquandle-not-rack.txt $directory/quandle-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}bRDX$s_yang_baxter$output_options $directory/quandle-related-birack-${n}-not-biquandle-not-rack.txt $directory/quandle-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out quandle-related-birack-${n}-not-biquandle-not-rack-$output_options.txt
		else
			mv biquandle.out quandle-related-birack-${n}-not-biquandle-not-rack.txt
		fi
		echo "biquandle-search -n=${n}bRDX$s_yang_baxter$output_options $directory/quandle-related-birack-${n}-not-biquandle.txt $directory/quandle-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}bRDX$s_yang_baxter$output_options $directory/quandle-related-birack-${n}-not-biquandle.txt $directory/quandle-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out quandle-related-birack-${n}-not-biquandle-$output_options.txt
		else
			mv biquandle.out quandle-related-birack-${n}-not-biquandle.txt
		fi
		echo "biquandle-search -n=${n}bRDX$s_yang_baxter$output_options $directory/quandle-related-birack-${n}-not-quandle.txt $directory/quandle-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}bRDX$s_yang_baxter$output_options $directory/quandle-related-birack-${n}-not-quandle.txt $directory/quandle-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out quandle-related-birack-${n}-not-quandle-$output_options.txt
		else
			mv biquandle.out quandle-related-birack-${n}-not-quandle.txt
		fi
		echo "biquandle-search -n=${n}bRDX$s_yang_baxter$output_options $directory/quandle-related-birack-${n}.txt $directory/quandle-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}bRDX$s_yang_baxter$output_options $directory/quandle-related-birack-${n}.txt $directory/quandle-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out quandle-related-birack-${n}-$output_options.txt
		else
			mv biquandle.out quandle-related-birack-${n}.txt
		fi
		echo "biquandle-search -n=${n}rRX$s_yang_baxter$output_options $directory/rack-${n}-not-quandle.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}rRX$s_yang_baxter$output_options $directory/rack-${n}-not-quandle.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out rack-${n}-not-quandle-$output_options.txt
		else
			mv biquandle.out rack-${n}-not-quandle.txt
		fi
		echo "biquandle-search -n=${n}rRX$s_yang_baxter$output_options $directory/rack-${n}.txt"
		/home/bart/source/biquandle/biquandle-search -n=${n}rRX$s_yang_baxter$output_options $directory/rack-${n}.txt
		if [[ $output_options != "" ]]
		then
			mv biquandle.out rack-${n}-$output_options.txt
		else
			mv biquandle.out rack-${n}.txt
		fi
	fi
fi
