/* test18.rexx */
signal ON BREAK_C
signal ON SYNTAX
signal ON ERROR

finalmsg = 'Program aborted!'

if ~show('L',"rexxsupport.library") then
   call addlib "rexxsupport.library",0,-30

if ~show('L',"rexxmathlib.library") then
   call addlib "rexxmathlib.library",0,-30

call pragma 'D','PG:'
options results
numeric digits 8

if  ~show('P', "PolyMeas.Host")  then do
   say 'Loading PolyGraph.V20.0'
   address COMMAND 'run polygraph.v20.0 -Xl0 -Xr50 -Yl-1.5 -Yr2.5 -PM -WB -t2 -p2048 -z8'
end
do  i=1 to 40
   if  show('P', "PolyMeas.Host")  then leave i
   address COMMAND 'Wait 2'
end i
if  ~show('P', "PolyMeas.Host")  then exit
address 'PolyMeas.Host'

say 'Testing the Menu Smoothing from ARexx'

pi = 3.141592
rad = pi/180
imax = 60

'ChooseMenu New'
'ChooseMenu AutoScaling'

/*
do i = 1 to 64
   xv.i = i*rad * (60/64)
   yv.i = sin( 6*xv.i) + sin( 2*xv.i)
*/
do i = 1 to imax
   xv.i = i
   yv.i = sin( 6*xv.i*rad) + sin( 4*xv.i*rad) + 0.2*cos( 500*xv.i*rad)

   'Plot' xv.i yv.i
end i
'ChooseKey LEFT ALT 1'
'ChooseKey RIGHT ALT 2'
'ChooseKey CTRL 8'
'ChooseMenu Narrator'
'ChooseMenu Set First Index 1'
'ChooseMenu Set Last Index 'imax
'ChooseMenu Smoothing Include=10 points, Window=3%'
'ChooseMenu Narrator'

finalmsg = 'program finished'
signal BREAK_C

ERROR:
say 'A Program Error occured!'
signal BREAK_C

SYNTAX:
say 'A Syntax Error occured!'

BREAK_C:
'MeasToBack'
'GraphToBack'
say 'Do you want to close PolyGraph ?'
pull answ
if answ = 'Y' then 'StopPoly'
else say finalmsg
exit
