function g=extrap(f)

g=f;

siu=1;
while (siu>0),
  f=g;
  [iu ju]=find(isnan(f));
  siu=size(iu,1);
  for n=1:siu,
    i=iu(n);
    j=ju(n);
    subg=f(max(1,i-1):min(end,i+1),max(1,j-1):min(end,j+1));
    ip=find(~isnan(subg));
    sip=size(ip,1);
    if (sip>0),
      g(i,j)=sum(subg(ip),1)/sip;
    end
  end
end
