#! /bin/bash

# file: next.sh

# This bash script analyzes the record named in its command-line argument ($1),
# saving the results as an annotation file for the record, with annotator 'qrs'.
# This script is run once for each record in the Challenge test set.

# For example, if invoked as
#    next.sh 100
# it analyzes record 100 using 'gqrs', and saves the results as an annotation
# file named '100.qrs'.
set -e #this command means that as soon as any command fails, whole script fails
START_TIME=$SECONDS
echo "Running 'next.sh' With parameter: '$1'"
echo "next.sh $1"
temp=`mktemp`'.csv'
annotations=`mktemp`'.annotations'


#convert data into CSV dile
echo "Converting input file into CSV: $temp"
  rdsamp -r "$1" -c -H -f 0 -v -pd > "$temp"
echo "Running processing program for input: $temp"
  java -cp ./bin:./sources/lib/commons-lang3-3.1.jar:./sources/lib/commons-math3-3.2.jar:./sources/lib/jcsv-1.4.0.jar:./sources/lib/joda-time-2.0.jar cz.academyofscience.upt.challenge2014.Challenge2014 "$temp" > "$annotations"
echo "Converting program output into annotation file"
  wrann -r $1 -a qrs < "$annotations"

rm $temp
rm $annotations
echo " * Running time of next.sh script: "$(($SECONDS - $START_TIME))"sec."
echo "------------------------------------------"

#remove all temporal files
#rm -rf $temp
# In your entry, you should replace the command above with one or more commands
# that will produce a '.qrs' annotation file using your own code.

