!******************************************************************************!
! Test that NORMALIZE works with pipes (for both input and output).
! Also test changing the real time controls (mode, scale, shift) of NORMALIZE.
!
! @author  Neon Ngo
! @version $Id: test_normalize_pipe.mm,v 1.1 2011/10/03 15:56:59 ntn Exp $
! @since   NeXtMidas 3.1.0
!******************************************************************************!
startmacro/poll=0.2 s:mode["SD"]
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch "AMP" amp get 100

if interAct then
  set instructions "Adjust the normalization mode, scale factor, and shift amount. &
                    The y axis should change accordingly in the Normalized data plot. &
                    Note: when adjusting the shift amount (plot may need a few seconds to auto scale)."
  pipe on
    panel/msgid=MAIN/setup/controls=gc
    waveform _pipe "SF" 1e11 sine amp=amp
    normalize/id=norm _pipe _normpipe mode=mode
    plot/id=origplot _pipe
    plot/id=normplot _normpipe

    gcontrol label macro "Test MACRO"
    gcontrol menu  main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /tleft
    gcontrol text  idtext "Instructions" instructions 24 12 /title

    gc choice mode  "Normalize Mode" reg.norm.modeList reg.norm.mode
    gc dval   scale "  Scale factor" reg.norm.scale 1.0 100.0 0.25
    gc dval   shift "  Shift Amount" reg.norm.shift 0.0 10k   10.0

    gc label  advanced "Advanced" "AlwaysOpen"
    gc choice shape "Waveform Shape" reg.waveform.shapeList reg.waveform.shape
  pipe off
endif
endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  elseif msg.name eqs "MODE"
    set reg.norm.mode msg.data
  elseif msg.name eqs "SCALE"
    set reg.norm.scale msg.data
  elseif msg.name eqs "SHIFT"
    set reg.norm.shift msg.data
  elseif msg.name eqs "SHAPE"
    set reg.waveform.shape msg.data
  endif
return
