function [orientation, arglist] = parseOrientations(arglist)
%parseOrientations parse argument list for position information
%   This file is for internal use only and may be removed in a future
%   version of MATLAB

%   Copyright 2017 The MathWorks, Inc.

if ~isempty(arglist) && isa(arglist{1},'quaternion')
    % try orientation quaternion...
    if ~isvector(arglist{1})
        error(message('shared_radarfusion:theaterPlot:OrientationQuaternionMustBeVector'));
    end
    orientation = arglist{1};
    orientation = rotmat(orientation(:),'frame');
    arglist = arglist(2:end);
elseif ~isempty(arglist) && size(arglist{1},1)==3 && size(arglist{1},2)==3
    % try orientation matrix...
    argsize = size(arglist{1});
    if numel(argsize)>3
        error(message('shared_radarfusion:theaterPlot:UnrecognizedOrientation'));
    end
    validateattributes(arglist{1}, {'numeric'}, {'real'}, ...
        'plotOrientation', 'orientations');
    orientation = arglist{1};
    arglist = arglist(2:end);
elseif numel(arglist)>=3 && isvector(arglist{1}) && isvector(arglist{2}) && isvector(arglist{3})
    % try (roll, pitch, yaw)...
    roll = arglist{1};
    pitch = arglist{2};
    yaw = arglist{3};
    if length(yaw) ~= length(pitch) || length(yaw) ~= length(roll) || length(pitch) ~= length(roll)
        error(message('shared_radarfusion:theaterPlot:RollPitchYawMismatch'));
    end
    validateattributes(arglist{1}, {'numeric'}, {'real', 'vector'}, ...
        'plotOrientation', 'roll');
    validateattributes(arglist{1}, {'numeric'}, {'real', 'vector'}, ...
        'plotOrientation', 'pitch');
    validateattributes(roll, {'numeric'}, {'real', 'vector'}, ...
        'plotOrientation', 'yaw');
    E = [deg2rad(yaw(:)),deg2rad(pitch(:)),deg2rad(roll(:))];
    Q = quaternion(E,'euler','zyx','frame');
    orientation = rotmat(Q,'frame');
    arglist = arglist(4:end);
else
    error(message('shared_radarfusion:theaterPlot:UnrecognizedOrientation'));
end
    