function NumLines = IMDC_Read_FileHeader(FileToRead);
%IMDC_READ_FILEHEADER    Read header of given file.
%   N = IMDC_READ_FILEHEADER(FileToRead) reads the number of lines used for 
%   the header in an ASCII file. Lines at the beginning of the file starting 
%   with '*' are seen as header.
%   FileToRead: File name as string of the file to be opened.
%   N: Number of lines containing file header.

% International Marine and Dredging Consultants, IMDC
% Antwerp, Belgium
%
% Written by: Fernando Toro
% Date: November 2004
% Modified by:
% Date:


% ********************
% Check input argument
% ********************

if ~ischar(FileToRead)
    error('Input argument must be a character array!')
end



% ********************************************************
% Replace substrings '\' and '\\' with '/' for convenience
% ********************************************************

FileToRead = strrep(FileToRead,'\','/');
FileToRead = strrep(FileToRead,'//','/');



% *********
% Open file
% *********
fid = fopen(FileToRead, 'r');
if (fid == -1)
   % The file did not open
   error(['Problems opening file ' FileToRead])
end;



% **************************************************************
% Read header (lines starting with "*") and first line of values
% **************************************************************

NumLines = 0;
while (1)
   line = fgets(fid);
   if (line == -1)
      % End of file
      break;
   end
   firstChar = sscanf(line, '%s', 1);
   if (firstChar ~= '*')
      break;
   end
   NumLines = NumLines + 1;
end

% **********
% Close file
% **********

fclose(fid);

return;