#!/bin/sh

echo 'script for finding out groups of a given order, admitting a near-factorization'

echo
echo '************************* input section ************************'

echo 'give the order of the groups to be processed'
read n

if !([ -f ./groups/group.$n.number ]);
then
echo '! this order is not available !'
echo 'please first use the script preprocessing_with_gap (GAP is required) !'
exit 0 ;
fi 

read number < ./groups/group.$n.number
echo 'there are '$number' distinct groups of order '$n

echo 'give the size of A of the near-factorizations (A,B)'
read omega
if !([ $(($n % $omega)) -eq 1 ]);
then
echo '! input size of A is not correct : exiting'
exit 0 ;
fi 

echo
echo '************************* output section ************************'
i=1

echo 'processing groups of order '$n', size of A='$omega
echo
echo 'list of groups admitting a near-factorization:'
while [ $i -le $number ] ;
do

# cleaning tmp directory
rm -fr tmp/*
mkdir tmp/split

echo $n > tmp/n
echo $omega > tmp/omega
echo $i > tmp/i
read sym < ../precalculated_groups/group.$n.$i.abelian_flag
echo $sym > tmp/sym 
echo '1' > tmp/redirection # write output in file tmp/output.$n.$i

echo $sym > tmp/datas
echo '1' >> tmp/datas # use equipartition filter
echo '0' >> tmp/datas # do not use dispersion filter
echo '0' >> tmp/datas # do not use intersection filter
echo $n >> tmp/datas # write order of the group
echo $omega >> tmp/datas # write size of A


cat ./groups/group.$n.$i >> tmp/datas # Cayley table of group processed
cat ../precalculated_groups/group.$n.$i.equipartition_filter >> tmp/datas # for equipartition filter
cat tmp/datas | ./bin/generate_input_file > tmp/input_file # generation of input file
./basic_scripts/split_input_file input_file # split input file in small blocks
./basic_scripts/process_input_file # look for B

wc --lines < tmp/output.$n.$i > tmp/number_of_near_factorizations
read nbsol < tmp/number_of_near_factorizations
if !([ $nbsol -eq 0 ]);
then
echo 'group number '$i
fi

i=$(($i+1))
done


 
