startmacro L:pauseTime[3]
!
! Test PLOT scaling with MAXRANGE= (with SCALE=) as well as RANGE= inputs
!
! @author  Jay Hallam
! @bug     1869
!
  ! 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

  call setDatDir

  maxmin ^{datDir}.fftdemo.prm maxout=ymax 
  res yrange 210
  calc ymin ymax yrange -
  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 the top plot looks like the bottom plot. &
                        The y-axis scales are automatically tested. &
                        They should be :  ymin(y1)=^{ymin} ymax(y2)=^{ymax}"
      
      gcontrol text idtext "Instructions" "^instructions" 24 10 /title
      plot/id=plotrng    ^{datDir}.fftdemo.prm range=yrange
      set reg.panel.panes.PLOTRNG.title "PLOT with RANGE"
      plot/id=plotmaxrng ^{datDir}.fftdemo.prm maxrange=yrange SCALE="MAXRANGE"
      set reg.panel.panes.PLOTMAXRNG.title "PLOT with MAXRANGE and SCALE"
    
    
    endif

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

endmacro

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

  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 RANGE= and MAXRANGE= tests" msg.data eqss "PASS"
    pipe stop

  endif

return

!******************************************************************************!
! Set the dat directory
!******************************************************************************!
procedure setDatDir
  invoke nxmMajor env.nmversion.subString(0,1)
  invoke major java.lang.Integer.valueOf(nxmMajor)
  if major GE 4 then
    invoke s:datDir           nxm.sys.test.DatLocator.getDatDirLocation()
    invoke s:datDirSlash      nxm.sys.test.DatLocator.getDatDirSlashLocation()
    invoke z:sysDatFull       nxm.sys.test.DatLocator.sysDatFull()
    invoke z:sysTestDatExists nxm.sys.test.DatLocator.sysTestDatExists()
  else
    set s:datDir           "nxm.sys.dat"
    set s:datDirSlash      "nxm/sys/dat"
    set z:sysDatFull       true
    set z:sysTestDatExists false
  endif
return

!**************************************************************************************************!
procedure checkPlotBounds
if debug then
  say "---------- checking plot bounds --------------"
  results reg.plotrng.y1
  results reg.plotrng.y2

  results reg.plotmaxrng.y1
  results reg.plotmaxrng.y2

  res ymin
  res ymax
endif

  assert/text="^reg.main.name: PLOT RANGE=^yrange - ymin(y1)"   reg.plotrng.y1   EQT ymin /tol=0.1
  assert/text="^reg.main.name: PLOT RANGE=^yrange - ymax(y2)"   reg.plotrng.y2   EQT ymax /tol=0.1

  assert/text="^reg.main.name: PLOT MAXRANGE=^yrange SCALE=MAXRANGE - ymin(y1)"   reg.plotmaxrng.y1   EQT ymin /tol=0.1
  assert/text="^reg.main.name: PLOT MAXRANGE=^yrange SCALE=MAXRANGE - ymax(y2)"   reg.plotmaxrng.y2   EQT ymax /tol=0.1
return
