function XYZ = Read_XYZ(Filename)
% Read XYZ from survey into Matlab
% Suitable for both Jetski and Walking survey files

% Check input
if exist('Filename') ~= 1
    Filename = 'XYZ_jetski_RD_NAP.txt';
end

%% find header length based on the X indication
fid = fopen(Filename);
go = 1;
header = 0;
while go
    tline = fgetl(fid);
    header = header + 1;
    if ~isempty(tline) && tline(1) == 'X'
        go = 0;
    end
end
fclose(fid);

%% Read file
XYZ = importdata(Filename,' ',header);
%% extract Metadata from header
linetest=strfind(XYZ.textdata,'Survey'); % find the line with the survey date.. This goes wrong if we decide to have the word Survey multiple times in the header!
for i_line=1:length(linetest)
    if  linetest{i_line} ~=0 % ectract the survey date from the line 
        [dum dum date] =strread(XYZ.textdata{i_line}, '%s %s %s ','delimiter', ' ');  %% Edit Matthieu 19/8
    end
end
XYZ.surveydate=date; %% Edit Matthieu 19/8