function z = readOneD(basename)
%readOneD(BASENAME) Read 1D data from a series of frames.
%  [Z,dataLength,nFrames] = readOneD(BASENAME) Data
%  is read from a series of data files all which have 
%  the common base name given by the string BASENAME, 
%  then a dot, then a frame index (generally starting
%  with zero).  Each frame corresponds to one row of Z.

% read the first frame and establish length of data
nFrames = 0;
filename = sprintf('%s.%d', basename, nFrames);
nFrames = nFrames + 1;
if exist(filename, 'file')
  z = readmatrix(filename, 'FileType', 'text');
  dataLength = length(z);
else
  return;
end

% loop through other frames and break out of loop
% when next frame does not exist
while 1
  filename = sprintf('%s.%d',basename,nFrames);
  nFrames = nFrames + 1;
  if exist(filename, 'file')
    zTmp = readmatrix(filename, 'FileType', 'text');
    if length(zTmp) ~= dataLength  % check length matches
      error('Frames have different sizes.')
      break;
    end
    z = [z zTmp]; % append new data to z 
  else
    break;
  end
end

% Reshape z to appropriate dimensions.  Want each row to correspond to
% a snapshot.
z = reshape(z, dataLength, nFrames - 1);
z=z';

end
