dd = [7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 1 2 3 4 5 6 7 8];
ens_num = zeros(size(dd));

add_to = 0;

for ii = 1:length(dd)     
     ens_num(ii) = dd(ii) + add_to;
    if (dd(ii) == 8)  %it can't drop to this value: this is the highest
        add_to = add_to + 8;
    else
        if (ii >= 2) %do we have a drop for some other reason?
           ensdiff = ens_num(ii) - ens_num(ii-1);
           if (ensdiff <= 0)
               ens_num(ii) = ens_num(ii) + (-ensdiff + 1); %increment it
               add_to = add_to + (-ensdiff + 1);  %add the increment to add_to
           end
       end
    end

     fprintf('ii is %d, dd is %d, add_to is %d, ensnum(ii) is %d\n',...
             ii, dd(ii), add_to,  ens_num(ii))

end

       