Index: /issm/trunk/externalpackages/export_fig/install.sh
===================================================================
--- /issm/trunk/externalpackages/export_fig/install.sh	(revision 1617)
+++ /issm/trunk/externalpackages/export_fig/install.sh	(revision 1617)
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+#Some cleanup
+rm -rf install
+
+#Create src and install directories
+mkdir install
+cp export_fig.zip install
+
+#uncompress
+cd install
+unzip export_fig.zip
+
+#remove zip
+rm export_fig.zip
Index: /issm/trunk/externalpackages/export_fig/install/eps2pdf.m
===================================================================
--- /issm/trunk/externalpackages/export_fig/install/eps2pdf.m	(revision 1617)
+++ /issm/trunk/externalpackages/export_fig/install/eps2pdf.m	(revision 1617)
@@ -0,0 +1,64 @@
+%EPS2PDF  Convert an eps file to pdf format using ghostscript
+%
+% Examples:
+%   eps2pdf source dest
+%   eps2pdf(source, dest, crop)
+%
+% This function converts an eps file to pdf format. If the output pdf file
+% already exists, the eps file is appended as a new page on the end of the
+% eps file.
+%
+% This function requires that you have ghostscript installed on your
+% system. Ghostscript can be downloaded from: http://www.ghostscript.com
+%
+%IN:
+%   source - filename of the source eps file to convert. The filename is
+%            assumed to already have the extension ".eps".
+%   dest - filename of the destination pdf file. The filename is assumed to
+%          already have the extension ".pdf".
+%   crop - boolean indicating whether to crop the borders off the pdf.
+%          Default: true.
+
+% Copyright (C) Oliver Woodford 2009
+
+% Suggestion of appending pdf files provided by Matt C at:
+% http://www.mathworks.com/matlabcentral/fileexchange/23629
+
+% $Id: eps2pdf.m,v 1.3 2009/07/29 20:15:24 ojw Exp $
+
+function eps2pdf(source, dest, crop)
+% Set crop option
+if nargin < 3 || ~isequal(crop, 0)
+    options =  '-dEPSCrop ';
+else
+    options = '';
+end
+% Construct the options string for ghostscript
+options = [options '-q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile="' dest '"'];
+% Check if the output file exists
+if exist(dest, 'file') == 2
+    % File exists, so append current figure to the end
+    tmp_nam = tempname;
+    % Copy the file
+    copyfile(dest, tmp_nam);
+    % Add the output file names
+    options = [options ' "' tmp_nam '" "' source '"'];
+    try
+        % Convert to pdf using ghostscript
+        ghostscript(options);
+    catch
+        % Delete the intermediate file
+        delete(tmp_nam);
+        rethrow(lasterror);
+    end
+    % Delete the intermediate file
+    delete(tmp_nam);
+else
+    % File doesn't exist
+    % Add the output file names
+    options = [options ' "' source '"'];
+    % Convert to pdf using ghostscript
+    ghostscript(options);
+end
+return
+
Index: /issm/trunk/externalpackages/export_fig/install/export_fig.m
===================================================================
--- /issm/trunk/externalpackages/export_fig/install/export_fig.m	(revision 1617)
+++ /issm/trunk/externalpackages/export_fig/install/export_fig.m	(revision 1617)
@@ -0,0 +1,454 @@
+%EXPORT_FIG  Exports figures suitable for publication
+%
+% Examples:
+%   im = export_fig
+%   [im alpha] = export_fig
+%   export_fig filename
+%   export_fig filename -format1 -format2
+%   export_fig ... -nocrop
+%   export_fig ... -a2
+%   export_fig ... -zbuffer
+%   export_fig(..., handle)
+%
+% This function saves a figure or single axes to one or more vector and/or
+% bitmap file formats, and/or outputs a rasterized version to the
+% workspace, with the following properties:
+%   - Figure/axes reproduced as it appears on screen
+%   - Cropped borders
+%   - Embedded fonts (vector formats)
+%   - Improved line and grid line styles (vector formats)
+%   - Anti-aliased graphics (bitmap formats)
+%   - Transparent background supported (pdf, eps, png)
+%   - Semi-transparent patch objects supported (png only)
+%   - Append to file (pdf only)
+%   - Vector formats: pdf, eps
+%   - Bitmap formats: png, tif, jpg, bmp, export to workspace 
+%   
+% This function is especially suited to exporting figures for use in
+% publications and presentations, because of the high quality and
+% portability of media produced.
+%
+% Note that the background color and figure dimensions are reproduced
+% (the latter approximately, and ignoring cropping) in the output file. For
+% transparent background (and semi-transparent patch objects), set the
+% figure (and axes) 'Color' property to 'none'; pdf, eps and png are the
+% only file formats to support a transparent background, whilst the png
+% format alone supports transparency of patch objects. 
+%
+% When exporting to vector format (pdf & eps), this function requires that
+% ghostscript is installed on your system. You can download this from:
+%   http://www.ghostscript.com
+% When exporting to eps it additionally requires pdftops, from the Xpdf
+% suite of functions. You can download this from:
+%   http://www.foolabs.com/xpdf
+%
+%IN:
+%   filename - string containing the name (optionally including full or
+%              relative path) of the file the figure is to be saved as. If
+%              a path is not specified, the figure is saved in the current
+%              directory. If no name and no output arguments are specified,
+%              the default name, 'export_fig_out', is used. If neither a
+%              file extension nor a format are specified, a ".png" is added
+%              and the figure saved in that format. If the file already
+%              exists, it is overwritten, except for pdf files, for which
+%              the figure is appended as a new page.
+%   -format1, -format2, etc. - strings containing the extensions of the
+%                              file formats the figure is to be saved as.
+%                              Valid options are: '-pdf', '-eps', '-png',
+%                              '-tif', '-jpg' and '-bmp'. All combinations
+%                              of formats are valid.
+%   -nocrop - optional string indicating the borders of the output are not
+%             to be cropped.
+%   -a1, -a2, -a3, -a4 - optional sting indicating the amount of
+%                        anti-aliasing to use for bitmap outputs. -a1 means
+%                        no anti-aliasing, -a4 is the maximum amount
+%                        (default).
+%   -zbuffer - optional string indicating the zbuffer renderer should be
+%              used in place of the opengl renderer (default) for bitmaps.
+%              Note that this renderer doesn't support transparent patches.
+%   handle - The handle of the figure or axes to be saved. Default: gcf.
+%
+%OUT:
+%   im - MxNxC uint8 image array of the figure.
+%   alpha - MxN single array of alphamatte values in range [0,1], for the
+%           case when the background is transparent.
+%
+%   See also PRINT, SAVEAS.
+
+% Copyright (C) Oliver Woodford 2008-2009
+
+% The idea of using ghostscript is inspired by Peder Axensten's SAVEFIG
+% (fex id: 10889) which is itself inspired by EPS2PDF (fex id: 5782).
+% The idea for using pdftops came from the MATLAB newsgroup (id: 168171).
+% The idea of editing the EPS file to change line styles comes from Jiro
+% Doke's FIXPSLINESTYLE (fex id: 17928).
+% The idea of changing dash length with line width came from comments on
+% fex id: 5743, but the implementation is mine :)
+% The idea of anti-aliasing bitmaps came from Anders Brun's MYAA (fex id:
+% 20979).
+% The idea of appending figures in pdfs came from Matt C in comments on the
+% FEX (id: 23629)
+
+% $Id: export_fig.m,v 1.20 2009/07/31 20:22:13 ojw Exp $
+
+function [im alpha] = export_fig(varargin)
+% Parse the input arguments
+[fig options] = parse_args(nargout, varargin{:});
+% Isolate the subplot, if it is one
+cls = strcmp(get(fig, 'Type'), 'axes');
+if cls
+    % Given a handle of a single set of axes
+    fig = isolate_subplot(fig);
+else
+    old_mode = get(fig, 'InvertHardcopy');
+end
+% Hack the font units where necessary (due to a font rendering bug in
+% print?). This may not work perfectly in all cases. Also it can change the
+% figure layout if reverted, so use a copy.
+if isbitmap(options) && options.aa_factor > 1
+    fontu = findobj(fig, 'FontUnits', 'normalized');
+    if ~isempty(fontu)
+        % Some normalized font units found
+        if ~cls
+            fig = copyfig(fig);
+            set(fig, 'Visible', 'off');
+            fontu = findobj(fig, 'FontUnits', 'normalized');
+            cls = true;
+        end
+        set(fontu, 'FontUnits', 'points');
+    end
+end
+% Set to print exactly what is there
+set(fig, 'InvertHardcopy', 'off');
+% Do the bitmap formats first
+if isbitmap(options)
+    % Get the background colour
+    tcol = get(fig, 'Color');
+    if isequal(tcol, 'none') && (options.png || options.alpha)
+        % Get out an alpha channel
+        % Set the background colour to black
+        set(fig, 'Color', 'k');
+        % Print large version to array
+        B = print2array(fig, options.aa_factor, options.zbuffer);
+        % Downscale the image
+        B = downsize(single(B), 0, options.aa_factor);
+        % Set background to white
+        set(fig, 'Color', 'w');
+        % Print large version to array
+        A = print2array(fig, options.aa_factor, options.zbuffer);
+        % Downscale the image
+        A = downsize(single(A), 255, options.aa_factor);
+        % Set the background colour back to normal
+        set(fig, 'Color', 'none');
+        % Compute the alpha map
+        alpha = sum(B - A, 3) / (255*3) + 1;
+        A = alpha;
+        A(A==0) = 1;
+        A = uint8(B ./ A(:,:,[1 1 1]));
+        clear B
+        % Crop the background
+        if options.crop
+            [alpha v] = crop_background(alpha, 0);
+            A = A(v(1):v(2),v(3):v(4),:);
+        end
+        if options.png
+            % Save the png
+            imwrite(A, [options.name '.png'], 'Alpha', alpha);
+            % Clear the png bit
+            options.png = false;
+        end
+        % Return only one channel for greyscale
+        if isbitmap(options)
+            A = check_greyscale(A);
+        end
+        if options.alpha
+            % Store the image
+            im = A;
+            % Clear the alpha bit
+            options.alpha = false;
+        end
+        % Get the non-alpha image
+        if isbitmap(options)
+            alph = alpha(:,:,ones(1, size(A, 3)));
+            A = uint8(single(A) .* alph + 255 * (1 - alph));
+            clear alph
+        end
+        if options.im
+            % Store the new image
+            im = A;
+        end
+    else
+        % Print large version to array
+        if isequal(tcol, 'none')
+            set(fig, 'Color', 'w');
+            A = print2array(fig, options.aa_factor, options.zbuffer);
+            set(fig, 'Color', 'none');
+            tcol = 255;
+        else
+            A = print2array(fig, options.aa_factor, options.zbuffer);
+            tcol = tcol * 255;
+            if ~isequal(tcol, round(tcol))
+                tcol = squeeze(A(1,1,:));
+            end
+        end
+        % Crop the background
+        if options.crop
+            A = crop_background(A, tcol);
+        end
+        % Downscale the image
+        A = downsize(A, tcol, options.aa_factor);
+        % Return only one channel for greyscale
+        A = check_greyscale(A);
+        % Outputs
+        if options.im
+            im = A;
+        end
+        if options.alpha
+            im = A;
+            alpha = zeros(size(A, 1), size(A, 2), 'single');
+        end
+    end
+    % Save the images
+    for a = {'png', 'tif', 'bmp'}
+        if options.(a{1})
+            imwrite(A, [options.name '.' a{1}]);
+        end
+    end
+    % Save jpeg with higher quality than default
+    if options.jpg
+        imwrite(A, [options.name '.jpg'], 'Quality', 95);
+    end
+end
+% Now do the vector formats
+if isvector(options)
+    % Generate some filenames
+    tmp_nam = [tempname '.eps'];
+    if options.pdf
+        pdf_nam = [options.name '.pdf'];
+    else
+        pdf_nam = [tempname '.pdf'];
+    end
+    try
+        % Generate an eps
+        print2eps(tmp_nam, fig);
+        % Generate a pdf
+        eps2pdf(tmp_nam, pdf_nam, options.crop);
+    catch
+        % Delete the eps
+        delete(tmp_nam);
+        rethrow(lasterror);
+    end
+    % Delete the eps
+    delete(tmp_nam);
+    if options.eps
+        try
+            % Generate an eps from the pdf
+            pdf2eps(pdf_nam, [options.name '.eps']);
+        catch
+            if ~options.pdf
+                % Delete the pdf
+                delete(pdf_nam);
+            end
+            rethrow(lasterror);
+        end
+        if ~options.pdf
+            % Delete the pdf
+            delete(pdf_nam);
+        end
+    end
+end
+if cls
+    % Close the created figure
+    close(fig);
+else
+    % Reset the hardcopy mode
+    set(fig, 'InvertHardcopy', old_mode);
+end
+return
+
+function [fig options] = parse_args(nout, varargin)
+% Parse the input arguments
+% Set the defaults
+fig = get(0, 'CurrentFigure');
+options = struct('name', 'export_fig_out', ...
+                 'crop', true, ...
+                 'zbuffer', false, ...
+                 'pdf', false, ...
+                 'eps', false, ...
+                 'png', false, ...
+                 'tif', false, ...
+                 'jpg', false, ...
+                 'bmp', false, ...
+                 'im', nout == 1, ...
+                 'alpha', nout == 2, ...
+                 'aa_factor', 4);
+
+% Go through the other arguments
+for a = 1:nargin-1
+    if ishandle(varargin{a})
+        fig = varargin{a};
+    elseif ischar(varargin{a}) && ~isempty(varargin{a})
+        if varargin{a}(1) == '-'
+            switch lower(varargin{a}(2:end))
+                case 'nocrop'
+                    options.crop = false;
+                case 'zbuffer'
+                    options.zbuffer = true;
+                case 'pdf'
+                    options.pdf = true;
+                case 'eps'
+                    options.eps = true;
+                case 'png'
+                    options.png = true;
+                case {'tif', 'tiff'}
+                    options.jpg = true;
+                case {'jpg', 'jpeg'}
+                    options.jpg = true;
+                case 'bmp'
+                    options.bmp = true;
+                case {'a1', 'a2', 'a3', 'a4'}
+                    options.aa_factor = str2double(varargin{a}(3));
+            end
+        else
+            name = varargin{a};
+            if numel(name) > 3 && name(end-3) == '.' && any(strcmpi(name(end-2:end), {'pdf', 'eps', 'png', 'tif', 'jpg', 'bmp'}))
+                options.(lower(name(end-2:end))) = true;
+                name = name(1:end-4);
+            end
+            options.name = name;
+        end
+    end
+end
+
+% Set the default format
+if ~isvector(options) && ~isbitmap(options)
+    options.png = true;
+end
+return
+
+function fh = isolate_subplot(ah, vis)
+% Isolate the axes in a figure on their own
+% Tag the axes so we can find them in the copy
+old_tag = get(ah, 'Tag');
+set(ah, 'Tag', 'AxesToCopy');
+% Create a new figure exactly the same as the old one
+fh = copyfig(ancestor(ah, 'figure')); %copyobj(ancestor(ah, 'figure'), 0);
+if nargin < 2 || ~vis
+    set(fh, 'Visible', 'off');
+end
+% Reset the axes tag
+set(ah, 'Tag', old_tag);
+% Get all the axes
+axs = findobj(fh, 'Type', 'axes');
+% Find the axes to save
+ah = findobj(axs, 'Tag', 'AxesToCopy');
+if numel(ah) ~= 1
+    close(fh);
+    error('Too many axes found');
+end
+I = true(size(axs));
+I(axs==ah) = false;
+% Set the axes tag to what it should be
+set(ah, 'Tag', old_tag);
+% Keep any legends which overlap the subplot
+ax_pos = get(ah, 'OuterPosition');
+ax_pos(3:4) = ax_pos(3:4) + ax_pos(1:2);
+for ah = findobj(axs, 'Tag', 'legend', '-or', 'Tag', 'Colorbar')'
+    leg_pos = get(ah, 'OuterPosition');
+    leg_pos(3:4) = leg_pos(3:4) + leg_pos(1:2);
+    % Overlap test
+    if leg_pos(1) < ax_pos(3) && leg_pos(2) < ax_pos(4) &&...
+       leg_pos(3) > ax_pos(1) && leg_pos(4) > ax_pos(2)
+        I(axs==ah) = false;
+    end
+end
+% Delete all axes except for the input axes and associated items
+delete(axs(I));
+return
+
+function fh = copyfig(fh)
+% Is there a legend?
+if isempty(findobj(fh, 'Type', 'axes', 'Tag', 'legend'))
+    % Safe to copy using copyobj
+    fh = copyobj(fh, 0);
+else
+    % copyobj will change the figure, so save and then load it instead
+    tmp_nam = [tempname '.fig'];
+    hgsave(fh, tmp_nam);
+    fh = hgload(tmp_nam);
+    delete(tmp_nam);
+end
+return
+
+function A = downsize(A, padval, factor)
+% Downsample an image
+if factor == 1
+    % Nothing to do
+    return
+end
+try
+    % Faster, but requires image processing toolbox
+    A = imresize(A, 1/factor, 'bilinear');
+catch
+    % No image processing toolbox - resize manually
+    % Lowpass filter - use Gaussian as is separable, so faster
+    switch factor
+        case 4
+            % sigma: 1.7
+            filt = single([0.0148395 0.0498173 0.118323 0.198829 0.236384 0.198829 0.118323 0.0498173 0.0148395]);
+        case 3
+            % sigma: 1.35
+            filt = single([0.025219 0.099418 0.226417 0.297892 0.226417 0.099418 0.025219]);
+        case 2
+            % sigma: 1.0
+            filt = single([0.054489 0.244201 0.40262 0.244201 0.054489]);
+    end
+    padding = floor(numel(filt) / 2);
+    if numel(padval) == 3 && padval(1) == padval(2) && padval(2) == padval(3)
+        padval = padval(1);
+    end
+    if numel(padval) == 1
+        B = repmat(single(padval), [size(A, 1) size(A, 2)] + (2 * padding));
+    end
+    for a = 1:size(A, 3)
+        if numel(padval) == 3
+            B = repmat(single(padval(a)), [size(A, 1) size(A, 2)] + (2 * padding));
+        end
+        B(padding+1:end-padding,padding+1:end-padding) = A(:,:,a);
+        A(:,:,a) = conv2(filt, filt', B, 'valid');
+    end
+    clear B
+    % Subsample
+    A = A(2:factor:end,2:factor:end,:);
+end
+return
+
+function A = check_greyscale(A)
+% Check if the image is greyscale
+if size(A, 3) == 3 && ...
+        all(reshape(A(:,:,1) == A(:,:,2), [], 1)) && ...
+        all(reshape(A(:,:,2) == A(:,:,3), [], 1))
+    A = A(:,:,1); % Save only one channel for 8-bit output
+end
+return
+
+function [A v] = crop_background(A, bcol)
+% Map the foreground pixels
+M = A(:,:,1) ~= bcol(1);
+for a = 2:size(A, 3)
+    M = M | A(:,:,a) ~= bcol(min(a, end));
+end
+% Crop the background
+N = any(M, 1);
+M = any(M, 2);
+v = [find(M, 1) find(M, 1, 'last') find(N, 1) find(N, 1, 'last')];
+A = A(v(1):v(2),v(3):v(4),:);
+return
+
+function b = isvector(options)
+b = options.pdf || options.eps;
+return
+
+function b = isbitmap(options)
+b = options.png || options.tif || options.jpg || options.bmp || options.im || options.alpha;
+return
Index: /issm/trunk/externalpackages/export_fig/install/fix_lines.m
===================================================================
--- /issm/trunk/externalpackages/export_fig/install/fix_lines.m	(revision 1617)
+++ /issm/trunk/externalpackages/export_fig/install/fix_lines.m	(revision 1617)
@@ -0,0 +1,124 @@
+function fix_lines(fname, fname2)
+%FIX_LINES  Improves the line style of eps files generated by print
+%
+% Examples:
+%   fix_lines fname
+%   fix_lines fname fname2
+%
+% This function improves the style of lines in eps files generated by
+% MATLAB's print function, making them more similar to those seen on
+% screen. Grid lines are also changed from a dashed style to a dotted
+% style, for greater differentiation from dashed lines.
+%
+% IN:
+%   fname - Name or path of source eps file.
+%   fname2 - Name or path of destination eps file. Default: same as fname.
+
+% $Id: fix_lines.m,v 1.7 2009/04/25 09:14:59 ojw Exp $
+% Copyright: Oliver Woodford, 2008-2009
+
+% The idea of editing the EPS file to change line styles comes from Jiro
+% Doke's FIXPSLINESTYLE (fex id: 17928)
+% The idea of changing dash length with line width came from comments on
+% fex id: 5743, but the implementation is mine :)
+
+% Read in the file
+fh = fopen(fname, 'rt');
+try
+    fstrm = fread(fh, '*char')';
+catch
+    fclose(fh);
+    rethrow(lasterror);
+end
+fclose(fh);
+
+% Make sure all line width commands come before the line style definitions,
+% so that dash lengths can be based on the correct widths
+% Find all line style sections
+ind = [regexp(fstrm, '[\n\r]SO[\n\r]'),... % This needs to be here even though it doesn't have dots/dashes!
+       regexp(fstrm, '[\n\r]DO[\n\r]'),...
+       regexp(fstrm, '[\n\r]DA[\n\r]'),...
+       regexp(fstrm, '[\n\r]DD[\n\r]')];
+ind = sort(ind);
+% Find line width commands
+[ind2 ind3] = regexp(fstrm, '[\n\r]\d* w[\n\r]');
+% Go through each line style section and swap with any line width commands
+% near by
+b = 1;
+m = numel(ind);
+n = numel(ind2);
+for a = 1:m
+    % Go forwards width commands until we pass the current line style
+    while b <= n && ind2(b) < ind(a)
+        b = b + 1;
+    end
+    if b > n
+        % No more width commands
+        break;
+    end
+    % Check we haven't gone past another line style (including SO!)
+    if a < m && ind2(b) > ind(a+1)
+        continue;
+    end
+    % Are the commands close enough to be confident we can swap them?
+    if (ind2(b) - ind(a)) > 8
+        continue;
+    end
+    % Move the line style command below the line width command
+    fstrm(ind(a)+1:ind3(b)) = [fstrm(ind(a)+4:ind3(b)) fstrm(ind(a)+1:ind(a)+3)];
+    b = b + 1;
+end
+
+% Find any grid line definitions and change to GR format
+% Find the DO sections again as they may have moved
+ind = int32(regexp(fstrm, '[\n\r]DO[\n\r]'));
+if ~isempty(ind)
+    % Find all occurrences of what are believed to be axes and grid lines
+    ind2 = int32(regexp(fstrm, '[\n\r] *\d* *\d* *mt *\d* *\d* *L[\n\r]'));
+    if ~isempty(ind2)
+        % Now see which DO sections come just before axes and grid lines
+        ind2 = repmat(ind2', [1 numel(ind)]) - repmat(ind, [numel(ind2) 1]);
+        ind2 = any(ind2 > 0 & ind2 < 12); % 12 chars seems about right
+        ind = ind(ind2);
+        % Change any regions we believe to be grid lines to GR
+        fstrm(ind+1) = 'G';
+        fstrm(ind+2) = 'R';
+    end
+end
+
+% Isolate line style definition section
+first_sec = findstr(fstrm, '% line types:');
+[second_sec remaining] = strtok(fstrm(first_sec+1:end), '/');
+[dummy remaining] = strtok(remaining, '%');
+
+% Define the new styles, including the new GR format
+% Dot and dash lengths have two parts: a constant amount plus a line width
+% variable amount. The constant amount comes after dpi2point, and the
+% variable amount comes after currentlinewidth. If you want to change
+% dot/dash lengths for a one particular line style only, edit the numbers
+% in the /DO (dotted lines), /DA (dashed lines), /DD (dot dash lines) and
+% /GR (grid lines) lines for the style you want to change.
+new_style = {'/dom { dpi2point 1 currentlinewidth 0.08 mul add mul mul } bdef',... % Dot length macro based on line width
+             '/dam { dpi2point 2 currentlinewidth 0.04 mul add mul mul } bdef',... % Dash length macro based on line width
+             '/SO { [] 0 setdash 0 setlinecap } bdef',... % Solid lines
+             '/DO { [1 dom 1.2 dom] 0 setdash 0 setlinecap } bdef',... % Dotted lines
+             '/DA { [4 dam 1.5 dam] 0 setdash 0 setlinecap } bdef',... % Dashed lines
+             '/DD { [1 dom 1.2 dom 4 dam 1.2 dom] 0 setdash 0 setlinecap } bdef',... % Dot dash lines
+             '/GR { [0 dpi2point mul 4 dpi2point mul] 0 setdash 1 setlinecap } bdef'}; % Grid lines - dot spacing remains constant
+new_style = sprintf('%s\r', new_style{:});
+
+if nargin < 2
+    % Overwrite the input file
+    fname2 = fname;
+end
+
+% Save the file with the section replaced
+fh = fopen(fname2, 'wt');
+try
+    fprintf(fh, '%s%s%s%s', fstrm(1:first_sec), second_sec, new_style, remaining);
+catch
+    fclose(fh);
+    rethrow(lasterror);
+end
+fclose(fh);
+return
Index: /issm/trunk/externalpackages/export_fig/install/license.txt
===================================================================
--- /issm/trunk/externalpackages/export_fig/install/license.txt	(revision 1617)
+++ /issm/trunk/externalpackages/export_fig/install/license.txt	(revision 1617)
@@ -0,0 +1,24 @@
+Copyright (c) 2009, Oliver Woodford
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without 
+modification, are permitted provided that the following conditions are 
+met:
+
+    * Redistributions of source code must retain the above copyright 
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright 
+      notice, this list of conditions and the following disclaimer in 
+      the documentation and/or other materials provided with the distribution
+      
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+POSSIBILITY OF SUCH DAMAGE.
Index: /issm/trunk/externalpackages/export_fig/install/pdf2eps.m
===================================================================
--- /issm/trunk/externalpackages/export_fig/install/pdf2eps.m	(revision 1617)
+++ /issm/trunk/externalpackages/export_fig/install/pdf2eps.m	(revision 1617)
@@ -0,0 +1,41 @@
+%PDF2EPS  Convert a pdf file to eps format using pdftops
+%
+% Examples:
+%   pdf2eps source dest
+%
+% This function converts a pdf file to eps format.
+%
+% This function requires that you have pdftops, from the Xpdf suite of
+% functions, installed on your system. This can be downloaded from:
+% http://www.foolabs.com/xpdf  
+%
+%IN:
+%   source - filename of the source pdf file to convert. The filename is
+%            assumed to already have the extension ".pdf".
+%   dest - filename of the destination eps file. The filename is assumed to
+%          already have the extension ".eps".
+
+% Copyright (C) Oliver Woodford 2009
+
+% $Id: pdf2eps.m,v 1.2 2009/04/19 21:48:42 ojw Exp $
+
+function pdf2eps(source, dest)
+% Construct the options string for pdftops
+options = ['-q -paper match -pagecrop -eps -level2 "' source '" "' dest '"'];
+% Convert to eps using pdftops
+pdftops(options);
+% Fix the DSC error created by pdftops
+fid = fopen(dest, 'r+');
+if fid == -1
+    % Cannot open the file
+    return
+end
+fgetl(fid); % Get the first line
+str = fgetl(fid); % Get the second line
+if strcmp(str(1:min(13, end)), '% Produced by')
+    fseek(fid, -numel(str)-1, 'cof');
+    fwrite(fid, '%'); % Turn ' ' into '%'
+end
+fclose(fid);
+return
+
Index: /issm/trunk/externalpackages/export_fig/install/print2array.m
===================================================================
--- /issm/trunk/externalpackages/export_fig/install/print2array.m	(revision 1617)
+++ /issm/trunk/externalpackages/export_fig/install/print2array.m	(revision 1617)
@@ -0,0 +1,51 @@
+%PRINT2ARRAY  Exports a figure to an image array
+%
+% Examples:
+%   A = print2array
+%   A = print2array(figure_handle)
+%   A = print2array(figure_handle, resolution)
+%   A = print2array(figure_handle, resolution, renderer)
+%
+% This function outputs a bitmap image of the given figure, at the desired
+% resolution.
+%
+% IN:
+%   figure_handle - The handle of the figure to be exported. Default: gcf.
+%   resolution - Resolution of the output, as a factor of screen
+%                resolution. Default: 1.
+%   renderer - Boolean indicating whether to use the zbuffer renderer (1)
+%              or the opengl renderer (0). Default: 0.
+%
+% OUT:
+%   A - MxNx3 uint8 image of the figure.
+
+% $Id: print2array.m,v 1.3 2009/07/31 20:21:13 ojw Exp $
+% Copyright (C) Oliver Woodford 2008-2009
+
+function A = print2array(fig, res, renderer)
+% Generate default input arguments, if needed
+if nargin < 2
+    res = 1;
+    if nargin < 1
+        fig = gcf;
+    end
+end
+if nargin > 2 && renderer
+    renderer = '-zbuffer';
+else
+    renderer = '-opengl';
+end
+% Generate temporary file name
+tmp_nam = [tempname '.tif'];
+% Set paper size
+old_mode = get(fig, 'PaperPositionMode');
+set(fig, 'PaperPositionMode', 'auto');
+% Print to tiff file
+print(fig, renderer, ['-r' num2str(get(0, 'ScreenPixelsPerInch')*res)], '-dtiff', tmp_nam);
+% Reset paper size
+set(fig, 'PaperPositionMode', old_mode);
+% Read in the printed file
+A = imread(tmp_nam);
+% Delete the file
+delete(tmp_nam);
+return
Index: /issm/trunk/externalpackages/export_fig/install/print2eps.m
===================================================================
--- /issm/trunk/externalpackages/export_fig/install/print2eps.m	(revision 1617)
+++ /issm/trunk/externalpackages/export_fig/install/print2eps.m	(revision 1617)
@@ -0,0 +1,44 @@
+%PRINT2EPS  Prints figures to eps with improved line styles
+%
+% Examples:
+%   print2eps filename
+%   print2eps(filename, fig_handle)
+%
+% This function saves a figure as an eps file, and improves the line style,
+% making dashed lines more like those on screen and giving grid lines their
+% own dotted style.
+%
+%IN:
+%   filename - string containing the name (optionally including full or
+%              relative path) of the file the figure is to be saved as. A
+%              ".eps" extension is added if not there already. If a path is
+%              not specified, the figure is saved in the current directory.
+%   fig_handle - The handle of the figure to be saved. Default: gcf.
+
+% Copyright (C) Oliver Woodford 2008-2009
+
+% The idea of editing the EPS file to change line styles comes from Jiro
+% Doke's FIXPSLINESTYLE (fex id: 17928)
+% The idea of changing dash length with line width came from comments on
+% fex id: 5743, but the implementation is mine :)
+
+% $Id: print2eps.m,v 1.2 2009/04/11 15:27:26 ojw Exp $
+
+function print2eps(name, fig)
+if nargin < 2
+    fig = gcf;
+end
+% Construct the filename
+if numel(name) < 5 || ~strcmpi(name(end-3:end), '.eps')
+    name = [name '.eps']; % Add the missing extension
+end
+% Set paper size
+old_mode = get(fig, 'PaperPositionMode');
+set(fig, 'PaperPositionMode', 'auto');
+% Print to eps file
+print(fig, '-depsc2', '-painters', '-r864', name);
+% Reset paper size
+set(fig, 'PaperPositionMode', old_mode);
+% Fix the line styles
+fix_lines(name);
+return
Index: /issm/trunk/externalpackages/export_fig/install/private/ghostscript.m
===================================================================
--- /issm/trunk/externalpackages/export_fig/install/private/ghostscript.m	(revision 1617)
+++ /issm/trunk/externalpackages/export_fig/install/private/ghostscript.m	(revision 1617)
@@ -0,0 +1,125 @@
+function varargout = ghostscript(cmd)
+%GHOSTSCRIPT  Calls a local GhostScript executable with the input command
+%
+% Example:
+%   [status result] = ghostscript(cmd)
+%
+% Attempts to locate a ghostscript executable, finally asking the user to
+% specify the directory ghostcript was installed into. The resulting path
+% is stored for future reference.
+% 
+% Once found, the executable is called with the input command string.
+%
+% This function requires that you have Ghostscript installed on your
+% system. You can download this from: http://www.ghostscript.com
+%
+% IN:
+%   cmd - Command string to be passed into ghostscript.
+%
+% OUT:
+%   status - 0 iff command ran without problem.
+%   result - Output from ghostscript.
+
+% $Id: ghostscript.m,v 1.7 2009/04/21 17:30:47 ojw Exp $
+% Copyright: Oliver Woodford, 2009
+
+% Call ghostscript
+[varargout{1:nargout}] = system(sprintf('"%s" %s', gs_path, cmd));
+return
+
+function path = gs_path
+% Return a valid path
+% Start with the currently set path
+path = current_gs_path;
+% Check the path works
+if check_gs_path(path)
+    return
+end
+% Check whether the binary is on the path
+if ispc
+    bin = 'gswin32c.exe';
+else
+    bin = 'gs';
+end
+if check_store_gs_path(bin)
+    path = bin;
+    return
+end
+% Search the obvious places
+if ispc
+    default_location = 'C:\Program Files\gs\';
+    executable = '\bin\gswin32c.exe';
+    dir_list = dir(default_location);
+    ver_num = 0;
+    % If there are multiple versions, use the newest
+    for a = 1:numel(dir_list)
+        ver_num2 = sscanf(dir_list(a).name, 'gs%g');
+        if ~isempty(ver_num2) && ver_num2 > ver_num
+            path2 = [default_location dir_list(a).name executable];
+            if exist(path2, 'file') == 2
+                path = path2;
+                ver_num = ver_num2;
+            end
+        end
+    end
+else
+    path = '/usr/local/bin/gs';
+end
+if check_store_gs_path(path)
+    return
+end
+% Ask the user to enter the path
+while 1
+    base = uigetdir('/', 'Ghostcript not found. Please select ghostscript installation directory.');
+    if isequal(base, 0)
+        % User hit cancel or closed window
+        break;
+    end
+    base = [base filesep];
+    bin_dir = {'', ['bin' filesep], ['lib' filesep]};
+    for a = 1:numel(bin_dir)
+        path = [base bin_dir{a} bin];
+        if exist(path, 'file') == 2
+            break;
+        end
+    end
+    if check_store_gs_path(path)
+        return
+    end
+end
+error('Ghostscript not found.');
+
+function good = check_store_gs_path(path)
+% Check the path is valid
+good = check_gs_path(path);
+if ~good
+    return
+end
+% Update the current default path to the path found
+fname = which(mfilename);
+% Read in the file
+fh = fopen(fname, 'rt');
+fstrm = fread(fh, '*char')';
+fclose(fh);
+% Find the path
+first_sec = regexp(fstrm, '[\n\r]*function path = current_gs_path[\n\r]*path = ''', 'end', 'once');
+second_sec = first_sec + regexp(fstrm(first_sec+1:end), ''';[\n\r]*return', 'once');
+if isempty(first_sec) || isempty(second_sec)
+    warning('Path to ghostscript installation could not be saved. Enter it manually in ghostscript.m.');
+    return
+end
+% Save the file with the path replaced
+fh = fopen(fname, 'wt');
+fprintf(fh, '%s%s%s', fstrm(1:first_sec), path, fstrm(second_sec:end));
+fclose(fh);
+return
+
+function good = check_gs_path(path)
+% Check the path is valid
+[good message] = system(sprintf('"%s" -h', path));
+good = good == 0;
+return
+
+function path = current_gs_path
+path = 'gswin32c.exe';
+return
Index: /issm/trunk/externalpackages/export_fig/install/private/pdftops.m
===================================================================
--- /issm/trunk/externalpackages/export_fig/install/private/pdftops.m	(revision 1617)
+++ /issm/trunk/externalpackages/export_fig/install/private/pdftops.m	(revision 1617)
@@ -0,0 +1,114 @@
+function varargout = pdftops(cmd)
+%PDFTOPS  Calls a local pdftops executable with the input command
+%
+% Example:
+%   [status result] = pdftops(cmd)
+%
+% Attempts to locate a pdftops executable, finally asking the user to
+% specify the directory pdftops was installed into. The resulting path is
+% stored for future reference.
+% 
+% Once found, the executable is called with the input command string.
+%
+% This function requires that you have pdftops (from the Xpdf package)
+% installed on your system. You can download this from:
+% http://www.foolabs.com/xpdf
+%
+% IN:
+%   cmd - Command string to be passed into pdftops.
+%
+% OUT:
+%   status - 0 iff command ran without problem.
+%   result - Output from pdftops.
+
+% $Id: pdftops.m,v 1.8 2009/04/21 17:51:40 ojw Exp $
+% Copyright: Oliver Woodford, 2009
+
+% Call pdftops
+[varargout{1:nargout}] = system(sprintf('"%s" %s', xpdf_path, cmd));
+return
+
+function path = xpdf_path
+% Return a valid path
+% Start with the currently set path
+path = current_xpdf_path;
+% Check the path works
+if check_xpdf_path(path)
+    return
+end
+% Check whether the binary is on the path
+if ispc
+    bin = 'pdftops.exe';
+else
+    bin = 'pdftops';
+end
+if check_store_xpdf_path(bin)
+    path = bin;
+    return
+end
+% Search the obvious places
+if ispc
+    path = 'C:\Program Files\xpdf\pdftops.exe';
+else
+    path = '/usr/local/bin/pdftops';
+end
+if check_store_xpdf_path(path)
+    return
+end
+% Ask the user to enter the path
+while 1
+    base = uigetdir('/', 'Pdftops not found. Please select pdftops installation directory.');
+    if isequal(base, 0)
+        % User hit cancel or closed window
+        break;
+    end
+    base = [base filesep];
+    bin_dir = {'', ['bin' filesep], ['lib' filesep]};
+    for a = 1:numel(bin_dir)
+        path = [base bin_dir{a} bin];
+        if exist(path, 'file') == 2
+            break;
+        end
+    end
+    if check_store_xpdf_path(path)
+        return
+    end
+end
+error('pdftops executable not found.');
+
+function good = check_store_xpdf_path(path)
+% Check the path is valid
+good = check_xpdf_path(path);
+if ~good
+    return
+end
+% Update the current default path to the path found
+fname = which(mfilename);
+% Read in the file
+fh = fopen(fname, 'rt');
+fstrm = fread(fh, '*char')';
+fclose(fh);
+% Find the path
+first_sec = regexp(fstrm, '[\n\r]*function path = current_xpdf_path[\n\r]*path = ''', 'end', 'once');
+second_sec = first_sec + regexp(fstrm(first_sec+1:end), ''';[\n\r]*return', 'once');
+if isempty(first_sec) || isempty(second_sec)
+    warning('Path to pdftops executable could not be saved. Enter it manually in pdftops.m.');
+    return
+end
+% Save the file with the path replaced
+fh = fopen(fname, 'wt');
+fprintf(fh, '%s%s%s', fstrm(1:first_sec), path, fstrm(second_sec:end));
+fclose(fh);
+return
+
+function good = check_xpdf_path(path)
+% Check the path is valid
+[good message] = system(sprintf('"%s" -h', path));
+% system returns good = 1 even when the command runs (on Windows, anyway)
+% Look for something distinct in the help text
+good = ~isempty(strfind(message, 'PostScript'));
+return
+
+function path = current_xpdf_path
+path = 'pdftops.exe';
+return
