comparison m-toolbox/classes/@ao/validate.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % VALIDATE checks that the input Analysis Object is reproducible and valid.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: VALIDATE checks that the input Analysis Object is
5 % reproducible and valid.
6 %
7 % CALL: b = validate(a)
8 %
9 % INPUTS: a - a vector, matrix or cell array of Analysis Objects
10 %
11 % OUTPUTS: b - a vector, matrix or cell array of logical results:
12 % 0 - input object failed
13 % 1 - input object passed
14 %
15 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'validate')">Parameters Description</a>
16 %
17 % VERSION: $Id: validate.m,v 1.15 2011/04/08 08:56:12 hewitson Exp $
18 %
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20
21 function varargout = validate(varargin)
22
23 % Check if this is a call for parameters
24 if utils.helper.isinfocall(varargin{:})
25 varargout{1} = getInfo(varargin{3});
26 return
27 end
28
29 import utils.const.*
30 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
31
32 % Collect input variable names
33 in_names = cell(size(varargin));
34 for ii = 1:nargin,in_names{ii} = inputname(ii);end
35
36 % Collect all AOs and plists
37 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
38
39 % --- Initial set up
40 versions = []; % initialised with function: ltpda_versions
41 ltpda_versions;
42 passed = zeros(1, numel(as));
43
44 % Check each input analysis object
45 for ec=1:numel(as)
46 % get a list of files that built this object
47 [n,a,nodes] = getNodes(as(ec).hist);
48
49 % Initialise the match vector
50 matches = zeros(length(nodes),1);
51
52 % Loop over each history node, i.e., each function
53 for jj=1:length(nodes)
54 % This node
55 node = nodes(jj);
56 % Assume failure to start with
57 matches(jj) = 0;
58 % get fcn name
59 fcnname = node.names;
60 % Find all functions in MATLAB path with this name
61 mfiles = which(fcnname, '-ALL');
62 % Find all matches in versions{}
63 idx = ismember(versions(:,2), fcnname);
64 ltpdafiles = versions(find(idx==1), 1);
65 % check against each one found
66 for kk=1:length(mfiles)
67 mfile = mfiles{kk};
68 % make file hash
69 try
70 % Load the full file contents
71 fd = fopen(mfile, 'r');
72 fc = fscanf(fd, '%s');
73 fclose(fd);
74 % Make MD5 hash
75 mhash = utils.prog.hash(fc, 'MD5');
76 % Check against all ltpda files with this function name
77 for ll=1:length(ltpdafiles)
78 % this file
79 lfile = ltpdafiles{ll};
80 % Load file contents
81 fd = fopen(lfile, 'r');
82 fc = fscanf(fd, '%s');
83 fclose(fd);
84 % Make MD5 hash
85 lhash = utils.prog.hash(fc, 'MD5');
86 % Compares hashes
87 if strcmp(mhash, lhash)
88 matches(jj) = 1;
89 end
90 end
91 catch
92 warning('!!! failed to test against: %s', mfile);
93 end
94 end % End loop over files on MATLAB path
95
96 if matches(jj)==0
97 fails = which(fcnname, '-ALL');
98 for ff=1:length(fails)
99 utils.helper.msg(msg.PROC1, 'Illegal function: %s', fails{ff});
100 end
101 end
102 end % end loop over nodes
103
104 % Decide whether or not this AO is valid
105 if sum(matches) == length(nodes)
106 passed(ec) = 1;
107 utils.helper.msg(msg.PROC1, 'AO validated');
108 else
109 passed(ec) = 0;
110 utils.helper.msg(msg.PROC1, 'AO not validated');
111 end
112 end % end loop over all objects
113
114 % Set outputs
115 varargout{1} = passed;
116 end
117
118 %--------------------------------------------------------------------------
119 % Get Info Object
120 %--------------------------------------------------------------------------
121 function ii = getInfo(varargin)
122 if nargin == 1 && strcmpi(varargin{1}, 'None')
123 sets = {};
124 pl = [];
125 else
126 sets = {'Default'};
127 pl = getDefaultPlist;
128 end
129 % Build info object
130 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.helper, '$Id: validate.m,v 1.15 2011/04/08 08:56:12 hewitson Exp $', sets, pl);
131 ii.setModifier(false);
132 end
133
134 %--------------------------------------------------------------------------
135 % Get Default Plist
136 %--------------------------------------------------------------------------
137 function plout = getDefaultPlist()
138 persistent pl;
139 if exist('pl', 'var')==0 || isempty(pl)
140 pl = buildplist();
141 end
142 plout = pl;
143 end
144
145 function pl = buildplist()
146 pl = plist.EMPTY_PLIST;
147 end
148 % END
149