# file: wavemenu.def	G. Moody	17 August 1990
#			Last revised:	16 April 1997
# Copyright(C) Massachusetts Institute of Technology 1997. All rights reserved.

# This is the default analysis menu for WAVE.  If you wish to use a
# customized version, copy this file to another directory, edit it,
# and set the value of the environment variable WAVEMENU to the name of
# the edited version before starting WAVE.  The contents of this file,
# or of your customized version of it, determine the appearance of the
# window that WAVE displays when you select its `Analyze' button, and the
# actions that are taken when you select a button in the `Analyze' window.

# Comment lines begin with `#', and may appear anywhere in this file.
# Lines that specify menu items contain a button label, followed by
# one or more tab characters, followed by the action to be taken when the
# button is selected.  The action may be any command acceptable to your
# shell.  Note that several strings found in commands are interpreted by
# WAVE before they are passed to the shell;  these are:
#	$RECORD		the current record name
#	$ANNOTATOR	the current input annotator name
#	$START		the current `Start' time as shown in the Analyze window
#			 (the time of the `<' marker, if any)
#	$END		the current `End' time as shown in the Analyze window
#			 (the time of the `>' marker, if any)
#	$DURATION	the time interval between $END and $START
#	$LEFT		the time of the left edge of the signal display window
#	$RIGHT		the time of the right edge of the signal display window
#	$WIDTH		the time interval between $RIGHT and $LEFT
#	$SIGNAL		the number of the selected signal
#	$SIGNALS	the signal list
#	$LOG		the name of the current log file
#	$DB		the DB path (from the Load window)
#	$DBCAL		the name of the DB calibration file (from the Load
#			 window)
#	$TSCALE		the time scale, in mm/sec
#	$VSCALE		the amplitude scale, in mm/mV
#	$DISPMODE	0: annotations displayed in center, no marker bars
#		        1: annotations displayed in center, long marker bars
#			2: annotations attached to signals, no bars
#			3: annotations attached to signals, short bars
#			4: annotations displayed as a signal, no bars
#			5: annotations displayed as a signal, long bars
#	$PSPRINT	the command for printing PostScript data from the
#			 standard input, as shown in the Print Setup window
#	$TEXTPRINT	the command for printing text from the standard input,
#			 as shown in the Print Setup window
#	$URL		the URL specified by the most recently selected link
# Other strings that begin with `$' are passed to the shell unchanged.
# The character `\', if immediately followed by a newline, causes the
# next line to be treated as a continuation of the current line.  Any
# initial whitespace on a continuation line is ignored.

# Default menu entries.  Delete or change any of these as you wish.
# If `lpr' is not the proper command for printing a PostScript file on your
# system, be sure to set PSPRINT (in the Print Setup window).

# Button labels		Commands
# -------------		--------
Mark QRS complexes	sqrs -r $RECORD -f $START -t $END -s $SIGNAL
Calibrate		calibrate -r $RECORD -f $START -t $END -s $SIGNALS
Extract segment		snip -i $RECORD -f $START -t $END -n n_$RECORD \
			 -a $ANNOTATOR
List annotations	rdann -r $RECORD -a $ANNOTATOR -f $START -t $END
List samples		rdsamp -r $RECORD -f $START -t $END -s $SIGNALS
Print chart		echo $RECORD $START-$END | \
			 pschart -a $ANNOTATOR -g -l -R -s $SIGNALS - | \
			 $PSPRINT
Print full disclosure	echo $RECORD $START-$END | \
			 psfd -a $ANNOTATOR -g -l -R -s $SIGNALS - | $PSPRINT

# Here are alternate versions of the two previous entries, for some BSD systems
# that have small /tmp partitions.  These assume that `lpr' prints PostScript.
#Print chart		echo $RECORD $START-$END | pschart -a $ANNOTATOR -g \
#			 -l -R -s $SIGNALS - >~/.pschart.$$; \
#			 lpr -r -s ~/.pschart.$$
#Print full disclosure	echo $RECORD $START-$END | psfd -a $ANNOTATOR -g \
#			 -l -R -s $SIGNALS - >~/.psfd.$$; \
#			 lpr -r -s ~/.psfd.$$

# Use the following entry to export WAVE's variables to your shell environment.
# This version is usable if your shell is `csh' or `tcsh':
#Set variables		setenv RECORD $RECORD; setenv ANNOTATOR $ANNOTATOR; \
#			 setenv START $START; setenv END $END; \
#			 setenv DURATION $DURATION; setenv LEFT $LEFT; \
#			 setenv RIGHT $RIGHT; setenv WIDTH $WIDTH; \
#			 setenv SIGNAL $SIGNAL; setenv SIGNALS "$SIGNALS"; \
#			 setenv LOG $LOG; setenv DB $DB; setenv DBCAL $DBCAL \
#			 setenv TSCALE $TSCALE; setenv VSCALE $VSCALE; \
#			 setenv DISPMODE $DISPMODE; setenv PSPRINT "$PSPRINT";\
#			 setenv TEXTPRINT "$TEXTPRINT"; setenv URL $URL

# Here is an alternate version of the previous entry, for use with `sh', `ksh',
# or `bash':
Set variables		RECORD=$RECORD; ANNOTATOR=$ANNOTATOR; START=$START; \
			 END=$END; DURATION=$DURATION; LEFT=$LEFT; \
			 RIGHT=$RIGHT; WIDTH=$WIDTH; SIGNAL=$SIGNAL; \
			 SIGNALS="$SIGNALS"; LOG=$LOG; DB=$DB; DBCAL=$DBCAL; \
			 TSCALE=$TSCALE; VSCALE=$VSCALE; DISPMODE=$DISPMODE; \
			 PSPRINT="$PSPRINT"; TEXTPRINT="$TEXTPRINT"; URL=$URL;\
			 export RECORD ANNOTATOR START END DURATION LEFT \
			 RIGHT WIDTH SIGNAL SIGNALS LOG DB DBCAL TSCALE \
			 VSCALE DISPMODE PSPRINT TEXTPRINT URL

# The label `<Print>' defines the command that is executed when the `Print'
# button in the File menu is selected.  If you wish to have a button with the
# same function appear in the Analysis menu, copy the command and use a
# different button label (for example, `Print window').
<Print>			echo $RECORD $LEFT-$RIGHT | pschart -a $ANNOTATOR -g \
			 -l -L -n 0 -R -s $SIGNALS -t 20 -v 2 - | $PSPRINT

# The alternate <Print> definition below makes charts at scales that match
# whatever is currently selected for WAVE (rather than the fixed scales used
# in the standard definition above).  If you wish to use the alternate
# definition, uncomment the next entry and comment out the previous one.
# <Print>		echo $RECORD $LEFT-$RIGHT | pschart -a $ANNOTATOR -g \
#			 -l -L -M$DISPMODE -n 0 -R -s $SIGNALS -t $TSCALE \
#			 -v $VSCALE - | $PSPRINT

# The label `<Open URL>' defines the command that is executed when a follow-
# link command is given in the signal window.  (To give a follow-link command,
# select a link annotation and press ENTER.)  `urlview' is itself a script that
# you may customize for your web browser.  The version of `urlview' supplied
# with WAVE uses Netscape (1.1 or any later version) to direct an already-
# running Netscape process to open the specified URL; if Netscape is not
# already running, `urlview' starts it.  If you prefer to use a different web
# browser, either change the action associated with `<Open URL>' below, or
# (preferably) replace the last command in `urlview' with one that invokes
# your browser (unfortunately, the syntax for doing so is not standard;
# consult your browser's documentation).
<Open URL>		urlview $URL

# The next two buttons use a file created using WAVE's Log window.  Typically,
# the file contains the times of interesting events selected by the user,
# with optional comments about each event.  The log is maintained in pschart
# script format.
# Print log (text)	$TEXTPRINT $LOG
# Print log with charts	pschart -a $ANNOTATOR -g -l -R -s $SIGNALS $LOG | \
#			 $PSPRINT

# The next entry can be used if you wish to relabel a segment in the currently
# open annotation file using an automated detector (sqrs in this example).  Any
# existing annotations before $START or after $END are unaffected;  any
# existing annotations between $START and $END are replaced by those produced
# by the automated detector.  To retain existing annotations between $START and
# $END (merging them with the new annotations), change `-m1' to `-m3' below.
# The current version of the annotation file (before merging) is saved as the
# backup version (with a prefixed `_' in the annotator name);  any existing
# backup with the same name is overwritten by this process.
Mark QRSs & merge	mv -f $ANNOTATOR.$RECORD _$ANNOTATOR.$RECORD; \
			 sqrs -r $RECORD -f $START -t $END -s $SIGNAL; \
			 mv qrs.$RECORD a$$.$RECORD; \
			 mrgann -r $RECORD -i a$$ _$ANNOTATOR -o $ANNOTATOR \
			  -m2 0 -m1 $START -m2 $END; \
			 rm -f a$$.$RECORD

# The next several entries illustrate how `wave' can be used to select data
# to be plotted by `gnuplot' (in these examples, via the `plot2d' and `plot3d'
# scripts provided in the DB Software Package).

# This entry derives a uniformly sampled instantaneous heart rate signal from
# the open annotation file (using `tach'), and displays it on-screen.
Plot HR	(tach)		tach -r $RECORD -a $ANNOTATOR -f $START -t $END -Vm | \
			 plot2d 0 1 -x "Time (minutes)" -y "HR (bpm)" \
			  -t "Record $RECORD ($START - $END)"

# The next entry prints the same plot that the previous entry displays.  Note
# that PRINTER is an ordinary environment variable (not interpreted by `wave');
# set it so that `lpr -P$PRINTER' prints on the desired printer.
Print HR (tach)		tach -r $RECORD -a $ANNOTATOR -f $START -t $END -Vm | \
			 plot2d 0 1 -x "Time (minutes)" -y "HR (bpm)" \
			  -t "Record $RECORD ($START - $END)" -T $PRINTER

# The next two entries make plots resembling VCGs (vectorcardiograms), by
# plotting the first signal in the signal list vs. the second one.  To obtain
# the proper plot titles, and for efficiency, be sure that the signal list
# contains only two signals.
VCG			rdsamp -r $RECORD -f $LEFT -t $RIGHT -s $SIGNALS -p | \
			 plot2d 1 2 -x "Amplitude (mV)" -y "Amplitude (mV)" -t \
			 "Record $RECORD, Signals: $SIGNALS ($LEFT - $RIGHT)"

VCG (with time axis)	rdsamp -r $RECORD -f $LEFT -t $RIGHT -s $SIGNALS -p | \
			 plot3d 0 1 2 -x "Time (seconds)" -y "Amplitude (mV)" \
			  -z "Amplitude (mV)" -rx 60 -rz 30 -t \
			  "Record $RECORD, Signals: $SIGNALS ($LEFT - $RIGHT)"
# The previous entry can be modified easily to plot a 3D VCG (just change
# `0 1 2' to '1 2 3', correct the x-axis label, and make sure that the signal
# list contains three signals).  Adjust the -rx and -rz options to obtain the
# desired viewpoint.

# The plot produced by this entry can take a long time -- try it out with a
# short data segment (ten seconds or so) the first time.  The `-100' argument
# to `format3d' specifies the time offset in samples between the annotation
# marks and the left edge of the plot (at x=0);  changing it to `-50' shifts the
# waveforms to the left.
`Waterfall' plot	rdsamp -r $RECORD -f $START -t $END -s $SIGNAL -p | \
			 format3d -100 \
			  `rr -r $RECORD -a $ANNOTATOR -f $START -t $END` | \
			 plot3d 1 -x "Time (samples)" -y "Beat number" \
			  -z "Amplitude (mV)" -rx 60 -rz 355 \
			  -t "Record $RECORD, Signal $SIGNAL ($START - $END)"

# The next group of entries is useful with the MIMIC Database.  You will need
# to install `rdtxt' (from the software/mimicmsc directory of a MIMIC CD-ROM)
# in order to use these buttons.
Plot HR from `txt'	rdtxt -r $RECORD -p HR -f $START -t $END | \
			 plot2d 0 2 -x "Time (minutes)" -y "HR (bpm)" \
			  -t "Record $RECORD ($START - $END)"
Plot mean ABP		rdtxt -r $RECORD -p ABP -f $START -t $END | \
			 plot2d 0 2 -x "Time (minutes)" -y "mean ABP (mmHg)" \
			  -t "Record $RECORD ($START - $END)" -ya 0 300
Plot systolic ABP	rdtxt -r $RECORD -p ABP -n 2 -f $START -t $END | \
			 plot2d 0 3 -x "Time (minutes)" -ya 0 300 \
			  -y "systolic ABP (mmHg)" \
			  -t "Record $RECORD ($START - $END)"
Plot diastolic ABP	rdtxt -r $RECORD -p ABP -n 3 -f $START -t $END | \
			 plot2d 0 4 -x "Time (minutes)" -ya 0 300 \
			  -y "diastolic ABP (mmHg)" \
			  -t "Record $RECORD ($START - $END)"
Plot RESP		rdtxt -r $RECORD -p RESP -f $START -t $END | \
			 plot2d 0 2 -x "Time (minutes)" -ya 0 50 \
			  -y "Respiration (breaths/min)" \
			  -t "Record $RECORD ($START - $END)"
Plot SpO2		rdtxt -r $RECORD -p SpO2 -f $START -t $END | \
			 plot2d 0 2 -x "Time (minutes)" -y "SpO2 (%)" \
			  -ya 80 100 -t "Record $RECORD ($START - $END)"

# Add additional entries below.
