startmacro
! Test the LAYER= input.  This shows how to use keep defaults on a layer
! through an OPENFILE message.
! 
! Author:  Jay Hallam
!
  switch INTERACTIVE interAct GET DEF=FALSE SDEF=TRUE

  call setDatDir

  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 both plot traces have the same color"
      gcontrol text idtext "Instructions" "^instructions" 24 5 /title
      
    endif

    plot/id=plot1 layer={COLOR=RED}
    message FUNC=SEND ID=PLOT1 NAME=OPENFILE INFO=-1 DATA=^{datDir}.fftdemo.prm

    plot/id=plot2 ^{datDir}.fftdemo.prm{layer={COLOR=RED}}
    message FUNC=SEND ID=MAIN NAME=START
  pipe off

endmacro

!**************************************************************************************************!
procedure processMessage m:msg

  if msg.name EQS "START" then
    if interAct then
      ! Nothing to do
    else
      ! Wait for the layer to appear
      set count 0
      while reg.plot1.layers.fftdemo NREXISTS
        pause 0.2
        calc count count+1
        if count GT 10 then break
      endwhile
      call assertColor
      call assertBug807
      pipe stop
    endif  

  elseif msg.name EQS "MAIN" then
    assert/text="Plot LAYER= tests" msg.data eqss "PASS" 
    call assertColor
    call assertBug807
    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 assertColor
  res color1 reg.plot1.layers.fftdemo.color
  res color2 reg.plot2.layers.fftdemo.color

  assert/text="^reg.main.name comparing color: " color1 EQO color2 AND "^color1" EQS "^color2"
return
!**************************************************************************************************!
procedure assertBug807
  set reg.plot1.xs 1.5
  res xstart reg.plot1.xs
  assert/text="^reg.main.name checking X Axis Start: " xstart EQ 1.5 
  
  set reg.plot1.xd 30.5
  res xdelta reg.plot1.xd
  assert/text="^reg.main.name checking X Axis Delta: " xdelta EQ 30.5
  
  set reg.plot1.ys 3.2
  res ystart reg.plot1.ys
  assert/text="^reg.main.name checking Y Axis Start: " ystart EQ 3.2
  
  set reg.plot1.yd 25.5
  res ydelta reg.plot1.yd
  assert/text="^reg.main.name checking Y Axis Delta: " ydelta EQ 25.5

return