VALIDATE checks that the input Analysis Object is reproducible and valid. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: VALIDATE checks that the input Analysis Object is reproducible and valid. CALL: b = validate(a) INPUTS: a - a vector, matrix or cell array of Analysis Objects OUTPUTS: b - a vector, matrix or cell array of logical results: 0 - input object failed 1 - input object passed M-FILE INFO: Get information about this methods by calling >> ao.getInfo('validate') Get information about a specified set-plist by calling: >> ao.getInfo('validate', 'None') VERSION: $Id: validate.m,v 1.6 2008/09/05 11:05:29 ingo Exp $ HISTORY: 22-02-08 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 % VALIDATE checks that the input Analysis Object is reproducible and valid. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: VALIDATE checks that the input Analysis Object is 0005 % reproducible and valid. 0006 % 0007 % CALL: b = validate(a) 0008 % 0009 % INPUTS: a - a vector, matrix or cell array of Analysis Objects 0010 % 0011 % OUTPUTS: b - a vector, matrix or cell array of logical results: 0012 % 0 - input object failed 0013 % 1 - input object passed 0014 % 0015 % M-FILE INFO: Get information about this methods by calling 0016 % >> ao.getInfo('validate') 0017 % 0018 % Get information about a specified set-plist by calling: 0019 % >> ao.getInfo('validate', 'None') 0020 % 0021 % VERSION: $Id: validate.m,v 1.6 2008/09/05 11:05:29 ingo Exp $ 0022 % 0023 % HISTORY: 22-02-08 M Hewitson 0024 % Creation 0025 % 0026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0027 0028 function varargout = validate(varargin) 0029 0030 % Check if this is a call for parameters 0031 if utils.helper.isinfocall(varargin{:}) 0032 varargout{1} = getInfo(varargin{3}); 0033 return 0034 end 0035 0036 import utils.const.* 0037 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); 0038 0039 % Collect input variable names 0040 in_names = cell(size(varargin)); 0041 for ii = 1:nargin,in_names{ii} = inputname(ii);end 0042 0043 % Collect all AOs and plists 0044 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); 0045 0046 % --- Initial set up 0047 versions = []; % initialised with function: ltpda_versions 0048 ltpda_versions; 0049 passed = zeros(1, numel(as)); 0050 0051 % Check each input analysis object 0052 for ec=1:numel(as) 0053 % get a list of files that built this object 0054 [n,a,nodes] = getNodes(as(ec).hist, [] ,0,1,[]); 0055 0056 % Initialise the match vector 0057 matches = zeros(length(nodes),1); 0058 0059 % Loop over each history node, i.e., each function 0060 for jj=1:length(nodes) 0061 % This node 0062 node = nodes(jj); 0063 % Assume failure to start with 0064 matches(jj) = 0; 0065 % get fcn name 0066 fcnname = node.names; 0067 % Find all functions in MATLAB path with this name 0068 mfiles = which(fcnname, '-ALL'); 0069 % Find all matches in versions{} 0070 idx = ismember(versions(:,2), fcnname); 0071 ltpdafiles = versions(find(idx==1), 1); 0072 % check against each one found 0073 for kk=1:length(mfiles) 0074 mfile = mfiles{kk}; 0075 % make file hash 0076 try 0077 % Load the full file contents 0078 fd = fopen(mfile, 'r'); 0079 fc = fscanf(fd, '%s'); 0080 fclose(fd); 0081 % Make MD5 hash 0082 mhash = utils.prog.hash(fc, 'MD5'); 0083 % Check against all ltpda files with this function name 0084 for ll=1:length(ltpdafiles) 0085 % this file 0086 lfile = ltpdafiles{ll}; 0087 % Load file contents 0088 fd = fopen(lfile, 'r'); 0089 fc = fscanf(fd, '%s'); 0090 fclose(fd); 0091 % Make MD5 hash 0092 lhash = utils.prog.hash(fc, 'MD5'); 0093 % Compares hashes 0094 if strcmp(mhash, lhash) 0095 matches(jj) = 1; 0096 end 0097 end 0098 catch 0099 warning('!!! failed to test against: %s', mfile); 0100 end 0101 end % End loop over files on MATLAB path 0102 0103 if matches(jj)==0 0104 fails = which(fcnname, '-ALL'); 0105 for ff=1:length(fails) 0106 utils.helper.msg(msg.PROC1, 'Illegal function: %s', fails{ff}); 0107 end 0108 end 0109 end % end loop over nodes 0110 0111 % Decide whether or not this AO is valid 0112 if sum(matches) == length(nodes) 0113 passed(ec) = 1; 0114 utils.helper.msg(msg.PROC1, 'AO validated'); 0115 else 0116 passed(ec) = 0; 0117 utils.helper.msg(msg.PROC1, 'AO not validated'); 0118 end 0119 end % end loop over all objects 0120 0121 % Set outputs 0122 varargout{1} = passed; 0123 end 0124 0125 %-------------------------------------------------------------------------- 0126 % Get Info Object 0127 %-------------------------------------------------------------------------- 0128 function ii = getInfo(varargin) 0129 if nargin == 1 && strcmpi(varargin{1}, 'None') 0130 sets = {}; 0131 pl = []; 0132 else 0133 sets = {'Default'}; 0134 pl = getDefaultPlist; 0135 end 0136 % Build info object 0137 ii = minfo(mfilename, 'ao', '', utils.const.categories.helper, '$Id: validate.m,v 1.6 2008/09/05 11:05:29 ingo Exp $', sets, pl); 0138 end 0139 0140 %-------------------------------------------------------------------------- 0141 % Get Default Plist 0142 %-------------------------------------------------------------------------- 0143 function pl_default = getDefaultPlist() 0144 pl_default = plist(); 0145 end 0146 % END 0147