function [sig_wave_ht,wave,jd_wave,amplitude,missing] = Riegl_reader(dfl,ddd,hhh)

% Reads Riegl 10Hz laser range meter for wave height.

flist = fopen(dfl,'r');
stx=[]; temp=[];

if flist>0
    while ~feof(flist) % end-of-file not reached
        temp = textscan(flist,'%2f%2f%3f %*c%f %*c%f %*[^\n]','headerLines',1,'delimiter',{';',' '});
        % for some reason, the 'emptyvalue', NaN option in textscan doesn't
        % work properly for the riegl files, so we use manual code to catch
        % empty values here.  Check for instance where date reads but data
        % doesn't.  First 3 columns of temp will have an extra value.
        ii = length(temp{1});           % insert NaNs when empty line with r;a occurs
        if length(temp{5}) == ii-1
            temp{1,4}(ii,1) = NaN;
            temp{1,5}(ii,1) = NaN;
        end;
        stx = [stx, cell2mat(temp)'];   % append cells to st1 and return for more
    end;
else
    stx = NaN(5,36000);
end
fclose(flist);

minu = stx(1,:);
sec = stx(2,:);
msec = stx(3,:);
wave = stx(4,:);
amplitude = stx(5,:);

jd_wave = ddd + (hhh+(minu+(sec+msec/1000)/60)/60)/24;
jd_wave = jd_wave';

[~,m,~] = unique(jd_wave);
jd_wave = jd_wave(m);
wave = wave(m)';
amplitude = amplitude(m)';

wave(wave<8) = NaN; % kill unreasonable values

mwave = nanmedian1(wave);
wave = wave - mwave;
sig_wave_ht = 4.*sqrt(nanvar1(wave));

missing = length(wave(isnan(wave)));
end

  
  