function [FloatArgs, FloatFields, OptArgs, OptFields, options] = parseoptemfloatargs(args)
%PARSEOPTEMFLOATARGS Parse input arguments to resolve NV pair for optional 
%                    arguments, and to set defaul values.
%
%   This is a private function that is not meant to be called directly
%   by the user.

%   Copyright 1998-2012 The MathWorks, Inc.

%--------------------------------------------
% Checking inputs
%--------------------------------------------
% Spread, Settle, Maturity, OptSpec, Strike, ExerciseDates...
FloatArgs = args(1:3);
OptArgs = args(4:6);

% We need to process NVPs to obtain the optional args
if(numel(args)>6)
    OptionalArgs = args(7:end);
else
    OptionalArgs = {};
end

%   Reset, Basis, Principal, Options, EndMonthRule, CapRate, FloorRate,
%   AmericanOpt

Names  = {'FloatReset', 'Basis', 'EndMonthRule', ...
    'Principal', 'AmericanOpt', 'CapRate', 'FloorRate', 'options'};

Defaults = {NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN};
[Reset, Basis, EndMonthRule, Principal, AmericanOpt, CapRate, FloorRate, options] = ...
    parsepvpairs(Names, Defaults, OptionalArgs{:}); 

% Verify input args consistency and set real default values
[Spread, Settle, Maturity, OptSpec, Strike, ExerciseDates, Reset, Basis, Principal, ...
    EndMonthRule, CapRate, FloorRate, AmericanOpt] = instargoptemfloat(FloatArgs{:}, ...
    OptArgs{:}, Reset, Basis, Principal, EndMonthRule, CapRate, FloorRate, AmericanOpt);

% Group args according to instruments:
% Float
FloatArgs = {Spread, Settle, Maturity, Reset, Basis, Principal, EndMonthRule, CapRate, FloorRate};
FloatFields = {'Spread', 'Settle', 'Maturity', 'Reset', 'Basis', 'Principal', 'EndMonthRule', 'CapRate', 'FloorRate'};

% Option
OptArgs = {OptSpec, Strike, ExerciseDates, AmericanOpt};
OptFields = {'OptSpec', 'Strike', 'ExerciseDates', 'AmericanOpt'};

% Sanity check on 'options'
if length(options) ~= 1 || (~isa(options,'struct') && ~isnan(options))
    error(message('finance:parseoptemfloatargs:InvalidOptions'));
end




