0001 function DBExportGallery(name,query,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 CheckMyM;
0046
0047
0048 hSize = 240;
0049 vSize = 240;
0050 nColumns = 3;
0051 showInfo = 'off';
0052 showCode = 'off';
0053
0054
0055 if nargin < 1,
0056 error('Incorrect number of parameters (type ''help <a href="matlab:help DBExportGallery">DBExportGallery</a>'' for details).');
0057 end
0058
0059
0060 if nargin == 1,
0061 query = '';
0062 elseif isastring(query,'size','ncolumns','info','code'),
0063 varargin = {query varargin{:}};
0064 query = '';
0065 end
0066
0067
0068 query = strtrim(query);
0069 query = regexprep(query,'^where','');
0070 if ~isempty(query), query = [' where ' query]; end
0071
0072
0073 for j = 1:2:length(varargin),
0074 if ~ischar(varargin{j}),
0075 error(['Parameter ' num2str(j+7) ' is not a property (type ''help <a href="matlab:help DBExportGallery">DBExportGallery</a>'' for details).']);
0076 end
0077 switch(lower(varargin{j})),
0078 case 'size',
0079 sizes = varargin{j+1};
0080 if ~isivector(sizes,'>0','#2'),
0081 error('Incorrect value for ''size'' (type ''help <a href="matlab:help DBExportGallery">DBExportGallery</a>'' for details).');
0082 end
0083 hSize = sizes(1);
0084 vSize = sizes(2);
0085
0086 case 'ncolumns',
0087 nColumns = varargin{j+1};
0088 if ~isiscalar(nColumns,'>0'),
0089 error('Incorrect value for ''ncolumns'' (type ''help <a href="matlab:help DBExportGallery">DBExportGallery</a>'' for details).');
0090 end
0091
0092 case 'info',
0093 showInfo = lower(varargin{j+1});
0094 if ~isastring(showInfo,'on','off'),
0095 error('Incorrect value for ''info'' (type ''help <a href="matlab:help DBExportGallery">DBExportGallery</a>'' for details).');
0096 end
0097
0098 case 'code',
0099 showCode = lower(varargin{j+1});
0100 if ~isastring(showCode,'on','off'),
0101 error('Incorrect value for ''code'' (type ''help <a href="matlab:help DBExportGallery">DBExportGallery</a>'' for details).');
0102 end
0103
0104 otherwise,
0105 error(['Unknown property ''' num2str(varargin{j}) ''' (type ''help <a href="matlab:help DBExportGallery">DBExportGallery</a>'' for details).']);
0106
0107 end
0108 end
0109
0110 showInfo = strcmp(showInfo,'on');
0111 showCode = strcmp(showCode,'on');
0112
0113
0114 query = strtrim(query);
0115 fullQuery = regexprep(query,'^where','');
0116 if ~isempty(fullQuery), fullQuery = [' where ' fullQuery]; end
0117
0118
0119 f = mym(['select png,eid,name,parameters,comments,mfiles,code,date,user from figures' fullQuery]);
0120 if isempty(f.eid),
0121 warning(['No figures match ''' query '''.']);
0122 end
0123
0124
0125 code = {};
0126 for i = 1:length(f.code),
0127 for j = 1:length(f.code{i}),
0128 code{i}{j} = char(f.code{i}{j})';
0129 end
0130 end
0131 f.code = code;
0132
0133
0134 nFigures = length(f.png);
0135 for i = 1:nFigures,
0136 f.eid{i} = strrep(f.eid{i},'/','_');
0137 f.name{i} = strrep(f.name{i},'/','_');
0138 end
0139
0140
0141 try
0142 mkdir(name);
0143 mkdir([name '/images']);
0144 mkdir([name '/thumbs']);
0145 if showCode,
0146 mkdir([name '/code']);
0147 end
0148 catch
0149 error('Cannot create gallery (check file access permissions).');
0150 end
0151 [path,name] = fileparts(name);
0152
0153
0154 for i = 1:nFigures,
0155
0156 figureName{i} = [f.eid{i} '-' f.name{i} '.png'];
0157 file = fopen([path name '/images/' figureName{i}],'wb');
0158 if file == -1,
0159 error(['Could not create figure ' figureName{i} '.']);
0160 end
0161 fwrite(file,f.png{i});
0162 fclose(file);
0163
0164
0165 pngData = imread([path name '/images/' figureName{i}],'png');
0166 [height,width,nz] = size(pngData);
0167 hScale = width/hSize;
0168 vScale = height/vSize;
0169 x = floor(1:hScale:width);
0170 y = floor(1:vScale:height);
0171 thumbnail = pngData(y,x,:);
0172 imwrite(thumbnail,[path name '/thumbs/' figureName{i}],'png');
0173
0174
0175 if showCode && ~isempty(f.code) && ~isempty(f.code{i}),
0176 file = fopen([path name '/code/' figureName{i}(1:end-4) '.m'],'w');
0177 if file == -1,
0178 error('Could not create code output.');
0179 end
0180 nFunctions = size(f.code{i},2);
0181 for j = 1:nFunctions,
0182 if j > 1, fprintf(file,'\n\n'); end
0183 fprintf(file,'%% =======================================================================================================\n');
0184 fprintf(file,['%% ' f.mfiles{i}{j} '\n']);
0185 fprintf(file,'%% =======================================================================================================\n\n\n');
0186 fprintf(file,'%s',f.code{i}{j});
0187 end
0188
0189
0190 fclose(file);
0191 end
0192 end
0193
0194
0195
0196 fid = fopen([path name '/index.html'],'w');
0197 fprintf(fid,'<?xml version="1.0" encoding="UTF-8" ?>\n');
0198 fprintf(fid,'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n');
0199 fprintf(fid,'<html xmlns="http://www.w3.org/1999/xhtml">\n');
0200 fprintf(fid,' <head>\n');
0201 fprintf(fid,' <title>%s</title>\n',name);
0202 fprintf(fid,' <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>\n');
0203 fprintf(fid,' <meta name="GENERATOR" content="FMAToolbox"/>\n');
0204 fprintf(fid,' <style type="text/css">\n');
0205 fprintf(fid,' BODY {color: #dddddd; background: #333333;margin: 1%%;\n');
0206 fprintf(fid,' font-family: sans-serif; font-size: 10pt; }\n');
0207 fprintf(fid,' A:LINK {color: #dddddd;}\n');
0208 fprintf(fid,' A:VISITED {color: #cccccc;}\n');
0209 fprintf(fid,' H1 {color: #eeeeee;}\n');
0210 fprintf(fid,' TABLE.enclosing {margin-left: auto; margin-right: auto}\n');
0211 fprintf(fid,' TD.enclosing {text-align: center; vertical-align:top; color: #dddddd; padding: 10px;background: #555555;border: 5px solid #333333;width: %dpx}\n',hSize*1.5);
0212 fprintf(fid,' TABLE.enclosed {color: #dddddd; padding: 10px 0px 0px 0px;background: #555555;width: %dpx}\n',hSize*1.5-20);
0213 fprintf(fid,' TD.left {text-align: right; color: #dddddd; padding: 0.1em 1em;background: #606060;border: 0px}\n');
0214 fprintf(fid,' TD.right {text-align: left; color: #dddddd; padding: 0.1em 1em;background: #777777;border: 0px}\n');
0215 fprintf(fid,' IMG {border: 1px solid #dddddd;}\n');
0216 fprintf(fid,' </style>\n');
0217 fprintf(fid,' </head>\n');
0218 fprintf(fid,' <body>\n');
0219 fprintf(fid,' <h1>%s</h1>\n',name);
0220 fprintf(fid,' <p>%d images (%s)<br/></p>\n',nFigures,datestr(now));
0221 fprintf(fid,' <hr/>\n');
0222 fprintf(fid,' <table class="enclosing">\n');
0223
0224
0225 nLines = ceil(nFigures/nColumns);
0226 i = 1;
0227 for line = 1:nLines,
0228 fprintf(fid,' <tr>\n');
0229 for column = 1:nColumns,
0230 if i > nFigures, break; end
0231 fprintf(fid,' <td class="enclosing">\n');
0232 fprintf(fid,' <a href="images/%s"><img src="thumbs/%s" width="%d" height="%d"></a>\n',figureName{i},figureName{i},hSize,vSize);
0233 fprintf(fid,' <table class="enclosed">\n');
0234 fprintf(fid,' <tr>\n');
0235 fprintf(fid,' <td class="left">\n');
0236 fprintf(fid,' EID\n');
0237 fprintf(fid,' </td>\n');
0238 fprintf(fid,' <td class="right">\n');
0239 fprintf(fid,' <div>%s</div>\n',f.eid{i});
0240 fprintf(fid,' </td>\n');
0241 fprintf(fid,' </tr>\n');
0242 fprintf(fid,' <tr>\n');
0243 fprintf(fid,' <td class="left">\n');
0244 fprintf(fid,' Name\n');
0245 fprintf(fid,' </td>\n');
0246 fprintf(fid,' <td class="right">\n');
0247 fprintf(fid,' <div>%s</div>\n',f.name{i});
0248 fprintf(fid,' </td>\n');
0249 fprintf(fid,' </tr>\n');
0250 if showInfo,
0251 fprintf(fid,' <tr>\n');
0252 fprintf(fid,' <td class="left">\n');
0253 fprintf(fid,' Comments\n');
0254 fprintf(fid,' </td>\n');
0255 fprintf(fid,' <td class="right">\n');
0256 fprintf(fid,' <div>%s</div>\n',f.comments{i});
0257 fprintf(fid,' </td>\n');
0258 fprintf(fid,' </tr>\n');
0259 fprintf(fid,' <tr>\n');
0260 fprintf(fid,' <td class="left">\n');
0261 fprintf(fid,' Parameters\n');
0262 fprintf(fid,' </td>\n');
0263 fprintf(fid,' <td class="right">\n');
0264 fprintf(fid,' <div>%s</div>\n',f.parameters{i});
0265 fprintf(fid,' </td>\n');
0266 fprintf(fid,' </tr>\n');
0267 end
0268 if showCode && ~isempty(f.code) && ~isempty(f.code{i}),
0269 codeName = [figureName{i}(1:end-4) '.m'];
0270 fprintf(fid,' <tr>\n');
0271 fprintf(fid,' <td class="left">\n');
0272 fprintf(fid,' Code\n');
0273 fprintf(fid,' </td>\n');
0274 fprintf(fid,' <td class="right">\n');
0275 fprintf(fid,' <a href="code/%s">[M-File]</a>\n',codeName);
0276 fprintf(fid,' </td>\n');
0277 fprintf(fid,' </tr>\n');
0278 end
0279 if showInfo,
0280 fprintf(fid,' <tr>\n');
0281 fprintf(fid,' <td class="left">\n');
0282 fprintf(fid,' Date\n');
0283 fprintf(fid,' </td>\n');
0284 fprintf(fid,' <td class="right">\n');
0285 fprintf(fid,' <div>%s</div>\n',f.date{i});
0286 fprintf(fid,' </td>\n');
0287 fprintf(fid,' </tr>\n');
0288 fprintf(fid,' <tr>\n');
0289 fprintf(fid,' <td class="left">\n');
0290 fprintf(fid,' User\n');
0291 fprintf(fid,' </td>\n');
0292 fprintf(fid,' <td class="right">\n');
0293 fprintf(fid,' <div>%s</div>\n',f.user{i});
0294 fprintf(fid,' </td>\n');
0295 fprintf(fid,' </tr>\n');
0296 end
0297 fprintf(fid,' </table>\n');
0298 fprintf(fid,' </td>\n');
0299 i = i+1;
0300 end
0301 fprintf(fid,' </tr>\n');
0302 end
0303
0304
0305 fprintf(fid,' </table>\n');
0306 fprintf(fid,' </body>\n');
0307 fprintf(fid,'</html>\n');