Browse code

starting som prediction fine-tuned class-performance visualisation

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@112 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on21/01/2009 16:34:25
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,572 @@
1
+function aout = rep_utils(action,fmt,fid)
2
+
3
+%REP_UTILS Utilities for print reports and report elements.
4
+%  
5
+% aout = rep_utils(action,fmt,[fid])
6
+% 
7
+%  Input and output arguments ([]'s are optional): 
8
+%   action      (string)     action identifier
9
+%               (cell array) {action,par1,par2,...}
10
+%                            the action identifier, followed by action 
11
+%                            parameters
12
+%   [fmt]       (string)     format of output, 'txt' by default
13
+%   [fid]       (scalar)     output file id, by default NaN in which
14
+%                            case output is not written, only returned
15
+%                            in aout
16
+%   
17
+%   aout        (varies)     output of the action
18
+%
19
+%  Here are the actions and their arguments: 
20
+%  'printlines'   par1 (cellstr)   print par1, each cell on a new line
21
+%  'header'       par1 (string)    print document header using par1 as title
22
+%  'footer'                        print document footer
23
+%  'compile'      par1 (string)    compile the named document (only 'ps' and 'pdf')
24
+%  'inserttable'  par1 (struct)    print given table
25
+%                 par2 (scalar)    print lines between rows if par2=1
26
+%                 par3 (scalar)    use longtable format (only 'ps' and 'pdf')
27
+%  'printfigure'  par1 (string)    print current figure to file, par1 = filename
28
+%                 par2 (scalar)    used resolution (150 dpi by default)
29
+%                 par3 (scalar)    if par3=1, insert figure in minipage
30
+%  'insertfigure' par1 (string)    insert figure to report, par1 = filename of figure
31
+%                 par2 (vector)    size 2 x 1, size of figure relative to page size 
32
+%                                  NaN = automatic scaling
33
+%                 par3 (scalar)    if par3=1, insert figure in minipage (only 'ps' and 'pdf')
34
+%  'insertbreak'                   insert paragraph break into report 
35
+%
36
+% See also  REP_STATS.
37
+
38
+% Contributed to SOM Toolbox 2.0, January 2nd, 2002 by Juha Vesanto
39
+% Copyright (c) by Juha Vesanto
40
+% http://www.cis.hut.fi/projects/somtoolbox/
41
+
42
+% Version 2.0beta juuso 020102
43
+
44
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45
+%% input arguments
46
+
47
+pars = {''}; 
48
+if iscell(action), 
49
+    if length(action)>1, pars = action(2:end); end
50
+    action = action{1}; 
51
+end
52
+
53
+if nargin<2 | isempty(fmt), fmt = 'txt'; end
54
+global REPORT_OUTPUT_FMT
55
+REPORT_OUTPUT_FMT = fmt;
56
+
57
+if nargin<3 | isempty(fid), fid = NaN; end
58
+
59
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60
+%% action
61
+
62
+aout = []; 
63
+printable = 0; 
64
+
65
+switch action,
66
+case 'printlines',
67
+    aout = pars{1}; 
68
+case 'header',     
69
+    switch fmt, 
70
+    case {'ps','pdf'}, aout = tex_startdocument(pars{1}); 
71
+    case 'html',       aout = html_startpage(pars{1});
72
+    case 'txt',        aout = cell(0);
73
+    end 
74
+    printable = 1; 
75
+case 'footer', 
76
+    switch fmt, 
77
+    case {'ps','pdf'}, aout = tex_enddocument; 
78
+    case 'html',       aout = html_endpage;
79
+    case 'txt',        aout = cell(0);
80
+    end 
81
+    printable = 1; 
82
+case 'compile',      aout = compiledocument(pars{1});
83
+case 'inserttable',  aout = inserttable(pars{:}); printable = 1; 
84
+case 'printfigure',  printfigure(pars{:});
85
+case 'insertfigure', aout = insertfigure(pars{:}); printable = 1;
86
+case 'insertbreak',  aout = insertbreak; printable = 1; 
87
+case 'joinstr',      aout = joinstr(pars{:}); printable = 1; 
88
+case 'rulestr',      aout = rulestr(pars{:}); printable = 1; 
89
+case 'c_and_p_str',  aout = c_and_p_str(pars{:}); printable = 1; 
90
+case 'p_str',        aout = p_str(pars{:}); printable = 1; 
91
+end 
92
+
93
+% if output file is given, print lines
94
+if ~isnan(fid) & printable,
95
+    if ~iscell(aout), aout = {aout}; end
96
+    for i = 1:length(aout), fprintf(fid,'%s\n',fmtline(aout{i})); end
97
+end
98
+
99
+return;
100
+
101
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102
+%% subfunctions
103
+
104
+%% simple formatter strings
105
+
106
+function s = joinstr(cs, sep1, sep2)
107
+  if nargin==1, sep1 = ', '; sep2 = ' and '; end
108
+  if nargin<3, sep2 = sep1; end
109
+  if isempty(cs), 
110
+    s = '';     
111
+  elseif strcmp(sep1,'\n'), 
112
+    if size(cs,1)==1, cs = cs'; end
113
+    s = char(cs); 
114
+  else
115
+    s = cs{1}; 
116
+    for i=2:length(cs)-1, s = [s sep1 cs{i}]; end
117
+    if length(cs)>1, s = [s sep2 cs{end}]; end
118
+  end
119
+  return; 
120
+
121
+function str = c_and_p_str(n,m)
122
+
123
+  % return a string of form # (%), e.g. '23 (12%)'
124
+  if n==m, p = '100'; 
125
+  elseif n==0, p = '0';
126
+  else p = sprintf('%.2g',100*n/m);
127
+  end
128
+  str = sprintf('%d (%s%%)',round(n),p); 
129
+  return;
130
+  
131
+function str = p_str(p)
132
+  % return a string of form %, e.g. '12%'
133
+  if round(p*100)>=100, p = sprintf('%3g',100*p); 
134
+  elseif abs(p)<eps, p = '0';
135
+  else p = sprintf('%.2g',100*p);
136
+  end
137
+  str = sprintf('%s%%',p); 
138
+  return;
139
+
140
+function cs = rulestr(sR,cnames)
141
+  global REPORT_OUTPUT_FMT
142
+  switch REPORT_OUTPUT_FMT
143
+   case {'ps','pdf'}, [leq,geq,infi,m,less,in] = deal('\leq','\geq','\inf','$','<','\in'); 
144
+   case 'html',  [leq,geq,infi,m,less,in]  = deal('&lt;=','&gt;=','Inf',' ','&lt;',' '); 
145
+   case 'txt', [leq,geq,infi,m,less,in]  = deal('<=','>=','inf',' ','<',''); 
146
+  end
147
+  nr = length(sR); 
148
+  cs = cell(nr,1); 
149
+  fmt = '%.2g'; 
150
+  if nargin<2, cnames = {sR.name}; end
151
+  if isempty(cnames), cnames = cell(nr,1); cnames(:) = {''}; end 
152
+  for i=1:nr,       
153
+    low  = sR(i).low; 
154
+    high = sR(i).high; 
155
+    switch isfinite(low) + 2*isfinite(high), 
156
+     case 0, cs{i} = [cnames{i} ' ' 'any']; 
157
+     case 1, cs{i} = [cnames{i} ' ' m geq sprintf(fmt,low) m];
158
+     case 2, cs{i} = [cnames{i} ' ' m less sprintf(fmt,high) m]; 
159
+     case 3, cs{i} = [cnames{i} ' ' m in '[' sprintf(fmt,low) ',' sprintf(fmt,high) ']' m];
160
+    end
161
+  end
162
+  return; 
163
+
164
+%% print figure
165
+
166
+function imgfmt = fmt2imgfmt
167
+  global REPORT_OUTPUT_FMT
168
+  switch REPORT_OUTPUT_FMT, 
169
+  case 'ps',   imgfmt = 'ps'; 
170
+  case 'pdf',  imgfmt = 'pdf'; 
171
+  case 'html', imgfmt = 'png'; 
172
+  case 'txt',  imgfmt = ''; 
173
+  end
174
+  return; 
175
+
176
+function printfigure(fname,resolution)
177
+  if nargin<2, resolution = 150; end
178
+  fnameps = [fname '.ps']; 
179
+  switch fmt2imgfmt,
180
+  case 'ps',  
181
+      print('-dpsc2',fnameps); 
182
+  case 'pdf', 
183
+      print('-dpsc2',fnameps);       
184
+      eval(sprintf('!ps2pdf %s',fnameps));  
185
+  case 'gif',       
186
+      print('-dpsc2',fnameps);              
187
+      cmd = 'pstogif'; 
188
+      opt = sprintf('-depth 1 -density %d',resolution); 
189
+      unix(sprintf('%s %s -out %s %s',cmd,opt,[fname '.gif'],fnameps));
190
+  case 'png',
191
+      opt = sprintf('-r%d',resolution); 
192
+      print('-dpng',opt,[fname '.png']);
193
+  end
194
+  return; 
195
+
196
+%% headers and footers, and compilation
197
+
198
+function cs = tex_startdocument(title)
199
+  % tex document headers
200
+  global REPORT_OUTPUT_FMT
201
+  cs = cell(0); 
202
+  cs{end+1} = '\documentclass[10pt,a4paper]{article}'; 
203
+  cs{end+1} = '\usepackage[dvips]{epsfig,graphicx,color}'; 
204
+  cs{end+1} = '\usepackage{float,graphics,subfigure}'; 
205
+  cs{end+1} = '\usepackage{multirow,rotating,portland,lscape,longtable,pifont}'; 
206
+  cs{end+1} = '\usepackage[T1]{fontenc}'; 
207
+  if strcmp(REPORT_OUTPUT_FMT,'pdf'), cs{end+1} = '\usepackage{pslatex}'; end
208
+  cs{end+1} = '\usepackage[english]{babel}'; 
209
+
210
+  cs{end+1} = '\oddsidemargin 0 mm';
211
+  cs{end+1} = '\evensidemargin 0 mm';
212
+  cs{end+1} = '\textwidth 17 cm';
213
+  cs{end+1} = '\topmargin 0 mm';
214
+  cs{end+1} = '\textheight 21 cm';
215
+  cs{end+1} = '\voffset 0 mm';
216
+
217
+  cs{end+1} = '\begin{document}'; 
218
+  cs{end+1} = ['\title{' title '}']; 
219
+  cs{end+1} = '\maketitle'; 
220
+  %cs{end+1} = '\tableofcontents'; 
221
+  %cs{end+1} = '\clearpage'; 
222
+  return;
223
+
224
+function cs = tex_enddocument
225
+  cs = cell(0);
226
+  cs{end+1} = '\end{document}';
227
+  return; 
228
+
229
+function cs = html_startpage(title)
230
+  % print HTML document headers
231
+  cs = cell(0);
232
+  cs{end+1} = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">';
233
+  cs{end+1} = '<HTML>';
234
+  cs{end+1} = '<HEAD>';
235
+  cs{end+1} = sprintf('  <TITLE>%s</TITLE>',title);
236
+  cs{end+1} = '</HEAD>';
237
+  cs{end+1} = '<BODY bgcolor=white vlink="#000033" link="#0000ff" text="#000000">';
238
+  if ~isempty(title), cs{end+1} = sprintf('<H1>%s</H1>',title); end
239
+  return;
240
+
241
+function cs = html_endpage
242
+  % print HTML document footers
243
+  cs = cell(0);
244
+  cs{end+1} = '<P><HR>';
245
+  cs{end+1} = '</BODY>';
246
+  cs{end+1} = '</HTML>';
247
+  return;
248
+
249
+function files = compiledocument(filename)
250
+  global REPORT_OUTPUT_FMT
251
+  switch REPORT_OUTPUT_FMT, 
252
+   case 'pdf', 
253
+    eval(sprintf('!pdflatex --interaction batchmode %s.tex',filename));
254
+    eval(sprintf('!pdflatex --interaction batchmode %s.tex',filename));
255
+    %eval(sprintf('!acroread %s.pdf &',filename)); 
256
+    files = {[filename '.aux'],[filename '.log'],[filename '.out'],[filename '.pdf']}; 
257
+   case 'ps', 
258
+    eval(sprintf('!latex --interaction batchmode %s.tex',filename));
259
+    eval(sprintf('!latex --interaction batchmode %s.tex',filename));
260
+    eval(sprintf('!dvips %s.dvi',filename)); 
261
+    eval(sprintf('!ps2pdf %s.ps',filename));
262
+    %eval(sprintf('!ghostview %s.ps &',filename)); 
263
+    files = {[filename '.aux'],[filename '.log'],[filename '.out'],[filename '.dvi'],[filename '.pdf']}; 
264
+   case 'html',   
265
+   case 'txt',
266
+  end
267
+  return; 
268
+
269
+
270
+function vstr = defaultformat(val)  
271
+  global REPORT_OUTPUT_FMT
272
+  if ischar(val),        vstr = val; 
273
+  elseif iscellstr(val), vstr = char(val); 
274
+  elseif isempty(val),   vstr = ''; 
275
+  elseif isnumeric(val), 
276
+    if val==round(val), fmt = '%d'; else fmt = '%.3g'; end 
277
+    if abs(val)<=eps, vstr = '0'; else vstr = sprintf(fmt,val); end
278
+  elseif isstruct(val) & isfield(val,'values') & isfield(val,'headers'), 
279
+    % a table
280
+    vstr = joinstr(inserttable(val,0),'\n');
281
+    if any(strcmp(REPORT_OUTPUT_FMT,{'ps','pdf'})), 
282
+      vstr= inserttominipage(vstr); 
283
+    end
284
+  else
285
+    vstr = ''; fprintf(1,'defaultformat unable to handle input\n');     
286
+    whos val
287
+  end
288
+  return; 
289
+
290
+%% report elements (list, table, image, link)
291
+
292
+function str = fmtline(str)
293
+  % replace some formatting elements depeding on output format
294
+  global REPORT_OUTPUT_FMT
295
+  if isempty(str), str = ''; return; end
296
+  switch REPORT_OUTPUT_FMT, 
297
+   case {'ps','pdf'}, 
298
+     str = strrep(str,'<B>',  '{\bf ');
299
+     str = strrep(str,'<I>',  '{\em ');
300
+     str = strrep(str,'<TT>', '{\tt ');
301
+     str = strrep(str,'</B>', '}');
302
+     str = strrep(str,'</I>', '}');
303
+     str = strrep(str,'</TT>','}');
304
+     str = strrep(str,'#','\#'); 
305
+     str = strrep(str,'%','\%');
306
+   case 'html', % nil
307
+   case 'txt', 
308
+     str = strrep(str,'<B>',  '*');
309
+     str = strrep(str,'<I>',  '*');
310
+     str = strrep(str,'<TT>', '');
311
+     str = strrep(str,'</B>', '*');
312
+     str = strrep(str,'</I>', '*');
313
+     str = strrep(str,'</TT>','');
314
+  end
315
+  return;
316
+
317
+function cs = insertbreak
318
+    global REPORT_OUTPUT_FMT
319
+    cs = cell(0); 
320
+    switch REPORT_OUTPUT_FMT
321
+    case {'ps','pdf'}, cs{end+1} = '';
322
+    case 'html', cs{end+1} = '<P>';
323
+    case 'txt', cs{end+1} = ''; 
324
+    end   
325
+    return;
326
+    
327
+function insertlist(list,enum)
328
+  % make list
329
+  global REPORT_OUTPUT_FMT
330
+  if nargin<2, enum = 0; end
331
+  cs = cell(0);
332
+  switch REPORT_OUTPUT_FMT
333
+   case {'ps','pdf'}, 
334
+    if enum, tag = 'enumerate'; else tag = 'itemize'; end
335
+    starttag = ['\begin{' tag '}'];
336
+    listtag = '\item ';
337
+    endtag = ['\end{' tag '}'];
338
+   case 'html', 
339
+    if enum, tag = 'OL'; else tag = 'UL'; end
340
+    starttag = ['<' tag '>'];
341
+    listtag = '<LI>';
342
+    endtag = ['</' tag '>'];   
343
+   case 'txt',
344
+    starttag = ''; 
345
+    listtag = '- ';
346
+    endtag = ''; 
347
+  end
348
+  cs{end+1} = starttag;
349
+  for i=1:length(list), cs{end+1} = sprintf('%s %s',listtag,list{i}); end
350
+  cs{end+1} = endtag; 
351
+  return;
352
+
353
+function csout = tablerow(cs,emp,span)
354
+  % construct one table row
355
+  global REPORT_OUTPUT_FMT
356
+  if nargin<2 | isempty(emp), emp = 'none'; end
357
+  if nargin<3 | isempty(span), span = ones(length(cs),2); end
358
+  rowspan = span(:,1); colspan = span(:,2);
359
+  switch emp,
360
+   case 'bold',   emp1 = '<B>';  emp2 = '</B>'; 
361
+   case 'italic', emp1 = '<I>';  emp2 = '</I>'; 
362
+   case 'fixed',  emp1 = '<TT>'; emp2 = '</TT>';           
363
+   case 'none',   emp1 = '';     emp2 = ''; 
364
+   case 'header', emp1 = '';     emp2 = ''; tag = 'TH';
365
+  end      
366
+  csout = cell(0); 
367
+  switch REPORT_OUTPUT_FMT, 
368
+   case {'pdf','ps'}, 
369
+    %switch emp,
370
+    % case 'bold',   emp1 = '{\bf '; emp2 = '}'; 
371
+    % case 'italic', emp1 = '{\em '; emp2 = '}'; 
372
+    % case 'fixed',  emp1 = '{\tt '; emp2 = '}';       
373
+    % case 'none',   emp1 = '';      emp2 = ''; 
374
+    %end    
375
+    s0 = ''; 
376
+    for i=1:length(cs), 
377
+      if rowspan(i) & colspan(i), 
378
+	 sp1 = ''; sp2 = '';
379
+         if colspan(i)>1, sp1 = [sp1 ' \multicolumn{' num2str(colspan(i)) '}{|c|}{']; sp2 = [sp2 '}']; end
380
+         if rowspan(i)>1, sp1 = [sp1 ' \multirow{' num2str(rowspan(i)) '}{2cm}{']; sp2 = [sp2 '}']; end
381
+	 s = s0; 
382
+	 content = cellstr(defaultformat(cs{i})); 
383
+	 csout{end+1} = [s sp1 emp1 content{1}]; 
384
+	 for j=2:length(content), csout{end+1} = content{j}; end
385
+	 csout{end} = [csout{end} emp2 sp2]; 
386
+	 s0 = ' & '; 
387
+      end
388
+    end
389
+    csout{end} = [csout{end} ' \\']; 
390
+   case 'html', 
391
+    tag = 'TD';
392
+    csout{end+1} = '<TR>';     
393
+    for i=1:length(cs),
394
+      if rowspan(i) & colspan(i), 
395
+         sp = '';
396
+         if rowspan(i)>1, sp = [sp ' ROWSPAN=' num2str(rowspan(i))]; end
397
+         if colspan(i)>1, sp = [sp ' COLSPAN=' num2str(colspan(i))]; end
398
+         s = sprintf('<%s%s>%s',tag,sp,emp1);
399
+	     content = cellstr(defaultformat(cs{i})); 
400
+	     csout{end+1} = [s content{1}]; 
401
+	     for j=2:length(content), csout{end+1} = content{j}; end
402
+	     csout{end} = [csout{end} emp2 '</' tag '>']; 
403
+      end
404
+    end
405
+    csout{end+1} = '</TR>'; 
406
+   case 'txt',
407
+    for i=1:length(cs), csout{end+1} = defaultformat(cs{i}); end
408
+  end
409
+  return;  
410
+
411
+function cs = inserttable(sTable,rowlines,long)
412
+  % put table contents to cellstr
413
+  global REPORT_OUTPUT_FMT  
414
+  if nargin<2, rowlines = 1; end
415
+  if nargin<3, long = 0; end
416
+  [rows cols] = size(sTable.values);
417
+  cs = cell(0); 
418
+  if isempty(sTable.colfmt), cf = 'c'; sTable.colfmt = cf(ones(1,cols)); end
419
+  if isempty(sTable.span), sTable.span = ones([rows cols 2]); end  
420
+  switch REPORT_OUTPUT_FMT
421
+   case {'ps','pdf','tex','latex'}
422
+    li1 = ' \hline';  
423
+    if rowlines>0, li2 = li1; li3 = li1; 
424
+    elseif rowlines==0, li2 = ''; li3 = li1; 
425
+    else li1 = ''; li2 = ''; li3 = '';  
426
+    end
427
+    if long, tbl = 'longtable'; else tbl = 'tabular'; end
428
+    cs{end+1} = ['\begin{' tbl '}{' sTable.colfmt '}' li1];
429
+    if ~isempty(sTable.headers), 
430
+      row = tablerow(sTable.headers,'bold'); 
431
+      for i=1:length(row), cs{end+1} = row{i}; end
432
+      cs{end} = [cs{end} li1 li2]; 
433
+    end
434
+    for i=1:rows, 
435
+      row = tablerow(sTable.values(i,:),'',squeeze(sTable.span(i,:,:))); 
436
+      for i=1:length(row), cs{end+1} = row{i}; end
437
+      cs{end} = [cs{end} li2]; 
438
+    end 
439
+    if ~rowlines, cs{end} = [cs{end} li3]; end
440
+    cs{end+1} = ['\end{' tbl '}'];
441
+   case 'html'
442
+    cs{end+1} = ['<TABLE BORDER=' num2str(rowlines>0) '>'];
443
+    if ~isempty(sTable.headers), 
444
+      row = tablerow(sTable.headers,'header'); 
445
+      for i=1:length(row), cs{end+1} = row{i}; end
446
+    end
447
+    for i=1:rows, 
448
+      row = tablerow(sTable.values(i,:),'',squeeze(sTable.span(i,:,:))); 
449
+      for i=1:length(row), cs{end+1} = row{i}; end
450
+    end
451
+    cs{end+1} = '</TABLE>';
452
+   case 'txt'
453
+    cT = [sTable.headers(:)'; sTable.values]; 
454
+    A = cell2char(cT); 
455
+    for i=1:size(A,1), cs{end+1} = A(i,:); end        
456
+  end  
457
+  return;
458
+
459
+function A = cell2char(T)
460
+
461
+  [nrow,ncol] = size(T); 
462
+  rowsep = 0; 
463
+  colsep = 1;
464
+
465
+  % change to strings
466
+  for i=1:nrow, 
467
+    for j=1:ncol, 
468
+      t = T{i,j};
469
+      if ischar(t),        % ok
470
+      elseif isempty(t),   T{i,j} = ''; 
471
+      elseif isstruct(t),  % ??
472
+      elseif iscell(t),    T{i,j} = cell2char(t); 
473
+      elseif isnumeric(t), T{i,j} = num2str(t,3); 
474
+      end
475
+    end
476
+  end
477
+
478
+  % widths of columns and heights of rows 
479
+  HW = ones(nrow,ncol,2);
480
+  for i=1:nrow, for j=1:ncol, HW(i,j,:) = size(T{i,j}); end, end
481
+  colw = max(HW(:,:,2),[],1); 
482
+  rowh = max(HW(:,:,1),[],2); 
483
+
484
+  % the table itself
485
+  A = char(32*ones(sum(rowh)+rowsep*(nrow-1),sum(colw)+colsep*(ncol-1)));
486
+  for i=1:nrow, 
487
+    for j=1:ncol,
488
+      i0 = (i-1)*rowsep+sum(rowh(1:i-1));
489
+      j0 = (j-1)*colsep+sum(colw(1:j-1)); 
490
+      S = char(32*ones(rowh(i),colw(j))); 
491
+      si = size(T{i,j}); S(1:si(1),1:si(2)) = T{i,j}; 
492
+      A(i0+[1:rowh(i)],j0+[1:colw(j)]) = S; 
493
+    end
494
+  end
495
+  return; 
496
+  
497
+
498
+function s = inserttominipage(s,width)
499
+  if nargin<2 | isempty(width) | isnan(width), width = 1; end
500
+  width = ['{' num2str(width) '\columnwidth}'];
501
+  mp1 = '\begin{minipage}[t]'; mp2 = '\end{minipage}';   
502
+  if size(s,1)==1, s = [mp1 width s mp2];
503
+  else s = char({[mp1 width]; s; mp2});
504
+  end
505
+  return; 
506
+  
507
+function cs = insertfigure(fname,boxsize,inminipage)
508
+  global REPORT_OUTPUT_FMT
509
+  if nargin<2, boxsize = [NaN 1]; end
510
+  if nargin<3, inminipage = 0; end
511
+  htmlpagewidth = 800;
512
+  si = cell(0); 
513
+  switch REPORT_OUTPUT_FMT,     
514
+   case {'ps','pdf'}, 
515
+    if ~isnan(boxsize(1)), si{end+1} = ['height=' num2str(boxsize(1)) '\textheight']; end
516
+    if ~isnan(boxsize(2)), si{end+1} = ['width=' num2str(boxsize(2)) '\columnwidth']; end
517
+    if length(si), si = [', ' joinstr(si, ', ', ', ')]; end
518
+   case 'html', 
519
+    if ~isnan(boxsize(1)), si{end+1} = ['HEIGHT=' num2str(htmlpagewidth*boxsize(1))]; end
520
+    if ~isnan(boxsize(2)), si{end+1} = ['WIDTH=' num2str(htmlpagewidth*boxsize(2))]; end   
521
+    if length(si), si = [' ' joinstr(si, ' ', ' ')]; end
522
+   case 'txt', 
523
+    % nil 
524
+  end    
525
+  switch REPORT_OUTPUT_FMT,     
526
+   case 'ps',   s = ['\epsfig{file=./' fname '.ps ' si '}']; 
527
+   case 'pdf',  s = ['\includegraphics[' si ']{./' fname '.pdf}'];
528
+   case 'html', 
529
+    fn = [fname '.' fmt2imgfmt]; 
530
+    s = ['<IMG SRC="' fn '" ALIGN="center" ALT="' fname '"' si '>'];
531
+    s = makelinkfrom(fn,s); 
532
+   case 'txt', 
533
+    s = ['[image:' fname ']'];
534
+  end
535
+  switch REPORT_OUTPUT_FMT, 
536
+   case {'ps','pdf'},
537
+    if inminipage, s = inserttominipage(s,boxsize(2)); end
538
+   case 'html', 
539
+    s = ['<CENTER>' s '</CENTER>']; 
540
+   case 'txt', 
541
+    % nil
542
+  end
543
+  cs = {s};
544
+  return;
545
+
546
+function str = makelinkfrom(linkto,anchor)  
547
+  global REPORT_OUTPUT_FMT
548
+  if iscell(linkto), 
549
+    if strcmp(REPORT_OUTPUT_FMT,'html'), linkto = joinstr(linkto,'','#'); 
550
+    else linkto = joinstr(linkto,'',''); 
551
+    end
552
+  end
553
+  switch REPORT_OUTPUT_FMT,  
554
+   case 'pdf',  str = ['\hyperlink{' linkto '}{' anchor '}'];
555
+   case 'ps',   str = [anchor ' (p.\pageref{' linkto '})']; 
556
+   case 'html', str = ['<a href="' linkto '">' anchor '</a>']; 
557
+   case 'txt', str = ''; 
558
+  end
559
+  return; 
560
+      
561
+function str = makelinkto(linkname)
562
+  global REPORT_OUTPUT_FMT
563
+  switch REPORT_OUTPUT_FMT,  
564
+   case 'pdf', 
565
+    fmt = '\pdfdest name {%s} fit \pdfoutline goto name {%s} {%s}'; 
566
+    str = sprintf(fmt,linkname,linkname,linkname);
567
+   case 'ps',   str = ['\label{' linkname '}']; 
568
+   case 'html', str = ['<a name="' linkname '"> </a>']; 
569
+   case 'txt', str = ''; 
570
+  end
571
+  return;
572
+