%caclualted the spatiall weighted correaltion coefficient from standard
%gridded data
function R = spcorr(X,Y, lat);

%X and Y are gridded fields (lat by lon)
%lat is the latitude vector (in degress)
[NN, N]=size(X);
[dumb, LAT]=meshgrid(ones(N,1), lat); %makes a gridded latitude matrix

RR = weightedcorrs([g2c(X) g2c(Y)], g2c(cos(LAT*pi/180)));
R=RR(2,1);