Home > chronux_1_15 > spikesort > utility > matlabtools > report_addpage.m

report_addpage

PURPOSE ^

REPORT_ADDPAGE Builds up a PS report by appending Matlab figures.

SYNOPSIS ^

function report_addpage(filename, fighandle, hangfraction, overlaytext)

DESCRIPTION ^

REPORT_ADDPAGE    Builds up a PS report by appending Matlab figures.
   REPORT_ADDPAGE(FILENAME, FIGUREHANDLE) prints FIGUREHANDLE and appends
   it to the Postscript file FILENAME (or creates FILENAME if it does not
   already exist) -- note that the file extension .PS is automatically
   appended to FILENAME if it is not already there.  If no FIGUREHANDLE
   is provided (or if FIGUREHANDLE is empty), a blank page is appended to
   FILENAME.  In either case, the page is printed with a white background
   on US Letter size paper (8.5-by-11 inches) with 1/4 inch margins.
 
   REPORT_ADDPAGE(FILENAME, FIGUREHANDLE, HANGFRACTION) scales the figure
   such that it occupies HANGFRACTION (range (0.0,1.0]) of a page,
   spaced such that the whitespace is at the bottom of the page.  This
   gives the appearance of the end of a section in the report.  If
   HANGFRACTION is not provided (or is empty), it defaults to 1.0.

   REPORT_ADDPAGE(FILENAME, FIGUREHANDLE, HANGFRACTION, OVERLAYTEXT)
   also specifies a string caption to be centered and overlaid over the
   printed page; cell arrays of strings result in multi-line text.  The
   caption is printed in black, 48-point font centered on the page.  When
   FIGUREHANDLE is empty, the caption is printed on a blank page.  

   The report uses PostScript rather than the friendlier PDF because of
   the inflexibility of the Matlab PDF driver (it won't allow pages to be
   appended).  Use PS2PDF to convert to PDF when the report is complete.

   See also PS2PDF

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function report_addpage(filename, fighandle, hangfraction, overlaytext)
0002 %REPORT_ADDPAGE    Builds up a PS report by appending Matlab figures.
0003 %   REPORT_ADDPAGE(FILENAME, FIGUREHANDLE) prints FIGUREHANDLE and appends
0004 %   it to the Postscript file FILENAME (or creates FILENAME if it does not
0005 %   already exist) -- note that the file extension .PS is automatically
0006 %   appended to FILENAME if it is not already there.  If no FIGUREHANDLE
0007 %   is provided (or if FIGUREHANDLE is empty), a blank page is appended to
0008 %   FILENAME.  In either case, the page is printed with a white background
0009 %   on US Letter size paper (8.5-by-11 inches) with 1/4 inch margins.
0010 %
0011 %   REPORT_ADDPAGE(FILENAME, FIGUREHANDLE, HANGFRACTION) scales the figure
0012 %   such that it occupies HANGFRACTION (range (0.0,1.0]) of a page,
0013 %   spaced such that the whitespace is at the bottom of the page.  This
0014 %   gives the appearance of the end of a section in the report.  If
0015 %   HANGFRACTION is not provided (or is empty), it defaults to 1.0.
0016 %
0017 %   REPORT_ADDPAGE(FILENAME, FIGUREHANDLE, HANGFRACTION, OVERLAYTEXT)
0018 %   also specifies a string caption to be centered and overlaid over the
0019 %   printed page; cell arrays of strings result in multi-line text.  The
0020 %   caption is printed in black, 48-point font centered on the page.  When
0021 %   FIGUREHANDLE is empty, the caption is printed on a blank page.
0022 %
0023 %   The report uses PostScript rather than the friendlier PDF because of
0024 %   the inflexibility of the Matlab PDF driver (it won't allow pages to be
0025 %   appended).  Use PS2PDF to convert to PDF when the report is complete.
0026 %
0027 %   See also PS2PDF
0028 
0029 try,   % need a try/catch because we need to cleanup up temp graphics if there's an error
0030 
0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%% Parse Inputs %%%%%%%%%%%%%%%%%%%%%%%%%%%%
0032 if (nargin  < 2), fighandle = [];  end;
0033 tempfig = 0;  tempaxs = 0;   axshandle = [];
0034 props = {};  oldvals = {};
0035 
0036 if (isempty(fighandle)), 
0037     fighandle = figure;   tempfig = 1;
0038 elseif (~ishandle(fighandle) || ~strcmp(get(fighandle,'type'),'figure'))
0039     error('Invalid figure handle.');  
0040 end
0041 figure(fighandle);    % make the target the current figure
0042 
0043 if (~exist('hangfraction') || isempty(hangfraction))
0044     hangfraction = 1.0;
0045 elseif (hangfraction <= 0.0 || hangfraction > 1.0)
0046     error('The HANGFRACTION must be > 0.0 and <= 1.0.');
0047 end
0048 
0049 if (exist('overlaytext')),    % add overlay text if needed
0050     tempaxs = 1;
0051     axshandle = axes('Position', [0 0 1.0 1.0], 'Visible', 'Off');  % 'canvas' covering entire figure
0052     txthandle = text(0.5, 0.5, overlaytext, 'FontSize', 48, 'HorizontalAlign', 'center', 'VerticalAlign', 'middle');
0053 end
0054 
0055 %%%%%%%%%%%%%%%%%%%%%%%%%%% Prep the Figure %%%%%%%%%%%%%%%%%%%%%%%%%%
0056 props = {'PaperUnits', 'PaperSize', 'PaperType', 'InvertHardCopy', 'Color'};
0057 newvals = {'inches', [8.5 11], 'usletter', 'off', 'w'};
0058 oldvals = get(fighandle, props);
0059 
0060 propvals = cat(1, props, newvals);
0061 set(fighandle, propvals{:});
0062 
0063 set(gcf, 'PaperPosition', [0.25 10.5*(1-hangfraction) 8 10.5*hangfraction]);
0064 
0065 
0066 %%%%%%%%%%%%%%%%%%%%%%%%%% Print the Figure %%%%%%%%%%%%%%%%%%%%%%%%%%
0067 print('-dpsc2', '-append', '-painters', filename);  % painters renderer is good for EPS
0068 
0069 
0070 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Clean Up %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0071 cleanup(tempfig, fighandle, tempaxs, axshandle, props, oldvals);
0072 
0073 catch,
0074     try,  cleanup(tempfig, fighandle, tempaxs, axshandle, props, oldvals);
0075     catch, 
0076     end    
0077     rethrow(lasterror);
0078 end
0079 
0080 
0081 % Cleans up any temporary objects so people get their graphics in good shape.
0082 function cleanup(tempfig, fighandle, tempaxs, axshandle, props, oldvals)
0083 
0084 if (tempaxs && ishandle(axshandle)), delete(axshandle);  end;  % deletes caption too, if it exists
0085 if (tempfig && ishandle(fighandle))
0086     close(fighandle);
0087 else
0088     propvals = cat(1, props, oldvals);
0089     set(fighandle, propvals{:});
0090 end

Generated on Tue 15-Aug-2006 22:51:57 by m2html © 2003