%tests getcdf_batch which can handle 2 or 4 input arguments.

%First retrieve a matrix

x1 = getcdf_batch('testjm', 'u', [-1 -1], [2 2], [1 1], 1, 2, 0);
c_x1 = isnan(x1);
ss = sum(sum(c_x1))

x2 = getcdf_batch('testjm', 'u');
c_x2 = isnan(x2);
nanrange(x1 - x2)
nanrange(c_x1 - c_x2)

x2 = getcdf_batch('testjm', 'u', [-1 -1], [2 2]);
c_x2 = isnan(x2);
nanrange(x1 - x2)
nanrange(c_x1 - c_x2)

x2 = getcdf_batch('testjm', 'u', [1 1], [12 11]);
c_x2 = isnan(x2);
nanrange(x1 - x2)
nanrange(c_x1 - c_x2)

x2 = getcdf_batch('testjm', 'u', [2 3], [9 10]);
c_x2 = isnan(x2);
nanrange(x1(3:10, 2:9) - x2)
nanrange(c_x1(3:10, 2:9) - c_x2)

x2 = getcdf_batch('testjm', 'u', [2 3], [2 10]);
c_x2 = isnan(x2);
nanrange(x1(3:10, 2:2)' - x2)
nanrange(c_x1(3:10, 2:2)' - c_x2)

%Next retrieve a vector

x1 = getcdf_batch('testjm', 'depth1', [-1], [2], [1], 1, 2, 0);
c_x1 = isnan(x1);
ss = sum(sum(c_x1))

x2 = getcdf_batch('testjm', 'depth1');
c_x2 = isnan(x2);
nanrange(x1 - x2)
nanrange(c_x1 - c_x2)

x2 = getcdf_batch('testjm', 'depth1', -1, -1);
c_x2 = isnan(x2);
nanrange(x1 - x2)
nanrange(c_x1 - c_x2)

x2 = getcdf_batch('testjm', 'depth1', 4, 8);
c_x2 = isnan(x2);
nanrange(x1(4:8) - x2)
nanrange(c_x1(4:8) - c_x2)

%retrieve a matrix from a 5 dimensional variable.

x1 = getcdf_batch('testjm', 'big_var', [2 3 -1 -1 3], ...
    [2  3 -1 -1 3], [1 1 1 1 1], 1, 2, 0);
c_x1 = isnan(x1);
ss = sum(sum(c_x1))

x2 = getcdf_batch('testjm', 'big_var', [2 3 -1 -1 3], [2  3 -1 -1 3]);
c_x2 = isnan(x2);
nanrange(x1 - x2)
nanrange(c_x1 - c_x2)

%retrieve a vector from a 5 dimensional variable.

x1 = getcdf_batch('testjm', 'big_var', [2 -1 3 6 3], [2 -1 3 6 3], ...
    [1 1 1 1 1], 1, 2, 0);
c_x1 = isnan(x1);
ss = sum(sum(c_x1))

x2 = getcdf_batch('testjm', 'big_var', [2 -1 3 6 3], [2 -1 3 6 3]);
c_x2 = isnan(x2);
nanrange(x1 - x2)
nanrange(c_x1 - c_x2)

%retrieve a scalar from a 5 dimensional variable.

x1 = getcdf_batch('testjm', 'big_var', [2 4 3 6 3], [2 4 3 6 3], ...
    [1 1 1 1 1], 1, 2, 0);
c_x1 = isnan(x1);
ss = sum(sum(c_x1))

x2 = getcdf_batch('testjm', 'big_var', [2 4 3 6 3], [2 4 3 6 3]);
c_x2 = isnan(x2);
nanrange(x1 - x2)
nanrange(c_x1 - c_x2)

%Try to retrieve in more than 2 dimensions.

disp('Should fail')
x1 = getcdf_batch('testjm', 'big_var');
