1 function [relerr,ssq,p,name]=ncdiff(file1,file2,var)
2 % [relerr,ssq,p,name]=ncdiff(file1,file2,var)
3 % compare variable var in 2 netcdf files
4 % if var is missing, compare all variables
5 % return structure s with fiels:
6 % relerr = max relative difference
7 % ssq = square mean relative difference
8 % p = p-value, close to +1 -1 means errors significantly in one direction
9 % for rounding errors expect relerr=const*eps, p small
10 % name = variable name
11 if ~exist('var','var'),
16 [relerr(i),ssq(i),p(i),name{i}]=ncdiff(file1,file2,var);
23 disp('Finished comparing files')
27 fprintf('%s relative diff %g p-value %g\n',name{i},relerr(i),p(i))
35 if length(s1) ~= length(s2),
36 error([var,' must be same numer of dimensions 1: ',num2str(s1),' 2: ',num2str(s2)])
39 warning(['using minimum size of 1:', num2str(s1),' 2: ',num2str(s2)])
41 s(1:length(s1))=min(s1,s2);
42 v1=v1(1:s(1),1:s(2),1:s(3),1:s(4));
43 v2=v2(1:s(1),1:s(2),1:s(3),1:s(4));
47 [relerr,ssq,p]=ncdiffvars('total',v1,v2);
50 s=['slice ',num2str(i)];
53 ncdiffvars(s,v1(:,:,:,i),v2(:,:,:,i));
55 ncdiffvars(s,v1(:,:,i),v2(:,:,i));