0001 function DBAddFigure(f,eid,name,comments,parameters,mfiles,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 global dbUser;
0046
0047
0048 CheckMyM;
0049
0050
0051 if nargin < 6,
0052 error('Incorrect number of parameters (type ''help <a href="matlab:help DBAddFigure">DBAddFigure</a>'' for details).');
0053 end
0054
0055
0056 onlyPNG = 'off';
0057
0058
0059 if ~ishandle(f),
0060 error('Incorrect figure handle (type ''help <a href="matlab:help DBAddFigure">DBAddFigure</a>'' for details).');
0061 end
0062 if ~ischar(eid),
0063 error('Incorrect EID string (type ''help <a href="matlab:help DBAddFigure">DBAddFigure</a>'' for details).');
0064 end
0065 if ~ischar(name),
0066 error('Incorrect figure name (type ''help <a href="matlab:help DBAddFigure">DBAddFigure</a>'' for details).');
0067 end
0068 if ~isempty(strfind(eid,'/')) || ~isempty(strfind(name,'/')),
0069 error('EIDs and names should not contain ''/'' (type ''help <a href="matlab:help DBAddFigure">DBAddFigure</a>'' for details).');
0070 end
0071 if ~ischar(comments),
0072 error('Incorrect comment string (type ''help <a href="matlab:help DBAddFigure">DBAddFigure</a>'' for details).');
0073 end
0074 if ~ischar(parameters),
0075 error('Incorrect figure parameters (type ''help <a href="matlab:help DBAddFigure">DBAddFigure</a>'' for details).');
0076 end
0077 if ~ischar(mfiles) && ~iscell(mfiles),
0078 error('Incorrect list of m-files (type ''help <a href="matlab:help DBAddFigure">DBAddFigure</a>'' for details).');
0079 end
0080 if ischar(mfiles),
0081 mfiles = {mfiles};
0082 end
0083
0084
0085 for i = 1:2:length(varargin),
0086 if ~ischar(varargin{i}),
0087 error(['Parameter ' num2str(i+firstIndex) ' is not a property (type ''help <a href="matlab:help DBAddFigure">DBAddFigure</a>'' for details).']);
0088 end
0089 switch(lower(varargin{i})),
0090 case 'onlypng',
0091 onlyPNG = lower(varargin{i+1});
0092 if ~isastring(onlyPNG,'on','off'),
0093 error('Incorrect value for property ''onlypng'' (type ''help <a href="matlab:help DBAddFigure">DBAddFigure</a>'' for details).');
0094 end
0095 otherwise,
0096 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help DBAddFigure">DBAddFigure</a>'' for details).']);
0097 end
0098 end
0099
0100 onlyPNG = strcmp(onlyPNG,'on');
0101
0102 basename = tempname;
0103 figName = [basename '.fig'];
0104 pngName = [basename '.png'];
0105 if ~onlyPNG,
0106 try
0107
0108 saveas(f,figName);
0109 catch
0110 error('Could not create temporary file for fig figure.');
0111 end
0112 end
0113 try
0114
0115 if ~isempty(which('export_fig')),
0116 export_fig(f,pngName,'-png','-a1');
0117 else
0118 saveas(f,pngName);
0119 end
0120 catch
0121 error('Could not create temporary file for png figure.');
0122 end
0123
0124
0125 code{1} = '';
0126 for i = 1:length(mfiles),
0127 mfileName = which(mfiles{i});
0128 if isempty(mfileName),
0129 error(['M-File for function ''' mfiles{i} ''' not found.']);
0130 end
0131 fid = fopen(mfileName);
0132 code{i} = fread(fid);
0133 fclose(fid);
0134 end
0135
0136
0137 d = datestr(now);
0138 md5 = CalcMD5(pngName);
0139
0140
0141 if onlyPNG,
0142 h = mym(['insert into figures (eid,name,comments,parameters,mfiles,code,date,user,md5,png) values ("{S}","{S}","{S}","{S}","{M}","{M}","{S}","{S}","{Si}","{uF}")'],eid,name,comments,parameters,mfiles,code,d,dbUser,md5,pngName);
0143 else
0144 h = mym(['insert into figures (eid,name,comments,parameters,mfiles,code,date,user,md5,fig,png) values ("{S}","{S}","{S}","{S}","{M}","{M}","{S}","{S}","{Si}","{F}","{uF}")'],eid,name,comments,parameters,mfiles,code,d,dbUser,md5,figName,pngName);
0145 end
0146
0147
0148 if ~onlyPNG,
0149 delete(figName);
0150 end
0151 delete(pngName);