Daniel@0: function aout = rep_utils(action,fmt,fid) Daniel@0: Daniel@0: %REP_UTILS Utilities for print reports and report elements. Daniel@0: % Daniel@0: % aout = rep_utils(action,fmt,[fid]) Daniel@0: % Daniel@0: % Input and output arguments ([]'s are optional): Daniel@0: % action (string) action identifier Daniel@0: % (cell array) {action,par1,par2,...} Daniel@0: % the action identifier, followed by action Daniel@0: % parameters Daniel@0: % [fmt] (string) format of output, 'txt' by default Daniel@0: % [fid] (scalar) output file id, by default NaN in which Daniel@0: % case output is not written, only returned Daniel@0: % in aout Daniel@0: % Daniel@0: % aout (varies) output of the action Daniel@0: % Daniel@0: % Here are the actions and their arguments: Daniel@0: % 'printlines' par1 (cellstr) print par1, each cell on a new line Daniel@0: % 'header' par1 (string) print document header using par1 as title Daniel@0: % 'footer' print document footer Daniel@0: % 'compile' par1 (string) compile the named document (only 'ps' and 'pdf') Daniel@0: % 'inserttable' par1 (struct) print given table Daniel@0: % par2 (scalar) print lines between rows if par2=1 Daniel@0: % par3 (scalar) use longtable format (only 'ps' and 'pdf') Daniel@0: % 'printfigure' par1 (string) print current figure to file, par1 = filename Daniel@0: % par2 (scalar) used resolution (150 dpi by default) Daniel@0: % par3 (scalar) if par3=1, insert figure in minipage Daniel@0: % 'insertfigure' par1 (string) insert figure to report, par1 = filename of figure Daniel@0: % par2 (vector) size 2 x 1, size of figure relative to page size Daniel@0: % NaN = automatic scaling Daniel@0: % par3 (scalar) if par3=1, insert figure in minipage (only 'ps' and 'pdf') Daniel@0: % 'insertbreak' insert paragraph break into report Daniel@0: % Daniel@0: % See also REP_STATS. Daniel@0: Daniel@0: % Contributed to SOM Toolbox 2.0, January 2nd, 2002 by Juha Vesanto Daniel@0: % Copyright (c) by Juha Vesanto Daniel@0: % http://www.cis.hut.fi/projects/somtoolbox/ Daniel@0: Daniel@0: % Version 2.0beta juuso 020102 Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: %% input arguments Daniel@0: Daniel@0: pars = {''}; Daniel@0: if iscell(action), Daniel@0: if length(action)>1, pars = action(2:end); end Daniel@0: action = action{1}; Daniel@0: end Daniel@0: Daniel@0: if nargin<2 | isempty(fmt), fmt = 'txt'; end Daniel@0: global REPORT_OUTPUT_FMT Daniel@0: REPORT_OUTPUT_FMT = fmt; Daniel@0: Daniel@0: if nargin<3 | isempty(fid), fid = NaN; end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: %% action Daniel@0: Daniel@0: aout = []; Daniel@0: printable = 0; Daniel@0: Daniel@0: switch action, Daniel@0: case 'printlines', Daniel@0: aout = pars{1}; Daniel@0: case 'header', Daniel@0: switch fmt, Daniel@0: case {'ps','pdf'}, aout = tex_startdocument(pars{1}); Daniel@0: case 'html', aout = html_startpage(pars{1}); Daniel@0: case 'txt', aout = cell(0); Daniel@0: end Daniel@0: printable = 1; Daniel@0: case 'footer', Daniel@0: switch fmt, Daniel@0: case {'ps','pdf'}, aout = tex_enddocument; Daniel@0: case 'html', aout = html_endpage; Daniel@0: case 'txt', aout = cell(0); Daniel@0: end Daniel@0: printable = 1; Daniel@0: case 'compile', aout = compiledocument(pars{1}); Daniel@0: case 'inserttable', aout = inserttable(pars{:}); printable = 1; Daniel@0: case 'printfigure', printfigure(pars{:}); Daniel@0: case 'insertfigure', aout = insertfigure(pars{:}); printable = 1; Daniel@0: case 'insertbreak', aout = insertbreak; printable = 1; Daniel@0: case 'joinstr', aout = joinstr(pars{:}); printable = 1; Daniel@0: case 'rulestr', aout = rulestr(pars{:}); printable = 1; Daniel@0: case 'c_and_p_str', aout = c_and_p_str(pars{:}); printable = 1; Daniel@0: case 'p_str', aout = p_str(pars{:}); printable = 1; Daniel@0: end Daniel@0: Daniel@0: % if output file is given, print lines Daniel@0: if ~isnan(fid) & printable, Daniel@0: if ~iscell(aout), aout = {aout}; end Daniel@0: for i = 1:length(aout), fprintf(fid,'%s\n',fmtline(aout{i})); end Daniel@0: end Daniel@0: Daniel@0: return; Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: %% subfunctions Daniel@0: Daniel@0: %% simple formatter strings Daniel@0: Daniel@0: function s = joinstr(cs, sep1, sep2) Daniel@0: if nargin==1, sep1 = ', '; sep2 = ' and '; end Daniel@0: if nargin<3, sep2 = sep1; end Daniel@0: if isempty(cs), Daniel@0: s = ''; Daniel@0: elseif strcmp(sep1,'\n'), Daniel@0: if size(cs,1)==1, cs = cs'; end Daniel@0: s = char(cs); Daniel@0: else Daniel@0: s = cs{1}; Daniel@0: for i=2:length(cs)-1, s = [s sep1 cs{i}]; end Daniel@0: if length(cs)>1, s = [s sep2 cs{end}]; end Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: function str = c_and_p_str(n,m) Daniel@0: Daniel@0: % return a string of form # (%), e.g. '23 (12%)' Daniel@0: if n==m, p = '100'; Daniel@0: elseif n==0, p = '0'; Daniel@0: else p = sprintf('%.2g',100*n/m); Daniel@0: end Daniel@0: str = sprintf('%d (%s%%)',round(n),p); Daniel@0: return; Daniel@0: Daniel@0: function str = p_str(p) Daniel@0: % return a string of form %, e.g. '12%' Daniel@0: if round(p*100)>=100, p = sprintf('%3g',100*p); Daniel@0: elseif abs(p)=','inf',' ','<',''); Daniel@0: end Daniel@0: nr = length(sR); Daniel@0: cs = cell(nr,1); Daniel@0: fmt = '%.2g'; Daniel@0: if nargin<2, cnames = {sR.name}; end Daniel@0: if isempty(cnames), cnames = cell(nr,1); cnames(:) = {''}; end Daniel@0: for i=1:nr, Daniel@0: low = sR(i).low; Daniel@0: high = sR(i).high; Daniel@0: switch isfinite(low) + 2*isfinite(high), Daniel@0: case 0, cs{i} = [cnames{i} ' ' 'any']; Daniel@0: case 1, cs{i} = [cnames{i} ' ' m geq sprintf(fmt,low) m]; Daniel@0: case 2, cs{i} = [cnames{i} ' ' m less sprintf(fmt,high) m]; Daniel@0: case 3, cs{i} = [cnames{i} ' ' m in '[' sprintf(fmt,low) ',' sprintf(fmt,high) ']' m]; Daniel@0: end Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: %% print figure Daniel@0: Daniel@0: function imgfmt = fmt2imgfmt Daniel@0: global REPORT_OUTPUT_FMT Daniel@0: switch REPORT_OUTPUT_FMT, Daniel@0: case 'ps', imgfmt = 'ps'; Daniel@0: case 'pdf', imgfmt = 'pdf'; Daniel@0: case 'html', imgfmt = 'png'; Daniel@0: case 'txt', imgfmt = ''; Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: function printfigure(fname,resolution) Daniel@0: if nargin<2, resolution = 150; end Daniel@0: fnameps = [fname '.ps']; Daniel@0: switch fmt2imgfmt, Daniel@0: case 'ps', Daniel@0: print('-dpsc2',fnameps); Daniel@0: case 'pdf', Daniel@0: print('-dpsc2',fnameps); Daniel@0: eval(sprintf('!ps2pdf %s',fnameps)); Daniel@0: case 'gif', Daniel@0: print('-dpsc2',fnameps); Daniel@0: cmd = 'pstogif'; Daniel@0: opt = sprintf('-depth 1 -density %d',resolution); Daniel@0: unix(sprintf('%s %s -out %s %s',cmd,opt,[fname '.gif'],fnameps)); Daniel@0: case 'png', Daniel@0: opt = sprintf('-r%d',resolution); Daniel@0: print('-dpng',opt,[fname '.png']); Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: %% headers and footers, and compilation Daniel@0: Daniel@0: function cs = tex_startdocument(title) Daniel@0: % tex document headers Daniel@0: global REPORT_OUTPUT_FMT Daniel@0: cs = cell(0); Daniel@0: cs{end+1} = '\documentclass[10pt,a4paper]{article}'; Daniel@0: cs{end+1} = '\usepackage[dvips]{epsfig,graphicx,color}'; Daniel@0: cs{end+1} = '\usepackage{float,graphics,subfigure}'; Daniel@0: cs{end+1} = '\usepackage{multirow,rotating,portland,lscape,longtable,pifont}'; Daniel@0: cs{end+1} = '\usepackage[T1]{fontenc}'; Daniel@0: if strcmp(REPORT_OUTPUT_FMT,'pdf'), cs{end+1} = '\usepackage{pslatex}'; end Daniel@0: cs{end+1} = '\usepackage[english]{babel}'; Daniel@0: Daniel@0: cs{end+1} = '\oddsidemargin 0 mm'; Daniel@0: cs{end+1} = '\evensidemargin 0 mm'; Daniel@0: cs{end+1} = '\textwidth 17 cm'; Daniel@0: cs{end+1} = '\topmargin 0 mm'; Daniel@0: cs{end+1} = '\textheight 21 cm'; Daniel@0: cs{end+1} = '\voffset 0 mm'; Daniel@0: Daniel@0: cs{end+1} = '\begin{document}'; Daniel@0: cs{end+1} = ['\title{' title '}']; Daniel@0: cs{end+1} = '\maketitle'; Daniel@0: %cs{end+1} = '\tableofcontents'; Daniel@0: %cs{end+1} = '\clearpage'; Daniel@0: return; Daniel@0: Daniel@0: function cs = tex_enddocument Daniel@0: cs = cell(0); Daniel@0: cs{end+1} = '\end{document}'; Daniel@0: return; Daniel@0: Daniel@0: function cs = html_startpage(title) Daniel@0: % print HTML document headers Daniel@0: cs = cell(0); Daniel@0: cs{end+1} = ''; Daniel@0: cs{end+1} = ''; Daniel@0: cs{end+1} = ''; Daniel@0: cs{end+1} = sprintf(' %s',title); Daniel@0: cs{end+1} = ''; Daniel@0: cs{end+1} = ''; Daniel@0: if ~isempty(title), cs{end+1} = sprintf('

%s

',title); end Daniel@0: return; Daniel@0: Daniel@0: function cs = html_endpage Daniel@0: % print HTML document footers Daniel@0: cs = cell(0); Daniel@0: cs{end+1} = '


'; Daniel@0: cs{end+1} = ''; Daniel@0: cs{end+1} = ''; Daniel@0: return; Daniel@0: Daniel@0: function files = compiledocument(filename) Daniel@0: global REPORT_OUTPUT_FMT Daniel@0: switch REPORT_OUTPUT_FMT, Daniel@0: case 'pdf', Daniel@0: eval(sprintf('!pdflatex --interaction batchmode %s.tex',filename)); Daniel@0: eval(sprintf('!pdflatex --interaction batchmode %s.tex',filename)); Daniel@0: %eval(sprintf('!acroread %s.pdf &',filename)); Daniel@0: files = {[filename '.aux'],[filename '.log'],[filename '.out'],[filename '.pdf']}; Daniel@0: case 'ps', Daniel@0: eval(sprintf('!latex --interaction batchmode %s.tex',filename)); Daniel@0: eval(sprintf('!latex --interaction batchmode %s.tex',filename)); Daniel@0: eval(sprintf('!dvips %s.dvi',filename)); Daniel@0: eval(sprintf('!ps2pdf %s.ps',filename)); Daniel@0: %eval(sprintf('!ghostview %s.ps &',filename)); Daniel@0: files = {[filename '.aux'],[filename '.log'],[filename '.out'],[filename '.dvi'],[filename '.pdf']}; Daniel@0: case 'html', Daniel@0: case 'txt', Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: Daniel@0: function vstr = defaultformat(val) Daniel@0: global REPORT_OUTPUT_FMT Daniel@0: if ischar(val), vstr = val; Daniel@0: elseif iscellstr(val), vstr = char(val); Daniel@0: elseif isempty(val), vstr = ''; Daniel@0: elseif isnumeric(val), Daniel@0: if val==round(val), fmt = '%d'; else fmt = '%.3g'; end Daniel@0: if abs(val)<=eps, vstr = '0'; else vstr = sprintf(fmt,val); end Daniel@0: elseif isstruct(val) & isfield(val,'values') & isfield(val,'headers'), Daniel@0: % a table Daniel@0: vstr = joinstr(inserttable(val,0),'\n'); Daniel@0: if any(strcmp(REPORT_OUTPUT_FMT,{'ps','pdf'})), Daniel@0: vstr= inserttominipage(vstr); Daniel@0: end Daniel@0: else Daniel@0: vstr = ''; fprintf(1,'defaultformat unable to handle input\n'); Daniel@0: whos val Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: %% report elements (list, table, image, link) Daniel@0: Daniel@0: function str = fmtline(str) Daniel@0: % replace some formatting elements depeding on output format Daniel@0: global REPORT_OUTPUT_FMT Daniel@0: if isempty(str), str = ''; return; end Daniel@0: switch REPORT_OUTPUT_FMT, Daniel@0: case {'ps','pdf'}, Daniel@0: str = strrep(str,'', '{\bf '); Daniel@0: str = strrep(str,'', '{\em '); Daniel@0: str = strrep(str,'', '{\tt '); Daniel@0: str = strrep(str,'', '}'); Daniel@0: str = strrep(str,'', '}'); Daniel@0: str = strrep(str,'','}'); Daniel@0: str = strrep(str,'#','\#'); Daniel@0: str = strrep(str,'%','\%'); Daniel@0: case 'html', % nil Daniel@0: case 'txt', Daniel@0: str = strrep(str,'', '*'); Daniel@0: str = strrep(str,'', '*'); Daniel@0: str = strrep(str,'', ''); Daniel@0: str = strrep(str,'', '*'); Daniel@0: str = strrep(str,'', '*'); Daniel@0: str = strrep(str,'',''); Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: function cs = insertbreak Daniel@0: global REPORT_OUTPUT_FMT Daniel@0: cs = cell(0); Daniel@0: switch REPORT_OUTPUT_FMT Daniel@0: case {'ps','pdf'}, cs{end+1} = ''; Daniel@0: case 'html', cs{end+1} = '

'; Daniel@0: case 'txt', cs{end+1} = ''; Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: function insertlist(list,enum) Daniel@0: % make list Daniel@0: global REPORT_OUTPUT_FMT Daniel@0: if nargin<2, enum = 0; end Daniel@0: cs = cell(0); Daniel@0: switch REPORT_OUTPUT_FMT Daniel@0: case {'ps','pdf'}, Daniel@0: if enum, tag = 'enumerate'; else tag = 'itemize'; end Daniel@0: starttag = ['\begin{' tag '}']; Daniel@0: listtag = '\item '; Daniel@0: endtag = ['\end{' tag '}']; Daniel@0: case 'html', Daniel@0: if enum, tag = 'OL'; else tag = 'UL'; end Daniel@0: starttag = ['<' tag '>']; Daniel@0: listtag = '

  • '; Daniel@0: endtag = ['']; Daniel@0: case 'txt', Daniel@0: starttag = ''; Daniel@0: listtag = '- '; Daniel@0: endtag = ''; Daniel@0: end Daniel@0: cs{end+1} = starttag; Daniel@0: for i=1:length(list), cs{end+1} = sprintf('%s %s',listtag,list{i}); end Daniel@0: cs{end+1} = endtag; Daniel@0: return; Daniel@0: Daniel@0: function csout = tablerow(cs,emp,span) Daniel@0: % construct one table row Daniel@0: global REPORT_OUTPUT_FMT Daniel@0: if nargin<2 | isempty(emp), emp = 'none'; end Daniel@0: if nargin<3 | isempty(span), span = ones(length(cs),2); end Daniel@0: rowspan = span(:,1); colspan = span(:,2); Daniel@0: switch emp, Daniel@0: case 'bold', emp1 = ''; emp2 = ''; Daniel@0: case 'italic', emp1 = ''; emp2 = ''; Daniel@0: case 'fixed', emp1 = ''; emp2 = ''; Daniel@0: case 'none', emp1 = ''; emp2 = ''; Daniel@0: case 'header', emp1 = ''; emp2 = ''; tag = 'TH'; Daniel@0: end Daniel@0: csout = cell(0); Daniel@0: switch REPORT_OUTPUT_FMT, Daniel@0: case {'pdf','ps'}, Daniel@0: %switch emp, Daniel@0: % case 'bold', emp1 = '{\bf '; emp2 = '}'; Daniel@0: % case 'italic', emp1 = '{\em '; emp2 = '}'; Daniel@0: % case 'fixed', emp1 = '{\tt '; emp2 = '}'; Daniel@0: % case 'none', emp1 = ''; emp2 = ''; Daniel@0: %end Daniel@0: s0 = ''; Daniel@0: for i=1:length(cs), Daniel@0: if rowspan(i) & colspan(i), Daniel@0: sp1 = ''; sp2 = ''; Daniel@0: if colspan(i)>1, sp1 = [sp1 ' \multicolumn{' num2str(colspan(i)) '}{|c|}{']; sp2 = [sp2 '}']; end Daniel@0: if rowspan(i)>1, sp1 = [sp1 ' \multirow{' num2str(rowspan(i)) '}{2cm}{']; sp2 = [sp2 '}']; end Daniel@0: s = s0; Daniel@0: content = cellstr(defaultformat(cs{i})); Daniel@0: csout{end+1} = [s sp1 emp1 content{1}]; Daniel@0: for j=2:length(content), csout{end+1} = content{j}; end Daniel@0: csout{end} = [csout{end} emp2 sp2]; Daniel@0: s0 = ' & '; Daniel@0: end Daniel@0: end Daniel@0: csout{end} = [csout{end} ' \\']; Daniel@0: case 'html', Daniel@0: tag = 'TD'; Daniel@0: csout{end+1} = ''; Daniel@0: for i=1:length(cs), Daniel@0: if rowspan(i) & colspan(i), Daniel@0: sp = ''; Daniel@0: if rowspan(i)>1, sp = [sp ' ROWSPAN=' num2str(rowspan(i))]; end Daniel@0: if colspan(i)>1, sp = [sp ' COLSPAN=' num2str(colspan(i))]; end Daniel@0: s = sprintf('<%s%s>%s',tag,sp,emp1); Daniel@0: content = cellstr(defaultformat(cs{i})); Daniel@0: csout{end+1} = [s content{1}]; Daniel@0: for j=2:length(content), csout{end+1} = content{j}; end Daniel@0: csout{end} = [csout{end} emp2 '']; Daniel@0: end Daniel@0: end Daniel@0: csout{end+1} = ''; Daniel@0: case 'txt', Daniel@0: for i=1:length(cs), csout{end+1} = defaultformat(cs{i}); end Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: function cs = inserttable(sTable,rowlines,long) Daniel@0: % put table contents to cellstr Daniel@0: global REPORT_OUTPUT_FMT Daniel@0: if nargin<2, rowlines = 1; end Daniel@0: if nargin<3, long = 0; end Daniel@0: [rows cols] = size(sTable.values); Daniel@0: cs = cell(0); Daniel@0: if isempty(sTable.colfmt), cf = 'c'; sTable.colfmt = cf(ones(1,cols)); end Daniel@0: if isempty(sTable.span), sTable.span = ones([rows cols 2]); end Daniel@0: switch REPORT_OUTPUT_FMT Daniel@0: case {'ps','pdf','tex','latex'} Daniel@0: li1 = ' \hline'; Daniel@0: if rowlines>0, li2 = li1; li3 = li1; Daniel@0: elseif rowlines==0, li2 = ''; li3 = li1; Daniel@0: else li1 = ''; li2 = ''; li3 = ''; Daniel@0: end Daniel@0: if long, tbl = 'longtable'; else tbl = 'tabular'; end Daniel@0: cs{end+1} = ['\begin{' tbl '}{' sTable.colfmt '}' li1]; Daniel@0: if ~isempty(sTable.headers), Daniel@0: row = tablerow(sTable.headers,'bold'); Daniel@0: for i=1:length(row), cs{end+1} = row{i}; end Daniel@0: cs{end} = [cs{end} li1 li2]; Daniel@0: end Daniel@0: for i=1:rows, Daniel@0: row = tablerow(sTable.values(i,:),'',squeeze(sTable.span(i,:,:))); Daniel@0: for i=1:length(row), cs{end+1} = row{i}; end Daniel@0: cs{end} = [cs{end} li2]; Daniel@0: end Daniel@0: if ~rowlines, cs{end} = [cs{end} li3]; end Daniel@0: cs{end+1} = ['\end{' tbl '}']; Daniel@0: case 'html' Daniel@0: cs{end+1} = ['']; Daniel@0: if ~isempty(sTable.headers), Daniel@0: row = tablerow(sTable.headers,'header'); Daniel@0: for i=1:length(row), cs{end+1} = row{i}; end Daniel@0: end Daniel@0: for i=1:rows, Daniel@0: row = tablerow(sTable.values(i,:),'',squeeze(sTable.span(i,:,:))); Daniel@0: for i=1:length(row), cs{end+1} = row{i}; end Daniel@0: end Daniel@0: cs{end+1} = '
    '; Daniel@0: case 'txt' Daniel@0: cT = [sTable.headers(:)'; sTable.values]; Daniel@0: A = cell2char(cT); Daniel@0: for i=1:size(A,1), cs{end+1} = A(i,:); end Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: function A = cell2char(T) Daniel@0: Daniel@0: [nrow,ncol] = size(T); Daniel@0: rowsep = 0; Daniel@0: colsep = 1; Daniel@0: Daniel@0: % change to strings Daniel@0: for i=1:nrow, Daniel@0: for j=1:ncol, Daniel@0: t = T{i,j}; Daniel@0: if ischar(t), % ok Daniel@0: elseif isempty(t), T{i,j} = ''; Daniel@0: elseif isstruct(t), % ?? Daniel@0: elseif iscell(t), T{i,j} = cell2char(t); Daniel@0: elseif isnumeric(t), T{i,j} = num2str(t,3); Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % widths of columns and heights of rows Daniel@0: HW = ones(nrow,ncol,2); Daniel@0: for i=1:nrow, for j=1:ncol, HW(i,j,:) = size(T{i,j}); end, end Daniel@0: colw = max(HW(:,:,2),[],1); Daniel@0: rowh = max(HW(:,:,1),[],2); Daniel@0: Daniel@0: % the table itself Daniel@0: A = char(32*ones(sum(rowh)+rowsep*(nrow-1),sum(colw)+colsep*(ncol-1))); Daniel@0: for i=1:nrow, Daniel@0: for j=1:ncol, Daniel@0: i0 = (i-1)*rowsep+sum(rowh(1:i-1)); Daniel@0: j0 = (j-1)*colsep+sum(colw(1:j-1)); Daniel@0: S = char(32*ones(rowh(i),colw(j))); Daniel@0: si = size(T{i,j}); S(1:si(1),1:si(2)) = T{i,j}; Daniel@0: A(i0+[1:rowh(i)],j0+[1:colw(j)]) = S; Daniel@0: end Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: Daniel@0: function s = inserttominipage(s,width) Daniel@0: if nargin<2 | isempty(width) | isnan(width), width = 1; end Daniel@0: width = ['{' num2str(width) '\columnwidth}']; Daniel@0: mp1 = '\begin{minipage}[t]'; mp2 = '\end{minipage}'; Daniel@0: if size(s,1)==1, s = [mp1 width s mp2]; Daniel@0: else s = char({[mp1 width]; s; mp2}); Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: function cs = insertfigure(fname,boxsize,inminipage) Daniel@0: global REPORT_OUTPUT_FMT Daniel@0: if nargin<2, boxsize = [NaN 1]; end Daniel@0: if nargin<3, inminipage = 0; end Daniel@0: htmlpagewidth = 800; Daniel@0: si = cell(0); Daniel@0: switch REPORT_OUTPUT_FMT, Daniel@0: case {'ps','pdf'}, Daniel@0: if ~isnan(boxsize(1)), si{end+1} = ['height=' num2str(boxsize(1)) '\textheight']; end Daniel@0: if ~isnan(boxsize(2)), si{end+1} = ['width=' num2str(boxsize(2)) '\columnwidth']; end Daniel@0: if length(si), si = [', ' joinstr(si, ', ', ', ')]; end Daniel@0: case 'html', Daniel@0: if ~isnan(boxsize(1)), si{end+1} = ['HEIGHT=' num2str(htmlpagewidth*boxsize(1))]; end Daniel@0: if ~isnan(boxsize(2)), si{end+1} = ['WIDTH=' num2str(htmlpagewidth*boxsize(2))]; end Daniel@0: if length(si), si = [' ' joinstr(si, ' ', ' ')]; end Daniel@0: case 'txt', Daniel@0: % nil Daniel@0: end Daniel@0: switch REPORT_OUTPUT_FMT, Daniel@0: case 'ps', s = ['\epsfig{file=./' fname '.ps ' si '}']; Daniel@0: case 'pdf', s = ['\includegraphics[' si ']{./' fname '.pdf}']; Daniel@0: case 'html', Daniel@0: fn = [fname '.' fmt2imgfmt]; Daniel@0: s = ['' fname '']; Daniel@0: s = makelinkfrom(fn,s); Daniel@0: case 'txt', Daniel@0: s = ['[image:' fname ']']; Daniel@0: end Daniel@0: switch REPORT_OUTPUT_FMT, Daniel@0: case {'ps','pdf'}, Daniel@0: if inminipage, s = inserttominipage(s,boxsize(2)); end Daniel@0: case 'html', Daniel@0: s = ['
    ' s '
    ']; Daniel@0: case 'txt', Daniel@0: % nil Daniel@0: end Daniel@0: cs = {s}; Daniel@0: return; Daniel@0: Daniel@0: function str = makelinkfrom(linkto,anchor) Daniel@0: global REPORT_OUTPUT_FMT Daniel@0: if iscell(linkto), Daniel@0: if strcmp(REPORT_OUTPUT_FMT,'html'), linkto = joinstr(linkto,'','#'); Daniel@0: else linkto = joinstr(linkto,'',''); Daniel@0: end Daniel@0: end Daniel@0: switch REPORT_OUTPUT_FMT, Daniel@0: case 'pdf', str = ['\hyperlink{' linkto '}{' anchor '}']; Daniel@0: case 'ps', str = [anchor ' (p.\pageref{' linkto '})']; Daniel@0: case 'html', str = ['' anchor '']; Daniel@0: case 'txt', str = ''; Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: function str = makelinkto(linkname) Daniel@0: global REPORT_OUTPUT_FMT Daniel@0: switch REPORT_OUTPUT_FMT, Daniel@0: case 'pdf', Daniel@0: fmt = '\pdfdest name {%s} fit \pdfoutline goto name {%s} {%s}'; Daniel@0: str = sprintf(fmt,linkname,linkname,linkname); Daniel@0: case 'ps', str = ['\label{' linkname '}']; Daniel@0: case 'html', str = [' ']; Daniel@0: case 'txt', str = ''; Daniel@0: end Daniel@0: return; Daniel@0: