Index: /issm/trunk-jpl/externalpackages/export_fig/export_fig.m
===================================================================
--- /issm/trunk-jpl/externalpackages/export_fig/export_fig.m	(revision 14173)
+++ /issm/trunk-jpl/externalpackages/export_fig/export_fig.m	(revision 14174)
@@ -123,6 +123,6 @@
 %   -bookmark - option to indicate that a bookmark with the name of the
 %               figure is to be created in the output file (pdf only).
-%   handle - The handle of the figure or axes (can be an array of handles
-%            of several axes, but these must be in the same figure) to be
+%   handle - The handle of the figure, axes or uipanels (can be an array of
+%            handles, but the objects must be in the same figure) to be
 %            saved. Default: gcf.
 %
@@ -166,17 +166,24 @@
 % 09/05/12: Incorporate patch of Arcelia Arrieta (many thanks), to keep
 %           tick marks fixed.
-
-function [im alpha] = export_fig(varargin)
+% 12/12/12: Add support for isolating uipanels. Thanks to michael for
+%           suggesting it.
+
+function [im, alpha] = export_fig(varargin)
 % Make sure the figure is rendered correctly _now_ so that properties like
 % axes limits are up-to-date.
 drawnow;
 % Parse the input arguments
-[fig options] = parse_args(nargout, varargin{:});
+[fig, options] = parse_args(nargout, varargin{:});
 % Isolate the subplot, if it is one
-cls = strcmp(get(fig(1), 'Type'), 'axes');
+cls = all(ismember(get(fig, 'Type'), {'axes', 'uipanel'}));
 if cls
     % Given handles of one or more axes, so isolate them from the rest
     fig = isolate_axes(fig);
 else
+    % Check we have a figure
+    if ~isequal(get(fig, 'Type'), 'figure');
+        error('Handle must be that of a figure, axes or uipanel');
+    end
+    % Get the old InvertHardcopy mode
     old_mode = get(fig, 'InvertHardcopy');
 end
@@ -198,5 +205,5 @@
     end
 end
-% MATLAB "feature": axes limits can change when printing
+% MATLAB "feature": axes limits and tick marks can change when printing
 Hlims = findall(fig, 'Type', 'axes');
 if ~cls
@@ -282,5 +289,5 @@
         % Crop the background
         if options.crop
-            [alpha v] = crop_background(alpha, 0);
+            [alpha, v] = crop_background(alpha, 0);
             A = A(v(1):v(2),v(3):v(4),:);
         end
@@ -289,5 +296,5 @@
             res = options.magnify * get(0, 'ScreenPixelsPerInch') / 25.4e-3;
             % Save the png
-            imwrite(A, [options.name '.png'], 'Alpha', alpha, 'ResolutionUnit', 'meter', 'XResolution', res, 'YResolution', res);
+            imwrite(A, [options.name '.png'], 'Alpha', double(alpha), 'ResolutionUnit', 'meter', 'XResolution', res, 'YResolution', res);
             % Clear the png bit
             options.png = false;
@@ -325,5 +332,5 @@
             tcol = 255;
         else
-            [A tcol] = print2array(fig, magnify, renderer);
+            [A, tcol] = print2array(fig, magnify, renderer);
         end
         % Crop the background
@@ -460,5 +467,5 @@
 return
 
-function [fig options] = parse_args(nout, varargin)
+function [fig, options] = parse_args(nout, varargin)
 % Parse the input arguments
 % Set the defaults
@@ -542,5 +549,5 @@
             end
         else
-            [p options.name ext] = fileparts(varargin{a});
+            [p, options.name, ext] = fileparts(varargin{a});
             if ~isempty(p)
                 options.name = [p filesep options.name];
@@ -577,5 +584,5 @@
 
 % Check whether transparent background is wanted (old way)
-if isequal(get(fig, 'Color'), 'none')
+if isequal(get(ancestor(fig, 'figure'), 'Color'), 'none')
     options.transparent = true;
 end
@@ -667,7 +674,7 @@
 return
 
-function [A v] = crop_background(A, bcol)
+function [A, v] = crop_background(A, bcol)
 % Map the foreground pixels
-[h w c] = size(A);
+[h, w, c] = size(A);
 if isscalar(bcol) && c > 1
     bcol = bcol(ones(1, c));
Index: /issm/trunk-jpl/externalpackages/export_fig/ghostscript.m
===================================================================
--- /issm/trunk-jpl/externalpackages/export_fig/ghostscript.m	(revision 14173)
+++ /issm/trunk-jpl/externalpackages/export_fig/ghostscript.m	(revision 14174)
@@ -1,3 +1,2 @@
-function varargout = ghostscript(cmd)
 %GHOSTSCRIPT  Calls a local GhostScript executable with the input command
 %
@@ -25,35 +24,35 @@
 % Thanks to Jonas Dorn for the fix for the title of the uigetdir window on
 % Mac OS.
-
 % Thanks to Nathan Childress for the fix to the default location on 64-bit
 % Windows systems.
-
 % 27/4/11 - Find 64-bit Ghostscript on Windows. Thanks to Paul Durack and
 % Shaun Kline for pointing out the issue
-
 % 4/5/11 - Thanks to David Chorlian for pointing out an alternative
 % location for gs on linux.
+% 12/12/12 - Add extra executable name on Windows. Thanks to Ratish
+% Punnoose for highlighting the issue.
 
+function varargout = ghostscript(cmd)
 % Call ghostscript
 [varargout{1:nargout}] = system(sprintf('"%s" %s', gs_path, cmd));
 return
 
-function path = gs_path
+function path_ = gs_path
 % Return a valid path
 % Start with the currently set path
-path = user_string('ghostscript');
+path_ = user_string('ghostscript');
 % Check the path works
-if check_gs_path(path)
+if check_gs_path(path_)
     return
 end
 % Check whether the binary is on the path
 if ispc
-    bin = {'gswin32c.exe', 'gswin64c.exe'};
+    bin = {'gswin32c.exe', 'gswin64c.exe', 'gs'};
 else
     bin = {'gs'};
 end
 for a = 1:numel(bin)
-    path = bin{a};
-    if check_store_gs_path(path)
+    path_ = bin{a};
+    if check_store_gs_path(path_)
         return
     end
@@ -76,5 +75,5 @@
                 path2 = [default_location dir_list(a).name executable{b}];
                 if exist(path2, 'file') == 2
-                    path = path2;
+                    path_ = path2;
                     ver_num = ver_num2;
                 end
@@ -82,5 +81,5 @@
         end
     end
-    if check_store_gs_path(path)
+    if check_store_gs_path(path_)
         return
     end
@@ -88,6 +87,6 @@
     bin = {'/usr/bin/gs', '/usr/local/bin/gs'};
     for a = 1:numel(bin)
-        path = bin{a};
-        if check_store_gs_path(path)
+        path_ = bin{a};
+        if check_store_gs_path(path_)
             return
         end
@@ -110,7 +109,7 @@
     for a = 1:numel(bin_dir)
         for b = 1:numel(bin)
-            path = [base bin_dir{a} bin{b}];
-            if exist(path, 'file') == 2
-                if check_store_gs_path(path)
+            path_ = [base bin_dir{a} bin{b}];
+            if exist(path_, 'file') == 2
+                if check_store_gs_path(path_)
                     return
                 end
@@ -121,12 +120,12 @@
 error('Ghostscript not found. Have you installed it from www.ghostscript.com?');
 
-function good = check_store_gs_path(path)
+function good = check_store_gs_path(path_)
 % Check the path is valid
-good = check_gs_path(path);
+good = check_gs_path(path_);
 if ~good
     return
 end
 % Update the current default path to the path found
-if ~user_string('ghostscript', path)
+if ~user_string('ghostscript', path_)
     warning('Path to ghostscript installation could not be saved. Enter it manually in ghostscript.txt.');
     return
@@ -134,7 +133,7 @@
 return
 
-function good = check_gs_path(path)
+function good = check_gs_path(path_)
 % Check the path is valid
-[good message] = system(sprintf('"%s" -h', path));
+[good, message] = system(sprintf('"%s" -h', path_));
 good = good == 0;
 return
Index: /issm/trunk-jpl/externalpackages/export_fig/isolate_axes.m
===================================================================
--- /issm/trunk-jpl/externalpackages/export_fig/isolate_axes.m	(revision 14173)
+++ /issm/trunk-jpl/externalpackages/export_fig/isolate_axes.m	(revision 14174)
@@ -5,11 +5,12 @@
 %   fh = isolate_axes(ah, vis)
 %
-% This function will create a new figure containing the axes specified, and
-% also their associated legends and colorbars. The axes specified must all
-% be in the same figure, but they will generally only be a subset of the
-% axes in the figure.
+% This function will create a new figure containing the axes/uipanels
+% specified, and also their associated legends and colorbars. The objects
+% specified must all be in the same figure, but they will generally only be
+% a subset of the objects in the figure.
 %
 % IN:
-%    ah - An array of axes handles, which must come from the same figure.
+%    ah - An array of axes and uipanel handles, which must come from the
+%         same figure.
 %    vis - A boolean indicating whether the new figure should be visible.
 %          Default: false.
@@ -23,4 +24,6 @@
 % 16/3/2012 Moved copyfig to its own function. Thanks to Bob Fratantonio
 % for pointing out that the function is also used in export_fig.m.
+% 12/12/12 - Add support for isolating uipanels. Thanks to michael for
+% suggesting it.
 
 function fh = isolate_axes(ah, vis)
@@ -29,10 +32,10 @@
     error('ah must be an array of handles');
 end
-% Check that the handles are all for axes, and are all in the same figure
+% Check that the handles are all for axes or uipanels, and are all in the same figure
 fh = ancestor(ah(1), 'figure');
 nAx = numel(ah);
 for a = 1:nAx
-    if ~strcmp(get(ah(a), 'Type'), 'axes')
-        error('All handles must be axes handles.');
+    if ~ismember(get(ah(a), 'Type'), {'axes', 'uipanel'})
+        error('All handles must be axes or uipanel handles.');
     end
     if ~isequal(ancestor(ah(a), 'figure'), fh)
@@ -40,5 +43,5 @@
     end
 end
-% Tag the axes so we can find them in the copy
+% Tag the objects so we can find them in the copy
 old_tag = get(ah, 'Tag');
 if nAx == 1
@@ -51,5 +54,5 @@
     set(fh, 'Visible', 'off');
 end
-% Reset the axes tags
+% Reset the object tags
 for a = 1:nAx
     set(ah(a), 'Tag', old_tag{a});
@@ -59,5 +62,5 @@
 if numel(ah) ~= nAx
     close(fh);
-    error('Incorrect number of axes found.');
+    error('Incorrect number of objects found.');
 end
 % Set the axes tags to what they should be
@@ -87,5 +90,5 @@
 % Get all the objects in the figure
 axs = findall(fh);
-% Delete everything except for the input axes and associated items
+% Delete everything except for the input objects and associated items
 delete(axs(~ismember(axs, [ah; allchildren(ah); allancestors(ah)])));
 return
Index: /issm/trunk-jpl/externalpackages/export_fig/pdftops.m
===================================================================
--- /issm/trunk-jpl/externalpackages/export_fig/pdftops.m	(revision 14173)
+++ /issm/trunk-jpl/externalpackages/export_fig/pdftops.m	(revision 14174)
@@ -33,10 +33,10 @@
 return
 
-function path = xpdf_path
+function path_ = xpdf_path
 % Return a valid path
 % Start with the currently set path
-path = user_string('pdftops');
+path_ = user_string('pdftops');
 % Check the path works
-if check_xpdf_path(path)
+if check_xpdf_path(path_)
     return
 end
@@ -48,14 +48,14 @@
 end
 if check_store_xpdf_path(bin)
-    path = bin;
+    path_ = bin;
     return
 end
 % Search the obvious places
 if ispc
-    path = 'C:\Program Files\xpdf\pdftops.exe';
+    path_ = 'C:\Program Files\xpdf\pdftops.exe';
 else
-    path = '/usr/local/bin/pdftops';
+    path_ = '/usr/local/bin/pdftops';
 end
-if check_store_xpdf_path(path)
+if check_store_xpdf_path(path_)
     return
 end
@@ -75,10 +75,10 @@
     bin_dir = {'', ['bin' filesep], ['lib' filesep]};
     for a = 1:numel(bin_dir)
-        path = [base bin_dir{a} bin];
-        if exist(path, 'file') == 2
+        path_ = [base bin_dir{a} bin];
+        if exist(path_, 'file') == 2
             break;
         end
     end
-    if check_store_xpdf_path(path)
+    if check_store_xpdf_path(path_)
         return
     end
@@ -86,12 +86,12 @@
 error('pdftops executable not found.');
 
-function good = check_store_xpdf_path(path)
+function good = check_store_xpdf_path(path_)
 % Check the path is valid
-good = check_xpdf_path(path);
+good = check_xpdf_path(path_);
 if ~good
     return
 end
 % Update the current default path to the path found
-if ~user_string('pdftops', path)
+if ~user_string('pdftops', path_)
     warning('Path to pdftops executable could not be saved. Enter it manually in pdftops.txt.');
     return
@@ -99,7 +99,7 @@
 return
 
-function good = check_xpdf_path(path)
+function good = check_xpdf_path(path_)
 % Check the path is valid
-[good message] = system(sprintf('"%s" -h', path));
+[good message] = system(sprintf('"%s" -h', path_));
 % system returns good = 1 even when the command runs
 % Look for something distinct in the help text
Index: /issm/trunk-jpl/externalpackages/export_fig/print2array.m
===================================================================
--- /issm/trunk-jpl/externalpackages/export_fig/print2array.m	(revision 14173)
+++ /issm/trunk-jpl/externalpackages/export_fig/print2array.m	(revision 14174)
@@ -25,25 +25,24 @@
 %   bcol - 1x3 uint8 vector of the background color
 
-% Copyright (C) Oliver Woodford 2008-2011
+% Copyright (C) Oliver Woodford 2008-2012
 
-% 5/9/2011 Set EraseModes to normal when using opengl or zbuffer renderers.
-% Thanks to Pawel Kocieniewski for reporting the issue.
+% 05/09/11: Set EraseModes to normal when using opengl or zbuffer
+%           renderers. Thanks to Pawel Kocieniewski for reporting the
+%           issue.
+% 21/09/11: Bug fix: unit8 -> uint8! Thanks to Tobias Lamour for reporting
+%           the issue.
+% 14/11/11: Bug fix: stop using hardcopy(), as it interfered with figure
+%           size and erasemode settings. Makes it a bit slower, but more
+%           reliable. Thanks to Phil Trinh and Meelis Lootus for reporting
+%           the issues.
+% 09/12/11: Pass font path to ghostscript.
+% 27/01/12: Bug fix affecting painters rendering tall figures. Thanks to
+%           Ken Campbell for reporting it.
+% 03/04/12: Bug fix to median input. Thanks to Andy Matthews for reporting
+%           it.
+% 26/10/12: Set PaperOrientation to portrait. Thanks to Michael Watts for
+%           reporting the issue.
 
-% 21/9/2011 Bug fix: unit8 -> uint8!
-% Thanks to Tobias Lamour for reporting the issue.
-
-% 14/11/2011 Bug fix: stop using hardcopy(), as it interfered with figure
-% size and erasemode settings. Makes it a bit slower, but more reliable.
-% Thanks to Phil Trinh and Meelis Lootus for reporting the issues.
-
-% 9/12/2011 Pass font path to ghostscript.
-
-% 27/1/2012 Bug fix affecting painters rendering tall figures. Thanks to
-% Ken Campbell for reporting it.
-
-% 3/4/2012 Bug fix to median input. Thanks to Andy Matthews for reporting
-% it.
-
-function [A bcol] = print2array(fig, res, renderer)
+function [A, bcol] = print2array(fig, res, renderer)
 % Generate default input arguments, if needed
 if nargin < 2
@@ -85,8 +84,8 @@
         % Execute the ghostscript command
         ghostscript(cmd_str);
-    catch
+    catch me
         % Delete the intermediate file
         delete(tmp_eps);
-        rethrow(lasterror);
+        rethrow(me);
     end
     % Delete the intermediate file
@@ -134,6 +133,7 @@
     err = false;
     % Set paper size
-    old_mode = get(fig, 'PaperPositionMode');
-    set(fig, 'PaperPositionMode', 'auto');
+    old_pos_mode = get(fig, 'PaperPositionMode');
+    old_orientation = get(fig, 'PaperOrientation');
+    set(fig, 'PaperPositionMode', 'auto', 'PaperOrientation', 'portrait');
     try
         % Print to tiff file
@@ -147,5 +147,5 @@
     end
     % Reset paper size
-    set(fig, 'PaperPositionMode', old_mode);
+    set(fig, 'PaperPositionMode', old_pos_mode, 'PaperOrientation', old_orientation);
     % Throw any error that occurred
     if err
Index: /issm/trunk-jpl/externalpackages/export_fig/print2eps.m
===================================================================
--- /issm/trunk-jpl/externalpackages/export_fig/print2eps.m	(revision 14173)
+++ /issm/trunk-jpl/externalpackages/export_fig/print2eps.m	(revision 14174)
@@ -28,22 +28,24 @@
 % fex id: 5743, but the implementation is mine :)
 
-% 14/11/2011 Fix a MATLAB bug rendering black or white text incorrectly.
-% Thanks to Mathieu Morlighem for reporting the issue and obtaining a fix
-% from TMW.
-
-% 8/12/2011 Added ability to correct fonts. Several people have requested
-% this at one time or another, and also pointed me to printeps (fex id:
-% 7501), so thank you to them. My implementation (which was not inspired by
-% printeps - I'd already had the idea for my approach) goes
-% slightly further in that it allows multiple fonts to be swapped.
-
-% 14/12/2011 Fix bug affecting font names containing spaces. Many thanks to
-% David Szwer for reporting the issue.
-
-% 25/1/2012 Add a font not to be swapped. Thanks to Anna Rafferty and Adam
-% Jackson for reporting the issue. Also fix a bug whereby using a font
-% alias can lead to another font being swapped in.
-
-% 10/4/2012 Make the font swapping case insensitive.
+% 14/11/2011: Fix a MATLAB bug rendering black or white text incorrectly.
+%             Thanks to Mathieu Morlighem for reporting the issue and
+%             obtaining a fix from TMW.
+% 08/12/11: Added ability to correct fonts. Several people have requested
+%           this at one time or another, and also pointed me to printeps
+%           (fex id: 7501), so thank you to them. My implementation (which
+%           was not inspired by printeps - I'd already had the idea for my
+%           approach) goes slightly further in that it allows multiple
+%           fonts to be swapped.
+% 14/12/11: Fix bug affecting font names containing spaces. Thanks to David
+%           Szwer for reporting the issue.
+% 25/01/12: Add a font not to be swapped. Thanks to Anna Rafferty and Adam
+%           Jackson for reporting the issue. Also fix a bug whereby using a
+%           font alias can lead to another font being swapped in.
+% 10/04/12: Make the font swapping case insensitive.
+% 26/10/12: Set PaperOrientation to portrait. Thanks to Michael Watts for
+%           reporting the issue.
+% 26/10/12: Fix issue to do with swapping fonts changing other fonts and
+%           sizes we don't want, due to listeners. Thanks to Malcolm Hudson
+%           for reporting the issue.
 
 function print2eps(name, fig, varargin)
@@ -59,5 +61,5 @@
 end
 % Find all the used fonts in the figure
-font_handles = findall(fig, '-property', 'FontName');
+font_handles = findobj(fig, '-property', 'FontName');
 fonts = get(font_handles, 'FontName');
 if ~iscell(fonts)
@@ -86,19 +88,44 @@
 require_swap = find(~ismember(fontslu, matlab_fontsl));
 unused_fonts = find(~ismember(matlab_fontsl, fontslu));
-font_swap = cell(3, 0);
-for a = 1:min(numel(require_swap), numel(unused_fonts))
-    ind = find(strcmp(fontslu{require_swap(a)}, fontsl));
-    n = numel(ind);
-    font_swap(1,end+1:end+n) = reshape(mat2cell(font_handles(ind), ones(n, 1)), 1, []);
-    font_swap(2,end-n+1:end) = matlab_fonts(unused_fonts(a));
-    font_swap(3,end-n+1:end) = reshape(fonts(ind), 1, []);
+font_swap = cell(3, min(numel(require_swap), numel(unused_fonts)));
+fonts_new = fonts;
+for a = 1:size(font_swap, 2)
+    font_swap{1,a} = find(strcmp(fontslu{require_swap(a)}, fontsl));
+    font_swap{2,a} = matlab_fonts{unused_fonts(a)};
+    font_swap{3,a} = fonts{font_swap{1,end}(1)};
+    fonts_new(font_swap{1,a}) = {font_swap{2,a}};
 end
 % Swap the fonts
-for a = 1:size(font_swap, 2)
-    set(font_swap{1,a}, 'FontName', font_swap{2,a});
+if ~isempty(font_swap)
+    fonts_size = get(font_handles, 'FontSize');
+    if iscell(fonts_size)
+        fonts_size = cell2mat(fonts_size);
+    end
+    M = false(size(font_handles));
+    % Loop because some changes may not stick first time, due to listeners
+    c = 0;
+    update = zeros(1000, 1);
+    for b = 1:10 % Limit number of loops to avoid infinite loop case
+        for a = 1:numel(M)
+            M(a) = ~isequal(get(font_handles(a), 'FontName'), fonts_new{a}) || ~isequal(get(font_handles(a), 'FontSize'), fonts_size(a));
+            if M(a)
+                set(font_handles(a), 'FontName', fonts_new{a}, 'FontSize', fonts_size(a));
+                c = c + 1;
+                update(c) = a;
+            end
+        end
+        if ~any(M)
+            break;
+        end
+    end
+    % Compute the order to revert fonts later, without the need of a loop
+    [update, M] = unique(update(1:c));
+    [M, M] = sort(M);
+    update = reshape(update(M), 1, []);
 end
 % Set paper size
-old_mode = get(fig, 'PaperPositionMode');
-set(fig, 'PaperPositionMode', 'auto');
+old_pos_mode = get(fig, 'PaperPositionMode');
+old_orientation = get(fig, 'PaperOrientation');
+set(fig, 'PaperPositionMode', 'auto', 'PaperOrientation', 'portrait');
 % MATLAB bug fix - black and white text can come out inverted sometimes
 % Find the white and black text
@@ -120,10 +147,10 @@
 set(white_text_handles, 'Color', [1 1 1]);
 % Reset paper size
-set(fig, 'PaperPositionMode', old_mode);
+set(fig, 'PaperPositionMode', old_pos_mode, 'PaperOrientation', old_orientation);
 % Correct the fonts
 if ~isempty(font_swap)
     % Reset the font names in the figure
-    for a = 1:size(font_swap, 2)
-        set(font_swap{1,a}, 'FontName', font_swap{3,a});
+    for a = update
+        set(font_handles(a), 'FontName', fonts{a}, 'FontSize', fonts_size(a));
     end
     % Replace the font names in the eps file
