# file: wavemenu.def	G. Moody	17 August 1990
#			Last revised:	12 August 1995
# Copyright(C) Massachusetts Institute of Technology 1995. 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
# panel that WAVE displays when you select its `Analyze' button, and the
# actions that are taken when you select a button on the `Analyze' panel.

# 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 panel
#			 (the time of the `<' marker, if any)
#	$END		the current `End' time as shown in the Analyze panel
#			 (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 panel)
#	$DBCAL		the name of the DB calibration file (from the Load
#			 panel)
#	$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
# 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, replace it as appropriate below.

# 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 - | lpr
Print full disclosure	echo $RECORD $START-$END | \
			 psfd -a $ANNOTATOR -g -l -R -s $SIGNALS - | lpr

# Here are alternate versions of the two previous entries, for some BSD systems
# that have small /tmp partitions:
#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

# 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; \
			 export RECORD ANNOTATOR START END DURATION LEFT \
			 RIGHT WIDTH SIGNAL SIGNALS LOG DB DBCAL TSCALE \
			 VSCALE DISPMODE

# 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 - | lpr

# 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 - | lpr

# The next two buttons use a file created using WAVE's Log panel.  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 file		lpr $LOG
Print logged strips	pschart -a $ANNOTATOR -g -l -R -s $SIGNALS $LOG | lpr

# 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 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.
