!******************************************************************************!
! SEE test_plot_prescaler for main baseline test - this is a test only to be run
! for finer diagnostic purposes (1000 files with internal prescale)
!
! @bug      NXM-3078 PLOT: Does not display zero-padded Pre-D data
! @since    3.9.1
! @author:  Jeanette McCall
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)
  switch COREGRAPHICS coreGraphics GET DEF=FALSE SDEF=TRUE ! for a quick check of graphics - more extreme tests - since 3.8.1

  switch NOPRESCALE  noprescale    GET DEF=FALSE SDEF=TRUE  ! do not do prescaling
  switch OUTSIDEPIPE outsidepipe   GET DEF=FALSE SDEF=TRUE  ! do test outside pipe
  switch RANDOM      randomPercent GET DEF=100   SDEF=10    ! get percentage of random frames/blocks to use
  switch MAKECOPY    makeCopy      GET DEF=FALSE SDEF=TRUE  ! have prescaler make a copy of the input file

  res myscaletbl {}
  res zero_padded_data ram:dara

  if interAct then
    set instructions "Run in default/pipe mode the plot will show the last part of the data 0s,1s, empty\n\n&
                      Run this test case a second time with switch OUTSIDEPIPE and then the full signal  0s,1s,0s,1s should render.\n\n&
                      If run with swiches NOPRESCALE  and OUTSIDEPIPE then you can see the behavior before the fis, where &
                      there is just a small partial line flicker on the left."

    ! Generate 0-padded type 1000 data
    waveform ram:f1 FORM=CI ELEM=67500  SHAPE=CONST AMP=0  !DR value 67500
    waveform ram:f2 FORM=CI ELEM=30500  SHAPE=CONST AMP=0  !DR value 30500
    waveform ram:f3 FORM=CI ELEM=672000 SHAPE=CONST AMP=1  !DR value 672000
    waveform ram:f4 FORM=CI ELEM=30000  SHAPE=CONST AMP=0  !DR value 30000
    waveform ram:f5 FORM=CI ELEM=7000   SHAPE=CONST AMP=1  !DR value 7000
    mergefile ram:f1 zero_padded_data
    mergefile ram:f2 zero_padded_data
    mergefile ram:f3 zero_padded_data
    mergefile ram:f4 zero_padded_data
    mergefile ram:f5 zero_padded_data

    if noprescale then
      if outsidepipe then
        call outsidepipe
      else
        call pipetest
      endif
    else
      if outsidepipe then
        call prescaletest
      else
        call pipeprescaletest
      endif
    endif

  endif
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the 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
  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  if expectedException REXISTS then
    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  endif
return


!******************************************************************************!
! Regular pipe test
!******************************************************************************!
procedure pipetest
  pipe on
    panel/msgid=MAIN/setup/controls=gc
    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 20 /title

    noop zero_padded_data _zero_padded 
    plot/all _zero_padded
  pipe off
return

!******************************************************************************!
! Special pipe prescale test
!******************************************************************************!
procedure pipeprescaletest
   pipe on
     panel/msgid=MAIN/setup/controls=gc
     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 20 /title

     noop zero_padded_data _zero_padded_in
     if MAKECOPY then
       plot/all/random=^randomPercent FILE=_zero_padded_in OUTCOPY=ram:prescale_out /PRESCALE
     else
       plot/all/random=^randomPercent FILE=_zero_padded_in /PRESCALE
     endif
   pipe off
return


!******************************************************************************!
! outside pipe prescale test
!******************************************************************************!
procedure prescaletest
  if MAKECOPY then
    plot/all/random=^randomPercent FILE=zero_padded_data OUTCOPY=ram:prescale_out /PRESCALE
  else
    plot/all/random=^randomPercent FILE=zero_padded_data /PRESCALE
  endif
return

!******************************************************************************!
! outside pipe no prescale test
!******************************************************************************!
procedure outsidepipe
  plot/all zero_padded_data
return