function [blocks] = readTekalFile(fname)

% Generic routine to read tekal files
% 
% Output is structure of tekal blocks with fields name, size and data
%

blocks = [];

fid = fopen(fname);

count = 1;

while ~feof(fid)
   
   str = fgetl(fid);
   % Replace empty strings with comment character '*', otherwise str(1) will
   % yield error message
   if isempty(deblank(str))
      str = '*';
   end
   
   
   if str==-1
       break
   end
   
   % Pick out non-comment lines
   if isempty(strmatch(str(1),'*'));
      block.BLname = str;
      block.BLsize = str2num(fgetl(fid));
      data = fscanf(fid, '%f',fliplr(block.BLsize));
      block.data = data';
      
      blocks = [blocks; block];
      block = [];
   end
   
end

fclose(fid);
