!------------------------------------------------------------------------------!
! Tests case where Layer1D data goes beyond plot bounds
!
! @bug     NXM-3847 PLOT: need to pan beyond bounds to see all data
!          NXM-4048 PLOT/ALL of 1000 file only showing portion of data
! @author  Jeanette McCall
! @since   NeXtMidas 4.1.1
!------------------------------------------------------------------------------!
startmacro
  switch INTERACTIVE interAct   GET DEF=TRUE  SDEF=TRUE
  switch ERASE       eraseFile  GET DEF=FALSE SDEF=TRUE ! erase the large file created/used by this test

  call setDatDir

  set def_instructions &
      "PLOT/ALL of 1000 files now does PRESCALE\n&
       (small plots FULL and large plots 10% RANDOM)\n\n&
       TOP:    PLOT misses data shift and scaling is off.\n        &
               PAN UP to see values are beyond bounds\n\n&
       MIDDLE:\n  &
         LEFT: PLOT/ALL of small file catches 1 outlier\n &
        RIGHT: PLOT/ALL of large file catches data shift\n\n&
       BOTTOM: PLOT/ALL of large file misses 2 outliers.\n        &
               PAN UP to see them."

  set waveproblem   bounds_waveform_problem_256k.tmp
  set waveproblem2x bounds_waveform_problem_512k.tmp
  set waveproblem2x_many bounds_waveform_problem_many_512k.tmp
  res elem 200k

  if interAct then
    if waveproblem NFEXISTS THEN
      INFO "This test takes a few seconds to create the data"
      waveform waveproblem form=SF elem=^elem shape=SIN AMP=5 freq=1/2560
      ! need to manually open this file and adjust data
      file open/d/W tag waveproblem
      foreach offset INSIZE FILE(waveproblem).size
        res F:dataVal tag.getdata(offset)
        if OFFSET GT 72500 AND OFFSET LT 72520 calc F:dataval dataVal 8 +
        res tag.setdata(offset) ^dataVal
      endfor
      file close tag
      file copy/f waveproblem waveproblem2x
      mergefile waveproblem waveproblem2x
      file copy/f waveproblem2x waveproblem2x_many
      ! need to manually open this file and adjust data
      file open/d/W tag waveproblem2x_many
      foreach offset INSIZE FILE(waveproblem2x_many).size
        res F:dataVal tag.getdata(offset)
        if OFFSET GT 72500 calc F:dataval dataVal 8 +
        res tag.setdata(offset) ^dataVal
      endfor
      file close tag
    ENDIF

    pipe init

    panel/msgid=MAIN/setup/controls=gc
    plot/id=2xmany/READOUT="+OnAxis" waveproblem2x_many X1=0 x2=100E3
    plot/ALL/id=idplot/READOUT="+OnAxis" waveproblem
    plot/ALL/id=2xmanyall/READOUT="+OnAxis" waveproblem2x_many
    plot/ALL/id=idplot2x/READOUT="+OnAxis" waveproblem2x x1=0 x2=400E3

    gcontrol label mainLabel "Main"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
    gcontrol text idtext "Instructions" "^def_instructions" 24 20 /title

    pipe off

    %test_plot_layer1d_data_scaled

    if eraseFile THEN
      erase waveproblem waveproblem2x waveproblem2x_many
    endif

  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
    ! do nothing
    say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  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
