function OK = interp_z2sigma_test
%interp_z2sigma_test unit test for interp_z2sigma
%
%See also: interp_z2sigma

OK = [];

for flip=0:1 % test whether source z data can have any matrix orientation in z-direction (k=1 is surface or bottom)

%% 1D

   z = [-1 1];zmatrix = [0 1];
   if flip; z= fliplr(z);zmatrix= fliplr(zmatrix);end
   smatrix = interp_z2sigma(z,zmatrix,[0 .25 .5 .75 1],2,-2);
   
   OK(end+1) = all(all(smatrix(1)==0  )); % below zrange
   OK(end+1) = all(all(smatrix(2)==0  ));
   OK(end+1) = all(all(smatrix(3)==0.5));
   OK(end+1) = all(all(smatrix(4)==1  ));
   OK(end+1) = all(all(smatrix(5)==1  )); % above zrange

%% 2D

   z = [-1 1];zmatrix = [0 1;0 1];
   if flip; z= fliplr(z);zmatrix= fliplr(zmatrix);end
   smatrix = interp_z2sigma(z,zmatrix,[0 .25 .5 .75 1],2,-2);
   
   OK(end+1) = all(all(smatrix(:,1)==0  )); % below zrange
   OK(end+1) = all(all(smatrix(:,2)==0  ));
   OK(end+1) = all(all(smatrix(:,3)==0.5));
   OK(end+1) = all(all(smatrix(:,4)==1  ));
   OK(end+1) = all(all(smatrix(:,5)==1  )); % above zrange
   
%% 3D

   z = [-1 1];
   zmatrix = repmat(0,[3 4 2]);
   zmatrix(:,:,1) = 0;
   zmatrix(:,:,2) = 1;
   sigma = [0 .25 .5 .75 1];
   eta   = 2;
   depth = -2;
   
   if flip; z= fliplr(z);zmatrix= zmatrix(:,:,end:-1:1);end
   smatrix = interp_z2sigma(z,zmatrix,sigma, eta, depth);
   
   OK(end+1) = all(all(smatrix(:,:,1)==0  )); % below zrange
   OK(end+1) = all(all(smatrix(:,:,2)==0  ));
   OK(end+1) = all(all(smatrix(:,:,3)==0.5));
   OK(end+1) = all(all(smatrix(:,:,4)==1  ));
   OK(end+1) = all(all(smatrix(:,:,5)==1  )); % above zrange

%% 3D - complex
   z = [-10 0];
   zmatrix = repmat(0,[3 4 2]);
   zmatrix(:,:,1) = 0;
   zmatrix(:,:,2) = 1;
   sigma = [0 .5 1];
   eta   = 0;
   depth = -[2 4 6 8;4 6 8 10; 6 8 10 10];
   
   if flip; z= fliplr(z);zmatrix= zmatrix(:,:,end:-1:1);end
   smatrix = interp_z2sigma(z,zmatrix,sigma, eta, depth);
   
   OK(end+1) = all(all(smatrix(:,:,1)*10-depth  ==10 )); % below zrange
   OK(end+1) = all(all(smatrix(:,:,2)*10-depth/2==10 ));
   OK(end+1) = all(all(smatrix(:,:,3)==1))

end   

