!------------------------------------------------------------------------------!
! Tests case where Layer1D data goes beyond plot bounds
!
! @bug     NXM-4048 PLOT/ALL of 1000 file only showing portion of data
! @author  Jeanette McCall
! @since   NeXtMidas 4.1.4
!------------------------------------------------------------------------------!
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 waveproblem   bounds_waveform_problem_256k.tmp
  res elem 200k
  res minrange 12

  set def_instructions &
      "PLOT/ALL of 1000 files now does PRESCALE\n&
       BUT NOT when other SCALING (other than AUTOSCALE) is set\n\n&
       TOP:    PLOT/ALL of 1000 show all of the 1 outlier.\n\n&
       BOTTOM: PLOT/ALL has MINRANGE=^{minRange} so only part of the outlier renders"


  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
    ENDIF

    pipe init

    panel/msgid=MAIN/setup/controls=gc
    plot/ALL/id=autopre/READOUT="+OnAxis" waveproblem
    plot/ALL/id=scaled/READOUT="+OnAxis" waveproblem scale="MINRANGE" MINRANGE=12


    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

    if eraseFile THEN
      erase waveproblem
    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
