startmacro
!
! Author : Jay Hallam
!
! DEPENDENCIES: NOOP
!

  set L:xferLength 3
  !
  !  Build a file on which it is easy for us to measure statistics.
  !
  file open/n/d tag test_statistics_pipe{FORMAT=SL}
    do i 0 8
      if i LE 2 then
        set tag.data(i) 1
      elseif i LE 5 then
        set tag.data(i) 3
      else
        set tag.data(i) 5
      endif
    enddo
  file close tag

!  set instructions "Press Start to start data flow. Then verify MEAN goes from 1 &
!                    to 3 then 5.  Final SUM should be 27."
  set instructions "Verify MEAN goes from 1 to 3 then 5. Final SUM should be 15."
  pipe on
    panel/controls=gc/setup
    noop/rt/tl=xferLength test_statistics_pipe _pipe{PS=20}    
    statistics/tl=xferLength/piecewise _pipe table=sTab
    shellgui/id=idshellgui
    gcontrol label  MACRO "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      gcontrol text idtext "Instructions" "^instructions" 24 5 /title

      gcontrol pipemon mypipe _pipe
      foreach key INLIST "MEAN,SDEV,ELEM,MIN,MAX,SUM"
        gcontrol/mon=sTab.^key/msg=f dval ^key "^key" 0 0 -1 
      endfor
  pipe off

  files/e test_statistics*

endmacro

!******************************************************************************!
procedure processMessage
  if msg.name EQS MAIN then
    assert/text="STATISTICS pipe test" msg.data eqss "PASS" 
    pipe stop
  elseif msg.name EQS START then

  else
    say "^reg.main.name: unrecognized message ^msg.name"
  endif
return
