function [FF_2D]=reconstruct_xx_2D(Fin,adxx_in,lag,method,frac)

nG_full=size(adxx_in,3);
nGa=nG_full;
nGb=nG_full-1;

sz=size(Fin);
nt=size(Fin,3);

%the fraction from the last record of adxx
add_into_timeseries=0;
if(method==6);
  if(add_into_timeseries==1);
    clear tmp;tmp=frac.*(Fin.*repmat(adxx_in(:,:,nG_full),[1 1 nt]));
    tmp=reshape(tmp,sz(1)*sz(2),nt);
    FF_add=sum(tmp,1);
    sz1=size(FF_add);isz=find(sz1==nt);if(isz~=1);FF_add=FF_add';end;

    FF_snap=0.*Fin;
  else;
    FF_add=zeros(nt,1);
    FF_snap=frac.*(Fin.*repmat(adxx_in(:,:,nG_full),[1 1 nt]));		%keep full 2-D
  end;
else;
  FF_add=zeros(nt,1);
  FF_snap=0.*Fin;
end;

fprintf('Method: %i , nG_full: %i nt: %i frac: %f ',[method,nG_full,nt,frac]);
if(method==6);fprintf('size FF_add: %i %i ',size(FF_add));end;

%predefine size
FF_2D=nan(sz(1),sz(2),nt,length(lag));

for ilag=1:length(lag);

  clear GG jj
  fprintf('lag: %i ',lag(ilag));

%set indices for adxx
  if(method==1|method==3);
    if(method==1);
      jj=nGa:-1:nGa-lag(ilag);    %ilag=1: nGa:nGa					%best slope, overshoot
    else;
      if(lag(ilag)==0);  jj=nGa:-1:nGa-lag(ilag);  else;  jj=nGa-1:-1:nGa-lag(ilag)-1;  end;	%same as method=2
    end;
    GG=adxx_in(:,:,1:nGa);
  elseif(method==2|method==4|method==6);
    if(method==2|method==6);
      jj=nGb:-1:nGb-lag(ilag);								%best corr, undershoot
    else;
      if(lag(ilag)==0);  jj=nGb:-1:nGb-lag(ilag);  else;  jj=nGb-1:-1:nGb-lag(ilag)-1;  end;	%totally useless
    end;
    GG=adxx_in(:,:,1:nGb);
  elseif(method==5);
    jj=nGb:-1:nGb-lag(ilag);
    GG=(1-frac).*adxx_in(:,:,1:nG_full-1)+frac.*adxx_in(:,:,2:nG_full);			%bad?
  end;

  for it=lag(ilag)+1:nt;
    clear ii;
    ii=it:-1:it-lag(ilag);
    clear tmp;tmp=sum(Fin(:,:,ii).*GG(:,:,jj),3)+FF_snap(:,:,it)+FF_add(it);FF_2D(:,:,it,ilag)=tmp;
  end;

end;

%cannot use here, already added inside for it loop
%%if(method==6);
%  FF=FF+repmat(FF_add,[1 length(lag)]);
%%end;

fprintf('\n');

return

