ShSl_index = nan(1801,3601);

for i=1:6485401;
    if Signature(i)==0;
        ShSl_index(i) = 0;
    end;
end;
clear i;
disp('Land masked in ShSl_index.....');

figure;pcolor(ShSl_index);shading flat;colorbar;

for i=1:6485401;
    if Signature(i)==3;
        ShSl_index(i) = 1999;
    end;
end;
clear i;
disp('Slope/Rise masked in ShSl_index.....');

figure;pcolor(ShSl_index);shading flat;colorbar;

for i=1:6485401;
    if Signature(i)==4;
        ShSl_index(i) = 2000;
    end;
end;
clear i;
disp('Deep Ocean masked in ShSl_index.....');

figure;pcolor(ShSl_index);shading flat;colorbar;

NaN_index = [];
NaN_index = find(isnan(ShSl_index));

NaNCount = sum(sum(isnan(ShSl_index)));
while NaNCount>0;
    disp(NaNCount);
	NaN_index = find(isnan(ShSl_index));
    for x=1:size(NaN_index);
        i = NaN_index(x);
        % Check if the cell is on -180 deg line
        if i<1802;
            % Check if the cell is on 90N deg line
            if i==1;
                Z = [ShSl_index(i+6481799) ShSl_index(i) ShSl_index(i+1801);ShSl_index(i+6481799) ShSl_index(i) ShSl_index(i+1801); ShSl_index(i+6481800) ShSl_index(i+1) ShSl_index(i+1802)];
            % Check if the cell is on 90S deg line
            elseif i==1801;
                Z = [ShSl_index(i+6481798) ShSl_index(i-1) ShSl_index(i+1800);ShSl_index(i+6481799) ShSl_index(i) ShSl_index(i+1801);ShSl_index(i+6481799) ShSl_index(i) ShSl_index(i+1801)];
            % Everywhere else
            else
                Z = [ShSl_index(i+6481798) ShSl_index(i-1) ShSl_index(i+1800);ShSl_index(i+6481799) ShSl_index(i) ShSl_index(i+1801);ShSl_index(i+6481800) ShSl_index(i+1) ShSl_index(i+1802)];
            end;
        % Check if the cell is on 180 deg line
        elseif i>6483600;
            % Check if the cell is on 90N deg line
            if i==6483601;
                Z = [ShSl_index(i-1801) ShSl_index(i) ShSl_index(i-6483600);ShSl_index(i-1801) ShSl_index(i) ShSl_index(i-6483600); ShSl_index(i-1800) ShSl_index(i+1) ShSl_index(i-6483599)];
            % Check if the cell is on 90S deg line
            elseif i==6485401;
                Z = [ShSl_index(i-1802) ShSl_index(i-1) ShSl_index(i-6483601); ShSl_index(i-1801) ShSl_index(i) ShSl_index(i-6483600);ShSl_index(i-1801) ShSl_index(i) ShSl_index(i-6483600)];
            % Everywhere else
            else
                Z = [ShSl_index(i-1802) ShSl_index(i-1) ShSl_index(i-6483601); ShSl_index(i-1801) ShSl_index(i) ShSl_index(i-6483600); ShSl_index(i-1800) ShSl_index(i+1) ShSl_index(i-6483599)];
            end;
        % Everywhere else
        else
            % Check if the cell is on 90N deg line
            if rem((i-1),1801)==0;
                Z = [ShSl_index(i-1801) ShSl_index(i) ShSl_index(i+1801);ShSl_index(i-1801) ShSl_index(i) ShSl_index(i+1801); ShSl_index(i-1800) ShSl_index(i+1) ShSl_index(i+1802)];
            % Check if the cell is on 90S deg line
            elseif rem(i,1801)==0;
                Z = [ShSl_index(i-1802) ShSl_index(i-1) ShSl_index(i+1800); ShSl_index(i-1801) ShSl_index(i) ShSl_index(i+1801);ShSl_index(i-1801) ShSl_index(i) ShSl_index(i+1801)];
            % Everywhere else
            else
                Z = [ShSl_index(i-1802) ShSl_index(i-1) ShSl_index(i+1800); ShSl_index(i-1801) ShSl_index(i) ShSl_index(i+1801); ShSl_index(i-1800) ShSl_index(i+1) ShSl_index(i+1802)];
            end;
        end;
        if min(Z(:))>=2000 || min(Z(:))>=1999;
			ShSl_index(i) = 1;
		else
			ShSl_index(i) = min(Z(:))+ 1;
        end;
    end;
    NaNCount = sum(sum(isnan(ShSl_index)));
%     disp(NaNCount);
end;

figure;pcolor(ShSl_index);shading flat;colorbar;

unique(ShSl_index(~isnan(ShSl_index(:))))

clear NaNCount;
clear NaN_index;
clear Z;
clear ans;
clear i;
clear x;