startmacro

  res dave3000file dave_3000_file.tmp
  res dave2000file dave_2000_file.tmp
  res fsize 250
  res timePerFrame 1000
  res numFrames 1000
  res moduloValue 4
  calc binSize timePerFrame fsize /
  res source1off 125
  res source2off 126
  res source3off 275

  call create_record_data dave3000file

  pipe on
    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}
      gcontrol text idtext "Instructions" "Prototype for NXM-4005" 24 12 /title

      noop/RT dave3000file _piped3000
      nxm.sys.test.timeslicer IN=_piped3000 OUT=_timevstime TIME_PER_FRAME=timePerFrame FS=fsize /TL=1
      plot/id=timeraster _timevstime /TYPE=RASTER /READOUT=+ONAXIS|+EXTPREC|+DATESTRING
      noop _timevstime dave2000file
  pipe off

  erase dave3000file dave2000file
endmacro

!******************************************************************************!
procedure processMessage m:msg
  !say "got ^{msg.toString(NAME|DATA)}"

  if msg.name eqs "MAIN" then
    assert/text="Plot files tests" msg.data eqss "PASS"
    pipe stop
  endif

!**********************************************************
procedure create_record_data fn:testfile

  if "^testfile" FEXISTS erase "^testfile"
  res sec_per_row timePerFrame
  calc binsize timePerFrame fsize /
  timex 2023:08:26::00:00:25 wsec=startTime
  res frametime startTime
!
! For ASCII (string data) we use the format 2A instead of SA to perform
! a more general test.
!
    file open/d/n tag testfile{SR=(AMP/SD,EVENT_TIME/SD,NAME/2A)}
    res i 0
    do row 0 numFrames-1
      if row NEQ 200 THEN
        calc modResult row 4 MOD
        ! source 1 - every frame
        calc time frametime source1off + 
        res tag.setdata(i,NAME) "SOURCE_1"
        res tag.setdata(i,AMP)  10
        res tag.setdata(i,EVENT_TIME) time
        calc i i 1 +
        ! source 2 - every 3rd frame
        if modResult EQ 0 THEN
         calc time frametime source2off + 
          res tag.setdata(i,NAME) "SOURCE_2"
          res tag.setdata(i,AMP)  20
          res tag.setdata(i,EVENT_TIME) ^time
          calc i i 1 +
        endif
        ! source 1 - every frame
        calc shift modResult binSize *
        calc time frametime source3off + shift +
        res tag.setdata(i,NAME) "SOURCE_3"
        res tag.setdata(i,AMP)  25
        res tag.setdata(i,EVENT_TIME) ^time
        calc i i 1 +
      endif
      calc frametime frametime timePerFrame +
    enddo
  file close tag
  headermod testfile XS=startTime
  !say "made 3000"

return
return