!------------------------------------------------------------------------------!
! Tests for plotting a feature at the top/beginning of a plot (BUG 2163 & BUG 2164).
!
!   Author : J. Hallam / J Bauer
!------------------------------------------------------------------------------!
!
startmacro cs:fpath["test2000_tcprec.prm"]

  debug on trace ! Turn on full stack traces

  call setDatDir

  set description "A red and green feature should show up on both plots. The plot &
                   on the left is zoomed in slightly. Right-click on the left plot. &
                   When unZOOMed, the plot should look identical to the right one."
                   
  set x1 1.5214703849192417E8
  set x2 1.6577063399754214E8
  set y1 14.395000000000001
  set y2 21.961428571428574
  
  pipe on

    ! Graphics panel to contain controls, lists and plots
    panel/id=panel/controls=gc/setup

    ! Controls
    gcontrol label  macro   "MACRO"
        gcontrol menu MAIN "Exit with Status = " "PASS,FAIL" /tleft
        set gc.MAIN.itemColors {PASS=GREEN,FAIL=RED}
    gcontrol label wbDownloadLabel "Details"  
      gcontrol text descript  "" "^description",,10

    ! Lists and plots
    plot/all/id=wbpsdplot readout=+T cmap=grayscale 
    plot/id=myplot/msgid=main        readout=+T cmap=grayscale 

    ! Set titles
    set reg.panel.panes.wbpsdplot.title "PLOT/ALL"
    set reg.panel.panes.myplot.title "PLOT"

    message func=send id="MAIN" name="START"

  pipe off

endmacro

procedure processMessage m:msg
  !say "^reg.main.name: Received message: ^msg.name from fid: ^msg.fid"
  
  if msg.name EQS "MAIN" then
    if msg.data EQS "EXIT" then
      pipe stop
    else
      assert/text="FEATURE TOP test: " "PASS" SUBS msg.data
      pipe stop
    endif

  elseif msg.name EQS "START" then
    message func=send id=wbpsdplot name=openfile info=-1 data="^{datDir}.^fpath"
    pause 0.2
    message func=send id=myplot name=openfile info=-1 data="^{datDir}.^fpath"
    call showNBActivityOnWBPlot
    message func=send id=myplot msg=zoom name=ZOOM data={xmin=^x1,xmax=^x2,ymin=^y1,ymax=^y2}
  else
    ! warning "^reg.main.name: unrecognized msg =^msg 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

!**************************************************************************************************!
procedure showNBActivityOnWBPlot

    res sbt 1.62526855E8
    res bw 250000.0
    res tstr "2010:04:22::17:46:58.405"
    timex tstr d:tcenter
    res deltaT 18.81
    ! info "Feature: X (sbt)=^sbt, DX (BW)=^bw, T=^tstr (^tcenter), DT=^deltaT"
    feature label=feat_temp plot=wbpsdplot &
      table={NAME="NBACT_D1R1T1_1",TYPE=BOX|TEXT,X=^sbt,DX=^bw,T=^tcenter,DT=^deltaT,TEXT="D1R1T1_1",COLOR="GREEN"}
    feature label=feat_temp plot=myplot &
      table={NAME="NBACT_D1R1T1_1",TYPE=BOX|TEXT,X=^sbt,DX=^bw,T=^tcenter,DT=^deltaT,TEXT="D1R1T1_1",COLOR="GREEN"}


    res sbt 1.59157715E8
    res bw 250000.0
    res tstr "2010:04:22::17:47:14.940"
    timex tstr d:tcenter
    res deltaT 11.87999999
    ! info "Feature: X (sbt)=^sbt, DX (BW)=^bw, T=^tstr (^tcenter), DT=^deltaT"
    feature label=feat_temp plot=wbpsdplot &
      table={NAME="NBACT_D1R1T1_2",TYPE=BOX|TEXT,X=^sbt,DX=^bw,T=^tcenter,DT=^deltaT,TEXT="D1R1T1_2",COLOR="RED"}
    feature label=feat_temp plot=myplot &
      table={NAME="NBACT_D1R1T1_2",TYPE=BOX|TEXT,X=^sbt,DX=^bw,T=^tcenter,DT=^deltaT,TEXT="D1R1T1_2",COLOR="RED"}


return
