1% Test ncBaseArray, ncCatArray and ncArray.
2function test_ncarray_nan()
3
4% for octave prior to 3.8.0
5if isempty(which('isequaln'))
6  isequaln = @(x,y) isequalwithequalnans(x,y);
7end
8
9varname = 'SST';
10
11tmpdir = tempname;
12mkdir(tmpdir);
13
14tmpfname = tempname(tmpdir);
15dataref = randn(220,144,3);
16%dataref(rand(size(dataref)) > 0.7) = NaN;
17dataref(50:80,30:90,1:2) = NaN;
18
19for i = 1:3
20  files{i} = fullfile(tmpdir,sprintf('file%d.nc',i));
21  ncarray_example_file(files{i},dataref(:,:,i));
22end
23
24data = ncCatArray(3,files,varname);
25reddata = nanmean(data,3);
26reddataref = nanmean(dataref,3);
27assertAlmostEqual(reddata, reddataref)
28
29reddata = nansum(data,3);
30reddataref = nansum(dataref,3);
31assertAlmostEqual(reddata, reddataref)
32
33reddata = nanvar(data,[],3);
34reddataref = nanvar(dataref,[],3);
35diff = reddata - reddataref;
36assert(max(diff(:)) < 1e-6)
37
38reddata = nanstd(data,[],3);
39reddataref = nanstd(dataref,[],3);
40diff = reddata - reddataref;
41assert(max(diff(:)) < 1e-6)
42
43% clean-up
44for i = 1:3
45  delete(files{i});
46end
47rmdir(tmpdir);
48
49
50
51
52% Copyright (C) 2013 Alexander Barth <barth.alexander@gmail.com>
53%
54% This program is free software; you can redistribute it and/or modify
55% it under the terms of the GNU General Public License as published by
56% the Free Software Foundation; either version 2 of the License, or
57% (at your option) any later version.
58%
59% This program is distributed in the hope that it will be useful,
60% but WITHOUT ANY WARRANTY; without even the implied warranty of
61% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
62% GNU General Public License for more details.
63%
64% You should have received a copy of the GNU General Public License
65% along with this program; If not, see <http://www.gnu.org/licenses/>.
66
67