clear
clf 
colormap('default')

%cfs
%loaddap('http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NCEP/.EMC/.CFS/.MONTHLY/.BelowSeaLevel/.temp/S/%281%20Oct%29VALUES/L/3/runningAverage/Z/removeGRID/L/3.5/VALUE/Y/-25/25/RANGE/dods')

loaddap('http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NCEP/.EMC/.CFS/.MONTHLY/.above_ground/.temp/S/%281%20Oct%29VALUES/L/3/runningAverage/Z/removeGRID/L/3.5/VALUE/Y/-25/25/RANGE/dods')


model = squeeze(temp.temp);
[ny,nx,mm,nt]=size(model);
msk = model(:,:,1)*0;
model(isnan(model))=0;


[p,q,bst,st,nn,nm,np] = sn_eofs_function_2(model,Y);
for im=1:np
  subplot(2,1,1)
  my_pcolor(X,Y,p(:,:,im)+msk)
  cbar('vert',[-1.5:0.5:1.5]/2)
  pacific_noresize_at_all
  subplot(2,1,2)
  bar((S+L)/12+1960,bst(:,im))
  pause
end



loaddap('http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NCEP/.CPC/.GHCN_CAMS/.gridded/.deg0p5/.temp/T/3/runningAverage/T/%28Dec-Feb%29VALUES/T/%281981%29%282009%29RANGE/X/-20/2./340/GRID/Y/-60/2/80/GRID/dods')

obs = squeeze(temp.temp);
obs = permute(obs,[2,1,3]);

%loaddap('http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NCEP/.CPC/.PRECL/.prcp/T/3/runningAverage/T/%28Dec-Feb%29VALUES/T/%281981%29%282009%29RANGE/dods')
%obs = squeeze(prcp.prcp);

[my,mx,nt] = size(obs);
y = reshape(obs,my*mx,nt);
x = [ones(1,nt);bst'];
clf

for ii=1:(np+1)
  inds{ii}=[1:ii];
  lbs{ii} = int2str(ii-1);
end
lbs{1}='CL';
make_pic=0;
casename='cfs_DJF_t2m';
selection_core
