function [newdatafiles] = splice()
[ecgfilename, cdfilename, rrfilename, hrfilename, ecgfilenameonly] = chooser('useold');
[ff,ft,fe] = fileparts(ecgfilename);
ifid = fopen([ff ft 'info' fe], 'wb');
tfid = fopen([ff ft 'time' fe], 'wb');
ofid = fopen(ecgfilename, 'r');
newdatafiles = {};
cl = fgetl(ofid);
le = '%[# b-df-mo-zB-DF-MO-Z]';
re = '%e';
te = '# %[0-9]';
cf = 0;
while (~feof(ofid))
  fprintf(ifid,'%4u\n',cf);
  while ((test(cl,le) | ~test(cl,re)) & ~feof(ofid))
    if test(cl, te)
      disp(sprintf('%04u: %s', cf, cl));
      fprintf(tfid,'%04u: %s\n', cf, cl);
    end %if
    fprintf(ifid,'%s\n',cl);
    cl = fgetl(ofid);
  end %while
  if (feof(ofid))
    disp(sprintf('Segment %g does not contain data.', cf));
    return;
  end %if
  newfilename = sprintf('%s%sp%04u%s', ff, ft, cf, fe);
  nfid = fopen(newfilename, 'wb');
  newfilenames = [newfilenames; {newfilename}];
  while ((~test(cl,le) & test(cl,re)) & ~feof(ofid))
    fprintf(nfid,'%s\n',cl);
    cl = fgetl(ofid);
  end %while
  if (feof(ofid)) fprintf(nfid,'%s\n',cl); end %if
  fclose(nfid);
  cf = cf + 1;
  fprintf(ifid,'\n');
end %while
fclose(ofid);

function [bool] = test(s, format)
bool = ~isempty(sscanf(s,format));
