#!/bin/env csh
#
# **************************************************************************** #
# Test initializing graphical macro many times in succession
#
# Arguments: 1st: (optional) desired NMROOT [DEF=login's NMROOT]
#            2nd: (optional) desired number of iterations [DEF=10,000]
#
# @bug:       2499: Panel: SWING AWT deadlocks when running a macro
# @bug:       2500: Occasional exceptions when running sd360 a multitude of times
# @author:    JC4 / J Bauer / Neon Ngo
# @version:   $Id: test_sd360_loop.sh,v 1.5 2012/02/23 14:14:22 ntn Exp $
#
# **************************************************************************** #
echo "start time = `date`"
set startTime = `date +%s`

# if arg1 is given, use it for path to NMROOT
if ($# > 0) then
  setenv NMROOT $1
endif

# if arg2 is given, use it for number of iteration to run
if ($# > 1) then
  set numIter = $2
else
  set numIter = 100000
endif

echo "using NMROOT = $NMROOT"
source $NMROOT/os/unix/nmstart

# turn on stacktrace for debugging
set args="debug on trace"
source $NMROOT/os/unix/nm

echo "Running sd360 in continuous loop for $numIter times ..."

set i=0
while (${i} < $numIter)
  echo -n "${i}: "
  set args="sd360 1e5"
  source $NMROOT/os/unix/nm
  @ i = `echo "${i}+1" | bc`
end

echo "end time = `date`"

# calc total run time of this script
set endTime = `date +%s`
@ duration = $endTime - $startTime
echo "Total elapsed time (sec) = $duration"
