function setfig(varargin)
%SETFIG   Set parameters of figure children objects
%   SETFIG(H, PROPERTY1, VALUE1, PROPERTY2, VALUE2, ...) sets the
%   properties of every child object in a figure or figures.
%
% Example:
%   f = figure;
%   formatfig;
%   plot(1:10, (1:10).^2, 'b', (1:10), (1:10).^3, 'r');
%   xlabel('x [m]');
%   legend({'Line A', 'Line B'}, 'location', 'NorthWest');
%   setfig(f, 'LineWidth', 1, 'FontSize', 14);
%   print -depsc figure.eps
%
% See also: FORMATFIG, PRINT

% Copyright (c) 2011-2014 Peter Fiala

if mod(nargin,2) == 1
    h = varargin{1};
    varargin = varargin(2:end);
else
    h = gcf;
end
prop = varargin(1:2:end);
val = varargin(2:2:end);

for i = 1 : length(prop)
    switch lower(prop{i})
        case 'fontsize'
            ax = findall(h, 'Type', 'axes');            
            for a = 1 : length(ax)
                set(ax(a), 'FontSize', val{i});
            end
%             set(findall(h, '-regexp', 'FontName', '[^'']'), 'FontSize', val{i})
        case 'linewidth'
            set(findall(h, 'Type', 'line'), 'LineWidth', val{i});
        case 'linestyle'
            set(findall(h, 'Type', 'patch'), 'LineStyle', val{i});
        otherwise
            error('uknown property %s', prop{i});
    end
end
end
