function computeForwardBackwardVec(lambda,direction,blockSizes)
if size(lambda,1)==1, lambda=lambda';end %lambda have to be a column vector
n=size(lambda,1)-1;k=(n+1)/2;
if rem(k,1)~=0, disp('error: k not integer');return; end
if sum(blockSizes) ~= length(lambda), disp('Error in block sizes');return;end
if blockSizes(end)~=2, disp('Last block not size 2');return;end
if strcmp(direction,'backward') lambda=flipud(lambda);end

for i=1:length(blockSizes),
    disp(['block num ' num2str(i)]);
    indices=sum(blockSizes(1:i-1))+1 : sum(blockSizes(1:i));
    if i==1,
         block = prepareBlock(lambda(indices),indices,k);
    else block = prepareBlock(lambda(indices),indices,k,block(end,:));
    end
    if strcmp(direction,'forward') 
         eval(['save runtimeFiles\forwardVec' num2str(i) ' block;']);
    else
        block = flipud(block);
        eval(['save runtimeFiles\backwardVec' num2str(length(blockSizes)-i) ' block;']);
        block = flipud(block);
    end
end
return;

function block=prepareBlock(lambda,indices,k,firstRow)
vec=0:k;
catalanVec = computeLogModCatalan(vec);
block = exp(log(lambda)*vec + repmat(catalanVec,[length(lambda) 1]));
if exist('firstRow'), 
    tmp = real(ifft( fft(block(1,:),(k+1)*2) .* fft(firstRow,(k+1)*2)));
    block(1,:)=tmp(1:k+1);
end
for i=2:length(indices),
    tmp = ifft( fft(block(i-1,:),(k+1)*2) .* ...
                     fft(block(i,:)  ,(k+1)*2) );
    block(i,:)=real(tmp(1:k+1));
end
return;