function [ecgfilename, cdfilename, rrfilename, hrfilename, ecgfilenameonly] = chooser(fileuse, ecgfilename, ecgpath);
if (nargin==0 | not(strcmp(fileuse, 'choosenew') | strcmp(fileuse, 'useold')))
  fileuse = 'choosenew';
end %if
canuseold = (size(who('global', 'ecgonlyfilename', 'ecgfullfilename', 'cdfullfilename', ...
                                'rrfullfilename', 'hrfullfilename'), 1) == 5);
global ecgfullfilename cdfullfilename rrfullfilename hrfullfilename ecgonlyfilename
if (strcmp(fileuse, 'choosenew') | not(canuseold))
  if (nargin <= 1)
    [ecgfilename, ecgpath] = uigetfile( ...
         {'*.TXT;*.DAT', 'All ECG Data Files (*.txt, *.dat)'; ...
          '*.*',  'All Files (*.*)'}, ...
          'Pick an ECG file');
  end %if
  if (ischar(ecgfilename) & ischar(ecgpath))
    ecgfilenameonly = ecgfilename;
    [nullpath ecgtitle] = fileparts(ecgfilename);
    cdfilename = [ecgpath filesep ecgtitle '.cdd'];
    rrfilename = [ecgpath filesep ecgtitle '.rrd'];
    hrfilename = [ecgpath filesep ecgtitle '.hrd'];
    ecgfilename = [ecgpath filesep ecgfilename];
    ecgonlyfilename = ecgfilenameonly;
    ecgfullfilename = ecgfilename;
    cdfullfilename = cdfilename;
    rrfullfilename = rrfilename;
    hrfullfilename = hrfilename;
    return;
  end %if
end %if
if (canuseold)
  ecgfilename = ecgfullfilename;
  cdfilename = cdfullfilename;
  rrfilename = rrfullfilename;
  hrfilename = hrfullfilename;
  ecgfilenameonly = ecgonlyfilename;
  return;
end %if
clear global ecgfullfilename cdfullfilename rrfullfilename hrfullfilename ecgonlyfilename
if (nargin > 0)
  error('ECG filename not acquired.  Program execution will terminate.');
end %if
