!******************************************************************************!
! Author : Jay Hallam
!
! DEPENDENCIES:
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)

  fname LABEL=truthfile AREA=TEST NAME="histogram_output_truth_1" EXT=prm opt=SYS
  if truthfile FEXISTS then
    waveform OUT=temp_histogram_in FORM=SF ELEM=16k SHAPE=COS
    HISTOGRAM,IN=temp_histogram_in,OUT=temp_histogram_out,START=-1,END=1,DELTA=0.02
    ! NOTE: must use /L modifier for file comparison now - since 3.7.0 (BUG 2861)
    assert/text="^reg.main.name: Compare output with truth file" &
                                 temp_histogram_out FEQ/D/L truthfile
  else
    assert/text="^reg.main.name: Unable to find ^truthfile for output comparison"
  endif


  pipe on
    waveform OUT=_pipe FORM=SF ELEM=16k SHAPE=COS
    HISTOGRAM/TL=16k,IN=_pipe,OUT=_hist,START=-1,END=1,DELTA=0.02
    noop _hist temp_histogram_out_frompipe
  pipe off

  ! NOTE: must use /L modifier for file comparison now - since 3.7.0 (BUG 2861)
  assert/text="^reg.main.name: Compare pipe output with truth file" &
                                 temp_histogram_out FEQ/D/L truthfile

  if interact then
    set instructions "Pipe output should look like file output"

    pipe on
      panel/setup/controls=gc
      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

      waveform OUT=_pipe FORM=SF ELEM=1e9 SHAPE=COS
      HISTOGRAM/TL=16k,IN=_pipe,OUT=_hist,START=-1,END=1,DELTA=0.02
      plot _hist
      plot temp_histogram_out
    pipe off

  endif

  files/e temp_histogram_*

  %test_histogram_complex/interactive=^{interact}       ! NXM-4051 Histogram fails with complex input data
  %test_histogram_complex_phase/interactive=^{interact} ! NXM-4051 Histogram fails with complex input data

endmacro

!******************************************************************************!
procedure processMessage
  if msg.name EQS "MAIN" then
    assert/text="^reg.main.name: User indicated pipe test" msg.data eqss "PASS"
    pipe stop

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