
function F=interp_2D_fn(s,kx,ky,KX,KY);

nx=length(KX);
ny=length(KY);
kxf=KX(:)*ones(1,ny);
kyf=ones(nx,1)*KY;
dkx=KX(2)-KX(1);
dky=KY(2)-KY(1);
X0=pi/dkx;
Y0=pi/dky;
ns=4;
kxs=(ns+1)*dkx;
kys=(ns+1)*dky;
Is=[-ns:ns];
ic=0;
for i=-ns:ns;
   for j=-ns:ns;
      ic=ic+1;
      I0(ic)=i+(j-1)*nx;
   end;
end;
%
%
[n,m]=size(s);

%
F=zeros(nx,ny);  % spectral array formed via sinc interpolation 

for i=1:n; i
    for j=1:m;
        
        % sinc interpolation
        %
        ikx=round((kx(i,j)-KX(1))/dkx)+1;
        iky=round((ky(i,j)-KY(1))/dky)+1;
        I=ikx+(iky-1)*nx+I0;
        Ic=find(I > 0 & I <= nx*ny);
        I=I(Ic);
        if length(I) > 0,
            sx=kx(i,j)-kxf(I); 
            sy=ky(i,j)-kyf(I);
            sx=sinc((sx*X0)/pi).*(1+cos((pi/kxs)*sx));
            sy=sinc((sy*Y0)/pi).*(1+cos((pi/kys)*sy));
            F(I)=F(I)+s(i,j)*sx.*sy;
        end;
    end;
end;











end

