function lc = line_count ( filename )

%*****************************************************************************80
%
%% line_count() counts the lines in a file.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 November 2018
%
%  Author:
%
%    Original MATLAB version by Matthew Dailey.
%    This version by John Burkardt.
%
%  Input:
%
%    string filename, the name of the file.
%
%  Output:
%
%    integer lc, the number of lines.
%
  fid = fopen ( filename, 'r' );

  lc = 0;

  if ( fid < 0 )
    return
  end

  while ( true )
    ln = fgetl ( fid );
    if ( ~ ischar ( ln ) ) 
      break; 
    end
    lc = lc + 1;
  end

  fclose ( fid );

  return
end
