% frames = readFluoro(filename, [Nframes]);
%
% Read the frames in a fluoro data set and store them in
% a 128x128xNframes array.
%
% without Nframes, defaults to returning all frames in a file.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

function frames = readFluoro(filename, nframes);

fid = fopen(filename);
data = fread(fid,inf,'uchar');
fclose(fid);

npts = 128^2;

if (nargin == 1),
  nframes = length(data)/npts;
end

if ((nframes - round(nframes)) ~= 0)
  disp('file format not correct');
  return;
end

frames = zeros(128,128,nframes);

for n = 1:nframes,
  imvector = data((n-1)*npts+1:n*npts);
  frames(:,:,n) = reshape(imvector,128,128);
end


