function [startind endind] = returnlength( index )
% 
% Copyright (C) 2017 
% Shreyasi Datta
% Chetanya Puri
% Ayan Mukherjee
% Rohan Banerjee
% Anirban Dutta Choudhury
% Arijit Ukil
% Soma Bandyopadhyay
% Rituraj Singh
% Arpan Pal
% Sundeep Khandelwal
% 
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
% 
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
% 
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

L = length(index);

startval = 1;
endval = [];
countval = [];
count = 0;

if L == 1
    startind = 1;
    endind = 1;
else
    for i = 2 : L
        if abs(index(i) - index(i-1)) == 1 && i~= L
            count = count + 1;
        elseif abs(index(i) - index(i-1))==1 && i == L
            count = count + 1;
            endval = [endval i];
            countval = [countval count];
            startval = [startval i];
        else
            endval = [endval i-1];
            countval = [countval count];
            count = 0;
            startval = [startval i];
        end
    end
    startval = startval(1:end-1);
    [val, ind] = max(countval);
    startind = startval(ind);
    endind = endval(ind);
end

startind = index(startind);
endind = index(endind);



end

