function CVV=blk2blk(x1,y1,x2,y2,n,L,model,model_para)
%% a square block to a square block 
%% (x1,y1)  coordinates of the center of block 1
%% (x2,y2)  coordinates of the center of block 2
%%  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

blk_res=L/n;				% resolution within the block
%% create block matrices 
xl1=linspace(x1-L/2+blk_res/2,x1+L/2-blk_res/2,n);
yl1=linspace(y1-L/2+blk_res/2,y1+L/2-blk_res/2,n);
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:n
   dX=xl1(i)-X2;
   for j=1:n
     dY=yl1(j)-Y2;
     R=sqrt(dX.*dX + dY.*dY);
     A=variogr(model,R,model_para);
     CVV=CVV+sum(sum(A));						% simple summation
   end
end
CVV=CVV/(n*n*n*n);
