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 VERSION: $Id: validate.html,v 1.4 2008/03/31 10:27:33 hewitson Exp $ The following call returns a parameter list object that contains the default parameter values: >> pl = validate(ao, 'Params') The following call returns a string that contains the routine CVS version: >> version = validate(ao,'Version') The following call returns a string that contains the routine category: >> category = validate(ao,'Category') HISTORY: 22-02-08 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function varargout = validate(varargin) 0002 % VALIDATE checks that the input Analysis Object is reproducible and valid. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: VALIDATE checks that the input Analysis Object is 0007 % reproducible and valid. 0008 % 0009 % CALL: b = validate(a) 0010 % 0011 % INPUTS: 0012 % a - a vector, matrix or cell array of Analysis Objects 0013 % 0014 % OUTPUTS: 0015 % 0016 % b - a vector, matrix or cell array of logical results: 0017 % 0 - input object failed 0018 % 1 - input object passed 0019 % 0020 % 0021 % VERSION: $Id: validate.html,v 1.4 2008/03/31 10:27:33 hewitson Exp $ 0022 % 0023 % The following call returns a parameter list object that contains the 0024 % default parameter values: 0025 % 0026 % >> pl = validate(ao, 'Params') 0027 % 0028 % The following call returns a string that contains the routine CVS version: 0029 % 0030 % >> version = validate(ao,'Version') 0031 % 0032 % The following call returns a string that contains the routine category: 0033 % 0034 % >> category = validate(ao,'Category') 0035 % 0036 % HISTORY: 22-02-08 M Hewitson 0037 % Creation 0038 % 0039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0040 0041 ALGONAME = mfilename; 0042 VERSION = '$Id: validate.html,v 1.4 2008/03/31 10:27:33 hewitson Exp $'; 0043 CATEGORY = 'Helper'; 0044 bs = []; 0045 0046 % Check if this is a call for parameters 0047 if nargin == 2 0048 if isa(varargin{1}, 'ao') && ischar(varargin{2}) 0049 in = char(varargin{2}); 0050 if strcmp(in, 'Params') 0051 varargout{1} = getDefaultPL(); 0052 return 0053 elseif strcmp(in, 'Version') 0054 varargout{1} = VERSION; 0055 return 0056 elseif strcmp(in, 'Category') 0057 varargout{1} = CATEGORY; 0058 return 0059 end 0060 end 0061 end 0062 0063 % Collect input ao's, plist's and ao variable names 0064 in_names = {}; 0065 for ii = 1:nargin 0066 in_names{end+1} = inputname(ii); 0067 end 0068 0069 [aos, ps, invars] = collect_inputs(varargin, in_names); 0070 0071 0072 % --- Initial set up 0073 ltpda_versions; 0074 passed = zeros(1, numel(aos)); 0075 0076 % Check each input analysis object 0077 for ec=1:numel(aos) 0078 0079 %----- Check this object against the list 0080 obj = aos(ec); 0081 0082 0083 % get a list of files that built this object 0084 [n,a,nodes] = getNodes(obj.hist, [] ,0,1,[]); 0085 0086 % Initialise the match vector 0087 matches = zeros(length(nodes),1); 0088 0089 % Loop over each history node, i.e., each function 0090 for jj=1:length(nodes) 0091 0092 % This node 0093 node = nodes(jj); 0094 % Assume failure to start with 0095 matches(jj) = 0; 0096 0097 % get fcn name 0098 fcnname = node.names; 0099 0100 % Find all functions in MATLAB path with this name 0101 mfiles = which(fcnname, '-ALL'); 0102 0103 % Find all matches in versions{} 0104 idx = ismember(versions(:,2), fcnname); 0105 ltpdafiles = versions(find(idx==1), 1); 0106 0107 % check against each one found 0108 for kk=1:length(mfiles) 0109 mfile = mfiles{kk}; 0110 0111 % make file hash 0112 try 0113 % Load the full file contents 0114 fd = fopen(mfile, 'r'); 0115 fc = fscanf(fd, '%s'); 0116 fclose(fd); 0117 % Make MD5 hash 0118 mhash = ltpda_hash(fc, 'MD5'); 0119 0120 % Check against all ltpda files with this function name 0121 for ll=1:length(ltpdafiles) 0122 % this file 0123 lfile = ltpdafiles{ll}; 0124 % Load file contents 0125 fd = fopen(lfile, 'r'); 0126 fc = fscanf(fd, '%s'); 0127 fclose(fd); 0128 % Make MD5 hash 0129 lhash = ltpda_hash(fc, 'MD5'); 0130 0131 % Compares hashes 0132 if strcmp(mhash, lhash) 0133 matches(jj) = 1; 0134 end 0135 end 0136 catch 0137 warning('!!! failed to test against: %s', mfile); 0138 end 0139 end % End loop over files on MATLAB path 0140 0141 if matches(jj)==0 0142 fails = which(fcnname, '-ALL'); 0143 for ff=1:length(fails) 0144 disp(sprintf('!!!! Illegal function: %s', fails{ff})); 0145 end 0146 end 0147 end % end loop over nodes 0148 0149 % Decide whether or not this AO is valid 0150 if sum(matches) == length(nodes) 0151 passed(ec) = 1; 0152 disp('*** AO validated') 0153 else 0154 passed(ec) = 0; 0155 disp('### AO not validated') 0156 end 0157 end % end loop over all objects 0158 0159 % Set outputs 0160 varargout{1} = passed; 0161 0162 % END