startmacro/nmq=8k/ps=128k/rmifid=2 N:nsamples[1e9]
!******************************************************************************!
!
! Training - Remoting - Original macro based on SD360 without remoting
!
! @author Jay Hallam
! @version $Id: remoteorig.txt,v 1.1 2006/11/02 13:01:25 jph Exp $
!******************************************************************************!

local item itemStr MainMenu
local sfreq,cfreq,fwidth,SRate,amp,StatusString
local FrameSize,form

local /M/

!Intentionally Global Variables
!  cities site world sv1 sv2

  ! No tables in the X-Midas macro language, set the individual results
  res SRate 1e5
  res sfreq SRate/10
  res form "SF"
  res cfreq 0.0
  res fwidth 0.1
  res amp 1e4
  res A:StatusString "Up and running"

  ! We will parse this menu later so we do not have to use item numbers
  res MainMenu "Get,Set,Reset,Test,Stop"

  ! Form the full path to the cities file in the NeXtMidas DAT area
  fname cities dat cities prm nxm
  fname site dat site prm nxm
  fname world dat world prm nxm
  fname sv1 dat sv1 prm nxm
  fname sv2 dat sv2 prm nxm
  
  xpipe/setup/controls on
    WAVEFORM/tl=1k/ctag=3:SFREQ _wave ^form nsamples SIN 1e4 1e4,,, 1/SRate
    MFFT/fftp=3 _wave _wavep 1k hann 0.0
    STATUS/quiet _wavep ,,,,, FrameSize
    XRTPLOT/xs=3/mtag=X:SFREQ/xcnt=2/mark=3 _wavep(cl=8*FrameSize) 1e-5 1e4 l2 ,, 70
    XRTRASTER/xs=2/mtag=X:CFREQ/lpb=2/stretch _wavep 1e-5 1e4 l2 FrameSize 20
    XRTDISPLAY/xs=4 SFREQ/"Sine Frequency" FWIDTH/"Filter Width" CFREQ/"Center Freq"

    if site FEXISTS then
      xgeoplot/xs=5 world|cities ^site
    else
      res alert "Could not find the SITE file for XGEOPLOT!"
      warning "^alert"
      xcall message "^alert" 3
      beep 2
    endif
  xpipe off

endmacro

!
! Start of the controls section
!
startcontrols

!******************************************************************************!
label initialentry

  ! The main MENU control widget
  xcontrol/lab=doMainMenu menu item ,, "MACRO;^MainMenu" 

  ! Widgets for controlling the Sine and Center frequencies
  xcontrol/name="SineFreq:   "/fmt="(F12.2)"/nocont/nobut dval &
                  sfreq sfreq -SRate SRate SRate/20 
  xcontrol/name="CenterFreq: "/fmt="(F12.2)"/nocont/nobut dval &
                  cfreq cfreq -SRate SRate SRate/20 

  xcontrol/disp/cols=32/len=32/name="Status: " AMON StatusString
  ! Monitor the global message queue for any msg addressed to this macro (ID=1)
  xcontrol/lab=getmsg msmon 1 10
return

!******************************************************************************!
label doMainMenu
  ! Parse the item string from the menu
  sedit MainMenu itemStr "ELEM" item "," UPCASE
  if itemStr eqs "GET" then
    ! Display the values
    say "Sine FREQ=^sfreq, Center FREQ=^cfreq"
  elseif itemStr eqs "SET" then
    ! Set the values
    res SFREQ 20E3
    res CFREQ 10E3
  elseif itemStr eqs "RESET"
    res SFREQ 10E3
    res CFREQ=10E3
  elseif itemStr eqs "TEST" then
    ! other test
  elseif itemStr eqs "STOP" then
    remove site world cities sv1 sv2 ! Remove all global vars
    stop
  endif
return

!******************************************************************************!
label getmsg

  ! Get any messages addressed to this macro (ID=1)
  message get /M/

  say "Got a ^M.name message from ^M.id"
return

!
! End of the controls section
!
endcontrols
