function Models = getmodels(LoopData,ModelIDs)
%GETMODELS  Returns current value of requested models.

%   Author(s): P. Gahinet
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.4 $  $Date: 2000/09/08 14:29:32 $

% RE: Closed-loop model is from [r,dy,du,n] to [y,u]

SavedDesigns = LoopData.SavedDesigns;
SavedComps = {SavedDesigns.Name};

if isa(ModelIDs,'char')
    ModelIDs = {ModelIDs};
end
Models = cell(length(ModelIDs),1);

for ct=1:length(ModelIDs)
    switch ModelIDs{ct}
    case '$G'
        Models{ct} = LoopData.Plant.Model;
    case '$H'
        Models{ct} = LoopData.Sensor.Model;
    case '$F'
        Models{ct} = LoopData.PreFilter.Model;
    case '$C'
        Models{ct} = zpk(LoopData.Compensator);
    case '$L'
        Models{ct} = abs(getgain(LoopData)) * LoopData.OpenLoop;
    case '$T_r2y'
        Models{ct} = LoopData.ClosedLoop(1,1);
    case '$T_r2u'
        Models{ct} = LoopData.ClosedLoop(2,1);
    case '$S_output'
        Models{ct} = LoopData.ClosedLoop(1,2);
    case '$S_input'
        Models{ct} = LoopData.ClosedLoop(1,3);
    case '$S_noise'
        Models{ct} = LoopData.ClosedLoop(1,4);
    case '$Tcl'
        Models{ct} = LoopData.ClosedLoop;
    otherwise
        % Look in list of saved compensators
        Models{ct} = ...
            SavedDesigns(strcmp(ModelIDs{ct},SavedComps)).Compensator.Model;
    end    
end
