!
! Performance test for plotting a pipe of cities
!
! Author:  J. Hallam
!
startmacro
switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE
if interAct then

  set instructions "Change the number of cities per second."

  call setDatDir

  res cities_file "^{datDir}.cities.prm"

  set bytesPerRecord FILE(cities_file).bpe
  set L:citiesPerSec 1
  calc L:bytesPerSec citiesPerSec bytesPerRecord *
  info "^reg.main.name: initial bytes/sec = ^bytesPerSec"
  pipe init
    noop/tl=1/wrap/rt/rate=bytesPerSec cities_file _cities{SIZE=5000}


    panel/msgid=MAIN/setup/controls=gc

    plot/id=idplot world|_cities

    gcontrol label macro "MACRO"
    gcontrol menu main "" EXIT
    gcontrol lval citiesPerSec "Cities/Sec" citiesPerSec 1 1e6 1
    gcontrol lval bytesPerSec "Bytes/Sec" citiesPerSec 1 1e6 1 /mon=bytesPerSec /msg=f
    gcontrol text idtext "Instructions" "^instructions" 24 5 /title
    gcontrol PIPEMON pmon _cities
  pipe off

else
  ! No non-interactive tests for PLOT yet
endif

endmacro

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

  !say "msg.name ^msg.name, data ^msg.data"

  if msg.name eqs "MAIN" then
    pipe stop

  elseif msg.name EQS "CITIESPERSEC" then
    set L:citiesPerSec ^msg.data
    calc L:bytesPerSec citiesPerSec bytesPerRecord *
    set reg.NOOP.rate ^bytesPerSec
  
  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
