clear
clf 
colormap('default')
%eofs

loaddap('http://iridl.ldeo.columbia.edu/expert/IRIONLY/ds:/SOURCES/.IRI/.FD/.ECHAM4p5/.Forecast/.ca_sst/.ensemble24/.MONTHLY/.t2m/Y/-15/15/RANGE/S/%281%20Oct%29VALUES/S/%281%20Oct%201960%29%281%20Oct%202001%29RANGE%5BM%5Daverage/L/3/runningAverage/L/3.5/VALUE/home/.tippett/.scratch/.na/.hindcasts/.obs/.t2m/Y/-60/80/RANGE/S/%281%20Oct%29VALUES/S/%281%20Oct%201960%29%281%20Oct%202001%29RANGE/L/3.5/VALUE/%28name%29%28obs%29def/:ds/dods')

obs = squeeze(obs.obs);
[my,mx,nt] = size(obs);
y = reshape(obs,my*mx,nt);


t2m = squeeze(t2m.t2m);
[ny,nx,nt] = size(t2m);

t2m_mean = mean(t2m,3);
t2m_std = std(t2m,[],3);
t2ma = (t2m - t2m_mean(:,:,ones(1,nt)))./t2m_std(:,:,ones(1,nt));;

[u,s,v] = svd(reshape(t2ma,ny*nx,nt),'econ');

nmodes=10

for im=1:nmodes
  subplot(2,1,1)
  my_pcolor(X_01,Y_01,t2m_std.*s(im,im).*reshape(u(:,im),ny,nx))
  cbar
  pacific_noresize_at_all
  subplot(2,1,2)
  bar((S+L)/12+1960,v(:,im))
  pause
end
clf

x = [ones(1,nt);v(:,1:nmodes)'];
for ii=1:(nmodes+1)
  inds{ii}=[1:ii];
  lbs{ii} = int2str(ii-1);
end

lbs{1} = 'CL';


make_pic=0;
casename='echam_DJF_t2m';
selection_core
