! xsearch
!
! $Revision: 1.1 $
! $Modtime:   22 Feb 1996 13:32:30  $
!
! SEARCH MACRO description
!
! adapted from the SEARCH macro by MNP
! last update 27 May 1992 by CPC (otter)
! last update 19 Sept 1992 by JGS - recode controls section
!
! Takes a pre-d file and FFTs the data and displays it (non-piped).  Then 
! allows the user to point to the rastered FFTs and look at two filtered pre-d 
! signals along with demodulated data.

startmacro/SETUP/NOEXIT/QUIET/NW=100/CONTROLS/TL=1K/XXXS=D &
                    A:DATA_IN   &     !input pre-d data file 
                    A:FFT_DATA  &     !input fft data file
                    I:BLOCK     &     !processing block size
                    I:BF              !processing block factor

  RESULTS P_DELTA_TIME 0		! initialize delta parameters
  RESULTS P_DELTA_FREQ 0

! set graphics window exit limits
! XCALL MENU P_TYPE 2 "Signal Type; Pre-D , AM , FM , Phase "
  RESULTS P_TYPE 1

! add beginning string for signal type
  IF P_TYPE EQ 1 RESULTS P_XM "_E"
  IF P_TYPE EQ 2 RESULTS P_XM "_A"
  IF P_TYPE EQ 3 RESULTS P_XM "_F"
  IF P_TYPE EQ 4 RESULTS P_XM "_P"

! add ending strings for compare signals (scaled) on plot
  CONCATENATE ^P_XM "M_1" P_XM_1
  CONCATENATE ^P_XM "M_2" P_XM_2

! obtain processing block size
  CALCULATOR BLOCK_BF BLOCK BF *
  CALCULATOR BLOCK2 BLOCK 2 /
  CALCULATOR BLOCK4 BLOCK 4 /

! obtain abscissa information on input data
  STATUS DATA_IN ,, P_ABS_START P_ABS_INCREMENT

! set scroll amount
  RESULTS P_SCROLL P_ABS_INCREMENT*BLOCK*BF

! scaler for FM demod
  IF ^FFT_DATA NFEXISTS 
    MFFT/S=H/BG/RSTAT=P_RSTAT DATA_IN FFT_DATA 1024 HANN 0
    XCALL/TEST=(P_RSTAT<>2) MESSAGE "Creating FFT of signal data ^DATA_IN" -4
  ENDIF

  XPIPE ON

! display all the fft data and use cursor to mark the data
  XRTRASTER/XS=3/WIDX=1/WIDY=2/WID=8001/XN="SPECTRAL ROADMAP"/STAY/BS &
    FFT_DATA ,,, LO

! display widget and parameter values
  XRTDISPLAY/XS=2/XN="GENERAL PARAMETERS" &
		W_/"W_1 ROADMAP FREQ    " &
		W_/"W_2 ROADMAP TIME    " &
		W_/"W_3 DEMOD TIME      " &
		W_/"W_4 DEMOD AMP       " &
		W_/"W_5 COMPARE TIME    " &
		W_/"W_6 COMPARE AMP     " 

! display more widget and parameter values
  XRTDISPLAY/XS=6/XN="SIGNAL 1-2 PARAMETERS"  &
       P_FREQ_CENTER_1/"SIGNAL CENTER 1     " &
		W_3003/"FILTER WIDTH 1      " &
		W_1002/"START TIME 1        " &
       P_FREQ_CENTER_2/"SIGNAL CENTER 2     " &
		W_4003/"FILTER WIDTH 2      " &
		W_2002/"START TIME 2        " &
	  P_DELTA_TIME/"DELTA TIME          " &
	  P_DELTA_FREQ/"DELTA FREQUENCY     "

! playback pre-d data starting at XRASTER Y cursor (WIDY=4)
  SOURCEFILE/REPLAY=1/WB=1 DATA_IN _PRED_1 P_ABS_START -BLOCK_BF 1 ABS
  SOURCEFILE/REPLAY=1/WB=2 DATA_IN _PRED_2 P_ABS_START -BLOCK_BF 1 ABS

! filter, translate and decimate SOIs.  Post-d translated to zero for demod. 
  RQFSHIFT/FFT=BLOCK_BF/WB=3/NOWARN _PRED_1 _EMPOST_1 ,,,, BF CF
  RQFSHIFT/FFT=BLOCK_BF/WB=4/NOWARN _PRED_2 _EMPOST_2 ,,,, BF CF

! filter, translate and decimate SOIs.  Pre-d centered at filter bw.
  RQFSHIFT/FFT=BLOCK_BF/WB=5/NOWARN _PRED_1 _EMPRE_1 ,,,, BF CF
  RQFSHIFT/FFT=BLOCK_BF/WB=6/NOWARN _PRED_2 _EMPRE_2 ,,,, BF CF

! detect channel a and b
  DETECT/block _EMPOST_1 _AM_1 _FM_1 _PM_1
  DETECT/block _EMPOST_2 _AM_2 _FM_2 _PM_2

! obtain real part of complex Pre-D files
  DEMUX _EMPRE_1 _EM_1
  DEMUX _EMPRE_2 _EM_2

! scale, combine pre-d, am, fm and pm data for plot in time amplitude display
  NORMALIZE/WB=7 _EM_1 _EM_A BLOCK PEAK 1.8 8
  NORMALIZE      _AM_1 _AM_A BLOCK PEAK 1.8 6
  NORMALIZE      _FM_1 _FM_A BLOCK PEAK 1.8 4
  NORMALIZE      _PM_1 _PM_A BLOCK PEAK 1.8 2
  FANIN/FS=BLOCK _FANIN_A _EM_A _AM_A _FM_A _PM_A 
  XRTPLOT/XS=4/WIDX=3/WIDY=4/LPS=4/XN="SIGNAL 1 DEMOD" &
	_FANIN_A 0 10 RE BLOCK 83

! scale, combine selected detect mode data for plot in time amplitude display
  NORMALIZE ^P_XM_1 _XM_1B BLOCK PEAK 1.8 4
  NORMALIZE ^P_XM_2 _XM_2B BLOCK PEAK 1.8 2
  FANIN/FS=BLOCK _FANIN_B _XM_1B _XM_2B 
  XRTPLOT/XS=7/WIDX=5/WIDY=8002/LPS=2/XN="SIGNAL 1-2 COMPARE" &
	_FANIN_B 0 6 RE BLOCK 83

! fft, combine selected detect mode data for plot in freq amplitude display
  MFFT _XM_1B _1FFT BLOCK HANN 0 AC
  MFFT _XM_2B _2FFT BLOCK HANN 0 AC
  FANIN _FANIN_C _1FFT _2FFT 
  XRTPLOT/XS=5/WIDX=7/WIDY=8/LPS=2/XN="SIGNAL 1-2 SPECTRUM" &
	_FANIN_C -1e-3 0.1 MA ,, 83 

! initiate controls section modes
  CONTROL/WB=8 DVAL 		! for spectral roadmap x+y
  CONTROL      DVAL 		! for time difference display
  res L:P_MM 0
  res L:P_SM 1
  res L:P_TM 1

ENDMACRO
!
STARTCONTROLS
!
!   search menu options 
!
  XCONTROL MENU P_MM 0 "MAIN OPTIONS;&
	REFRESH,DEFINE FILTER 1-2,DEFINE FILTER 2,QUE POINTS,SAVE/RECALL,EXIT"

  XCONTROL MENU P_SM P_SM "SELECT SIGNAL MODE;&
	MARK SIGNAL 1,MARK SIGNAL 2,OFFSET SEARCH"

  XCONTROL MONI W_8001
  XCONTROL MONI W_8002
!
!** Mouse click in spectral roadmap window for signal select change
!
LABEL START3
!
!*** mark signal 1 selection
!
  IF P_SM EQ 1
! move start of signal 1 to SOURCEFILE start widget
    RESULTS W_1002 W_2
! obtain signal 1 center frequency
    RESULTS P_FREQ_CENTER_1 W_1
! transfer post-d soi frequency shift to RQFSHIFT widget
    RESULTS W_3001 -W_1 
! transfer pre-d soi frequency shift to RQFSHIFT widget
    CALCULATOR W_5001 W_5002 W_1 -
! determine delta time (signal 1 is ref)
    CALCULATOR P_DELTA_TIME W_2002 W_1002 -
! determine delta frequency (signal 1 is ref)
    CALCULATOR P_DELTA_FREQ W_3001 W_4001 -
!
!*** mark signal 2 selection
!
  ELSEIF P_SM EQ 2

    RESULTS W_2002 W_2
! obtain signal 2 center frequency
    RESULTS P_FREQ_CENTER_2 W_1
! transfer soi frequency shift to RQFSHIFT widget
    RESULTS W_4001 -W_1 
    CALCULATOR W_6001 W_6002 W_1 -
! determine delta time (signal 1 is ref)
    CALCULATOR P_DELTA_TIME W_2002 W_1002 -
! determine delta frequency (signal 1 is ref)
    CALCULATOR P_DELTA_FREQ W_3001 W_4001 -
!
!*** offset search
!
  ELSEIF P_SM EQ 3
! move start of signal 1 to SOURCEFILE start widget
    RESULTS W_1002 W_2
! obtain signal 1 center frequency
    RESULTS P_FREQ_CENTER_1 W_1
! obtain signal 2 center frequency
    CALCULATOR P_FREQ_CENTER_2 W_1 P_DELTA_FREQ +
! obtain post-d signal 1 frequency shift (to zero) for RQFSHIFT widget
    RESULTS W_3001 -W_1
! obtain new post-d frequency shift of signal 2 for RQFSHIFT widget
    CALCULATOR W_4001 W_3001 P_DELTA_FREQ -
! obtain pre-d signal 1 frequency shift for RQFSHIFT widget
    CALCULATOR W_5001 W_5002 P_FREQ_CENTER_1 -
! obtain pre-d signal 2 frequency shift for RQFSHIFT widget
    CALCULATOR W_6001 W_6002 P_FREQ_CENTER_2 -
! determine new time of signal 2 for SOURCEFILE widget
    CALCULATOR W_2002 W_1002 P_DELTA_TIME +
!
  ENDIF
! send a oneshot to SOURCEFILE 
  RESULTS W_1001 1
  RESULTS W_2001 1
! wait for sourcefiles to finish
  WHILE W_1001 EQ 1 OR W_2001 EQ 1
    XCALL MESSAGE "BUSY" 0.2
  ENDWHILE
  XCALL SETC W_8001 -123
!
LABEL END3


!** Mouse click in plot window for time select change
!
LABEL START4

!
!***  adjust dual signal selection
!
  IF W_8002 LT 0 
    IF W_5 GE 0		! add to start
      CALCULATOR W_1002 W_1002 W_5 +	! signal 1
      CALCULATOR W_2002 W_2002 W_5 +	! signal 2
    ELSE		! back one frame
      CALCULATOR W_1002 W_1002 P_SCROLL - 	! signal 1
      CALCULATOR W_2002 W_2002 P_SCROLL -	! signal 2
    ENDIF
!
!***  adjust signal 2 selection
!
  ELSEIF W_8002 LT 3
    IF W_5 LE 0			! back one frame
      CALCULATOR W_2002 W_2002 P_SCROLL - 	! signal 2
    ELSEIF W_5 GT P_SCROLL	! forward one frame
      CALCULATOR W_2002 W_2002 P_SCROLL + 	! signal 2
    ELSE			! channel 1 delta move
      RESULTS MOUSE_X1 W_5
      RESULTS W_8002 -123
      WHILE W_8002 EQ -123
        XCALL MESSAGE " Click reference point in channel B " 0.5
      ENDWHILE
      RESULTS MOUSE_X2 W_5
      CALCULATOR W_2002 W_2002 MOUSE_X1 + MOUSE_X2 -
    ENDIF
!
!***  adjust signal 1 selection
!
  ELSEIF W_8002 LT 6
    IF W_5 LE 0			! back one frame
      CALCULATOR W_1002 W_1002 P_SCROLL - 	! signal 1
    ELSEIF W_5 GT P_SCROLL	! forward one frame
      CALCULATOR W_1002 W_1002 P_SCROLL + 	! signal 1
    ELSE			! channel 1 delta move
      RESULTS MOUSE_X1 W_5
      RESULTS W_8002 -123
      WHILE W_8002 EQ -123
        XCALL MESSAGE " Click reference point in channel B " 0.5
      ENDWHILE
      RESULTS MOUSE_X2 W_5
      CALCULATOR W_1002 W_1002 MOUSE_X1 + MOUSE_X2 -
    ENDIF
  ENDIF
! determine delta time (signal 1 is ref)
    CALCULATOR P_DELTA_TIME W_2002 W_1002 -
! send a oneshot to SOURCEFILE 
  RESULTS W_1001 1
  RESULTS W_2001 1
! wait for sourcefiles to finish
  WHILE W_1001 EQ 1 OR W_2001 EQ 1
    XCALL MESSAGE "BUSY" 0.2
  ENDWHILE
  XCALL SETC W_8002 -123
!
LABEL END4



!**  Main Menu Handler - keep at bottom cause speed is unnecessary

LABEL START1

!***  refresh
!
  IF P_MM EQ 1

! send oneshots to sourcefiles
    RESULTS W_1001 1
    RESULTS W_2001 1
!
!***  define filter 1-2 selection
!
  ELSEIF P_MM EQ 2
! set widx and test for mouse click
    RESULTS W_8001 -123
    WHILE W_8001 EQ -123
      XCALL MESSAGE "Define Filter 1-2 start" 0.5
    ENDWHILE
! a data click was made, save x and y values
    RESULTS MOUSE_X1 W_1
    RESULTS MOUSE_Y1 W_2
! set widx and test for mouse click
    RESULTS W_8001 -123
    WHILE W_8001 EQ -123
      XCALL MESSAGE "Define Filter 1-2 end" 0.5
    ENDWHILE
! a data click was made, save x and y values
    RESULTS MOUSE_X2 W_1
    RESULTS MOUSE_Y2 W_2
! obtain soi bandwidth value
    CALCULATOR P_FILTER_WIDTH MOUSE_X2 MOUSE_X1 - ABS
! set the pre-d filter center equal to the bandwidth
    RESULTS P_FILTER_CENTER P_FILTER_WIDTH
! obtain soi frequency center value 
    CALCULATOR P_FREQ_CENTER_1 MOUSE_X2 MOUSE_X1 + 2 /
! obtain post-d signal frequency shift (to zero) for RQFSHIFT
    RESULTS W_3001 -P_FREQ_CENTER_1 
    RESULTS W_4001 -P_FREQ_CENTER_1 
! obtain pre-d signal frequency shift for RQFSHIFT
    CALCULATOR W_5001 P_FILTER_CENTER P_FREQ_CENTER_1 -
    CALCULATOR W_6001 P_FILTER_CENTER P_FREQ_CENTER_1 -
! set post-d output filter center to zero for RQFSHIFT widget
    RESULTS W_3002 0
    RESULTS W_4002 0
! set pre-d output filter center to RQFSHIFT widget
    RESULTS W_5002 P_FILTER_CENTER
    RESULTS W_6002 P_FILTER_CENTER
! set filter width for RQFSHIFT
    RESULTS W_3003 P_FILTER_WIDTH
    RESULTS W_4003 P_FILTER_WIDTH
    RESULTS W_5003 P_FILTER_WIDTH
    RESULTS W_6003 P_FILTER_WIDTH
! obtain start of signal 1 for SOURCEFILE widget
    CALCULATOR W_1002 MOUSE_Y1 MOUSE_Y2 MINIMUM
! determine delta time (signal 1 is ref)
    CALCULATOR P_DELTA_TIME W_2002 W_1002 -
! determine delta frequency (signal 1 is ref)
    CALCULATOR P_DELTA_FREQ W_3001 W_4001 -
! send a oneshot to SOURCEFILE 
    RESULTS W_1001 1
    RESULTS W_2001 1
!
!***  define filter 2 selection
!
  ELSEIF P_MM EQ 3
! set widx to test for mouse click
    RESULTS W_1 -123
    WHILE W_1 EQ -123
      XCALL MESSAGE "Define Filter 2  - start" 0.5
    ENDWHILE
! a data click was made, save x and y values
    RESULTS MOUSE_X1 W_1
    RESULTS MOUSE_Y1 W_2
! set widx to test for mouse click
    RESULTS W_1 -123
    WHILE W_1 EQ -123
      XCALL MESSAGE "Define Filter 2  - end" 0.5
    ENDWHILE
! a data click was made, save x and y values
    RESULTS MOUSE_X2 W_1
    RESULTS MOUSE_Y2 W_2
! obtain x (frequency) delta value
    CALCULATOR P_FILTER_WIDTH MOUSE_X2 MOUSE_X1 - ABS
! the filter center is equal to the bandwidth
    RESULTS P_FILTER_CENTER P_FILTER_WIDTH
! obtain x (frequency) center value 
    CALCULATOR P_FREQ_CENTER_2 MOUSE_X2 MOUSE_X1 + 2 /
! obtain post-d signal frequency shift (to zero) for RQFSHIFT
    RESULTS W_4001 -P_FREQ_CENTER_2 
! obtain pre-d signal frequency shift for RQFSHIFT
    CALCULATOR W_6001 P_FILTER_CENTER P_FREQ_CENTER_2 -
! set post-d output filter center to zero for RQFSHIFT widget
    RESULTS W_4002 0
! set pre-d output filter center to RQFSHIFT widget
    RESULTS W_6002 P_FILTER_CENTER
! get filter width for RQFSHIFT
    RESULTS W_4003 P_FILTER_WIDTH
    RESULTS W_6003 P_FILTER_WIDTH
! obtain start of signal 2 for SOURCEFILE widget
    CALCULATOR W_2002 MOUSE_Y1 MOUSE_Y2 MINIMUM
! determine delta time (signal 1 is ref)
    CALCULATOR P_DELTA_TIME W_2002 W_1002 -
! determine delta frequency (signal 1 is ref)
    CALCULATOR P_DELTA_FREQ W_3001 W_4001 -
! send a oneshot to SOURCEFILE 
    RESULTS W_1001 1
    RESULTS W_2001 1
!
!***  que points selection
!
  ELSEIF P_MM EQ 4
!
    XCALL MENU P_QUEMENU 0 "QUE POINTS;SET 1,SET 2,SET 1-2,RESET 1,RESET 2,&
                               RESET 1-2"
!
    IF P_QUEMENU EQ 0
      XCALL MESSAGE  "NO QUE POINTS SELECTION MADE" -1
!
!****  set 1 selection
!
    ELSEIF P_QUEMENU EQ 1
!
      XCALL MENU P_SET1MENU 0 "SET 1; A , B , C , D , E , F , G , H "
!
      IF P_SET1MENU EQ 0
        XCALL MESSAGE  "NO SET 1 SELECTION MADE" 2
        GOTO EXIT_QUE
      ENDIF
! setup name with selected character
      IF P_SET1MENU EQ 1 RESULTS P_SET1 "P_SET1A"
      IF P_SET1MENU EQ 2 RESULTS P_SET1 "P_SET1B"
      IF P_SET1MENU EQ 3 RESULTS P_SET1 "P_SET1C"
      IF P_SET1MENU EQ 4 RESULTS P_SET1 "P_SET1D"
      IF P_SET1MENU EQ 5 RESULTS P_SET1 "P_SET1E"
      IF P_SET1MENU EQ 6 RESULTS P_SET1 "P_SET1F"
      IF P_SET1MENU EQ 7 RESULTS P_SET1 "P_SET1G"
      IF P_SET1MENU EQ 8 RESULTS P_SET1 "P_SET1H"
! setup center frequency name for selected character
      CONCATENATE ^P_SET1 "_CF" P_SET1X_CF
! setup bandwidth name for selected character
      CONCATENATE ^P_SET1 "_BW" P_SET1X_BW
! setup start time name for selected character
      CONCATENATE ^P_SET1 "_TI" P_SET1X_TI
! store center frequency value in que point name
      RESULTS ^P_SET1X_CF P_FREQ_CENTER_1
! store bandwidth value in que point name
      RESULTS ^P_SET1X_BW W_3003
! store start time value in que point name
      RESULTS ^P_SET1X_TI W_1002
!
!****  set 2 selection
!
    ELSEIF P_QUEMENU EQ 2
!
      XCALL MENU P_SET2MENU 0 "SET 2; A , B , C , D , E , F , G , H "
!
      IF P_SET2MENU EQ 0
        XCALL MESSAGE  "NO SET 2 SELECTION MADE" 2
        GOTO EXIT_QUE
      ENDIF
! setup name with selected character
      IF P_SET2MENU EQ 1 RESULTS P_SET2 "P_SET2A"
      IF P_SET2MENU EQ 2 RESULTS P_SET2 "P_SET2B"
      IF P_SET2MENU EQ 3 RESULTS P_SET2 "P_SET2C"
      IF P_SET2MENU EQ 4 RESULTS P_SET2 "P_SET2D"
      IF P_SET2MENU EQ 5 RESULTS P_SET2 "P_SET2E"
      IF P_SET2MENU EQ 6 RESULTS P_SET2 "P_SET2F"
      IF P_SET2MENU EQ 7 RESULTS P_SET2 "P_SET2G"
      IF P_SET2MENU EQ 8 RESULTS P_SET2 "P_SET2H"
! setup center frequency name for selected character
      CONCATENATE ^P_SET2 "_CF" P_SET2X_CF
! setup bandwidth name for selected character
      CONCATENATE ^P_SET2 "_BW" P_SET2X_BW
! setup start time name for selected character
      CONCATENATE ^P_SET2 "_TI" P_SET2X_TI
! store center frequency value in que point name
      RESULTS ^P_SET2X_CF P_FREQ_CENTER_2
! store bandwidth value in que point name
      RESULTS ^P_SET2X_BW W_3003
! store start time value in que point name
      RESULTS ^P_SET2X_TI W_2002
!
!****  set 1-2 selection
!
    ELSEIF P_QUEMENU EQ 3
!
      XCALL MENU P_SET12MENU 0 "SET 1-2; A , B , C , D , E , F , G , H "
!
      IF P_SET12MENU EQ 0
        XCALL MESSAGE  "NO SET 1-2 SELECTION MADE" 2
        GOTO EXIT_QUE
      ENDIF
! setup name with selected character
      IF P_SET12MENU EQ 1 RESULTS P_SET12 "P_SET12A"
      IF P_SET12MENU EQ 2 RESULTS P_SET12 "P_SET12B"
      IF P_SET12MENU EQ 3 RESULTS P_SET12 "P_SET12C"
      IF P_SET12MENU EQ 4 RESULTS P_SET12 "P_SET12D"
      IF P_SET12MENU EQ 5 RESULTS P_SET12 "P_SET12E"
      IF P_SET12MENU EQ 6 RESULTS P_SET12 "P_SET12F"
      IF P_SET12MENU EQ 7 RESULTS P_SET12 "P_SET12G"
      IF P_SET12MENU EQ 8 RESULTS P_SET12 "P_SET12H"
! setup center frequency name for selected character
      CONCATENATE ^P_SET12 "_1CF" P_SET12X_1CF
      CONCATENATE ^P_SET12 "_2CF" P_SET12X_2CF
! setup bandwidth name for selected character
      CONCATENATE ^P_SET12 "_1BW" P_SET12X_1BW
      CONCATENATE ^P_SET12 "_2BW" P_SET12X_2BW
! setup start time name for selected character
      CONCATENATE ^P_SET12 "_1TI" P_SET12X_1TI
      CONCATENATE ^P_SET12 "_2TI" P_SET12X_2TI
! store center frequency value in que point name
      RESULTS ^P_SET12X_1CF P_FREQ_CENTER_1
      RESULTS ^P_SET12X_2CF P_FREQ_CENTER_2
! store bandwidth value in que point name
      RESULTS ^P_SET12X_1BW W_3003
      RESULTS ^P_SET12X_2BW W_5003
! store start time value in que point name
      RESULTS ^P_SET12X_1TI W_1002
      RESULTS ^P_SET12X_2TI W_2002
!
!****  reset 1 selection
!
    ELSEIF P_QUEMENU EQ 4
!                                            initialize no option selected code
      RESULTS P_SELECT 0
!
 LABEL AGAIN_R1
!
      XCALL MENU P_RESET1MENU 0 "RESET 1; A , B , C , D , E , F , G , H "
!
! option selected at least once
      IF P_RESET1MENU EQ 0
        XCALL MESSAGE  "NO RESET 1 SELECTION MADE" 2
        GOTO EXIT_QUE
      ENDIF
! set option selected code
      RESULTS P_SELECT 1
! setup name with selected character
      IF P_RESET1MENU EQ 1 RESULTS P_RESET1 "P_SET1A"
      IF P_RESET1MENU EQ 2 RESULTS P_RESET1 "P_SET1B"
      IF P_RESET1MENU EQ 3 RESULTS P_RESET1 "P_SET1C"
      IF P_RESET1MENU EQ 4 RESULTS P_RESET1 "P_SET1D"
      IF P_RESET1MENU EQ 5 RESULTS P_RESET1 "P_SET1E"
      IF P_RESET1MENU EQ 6 RESULTS P_RESET1 "P_SET1F"
      IF P_RESET1MENU EQ 7 RESULTS P_RESET1 "P_SET1G"
      IF P_RESET1MENU EQ 8 RESULTS P_RESET1 "P_SET1H"
! setup center frequency name for selected character
      CONCATENATE ^P_RESET1 "_CF" P_RESET1X_CF
! setup bandwidth name for selected character
      CONCATENATE ^P_RESET1 "_BW" P_RESET1X_BW
! setup start time name for selected character
      CONCATENATE ^P_RESET1 "_TI" P_RESET1X_TI
! que point was not set yet
      IF ^P_RESET1X_CF NREXISTS 
! pull off que point character a,b,c...
        SEDIT ^P_RESET1 CHAR RANGE 7 7         
!
        XCALL MESSAGE "QUE POINT 'SET 1 = ^CHAR' HAS NOT BEEN SET YET" -1
! exit go to 1 option without any action
        GOTO EXIT_QUE
!
      ENDIF
! transfer stored center frequency to parameter
      RESULTS P_FREQ_CENTER_1 ^(^P_RESET1X_CF)
! transfer stored bandwidth to filter center parameter
      RESULTS P_FILTER_CENTER ^(^P_RESET1X_BW) 
! transfer stored start time to SOURCEFILE
      RESULTS W_1002 ^(^P_RESET1X_TI) 
! obtain post-d signal frequency shift (to zero) for RQFSHIFT
      RESULTS W_3001 -P_FREQ_CENTER_1 
! obtain pre-d signal frequency shift for RQFSHIFT
      CALCULATOR W_5001 P_FILTER_CENTER P_FREQ_CENTER_1 -
! set post-d output filter center to zero for RQFSHIFT widget
      RESULTS W_3002 0
! set pre-d output filter center to RQFSHIFT widget
      RESULTS W_5002 P_FILTER_CENTER
! transfer stored bandwidth to RQFSHIFT widget
      RESULTS W_3003 ^(^P_RESET1X_BW) 
      RESULTS W_5003 ^(^P_RESET1X_BW) 
! determine delta time (signal 1 is ref)
      CALCULATOR P_DELTA_TIME W_2002 W_1002 -
! determine delta frequency (signal 1 is ref)
      CALCULATOR P_DELTA_FREQ W_3001 W_4001 -
! send a oneshot to SOURCEFILE 
      RESULTS W_1001 1
      RESULTS W_2001 1
!
      GOTO AGAIN_R1
!
!****  reset 2 selection
!
    ELSEIF P_QUEMENU EQ 5
!                                            initialize no option selected code
      RESULTS P_SELECT 0
!
 LABEL AGAIN_R2
!
      XCALL MENU P_RESET2MENU 0 "RESET 2; A , B , C , D , E , F , G , H "
!
! option selected at least once
      IF P_RESET2MENU EQ 0
        XCALL MESSAGE  "NO RESET 2 SELECTION MADE" 2
        GOTO EXIT_QUE
      ENDIF
! set option selected code
      RESULTS P_SELECT 1
! setup name with selected character
      IF P_RESET2MENU EQ 1 RESULTS P_RESET2 "P_SET2A"
      IF P_RESET2MENU EQ 2 RESULTS P_RESET2 "P_SET2B"
      IF P_RESET2MENU EQ 3 RESULTS P_RESET2 "P_SET2C"
      IF P_RESET2MENU EQ 4 RESULTS P_RESET2 "P_SET2D"
      IF P_RESET2MENU EQ 5 RESULTS P_RESET2 "P_SET2E"
      IF P_RESET2MENU EQ 6 RESULTS P_RESET2 "P_SET2F"
      IF P_RESET2MENU EQ 7 RESULTS P_RESET2 "P_SET2G"
      IF P_RESET2MENU EQ 8 RESULTS P_RESET2 "P_SET2H"
! setup center frequency name for selected character
      CONCATENATE ^P_RESET2 "_CF" P_RESET2X_CF
! setup bandwidth name for selected character
      CONCATENATE ^P_RESET2 "_BW" P_RESET2X_BW
! setup start time name for selected character
      CONCATENATE ^P_RESET2 "_TI" P_RESET2X_TI
! transfer stored center frequency to parameter
      RESULTS P_FREQ_CENTER_2 ^(^P_RESET2X_CF)
! transfer stored bandwidth to filter center parameter
      RESULTS P_FILTER_CENTER ^(^P_RESET2X_BW) 
! transfer stored start time to SOURCEFILE
      RESULTS W_2002 ^(^P_RESET2X_TI) 
! obtain post-d signal frequency shift (to zero) for RQFSHIFT
      RESULTS W_4001 -P_FREQ_CENTER_2 
! obtain pre-d signal frequency shift for RQFSHIFT
      CALCULATOR W_6001 P_FILTER_CENTER P_FREQ_CENTER_2 -
! set post-d output filter center to zero for RQFSHIFT widget
      RESULTS W_4002 0
! set pre-d output filter center to RQFSHIFT widget
      RESULTS W_6002 P_FILTER_CENTER
! transfer stored bandwidth to RQFSHIFT widget
      RESULTS W_4003 ^(^P_RESET2X_BW) 
      RESULTS W_6003 ^(^P_RESET2X_BW) 
! determine delta time (signal 1 is ref)
      CALCULATOR P_DELTA_TIME W_2002 W_1002 -
! determine delta frequency (signal 1 is ref)
      CALCULATOR P_DELTA_FREQ W_3001 W_4001 -
! send a oneshot to SOURCEFILE 
      RESULTS W_1001 1
      RESULTS W_2001 1
!
      GOTO AGAIN_R2
!
!****  reset 1-2 selection
!
    ELSEIF P_QUEMENU EQ 6
!                                            initialize no option selected code
      RESULTS P_SELECT 0
!
 LABEL AGAIN_R12
!
      XCALL MENU P_RESET12MENU 0 "RESET 1-2; A , B , C , D , E , F , G , H "
!
! option selected at least once
      IF P_RESET12MENU EQ 0
        XCALL MESSAGE  "NO RESET 1-2 SELECTION MADE" 2
        GOTO EXIT_QUE
      ENDIF
! set option selected code
      RESULTS P_SELECT 1
! setup name with selected character
      IF P_RESET12MENU EQ 1 RESULTS P_RESET12 "P_SET12A"
      IF P_RESET12MENU EQ 2 RESULTS P_RESET12 "P_SET12B"
      IF P_RESET12MENU EQ 3 RESULTS P_RESET12 "P_SET12C"
      IF P_RESET12MENU EQ 4 RESULTS P_RESET12 "P_SET12D"
      IF P_RESET12MENU EQ 5 RESULTS P_RESET12 "P_SET12E"
      IF P_RESET12MENU EQ 6 RESULTS P_RESET12 "P_SET12F"
      IF P_RESET12MENU EQ 7 RESULTS P_RESET12 "P_SET12G"
      IF P_RESET12MENU EQ 8 RESULTS P_RESET12 "P_SET12H"
! setup center frequency name for selected character
      CONCATENATE ^P_RESET12 "_1CF" P_RESET12X_1CF
      CONCATENATE ^P_RESET12 "_2CF" P_RESET12X_2CF
! setup bandwidth name for selected character
      CONCATENATE ^P_RESET12 "_1BW" P_RESET12X_1BW
      CONCATENATE ^P_RESET12 "_2BW" P_RESET12X_2BW
! setup start time name for selected character
      CONCATENATE ^P_RESET12 "_1TI" P_RESET12X_1TI
      CONCATENATE ^P_RESET12 "_2TI" P_RESET12X_2TI
! transfer stored center frequency to parameter
      RESULTS P_FREQ_CENTER_1 ^(^P_RESET12X_1CF)
      RESULTS P_FREQ_CENTER_2 ^(^P_RESET12X_2CF)
! transfer stored bandwidth to filter center parameter
      RESULTS P_FILTER_CENTER_1 ^(^P_RESET12X_1BW) 
      RESULTS P_FILTER_CENTER_2 ^(^P_RESET12X_2BW) 
! transfer stored start time to SOURCEFILE
      RESULTS W_1002 ^(^P_RESET12X_1TI) 
      RESULTS W_2002 ^(^P_RESET12X_2TI) 
! obtain post-d signal frequency shift (to zero) for RQFSHIFT
      RESULTS W_3001 -P_FREQ_CENTER_1 
      RESULTS W_4001 -P_FREQ_CENTER_2 
! obtain pre-d signal frequency shift for RQFSHIFT
      CALCULATOR W_5001 P_FILTER_CENTER_1 P_FREQ_CENTER_1 -
      CALCULATOR W_6001 P_FILTER_CENTER_2 P_FREQ_CENTER_2 -
! set post-d output filter center to zero for RQFSHIFT widget
      RESULTS W_3002 0
      RESULTS W_4002 0
! set pre-d output filter center to RQFSHIFT widget
      RESULTS W_5002 P_FILTER_CENTER_1
      RESULTS W_6002 P_FILTER_CENTER_2
! transfer stored bandwidth to RQFSHIFT widget
      RESULTS W_3003 ^(^P_RESET12X_1BW) 
      RESULTS W_4003 ^(^P_RESET12X_1BW) 
      RESULTS W_5003 ^(^P_RESET12X_2BW) 
      RESULTS W_6003 ^(^P_RESET12X_2BW) 
! determine delta time (signal 1 is ref)
      CALCULATOR P_DELTA_TIME W_2002 W_1002 -
! determine delta frequency (signal 1 is ref)
      CALCULATOR P_DELTA_FREQ W_3001 W_4001 -
! send a oneshot to SOURCEFILE 
      RESULTS W_1001 1
      RESULTS W_2001 1
!
      GOTO AGAIN_R12
!
    ENDIF
    LABEL EXIT_QUE


  ELSEIF P_MM EQ 5
    XCALL MESS "Save/Recall function not implemented yet" -1

  ELSEIF P_MM EQ 6
    ENV SET BREAK 1

  ENDIF
! wait for sourcefiles
  WHILE W_1001 EQ 1 OR W_2001 EQ 1
    XCALL MESSAGE "BUSY" 0.2
  ENDWHILE
!
  XCALL SETC W_8001 -123
LABEL END1

ENDCONTROLS
