#!/bin/sh # file: hp_rrlist # # Create a heartprint from an RR interval list # # This script invokes hp_scatter and hp_hist to generate the histograms, and # then generates a heartprint from them using imageplt and plt. AWK=awk FREQ=128; LWCAT=: NNMAX=2 NNMIN=0.3 PLTOUT="" RRLIST="" # Override defaults with user-specified values while [ $# -gt 0 ] do case $1 in -F) FREQ=$2; shift ;; -i) RRLIST=$2; shift ;; -m) userNNMIN=$2; shift ;; -M) userNNMAX=$2; shift ;; -T) case $2 in eps|pdf|png|ps) PLTOUT="-T lw"; LWCAT="lwcat -$2"; shift ;; esac ;; -*) cat <$RRLIST TFILES="$TFILES $RRLIST" fi # determine the file length and histogram bin size RRLIST_LEN=`wc -l $RRLIST | $AWK '{ print $1 }'` BINSIZE=`echo $FREQ | awk '{print 1/$FREQ}'` if [ x$userNNMIN = x -o x$userNNMAX = x ] # the user did not specify both min and max values then # autoscale by running the program once to generate a histogram hp_scatter $RRLIST $NNMIN $NNMAX $BINSIZE $RRLIST_LEN >$SFILE hp_hist $SFILE $NNMIN $NNMAX $BINSIZE >/dev/null # eliminate bins with fewer than five members MINBIN=5.0 $AWK "{if (\$2 > $MINBIN) print \$1,\$2}" $SFILE.hist_rr >tempoutfile.$$ # assign NNMIN and NNMAX to the lowest and highest remaining values NNMIN=`head -1 tempoutfile.$$ | $AWK '{ print $1 }'` NNMAX=`tail -1 tempoutfile.$$ | $AWK '{ print $1 }'` rm tempoutfile.$$ fi if test "$userNNMIN" then NNMIN=$userNNMIN fi if test "$userNNMAX" then NNMAX=$userNNMAX fi # run the program with the NNMIN and NNMAX determined either by autoscale or # user override hp_scatter $RRLIST $NNMIN $NNMAX $BINSIZE $RRLIST_LEN >$SFILE hp_hist $SFILE $NNMIN $NNMAX $BINSIZE >$HFILE # temporary files containing histogram information used in the plotting VVHIST=./$SFILE.hist_Tv NIBHIST=./$SFILE.hist_nib CIHIST=./$SFILE.hist_coup NNHIST=./$SFILE.hist_rr VVSC=./$SFILE.rrTv NIBSC=./$SFILE.rrnib CISC=./$SFILE.rrcoup TFILES="$TFILES $VVHIST $NIBHIST $CIHIST $NNHIST $VVSC $NIBSC $CISC" # begin the plt code ( $AWK 'BEGIN{old=0;}{print $1, old;print $1, 0;print $1, $2;old=$2;}' $VVHIST | plt $PLTOUT 0 1 -F" sf t Ft-i P18 t "" X (P14) 0 10 s Xt s Yt sf a P10 W 0.205 0.65 0.435 0.92 B 0. 0. 1 1" $AWK '{print $1-0.5, $2; print $1+0.5, $2; print $1+0.5, 0;}' $NIBHIST | plt $PLTOUT 0 1 -F" sf t Ft-i P18 t "" X 0 15 W 0.48 0.65 0.71 0.92 B 0. 0. 1 1 xa (P14) -0.5 15.5 1 - 5 - sf a P10 s e s Xt s Yt" $AWK 'BEGIN{old=0}{print $1, old; print $1, 0; print $1, $2;old=$2;}' $CIHIST | plt $PLTOUT 0 1 -F" sf t Ft-i P18 t "" X (P14) 0.25 1.25 W 0.755 0.65 0.985 0.92 B 0. 0. 1 1 sf a P10 s e s Xt s Yt" $AWK 'BEGIN{old=0}{print old, $1;print 0, $1; print $2, $1;old=$2;}' $NNHIST | plt $PLTOUT 0 1 -F" y Sinus RR Interval[s] W 0.08 0.1 0.165 0.57 B 0. 0. 1 1 t '' #xa - - 1000 - 5 - #ya (P12) $2 $3 - - - - s e s x s Xt" read a b <$VVSC imageplt -d $a $b -x 0 10 $VVSC | plt $PLTOUT 0 1 2 -F" p c W 0.205 0.1 0.435 0.57 B 0. 0. 1 1 t "" xa 0 10 1 - 2 - x VV-Interval[s] s e s Y s n" read a b <$NIBSC imageplt -d $a $b -x -0.5 14.5 $NIBSC | plt $PLTOUT 0 1 2 -F" p c X 0 15 W 0.48 0.1 0.71 0.57 B 0. 0. 1 1 t "" xa -0.5 15.5 1 - 5 - x NIB s e s Y s n" read a b <$CISC imageplt -d $a $b -x 0.25 1.25 $CISC | plt $PLTOUT 0 1 2 -F" p c W 0.755 0.1 0.985 0.57 B 0. 0. 1 1 t "" xa 0.25 1.25 0.1 - 2 - x Coupling Interval[s] s e s Y s n" ) | $LWCAT # Remove temporary files rm -f $TFILES NN_intervals