shelf = nan(1801,3601);

for i=1:6485401;
    if Signature(i) == 1 && ShSl_index(i) == 1;
      shelf(i) = 11113.2952*(-56/100000);
    end;
end;
clear i;

b = unique(ShSl_index(~isnan(ShSl_index(:))));
a = max(b(1:(size(b)-2)));

c = 2;
while c<=a;
    x2=strcat('Workting on index value: ',num2str(c));
    disp(x2);
    for i=1:6485401;
        % Check for: empty shell, shelf area index
        if Signature(i) == 1 && ShSl_index(i)==c;
            if i<1802;
                % Check if the cell is on 90N deg line
                if i==1;
                    Z = [shelf(i+6481799) shelf(i) shelf(i+1801);shelf(i+6481799) shelf(i) shelf(i+1801); shelf(i+6481800) shelf(i+1) shelf(i+1802)];
                % Check if the cell is on 90S deg line
                elseif i==1801;
                    Z = [shelf(i+6481798) shelf(i-1) shelf(i+1800);shelf(i+6481799) shelf(i) shelf(i+1801);shelf(i+6481799) shelf(i) shelf(i+1801)];
                % Everywhere else
                else
                    Z = [shelf(i+6481798) shelf(i-1) shelf(i+1800);shelf(i+6481799) shelf(i) shelf(i+1801);shelf(i+6481800) shelf(i+1) shelf(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 = [shelf(i-1801) shelf(i) shelf(i-6483600);shelf(i-1801) shelf(i) shelf(i-6483600); shelf(i-1800) shelf(i+1) shelf(i-6483599)];
                % Check if the cell is on 90S deg line
                elseif i==6485401;
                    Z = [shelf(i-1802) shelf(i-1) shelf(i-6483601); shelf(i-1801) shelf(i) shelf(i-6483600);shelf(i-1801) shelf(i) shelf(i-6483600)];
                % Everywhere else
                else
                    Z = [shelf(i-1802) shelf(i-1) shelf(i-6483601); shelf(i-1801) shelf(i) shelf(i-6483600); shelf(i-1800) shelf(i+1) shelf(i-6483599)];
                end;
            % Everywhere else
            else
                % Check if the cell is on 90N deg line
                if rem((i-1),1801)==0;
                    Z = [shelf(i-1801) shelf(i) shelf(i+1801);shelf(i-1801) shelf(i) shelf(i+1801); shelf(i-1800) shelf(i+1) shelf(i+1802)];
                % Check if the cell is on 90S deg line
                elseif rem(i,1801)==0;
                    Z = [shelf(i-1802) shelf(i-1) shelf(i+1800); shelf(i-1801) shelf(i) shelf(i+1801);shelf(i-1801) shelf(i) shelf(i+1801)];
                % Everywhere else
                else
                    Z = [shelf(i-1802) shelf(i-1) shelf(i+1800); shelf(i-1801) shelf(i) shelf(i+1801); shelf(i-1800) shelf(i+1) shelf(i+1802)];
                end;
            end;
%             for j = 1:9;
%                 if isnan(Z(j))==1 && j ~=5;
%                     Z(j) = 0;
%                 end;
%             end;
            % Get Average value
            AvgDepth =mean(Z(~isnan(Z)));
%             if isnan(Z)==1;
%                 AvgDepth = 0;
%             end;
			
            NewDepth = AvgDepth + (11113.2952*(-56/100000));
            shelf(i) = NewDepth;
            
        end;
    end;
    c = c + 1;
end;
clear Z;
clear a b;
clear c;
clear i j;
clear x2;
clear AvgDepth NewDepth;
