% function  [a] =covar(pos_grid,pos_data,lat_ls,long_ls)
% a 	        m*n  unscaled gaussian covaraince function
% pos_grid	m*3  model grid position vector col 1+2 are lat, long,central
% desired historical year
% pos_data	n*3  data position vector col 1+2 are lat, long, year 
% lat_ls        scalar latitude length scale
% long_ls	scalar longitude length scale
% year_ls scalar year length scale
% 
%
% Note: by choosing the positions to be in terms of indexe or actual
%	distance one can vary the horizontal and vertical scales 
%	according to indices or distance
% Author Sarah Howe and N.L. Bindoff
% date   9/February/2000
%
% v2. Kieran Helm (5-6-2006) -added time component
function  [a]=covar_latlong2(pos_grid,pos_data,lat_ls,long_ls,year_ls)
m=size(pos_grid);
n=size(pos_data);
a=zeros(m(1),n(1));
one=ones(n(1),1);
for i=1:m(1)
	tmp1=((pos_grid(i,1)*one-pos_data(:,1))/lat_ls).^2 ...
	    + ((pos_grid(i,2)*one-pos_data(:,2))/long_ls).^2 ...
        + ((pos_grid(i,3)*one-pos_data(:,3))/year_ls).^2;
	a(i,:)=exp(-tmp1)';
end
