0001 function DBAddVariable(v,eid,name,parameters,comments,mfiles)
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 global dbUser;
0041 defaultMaxSize = 2^16-1;
0042
0043
0044 CheckMyM;
0045
0046
0047 if nargin < 6,
0048 error('Incorrect number of parameters (type ''help <a href="matlab:help DBAddVariable">DBAddVariable</a>'' for details).');
0049 end
0050
0051
0052 if ~ischar(eid),
0053 error('Incorrect EID string (type ''help <a href="matlab:help DBAddVariable">DBAddVariable</a>'' for details).');
0054 end
0055 if ~ischar(name),
0056 error('Incorrect figure name (type ''help <a href="matlab:help DBAddVariable">DBAddVariable</a>'' for details).');
0057 end
0058 if ~isempty(strfind(eid,'/')) || ~isempty(strfind(name,'/')),
0059 error('EIDs and names should not contain ''/'' (type ''help <a href="matlab:help DBAddVariable">DBAddVariable</a>'' for details).');
0060 end
0061 if ~ischar(comments),
0062 error('Incorrect comment string (type ''help <a href="matlab:help DBAddVariable">DBAddVariable</a>'' for details).');
0063 end
0064 if isempty(comments),
0065 comments = '-';
0066 end
0067 if ~ischar(parameters),
0068 error('Incorrect figure parameters (type ''help <a href="matlab:help DBAddVariable">DBAddVariable</a>'' for details).');
0069 end
0070 if ~ischar(mfiles) && ~iscell(mfiles),
0071 error('Incorrect list of m-files (type ''help <a href="matlab:help DBAddVariable">DBAddVariable</a>'' for details).');
0072 end
0073 if ischar(mfiles),
0074 mfiles = {mfiles};
0075 end
0076
0077
0078 code = '';
0079 for i = 1:length(mfiles),
0080 mfileName = which(mfiles{i});
0081 if isempty(mfileName),
0082 error(['M-File for function ''' mfiles{i} ''' not found.']);
0083 end
0084 fid = fopen(mfileName);
0085 code{i} = fread(fid);
0086 fclose(fid);
0087 end
0088
0089
0090 d = datestr(now);
0091 try
0092 md5 = CalcMD5(v);
0093 catch
0094 warning('Could not compute MD5 (works only for numeric arrays)');
0095 md5 = 0;
0096 end
0097
0098
0099 warning('off','FMAToolbox:GetCustomDefaults:UsingCustomDefaults');
0100 maxSize = GetCustomDefaults([],'maxsize',defaultMaxSize);
0101 warning('on','FMAToolbox:GetCustomDefaults:UsingCustomDefaults');
0102 storage = DBExternalStoragePath;
0103 s = whos('v');
0104 if s.bytes > maxSize,
0105
0106 targetDirectory = [storage '/' DBUse];
0107 if ~isdir(targetDirectory), mkdir(targetDirectory); end
0108 if ~isdir([targetDirectory '/variables']), mkdir([targetDirectory '/variables']); end
0109 matFile = [targetDirectory '/variables/' eid '-' name '.mat'];
0110 h = mym(['insert into variables (eid,name,comments,parameters,mfiles,code,date,user,md5,v) values ("{S}","{S}","{S}","{S}","{M}","{M}","{S}","{S}","{Si}","{M}")'],eid,name,comments,parameters,mfiles,code,d,dbUser,md5,matFile);
0111 save(matFile,'v');
0112 else
0113
0114 h = mym(['insert into variables (eid,name,comments,parameters,mfiles,code,date,user,md5,v) values ("{S}","{S}","{S}","{S}","{M}","{M}","{S}","{S}","{Si}","{M}")'],eid,name,comments,parameters,mfiles,code,d,dbUser,md5,v);
0115 end