function [out]= gridsmoothp(in,xpoints,ypoints);

%smooths grided data by taking a mean over xpoints in x and ypoints in y

[NN,N]=size(in);


for n=1+xpoints:N-xpoints
    for nn=1+ypoints:NN-ypoints
        out(nn,n)=mean2(g2c(in(nn-ypoints:nn+ypoints,n-xpoints:n+xpoints)));
    end
end



for  n=1:xpoints
    for nn=1+ypoints:NN-ypoints
        out(nn,n)=mean2(g2c([in(nn-ypoints:nn+ypoints,1:n+xpoints) in(nn-ypoints:nn+ypoints,N-(xpoints-n):N)])); 
       
    end
end



for  n=N-xpoints+1:N
    for nn=1+ypoints:NN-ypoints
        out(nn,n)=mean2(g2c([in(nn-ypoints:nn+ypoints,n-xpoints:N) in(nn-ypoints:nn+ypoints,1:xpoints-(N-n))]));        
    end
end



for n=1+xpoints:N-xpoints
    for nn=1:ypoints
        out(nn,n)=mean2(g2c(in(1:2*ypoints+1,n-xpoints:n+xpoints)));
    end
end



for n=1+xpoints:N-xpoints
    for nn=NN-ypoints+1:NN
        out(nn,n)=mean2(g2c(in(NN-2*ypoints:NN,n-xpoints:n+xpoints)));
    end
end



for  n=1:xpoints
    for nn=1:ypoints
        out(nn,n)=mean2(g2c([in(1:2*ypoints+1,1:n+xpoints) in(1:2*ypoints+1,N-(xpoints-n):N)]));
    end
end



for  n=1:xpoints
    for nn=NN-ypoints+1:NN
        out(nn,n)=mean2(g2c([in(NN-2*ypoints:NN,1:n+xpoints) in(NN-2*ypoints:NN,N-(xpoints-n):N)]));
    end
end


for  n=N-xpoints+1:N
    for nn=1:ypoints
        out(nn,n)=mean2(g2c([in(1:2*ypoints+1,n-xpoints:N) in(1:2*ypoints+1,1:xpoints-(N-n))]));        
    end
end

for  n=N-xpoints+1:N
    for nn=NN-ypoints+1:NN
        out(nn,n)=mean2(g2c([in(NN-2*ypoints:NN,n-xpoints:N) in(NN-2*ypoints:NN,1:xpoints-(N-n))]));        
    end
end



        



