#!xerion
# '$Id: printError,v 1.1 93/04/14 11:12:19 drew Exp $'
# Sets up a trace for 'doExamples' that prints the absolute error
# of all the units in an output group. It prompts for the name of
# the output group.
#

############################################################
# create OutputName and y-n-response if they don't exist, 
# then set them to default values ("Output", and "n")
############################################################
unset unset-error
if same "$OutputName" "" ; then
    var String OutputName
    set OutputName = "Output"
fi
if same "$y-n-response" "" ; then
	var String y-n-response
	set y-n-response = n
fi
set unset-error

############################################################
# if no command args, prompt for a value for OutputName
############################################################
if same "$tokc" "1" ; then
    prompt OutputName "Enter the name of the output group: ($OutputName) "

############################################################
# if one command argument, set OutputName to it
############################################################
elif same "$tokc" "2" ; then
    set OutputName="${tokv[1]}"

############################################################
# anything else is an error
############################################################
else
    echo "usage: ${tokv[0]} [OutputName]"
    exit
fi

# see if the group actually exists, if not prompt for new name
if groupLongName "$OutputName" > /dev/null ; then
    var String group
    set group = $(groupLongName "$OutputName") 
else
    ${tokv[0]}
    exit
done

# generate a string containing "0 1 2 ... group.numUnits - 1"
var int	   idx
var String range
set idx = 0
while same $(calc $idx < ${${group}.numUnits}) "1" ; do
    set range = "$range $idx"
    set idx   = $(calc $idx + 1)
done

# create variables for holding the errors (an array)
var Real error[${${group}.numUnits}]

# Now add the trace to 'doExamples' (we use another script file
# to make all the parsing simpler)
addTrace +0 doExamples "printExampleError"

# run doExamples
doExamples

# delete the command we added to the trace
deleteTrace doExamples 0
