startmacro
!
! Test the plotting of files with the /ALL switch.
!
! Author:  J. Hallam
!
  call setDatDir

  set instructions "This macro tests the PLOT/ALL switch.\n\n&
                    1. Select Small, Medium, Large\n&
                       => Make sure plots render\n\n&
                    2. On Large, verify scrolling works\n\n&
                    3. On Large, scroll down to the bottom and verify zooming still works after scrolling"

  ! Make a small file
  noop ^{datDir}.apenny.prm(0:4) test_plot_all_small

  ! Make a 1/2M (medium) file
  if test_plot_all_medium NFEXISTS then
    info "^reg.main.name: generating medium size (1/2M) file..."
    WAVEFORM,OUT=test_plot_all_medium,FORM=SF,ELEM=.5M,SHAPE=SAW,AMP=1,FREQ=1/128,PHASE=0,START=0,DELTA=1
    HEADERMOD test_plot_all_medium FS=128
  endif

  res numEls FILE(test_plot_all_medium).size
  res frameSize FILE(test_plot_all_medium).framesize
  calc numBytes numEls frameSize *

  info "^reg.main.name: medium file of ^numBytes bytes"

  ! Make a 4M (large) file
  if test_plot_all_large NFEXISTS then
    info "^reg.main.name: generating large size (4M) file..."
    mergefile/replay=8 test_plot_all_medium test_plot_all_large
    HEADERMOD test_plot_all_large FS=128
  endif
  res numEls FILE(test_plot_all_large).size
  res frameSize FILE(test_plot_all_large).framesize
  calc numMBytes numEls frameSize * 1M /

stat test_plot_all_large
  info "^reg.main.name: large file of ^numMBytes MBytes"

  ! TBD - Huge - noop apenny test_plot_all_medium

  pipe on
    panel/setup/controls=gc
    gcontrol text   idtext "Instructions" "^{instructions}" 24 12 /title
    gcontrol choice rasterType    "File Size" "Small,Medium,Large,Huge" "Small" /NC=1
    gcontrol menu   main   "Exit with Status = " "PASS,FAIL" /tleft

    set gc.main.itemColors {PASS=GREEN,FAIL=RED}

    plot/id=plot         test_plot_all_small
    plot/id=plot_all/all test_plot_all_small

  pipe off

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
  elseif msg.name eqs "RASTERTYPE" then
    if msg.data EQS "HUGE" then
      beep 1
      warning "^reg.main.name: HUGE FILE NOT YET IMPLEMENTED"
      return
    endif
    set S:str ^msg.data
    set str str.toLowerCase()

    message FUNC=send ID=PLOT NAME=EXIT
    pause 0.5
    plot/id=plot/bg test_plot_all_^str
!    message FUNC=send ID=PLOT NAME=OPENFILE DATA=test_plot_all_^str
    set reg.panel.panes.plot.title     "PLOT     - ^str file"

    message FUNC=send ID=PLOT_ALL NAME=EXIT
    pause 0.5
    plot/id=plot_all/all/bg test_plot_all_^str
!    message FUNC=send ID=PLOT_ALL NAME=OPENFILE DATA=test_plot_all_^str
    set reg.panel.panes.plot_all.title "PLOT/ALL - ^str file"

  else
    say "Unhandled message ^msg.name = ^msg.data from ^msg.fid"
  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
