function h = load(h,filename)
%LOAD  Load Toolbox Preferences from disk

%   Author(s): A. DiVergilio
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.5 $  $Date: 2000/09/07 20:19:24 $

if nargin<2
   %---If no file name is specified, load from default preference file
   filename = h.defaultfile;
end

if exist(filename,'file')
   %---Load preference file from disk
   load(filename);

   %---Make sure variable 'p' is found
   if exist('p','var')
      fnp = fieldnames(p);
      fnh = fieldnames(h);
      %---Quick set (property list unchanged)
      if isequal(fnp,fnh)
         set(h,p);
      %---Partial set (property list has changed)
      else
         disp('Older version of Control Toolbox Preferences found... updating...');
         hs = get(h);
         for n=1:length(fnp)
            %---Copy any common properties to the new version
            if isfield(hs,fnp{n})
               set(h,fnp{n},getfield(p,fnp{n}));
            end
         end
         disp('done');
         %---Save to disk so we don't have to do this again
         h.save;
      end
      %---Update old property values
      localUpdateValues(h);
   end
end

%---Define our Java fonts (this may not be neccessary if java.awt.Font is system/version independent)
if usejava('AWT')
   h.JavaFontP = java.awt.Font('Dialog',java.awt.Font.PLAIN,h.JavaFontSize);
   h.JavaFontB = java.awt.Font('Dialog',java.awt.Font.BOLD,h.JavaFontSize);
   h.JavaFontI = java.awt.Font('Dialog',java.awt.Font.ITALIC,h.JavaFontSize);
end


%%%%%%%%%%%%%%%%%%%%%
% localUpdateValues %
%%%%%%%%%%%%%%%%%%%%%
function localUpdateValues(h)
% Update old property values to new equivalent values
hs = get(h);
if isfield(hs,'CompensatorFormat') & strcmp(h.CompensatorFormat,'ZPK1')
   h.CompensatorFormat = 'ZeroPoleGain';
end
