function m = read_text_mat( filename )
  
  if nargin < 1
    error( [ mfilename ' needs one input argument.' ] );
  end
  
  fid = fopen( filename, 'rt' );
  if fid < 0 
    error( [ mfilename ' could not read-open "' filename '".' ] );
  end
  
  % Find how many numbers per line (dim)
  while 1
    
    tmp_line = fgetl( fid );
    if ~ischar( tmp_line )
      error( [ mfilename ' could not find a non-empty first line in file "' filename '".' ] );
    end
    
    tmp_line = deblank( tmp_line );
    if ~isempty( tmp_line )
      break;
    end
    
  end
  
  fclose( fid );
  
  a = sscanf( tmp_line, '%f' );
  
  dim = numel( a );
  
  % Now read the whole file
  fid = fopen( filename, 'rt' );
  m = fscanf( fid, '%f', [ dim +Inf ] );
  fclose( fid );
  m = m.';
  
  