!******************************************************************************!
! Test Histogram with complex and scalar input
! CXMODE: PHASE
!
! Note: The former test_histogram_mods just tested if things worked the way they
!       had in the past. It verified that one complex mode gave the same incorrect
!       results it had been giving. test_histogram_complex & test_histogram_complex_phase'
!       have replaced it.
!
! @bug      NXM-4051 Histogram fails with complex input data
! @since    NeXtMidas 4.1.4
! @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)

  res cwave_phase       ram:test_cwave_phase
  res fcalc_swave_phase ram:test_fcalc_swave_phase
  res hist_cwave_phase  ram:test_hist_cwave_phase
  res hist_swave_phase  ram:test_hist_swave_phase

  waveform out=cwave_phase form=cf elem=64 shape=pulse amp=64 freq=200 phase=0.5
  fcalc fcalc_swave_phase cwave_phase PHASE
  histogram in=cwave_phase out=hist_cwave_phase start=0 end=1 bins=10 cxmode="PHASE"
  histogram in=fcalc_swave_phase out=hist_swave_phase start=0 end=1 bins=10

  ASSERT/text="^reg.main.name: CXMODE=PHASE matches" hist_cwave_phase FEQ/D hist_swave_phase

  if interAct then
    set instructions "Check the terminal for automated tests passing\n\n&
                      ******************************\n\n&
                      Histogram Bins:\n&
                      ##  start   phase\n&
                      01   0.0      1 \n&
                      02   0.1      0 \n&
                      03   0.2      0 \n&
                      04   0.3      0 \n&
                      05   0.4      0 \n&
                      06   0.5      0 \n&
                      07   0.6      0 \n&
                      08   0.7     63 \n&
                      09   0.8      0 \n&
                      10   0.9      0 \n&
                      "

    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

      plot/id=cxmode hist_cwave_phase{layer={line={TYPE=+BAR,THICKNESS=4}}} x1=-0.1 x2=1.1 type=dot
      plot/id=sfcalc hist_swave_phase{layer={line={TYPE=+BAR,THICKNESS=4}}} x1=-0.1 x2=1.1 type=dot

      list2/id=fcalc   fcalc_swave_phase
      list2/id=lcxmode hist_cwave_phase

    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

  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return
