function [type,out,next,Error] = getNextFilterOperand(type,obligation,next,varargin);

args = varargin{1};
nrArgs = length(args);

Error.Code = 0;
Error.Message = 'No error';
if next > nrArgs
    if strcmp(upper(obligation),'NEEDED')
        Error.Code = '1';
        Error.Message = 'WARN ADMINISTRATOR. No needed filteroperand found';
    elseif strcmp(upper(type),'RELOP')
        out = '==';
    end
    return
end

if ~isnumeric(args{next}) && ~strcmp(upper(args{next}),'RELOP') && ~strcmp(upper(args{next}),'VALUE')
    Error.Code = 2;
    Error.Message = 'WARN ADMINISTRATOR. No correct filteroperand';
    return
end

if strcmp(upper(args{next}),'RELOP')
    type = 'relop';
    if strcmp(upper(type),'FREE') || strcmp(upper(type),'RELOP')
        next = next + 1;
        if next > nrArgs
            Error.Code = 6;
            Error.Message = 'WARN ADMINISTRATOR. Expected a relational operator';
        else
            if ~RelOpOK(args{next})
                Error.Code = 7;
                Error.Message = 'WARN ADMINISTRATOR. No correct relational operator';
            else
                out = args{next};
                next = next + 1;
            end
        end
    else
        Error.Code = 3;
        Error.Message = 'WARN ADMINISTRATOR. Filteroperand does not match request';
    end
elseif strcmp(upper(args{next}),'VALUE')
    type = 'value';
    if strcmp(upper(type),'FREE') || strcmp(upper(type),'VALUE')
        next = next + 1;
        if next > nrArgs
            Error.Code = 8;
            Error.Message = 'WARN ADMINISTRATOR. Expected a value as a filteroperand';
        else
            if isnumeric(args{next})
                out = args{next};
                next = next + 1;
            else
                Error.Code = 9;
                Error.Message = 'WARN ADMINISTRATOR. Filteroperand must be a value';
            end
        end
    else
        Error.Code = 4;
        Error.Message = 'WARN ADMINISTRATOR. Filteroperand does not match request';
    end
elseif isnumeric(args{next})
    if strcmp(upper(type),'FREE') || strcmp(upper(type),'VALUE')
        type = 'value';
        out = args{next};
        next = next + 1;
    elseif strcmp(upper(obligation),'NEEDED')
        Error.Code = 5;
        Error.Message = 'WARN ADMINISTRATOR. Filteroperand must be a value';
    else
        out = '==';
        type = 'relop';
    end
end
    
    
        
