#!/bin/bash
# example: ./stats.sh  aces  mcl2

dataset=$1
method=$2

source script_variables.sh
set -e # exit on error
set -o pipefail


for algo_output in ${dataset}_chunks/${method}/???; do
	chunk_id=`basename ${algo_output}`

	       stats=${dataset}_chunks/${method}/${chunk_id}_stats.json
	stats_matlab=${dataset}_chunks/${method}/${chunk_id}_stats.m
           chunk=${dataset}_chunks/${chunk_id}
	
	echo Dataset: ${dataset} Method: ${method}
	echo Reading stats from:   ${algo_output}
	echo Chunk with true_pose: ${chunk}
	echo Creating file:        ${stats}

	${fts_exp_eval} -file_in ${algo_output} -file_log ${chunk} > ${stats}
	status=$?
	
	
	if [ ${status} -ne 0 ]; then 
		echo -e 'Error while getting stats.'
		exit ${status}
	fi
	
	echo ... converting to Matlab:
	${json2matlab}  ${stats} ${stats_matlab} 
	#stats_${chunk_id}

	if [ ${status} -ne 0 ]; then 
		echo -e 'Error while converting to Matlab.'
		exit ${status}
	fi
done



