1 |
gforget |
1.1 |
function [report0]=diff_mat(file1,dir2,varargin); |
2 |
|
|
%object: compute the %rms difference between fields in two mat files |
3 |
|
|
%inputs: file1 is the file to compare with a reference |
4 |
|
|
% dir2 is the reference file directory |
5 |
|
|
%optional: file2 is the reference file (file1 by default) |
6 |
|
|
%output: cell array containing the % rms difference display per field |
7 |
|
|
|
8 |
|
|
if nargin>2; file2=varargin{1}; else; file2=file1; end; |
9 |
|
|
|
10 |
|
|
new=open(file1); old=open([dir2 file2]); |
11 |
|
|
|
12 |
|
|
%new list of fields: |
13 |
|
|
%=================== |
14 |
|
|
IInew=fieldnames(new); NInew=length(IInew); |
15 |
|
|
%extend to structure fields: |
16 |
|
|
JJ={}; |
17 |
|
|
for ii=1:NInew; |
18 |
|
|
tmp0=IInew{ii}; tmp1=getfield(new,tmp0); |
19 |
|
|
if isstruct(tmp1); |
20 |
|
|
tmp2=fieldnames(tmp1); |
21 |
|
|
for jj=1:length(tmp2); JJ{length(JJ)+1}=[tmp0 '.' tmp2{jj}]; end; |
22 |
|
|
else; |
23 |
|
|
JJ{length(JJ)+1}=tmp0; |
24 |
|
|
end; |
25 |
|
|
end; |
26 |
|
|
%overwrite list of fields: |
27 |
|
|
IInew=JJ; NInew=length(IInew); |
28 |
|
|
|
29 |
|
|
%old list of fields: |
30 |
|
|
%=================== |
31 |
|
|
IIold=fieldnames(old); NIold=length(IIold); |
32 |
|
|
%extend to structure fields: |
33 |
|
|
JJ={}; |
34 |
|
|
for ii=1:NIold; |
35 |
|
|
tmp0=IIold{ii}; tmp1=getfield(old,tmp0); |
36 |
|
|
if isstruct(tmp1); |
37 |
|
|
tmp2=fieldnames(tmp1); |
38 |
|
|
for jj=1:length(tmp2); JJ{length(JJ)+1}=[tmp0 '.' tmp2{jj}]; end; |
39 |
|
|
else; |
40 |
|
|
JJ{length(JJ)+1}=tmp0; |
41 |
|
|
end; |
42 |
|
|
end; |
43 |
|
|
%overwrite list of fields: |
44 |
|
|
IIold=JJ; NIold=length(IIold); |
45 |
|
|
|
46 |
|
|
%compare new to old fields: |
47 |
|
|
%========================== |
48 |
|
|
report0={}; |
49 |
|
|
report1={}; |
50 |
|
|
for ii=1:NInew; |
51 |
|
|
test0=isempty(find(strcmp(IIold,IInew{ii}))); |
52 |
|
|
test1=strfind(IInew{ii},'gcm2faces'); |
53 |
|
|
if test0; |
54 |
|
|
txt0=sprintf(['new contains ' IInew{ii} ' BUT ref does not']); |
55 |
|
|
report1{length(report1)+1,1}=txt0; |
56 |
|
|
elseif test1; |
57 |
|
|
txt0=sprintf(['test of ' IInew{ii} ' was omitted']); |
58 |
|
|
report1{length(report1)+1,1}=txt0; |
59 |
|
|
else; |
60 |
|
|
tmp0=IInew{ii}; tmp00=strfind(tmp0,'.'); |
61 |
|
|
if isempty(tmp00); |
62 |
|
|
%get the field: |
63 |
|
|
tmp1=getfield(new,IInew{ii}); tmp2=getfield(old,IInew{ii}); |
64 |
|
|
elseif length(tmp00)==1; |
65 |
|
|
%get the sub field: |
66 |
|
|
tmp11=IInew{ii}(1:tmp00-1); |
67 |
|
|
tmp1=getfield(new,tmp11); tmp2=getfield(old,tmp11); |
68 |
|
|
tmp11=IInew{ii}(tmp00+1:end); |
69 |
|
|
tmp1=getfield(tmp1,tmp11); tmp2=getfield(tmp2,tmp11); |
70 |
|
|
else; |
71 |
|
|
error(sprintf('cannot compare %s',tmp0)); |
72 |
|
|
end; |
73 |
|
|
%do the comparison: |
74 |
|
|
if isa(tmp1,'double')|isa(tmp1,'gcmfaces'); |
75 |
|
|
%add blanks for display: |
76 |
|
|
tmp11=ceil(length(tmp0)/10)*10-length(tmp0); tmp11=char(32*ones(1,tmp11)); |
77 |
|
|
%compute difference: |
78 |
|
|
tmp22=nanstd(tmp1(:))^2; if tmp22==0; tmp22=nanmean( tmp1(:).^2 ); end; |
79 |
|
|
tmp22=100*sqrt(nanmean( (tmp1(:)-tmp2(:)).^2 )./tmp22); |
80 |
|
|
%full text for display: |
81 |
|
|
txt0=[tmp0 tmp11]; |
82 |
|
|
%txt0=sprintf('%s differs by %i%% from %s',txt0,round(tmp22),[dir2 file2]); |
83 |
|
|
txt0=sprintf('%s diff by %i%%',txt0,round(tmp22)); |
84 |
|
|
%do display: |
85 |
|
|
if tmp22~=0; fprintf([txt0 '\n']); end; |
86 |
|
|
%add to report: |
87 |
|
|
report0{length(report0)+1,1}=txt0; |
88 |
|
|
end; |
89 |
|
|
end; |
90 |
|
|
end; |
91 |
|
|
|
92 |
|
|
%compare old field to new fields: |
93 |
|
|
%================================ |
94 |
|
|
report2={}; |
95 |
|
|
for ii=1:NIold; |
96 |
|
|
test0=~isempty(find(strcmp(IInew,IIold{ii}))); |
97 |
|
|
if ~test0; |
98 |
|
|
txt0=sprintf(['ref contains ' IIold{ii} ' BUT new does not']); |
99 |
|
|
report2{length(report2)+1,1}=txt0; |
100 |
|
|
end; |
101 |
|
|
end; |
102 |
|
|
|
103 |
|
|
%combine the various reports: |
104 |
|
|
%============================ |
105 |
|
|
report0={report0{:} report1{:}}'; |
106 |
|
|
report0={report0{:} report2{:}}'; |
107 |
|
|
|