function mot = read_kongsberg_PISTON_MISOBOB_2018(dfl,ddd,hhh)

%{
    Reads Kongsberg motion files from W band radar and returns
    Nx5 matrix: mot = [jd,roll,pitch,yaw,z_velocity];
    Note: header in some raw Kongsberg files is wrong: roll is always the
    first column, then pitch, yaw and vertical velocities.
    Inputs: dfl = string path to kongsberg file
            ddd, hhh = day of year and hour variables

    Applies fix to seconds variable if it is missing digits left of the
    decimal.

    Angle units are radians.

    The last two columns (10 and 11) in the raw file are vertical velocity
    in the mru coordinates and corrected vertical velocity in the earth
    frame, we use the mru coordinate frame to correct radar doppler
    velocity, so only col 10 is read and copied to the output array.
%}

%% check if file exists, if not return NaN array
if exist(dfl,'file')==2
    %% read file
    flist = fopen(dfl,'r');
    temp = {};    % cell array will hold one line of data, as read from file
    z = [];       % destination matrix for data read from file
    N = 10;       % columns of data to read
    while ~feof(flist)
        try
            % temp will be 1x10 cell array
            temp = textscan(flist,'%2f/%2f/%4f %f:%f:%f %f %f %f %f %*[^\n]','headerlines', 4);
            z = [z cell2mat(temp)'];
        catch
            [lnr2,~] = size(temp{1,N});
            if lnr2<=1
                temp = [];
            else
                for ll=1:N
                    if length(temp{1,ll})~=lnr2
                        temp{1,ll}(lnr2+1)=[];
                    end
                end
                if ~isempty(temp{1,1})
                    z = [z cell2mat(temp)'];
                end
            end
        end
    end
    fclose(flist);
    z = z';

    ss = z(:,6);
    if all(ss<1.0)
        % fix seconds variable
        sdiff = diff(z(:,6));
        zz = find(sdiff<0);     % indices for the end of each second
        zz = [0;zz;length(ss)]; % add begin and end indices
        sec = 0;
        % add whole part of fractional seconds to each timestamp
        for ii = 1:length(zz)-1
            ss(zz(ii)+1:zz(ii+1)) = ss(zz(ii)+1:zz(ii+1)) + sec;
            if sec==59
                sec = 0;
            else
                sec = sec + 1;
            end
        end
    end

    % compute timestamp as decimal jd, nominally at 20 Hz
    tmotion = md2yd_vn(z(:,3), z(:,1), z(:,2));
    tmotion = tmotion + z(:,4)/24 + z(:,5)/1440 + ss/86400;

    % format mot array
    mot = [tmotion,z(:,7:10)];
    kk = find(diff(mot(:,1))>0); % select good timestamps only
    mot = mot(kk,:);

else
     %% no file found, so return NaN array
    start = (ddd+hhh/24);
    delta = double(1/(20*86400));  % 20 Hz timestamp
    last = start + 71999*delta;
    tref = start:delta:last;
    mot = NaN(72000,5);
    mot(:,1) = tref;
end

end
