function Csb=sta2blk(x1,y1,x2,y2,n,L,model,model_para)
%% stations to a square block 
%% (x1,y1)  coordinates of stations
%% (x2,y2)  coordinates of the center of block 
%%  n x n   no. of elements of the block
%%    L     block size  
%%  model:  semi-variogram model index
%%  model_para model parameters
% Author: Jim Ledwell, 10/97 Woods Hole Oceanographic Institution
% Revised by Dezhang Chu,   10-29-98

ns=length(x1);
blk_res=L/n;				% resolution within the block
%% create block matrices 
xl2=linspace(x2-L/2+blk_res/2,x2+L/2-blk_res/2,n);
yl2=linspace(y2-L/2+blk_res/2,y2+L/2-blk_res/2,n);

[X2,Y2]=meshgrid(xl2,yl2);
CVV=0;
for i=1:ns
   dX=x1(i)-X2;
   dY=y1(i)-Y2;
   R=sqrt(dX.*dX + dY.*dY);
   A=variogrammodel(model,R,model_para);
   Csb(i)=sum(sum(A))/(n*n);						% simple summation
end
