function out=sp_corr(DATA1,DATA2,lat,lon);



%takes grid data and takes the area weighted correlation

[LON, WEIGHT] = meshgrid(lon,cos(lat*pi/180)); %mesh of area weighted data points

%convert to columns
W = g2c(WEIGHT)/sum(g2c(WEIGHT)); %normalized column weighting vector
D1 = g2c(DATA1);
D2 = g2c(DATA2);
SMEAN1=sum(W.*D1); %SPATIAL MEAN
SMEAN2=sum(W.*D2); %SPATIAL MEAN

out=sum((D1-SMEAN1).*(D2-SMEAN2))/((sum((D1-SMEAN1).^2)^.5)*(sum((D2-SMEAN2).^2)^.5));
