#!/bin/bash

########################################
#
#  Dorothy Puma CPSC4240 - Spring 2016 
#
#  runHW1.sh will run hw1 to create datasets for analysis
# 
# usage: ./runHW1.sh 1000000 1 10 Results hw1
#        ./runHW1.sh <ITERATION COUNT> <FIRST SCALING PARAMETER> <NUMBER OF RUNS> <NAME OF RESULTS DIR> <BASE FILENAME>
#
########################################


show_usage() {
  echo "                     "
  echo "usage: ./runHW1.sh 1000000 1 10 Results hw1"
  echo "       ./runHW1.sh <ITERATION COUNT> <FIRST SCALING PARAMETER> <NUMBER OF RUNS> <NAME OF RESULTS DIR> <BASE FILENAME>"
  echo "                     "
}

  echo "$*"
  if [ "$#" -ne 5 ]; then
    echo "Incorrect number of parameters"
    show_usage;
  else
  iterationCountP=$1
  firstScalingP=$2
  numberRuns=$3
  resultsDirectory=$4
  baseDataFile=$5

  echo "You entered $iterationCountP $firstScalingP $numberRuns, $resultsDirectory $baseDataFile"
  if [ ! -d ./$resultsDirectory ]; then
    mkdir "./$resultsDirectory"           # create the directory if it does not exist
  else 
    rm -rf "./$resultsDirectory"       # to create clean test, delete existing directory
    mkdir "./$resultsDirectory"           # create the directory again so it's empty
  fi

  let "loopcount=$numberRuns -1"
  for i in $(eval echo {0..$loopcount})
  do
      echo -n "$i "
      let "dataBlockSize=(2**($firstScalingP+$i))"
      echo $dataBlockSize
        ./hw1 $iterationCountP $dataBlockSize > ./$resultsDirectory/$baseDataFile.$dataBlockSize
  done
    
  fi
