% script to read raw jarkus data (xyz files)

fname = 'p:\1204421-kpp-benokust\2013\jarkus\2013data\Raai Ascii - Jarkus Rijnland - 2013.txt';

fid = fopen(fname);
i = 0;
S = repmat(struct('x', [], 'y', [], 'z', [], 'code', '', 'alongshore', [], 'datevec', []), 1, 500);
while ~feof(fid)    % Statement is valid until the end of each area data file is reached
    l = fgetl (fid);
    match = regexp(l, '\D{3}\d{4}\.\d{3}', 'match');
    if ~isempty(match)
        if i>0
            S(i).x = x;
            S(i).y = y;
            S(i).z = z;
        end
        i = i + 1;
        [x, y, z] = deal([]);
    else
        % 24/01/13 09:26:46   97093.09  497090.01 -15.52
        l = strtrim(l);
        S(i).datevec = datevec(l(1:17), 'dd/mm/yy HH:MM:SS');
        tmp = num2cell(sscanf(l(18:end), '%f'));
        [x(end+1), y(end+1), z(end+1)] = deal(tmp{:});
    end

end
% txt = fread(fid, '*char')';
fclose(fid);

S(i).x = x;
S(i).y = y;
S(i).z = z;

S(i+1:end) = [];