!******************************************************************************!
! Test prototype support for accurate RF readouts on raster plots
!
! Author:  Jeanette McCall
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)

  if interAct then
    call setDatDir

    res fm_file_fnom  "fm_file_fnom.tmp"
    res fm_file       "fm_file_fnom.tmp"
    res fm_file_tune  "fm_file_tune_adj.tmp"
    res psd_tune      "psd_tune_adj.tmp"
    res z:mytrue true

    file copy/f ^{datDir}.fm_capture_t1000.prm fm_file_fnom
    ! put in a workable FNOM value (NONE is NOT valid)
    key fm_file_fnom put FNOM 4000.0
    file copy/f fm_file_fnom fm_file_tune
    call addTuneAdjustments
    fft/psd/log fm_file_tune psd_tune nfft=1k

    pipe init
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label  macro   "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      set instructions "Raster Tune Adjustments Prototype"
      gcontrol text idtext "Instructions" "^instructions" 24 8 /title

      noop/rt/wrap/id=fm fm_file _fmwave{ps=32k}
      fft/psd/log _fmwave _fmpsd nfft=1k
      plot/id=psd1sbt _fmpsd{RasterTuneAdjust=^mytrue} /TYPE=RASTER /READOUT=+SHOW|+ONAXIS|+X|+Y|+T|+ExtPREC
      plot/id=psdsbts psd_tune{RasterTuneAdjust=^mytrue} /TYPE=RASTER /READOUT=+SHOW|+ONAXIS|+X|+Y|+T|+ExtPREC
    pipe off
  endif

  erase fm_file

endmacro

!******************************************************************************!
procedure processMessage m:msg
  !say "msg.name ^msg.name, data ^msg.data"

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name " msg.data eqss "PASS"
    pipe stop
  else
    ! do nothing
    say "Unhandled message name: ^msg.name from fid: ^msg.fid dats: ^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 addTuneAdjustments

  key fm_file_tune GET SBT sbt1
  key fm_file_tune DEL SBT
  key fm_file_tune PUT SBT_1 sbt1
  status fm_file_tune TC jtime1
  file open/d tag fm_file_tune
    invoke jtime1 tag.getStart()
  file close tag
  key fm_file_tune PUT JTIME_1 jtime1
  calc jtime jtime1 1 +
  calc sbt sbt1 250 +
  key fm_file_tune PUT SBT_2 sbt
  key fm_file_tune PUT JTIME_2 jtime
  calc jtime jtime 1 +
  calc sbt sbt 250 +
  key fm_file_tune PUT SBT_3 sbt
  key fm_file_tune PUT JTIME_3 jtime
  
return
