function dummy = optlims(Editor,NormOpenLoop)
%OPTLIMS  Derives adequate frequency range and grid for Bode plots.

%   Author(s): P. Gahinet
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.3 $ $Date: 2000/06/14 20:19:42 $

% REVISIT
dummy = []; 

% Sample time
Ts = getTs(Editor.LoopData);

% Determine 
%  1) Preferred frequency range [Wmin,Wmax]
%  2) frequency grid W that allows for Xlim expansion when moving poles/zeros 
W = fgrid('bode',[],[],[],[],NormOpenLoop);
W = W{1}{1};
Wmin = W(1);
if Ts,
   % Discrete time: Adjust upper lim based on Nyquist freq.
   NyqFreq = pi/abs(Ts); % Nyquist frequency
   if abs(W(end)-NyqFreq)<0.01*NyqFreq | W(end)-NyqFreq>0.01,
      % Push upper limit beyond Nyq. freq
      nfdec = 10^floor(log10(NyqFreq));    % corresponding decade
      nftick = round(NyqFreq/nfdec);
      Wmax = max(nftick+1,(nftick>6)*10) * nfdec;
   else
      Wmax = W(end);
   end
   W = [W(W<0.999*NyqFreq,:) ; NyqFreq];
else
   % Continuous time: Expand freq. vector toward HF
   Wmax = W(end);
   W = [W ; W(end)*[1e1;1e3;1e5]]; 
end
W = [W(1)./[1e5;1e3;1e1] ; W];     % expand freq. vector toward LF

% Save resulting settings
Editor.XlimOpt = [Wmin,Wmax];
Editor.Frequency = W;