clear;
close all;
loaddods('http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NCEP/.EMC/.CFS/.MONTHLY/.surface/.prate%5BM%5Daverage/S/%28Apr%201981%29%28Apr%202005%29RANGE/S/12/STEP/L/3.5/5.5/RANGE%5BL%5Daverage/S/%28T%29renameGRID/dods')
c(1,:,:,:)=prate.prate;
%apr=prate.prate;
clear prate;
loaddods('http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NCEP/.EMC/.CFS/.MONTHLY/.surface/.prate%5BM%5Daverage/S/%28May%201981%29%28May%202005%29RANGE/S/12/STEP/L/2.5/4.5/RANGE%5BL%5Daverage/S/%28T%29renameGRID/dods');
%may=prate.prate;
c(2,:,:,:)=prate.prate;
clear prate;
loaddods('http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NCEP/.EMC/.CFS/.MONTHLY/.surface/.prate%5BM%5Daverage/S/%28Jun%201981%29%28Jun%202005%29RANGE/S/12/STEP/L/1.5/3.5/RANGE%5BL%5Daverage/S/%28T%29renameGRID/dods');
%jun=prate.prate;
c(3,:,:,:)=prate.prate;
fid=fopen('xiearkin8105jas.bin','rb');
b=fread(fid,inf,'float32'); 
b=reshape(b,[192 94 25]); 
[x,y]=meshgrid(X,Y); 
%b= b192x94(:,:,1); 
for k=1:3
	for i=1:192
		for j=1:94
		xx=reshape(b(i,j,:),[1 25]);
		yy=reshape(c(k,j,i,:),[1 25]);
		r=corrcoef(xx,yy);
		corr(k,j,i)=r(1,2);
		end
	end
end
load coast;
b=reshape(corr(1,:,:),[94 192]);
contourf(x,y,b);
hold on
plot(long+360,lat,'-r','LineWidth',2)
hold on
plot(long,lat,'-r','LineWidth',2)
% rewrite for grads
fid = fopen('CFS_rr_skill_8105JAS.bin','wb');
for k=1:3
b=reshape(corr(k,:,:),[94 192]);
a=fwrite(fid,b','float32');
end
fclose(fid);

