#!/bin/sh

DIR=D007_Results_Jan2009
cd ${DIR}
FILES=`ls s*.txt`
cd ..

mkdir -p ${DIR}_clean

#NANS="NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN"
#"NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	0	0	0	0	0	0	0	0	0	0	0	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN	NaN"

for AFILE in ${FILES}; do
    if [ "X${1}" = "X-4" ]; then
        grep "^--> ." ${DIR}/${AFILE} | grep -v "UncodedFrames" | sed "s/^--> \r/${NANS}/" | sed "s/^--> 	0	0	0	0/${NANS}/" | sed "s/^--> //" | sed "s/\r//" > ${DIR}_clean/${AFILE}
    else
        grep "frame" ${DIR}/${AFILE} | grep -v "UncodedFrames" | sed "s/^.*frame\([0-9][0-9]*\)\.bmp/\1/" > ${DIR}_clean/${AFILE}
    fi
done

#| sed "s/${WS}Eyes: {[^}]\+}${WS}{[^}]\+}//" | sed "s/{[^}]*}\t//g" | sed "s/^\([0-9][0-9][0-9][0-9][0-9]\)${WS}*$/\1${NANS}/" | sed "s/\([0-9][0-9][0-9][0-9][0-9]\)\t\tNaN\tNaN${WS}*$/\1${NANS}/" | sed "s/\([0-9][0-9][0-9][0-9][0-9]\)\t\tNA*$/\1${NANS}/" | sed "s/\([0-9][0-9][0-9][0-9][0-9]\)\t\t0\t0\t0\t0${WS}*$/\1${NANS}/" | sed "s/\([0-9][0-9][0-9][0-9][0-9]\)\tNA.*$/\1\t${NANS}/" > ${TMP}



#Enter path to image (Windows demo only accepts 24 bit bitmaps) or ctrl-c to exit
#--> -1.8582071	-1.1470694	1.1127802	-0.008540196	-0.30579841	0.039584115	-2.1914561	0.47640214	2.4750739	-0.32789926	1.2952335	-3.2950795	-0.6673739	-2.9284008	-0.54967635
#Enter path to image (Windows demo only accepts 24 bit bitmaps) or ctrl-c to exit
#--> -1.6496473	-1.1609645	1.3938321	0.035822225	-0.43390033	0.32972267	-2.1561444	0.48357226	2.4265263	-0.44142859	1.2498718	-3.2320058	-0.61735397	-2.9853535	-0.51852501
#--> 	0	0	0	0

