function checkInterfaceInfo(obj)
%

%   Copyright 2010 The MathWorks, Inc.

    baseInterfaceInfo = obj.Data(1).InterfaceInfo;
    for idx=2:length(obj.Data)
        currentInrefaceInfo = obj.Data(idx).InterfaceInfo;
        if ~sampletTimesAcceptable(baseInterfaceInfo, currentInrefaceInfo)
            obj.handleMsg('error', message('Sldv:DataMerger:SampleTimeMismatch', obj.UtilityName, idx));
        end
        if length(baseInterfaceInfo.InputPortInfo) ~= length(currentInrefaceInfo.InputPortInfo)
            obj.handleMsg('error', message('Sldv:DataMerger:NumInportMismatch', obj.UtilityName, idx));
        end
        if length(baseInterfaceInfo.OutputPortInfo) ~= length(currentInrefaceInfo.OutputPortInfo)
            obj.handleMsg('error', message('Sldv:DataMerger:NumOutportMismatch', obj.UtilityName, idx));
        end        
        if ~interfaceAcceptable(baseInterfaceInfo.InputPortInfo, currentInrefaceInfo.InputPortInfo)
            obj.handleMsg('error', message('Sldv:DataMerger:InportMismatch', obj.UtilityName, idx));
        end
        if ~interfaceAcceptable(baseInterfaceInfo.OutputPortInfo, currentInrefaceInfo.OutputPortInfo)
            obj.handleMsg('error', message('Sldv:DataMerger:OutportMismatch', obj.UtilityName, idx));
        end
    end
end

function out = sampletTimesAcceptable(baseInterfaceInfo, currentInrefaceInfo)
    out = true;
    if length(baseInterfaceInfo.SampleTimes)~=length(currentInrefaceInfo.SampleTimes) || ...
            any(baseInterfaceInfo.SampleTimes~=currentInrefaceInfo.SampleTimes)
        out = false;
    end
end

function out = interfaceAcceptable(baseInfo, currentInfo)
    out = true;
    for idx=1:length(baseInfo)
        if ~strcmp(class(baseInfo{idx}),class(currentInfo{idx})) || ...
                ~isInterfaceSame(baseInfo{idx}, currentInfo{idx})                
            out = false;
            break;                                
        end
    end
end

function out = isInterfaceSame(baseInfo, currentInfo)
    out = true;
    if ~iscell(baseInfo)
        if length(baseInfo.Dimensions) ~= length(currentInfo.Dimensions) || ...
                any(baseInfo.Dimensions ~= currentInfo.Dimensions) || ...
                ~strcmp(baseInfo.DataType, currentInfo.DataType) || ...
                ~strcmp(baseInfo.SampleTimeStr, currentInfo.SampleTimeStr)
            out = false;
        end
    else
        for idx=2:length(baseInfo)
            if ~isInterfaceSame(baseInfo{idx}, currentInfo{idx})
                out = false;
                break;
            end
        end
    end
end