startmacro L:pauseTime[3]
!
! Test scaling with PLOT/ALL for xmin, xmax, y1 (ymin), y2 (ymax)
! of Type 2000 (line plots for Frequency vs Time, or None vs Time)
!
! @author  Neon Ngo
! @bug     1502, 2478
!
  ! this is a non-interactive test case, unless user wants to "see" the problem
  switch INTERACTIVE interAct GET DEF=TRUE SDEF=TRUE
  switch DEBUG       debug    GET DEF=FALSE SDEF=TRUE

  ! generate test data
  set fs1   200 ! frame size for testfile 1 (2000 SD)
  set fs2   4K  ! frame size for testfile 2 (2000 CF) - FS=64K in original problem file, but this is enough to show problem
  set xd1  0.01 ! abscissa delta for test file 1 (SD)
  set xd2  0.02 ! abscissa delta for test file 2 (CF)
  set xs1   0.0 ! abscissa start (xmin) for test file 1
  set xs2   -8k ! abscissa start (xmin) for test file 2
  set xmax1 xs1+((fs1-1)*xd1) ! expected xmax (x2) for test file 1
  set xmax2 xs2+((fs2-1)*xd2) ! expected xmax (x2) for test file 2
  set amp1 2.0
  set amp2 3.0
  set ymin1 -amp1 ! expected y1 for test file 1
  set ymax1  amp1 ! expected y2 for test file 1
  set ymin2 -amp2 ! expected y1 for test file 2
  set ymax2  amp2 ! expected y2 for test file 2
  set ys1  2008:07:02::00:00:00
  set ys2  2008:07:03::00:00:00
  set yd   1.0

  res testfile1 ram:test_plot_scale_sd.tmp
  res testfile2 ram:test_plot_scale_cf.tmp

  ! generate sample data to match sample data from DR
  waveform testfile1 form=sd elem=fs1 shape=LRS  amp=amp1 start=xs1 delta=xd1
  waveform testfile2 form=cf elem=fs2 shape=sine amp=amp2 start=xs2 delta=xd2
  headermod testfile1 framesize=fs1 xu=none xs=xs1 xd=xd1 ys=ys1 yd=yd
  headermod testfile2 framesize=fs2 xu=none xs=xs2 xd=xd2 ys=ys2 yd=yd

  pipe on
    if interAct then
      panel/controls=gc/setup
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      set instructions "Verify that:\n&
                        top plots look like the bottom plots.\n\n&
                        *************************************\n&
                        AUTOMATICALLY TESTED\n&
                        expected x-axis and y-axis scales:\n&
                        Plot1: x1=^{xs1} x2=^{xmax1} y1=^{ymin1} y2=^{ymax1}\n&
                        Plot2: x1=^{xs2} x2=^{xmax2} y1=^{ymin2} y2=^{ymax2}."
      gcontrol text idtext "Instructions" "^instructions" 24 10 /title

      plot/id=plot1_exp/all/axisbuffer=0 testfile1 x1=xs1 x2=xmax1 y1=-amp1 y2=amp1
      plot/id=plot2_exp/all/axisbuffer=0 testfile2 x1=xs2 x2=xmax2 y1=-amp2 y2=amp2
    endif

     ! Note 1: specifying /wpos= for when running test case in non-interactive mode
     ! Note 2: use if the /axisBuffer switch is for the equality assert checks later, and tests /axisBuffer= for Bug 2478
     plot/id=plot1_sd/wpos=(30,30,300,300)/all/axisbuffer=0  testfile1
     plot/id=plot2_cf/wpos=(350,30,300,300)/all/axisbuffer=0  testfile2

    message FUNC=SEND ID=MAIN NAME=START
  pipe off

endmacro

!**************************************************************************************************!
procedure processMessage m:msg
  if debug then say "^reg.main.name: message name: ^msg.name from fid: ^msg.fid data: ^msg.data"

  if msg.name EQS "START" then
    ! Wait for the plot and layers to draw and initialize variables
    pause 1.0
    call checkPlotBounds

    if interAct then
      ! Nothing to do
    else
      pause pauseTime
      pipe stop
    endif

  elseif msg.name EQS "MAIN" then
    assert/text="^reg.main.name: Plot/ALL SCALE tests" msg.data eqss "PASS"
    ! call checkPlotBounds
    pipe stop

  endif

return

!**************************************************************************************************!
procedure checkPlotBounds
if debug then
  say "---------- checking plot bounds --------------"
  results reg.plot1_sd.xmin
  results reg.plot1_sd.xmax
  results reg.plot1_sd.y1
  results reg.plot1_sd.y2
  res amp1

  results reg.plot2_cf.xmin
  results reg.plot2_cf.xmax
  results reg.plot2_cf.y1
  results reg.plot2_cf.y2
  res amp2
endif

  assert/text="^reg.main.name: PLOT/ALL on 2000 SD file - xmin" reg.plot1_sd.xmin EQ  xs1
  assert/text="^reg.main.name: PLOT/ALL on 2000 SD file - xmax" reg.plot1_sd.xmax EQ  xmax1
  assert/text="^reg.main.name: PLOT/ALL on 2000 SD file - y1"   reg.plot1_sd.y1   EQT ymin1 /tol=0.1
  assert/text="^reg.main.name: PLOT/ALL on 2000 SD file - y2"   reg.plot1_sd.y2   EQT ymax1 /tol=0.1

  assert/text="^reg.main.name: PLOT/ALL on 2000 CF file - xmin" reg.plot2_cf.xmin EQ  xs2
  assert/text="^reg.main.name: PLOT/ALL on 2000 CF file - xmax" reg.plot2_cf.xmax EQ  xmax2
  assert/text="^reg.main.name: PLOT/ALL on 2000 CF file - y1"   reg.plot2_cf.y1   EQT ymin2 /tol=0.1
  assert/text="^reg.main.name: PLOT/ALL on 2000 CF file - y2"   reg.plot2_cf.y2   EQT ymax2 /tol=0.1
return
