#! /bin/bash
# Last edited on 2021-12-07 17:42:28 by stolfi

# Extracts {Tcpu} for a given inout dataset and {Delta} for various maxband {mu}
# values, writes them to stdout in the format "{mu} {Tcpu}" (with no decimals,
# as in the paper's table).

datadir="$1"; shift  # Top directory for input "out.txt" files.
regdir="$1"; shift   # Top directory for output "raw.txt" files.
Delta="$1"; shift    # Value of {Delta}, with one decimal.
args=( "$@" )        # Values of {mu} and datasets to consider.
mus=()
sets=()
for arg in "$@" ; do
  if [[ "/${arg}" =~ /[0-9] ]]; then
    mus+=( ${arg} )
  else
    sets+=( ${arg} )
  fi
done

echo "mus = ${mus[@]}" 1>&2 
echo "sets = ${sets[@]}" 1>&2 

for ds in ${sets[@]}; do 
  dsregdir=${regdir}/${ds}_delta${Delta}
  rm -rf ${dsregdir}
  mkdir -p ${dsregdir}
  rawfile=${dsregdir}/raw.txt
  rm -f ${rawfile}
  for mu in ${mus[@]}; do 
    ifile=${datadir}/out/${ds}_delta${Delta}_maxband${mu}/out.txt
    if [[ ! ( -s ${ifile} ) ]]; then echo "** no file ${ifile}" 1>&2; exit 1; fi
    Tcpu=( `cat ${ifile} | egrep -e 'CpuTime:' ` ); Tcpu="${Tcpu[1]}"
    printf "%02d %.0f\n" "${mu}" "${Tcpu}" >> ${rawfile}
  done
done


