function test=inrange(x,y,I,J,r)

% In-rang test for DTW
% test = inrange(x,y,I,J,r)
%
% (x,y) - point to be tested
% (I,J) - terminal point
%     r - ajustment window size


    if( (x<1) | (y<1) | (x>I) | (y>J))
       test = 0;
    elseif ( (x<(y-r)) | (x>(y+r)) | (x>2*y-1) | (x<floor(y/2)+1))
       test = 0;
    else
       test =1;
    end

return                      