clear all; close all;
load ./instdata/instfilled_3d
load ./instdata/enough_3d
load ./instdata/toofew_3d

% standardize sst/sat based on interval 1850-1995 for the full series(1850-2006)
  respliced=instfilled_3d;
  [nrows,ncols]=size(respliced)
  means=nanmean(respliced(1:146,:));
  stdevs=nanstd(respliced(1:146,:));
  respliced=respliced-repmat(means,nrows,1);
  respliced=respliced./repmat(stdevs,nrows,1);
  
  annfull(:,[enough_3d])=respliced;
  annfull(:,[toofew_3d])=NaN;
  
% the first 72 data are SH -87.5 and -177.5 -172.5-------172.5 177.5, then SH -82.5 and -177.5 -172.5-------172.5 177.5
% the last 72 data are NH 87.5 and -177.5 -172.5-------172.5 177.5.
for i=1:36
    for j=1:72
        locate(1,(i-1)*72+j)=((j-1)*5-177.5);
        locate(2,(i-1)*72+j)=((i-1)*5-87.5);
    end
end

annsst=locate;
annsst(3:159,1:2592)=annfull; % add location info

annsst1=annsst(:,[enough_3d]); % remove any NaN columns

% re-format climate dataset into my designed form
% with first tow rows location, the third row numbles or NaNs
% and the first column the years
[rrow,llen]=size(annsst1)
meansst(1:rrow+1,1:llen+1)=NaN;
meansst(1:2,2:llen+1)=annsst1(1:2,1:llen);
meansst(4:rrow+1,1)=(1850:1:2006)';
meansst(4:rrow+1,2:llen+1)=annsst1(3:rrow,1:llen);

meansstmm=meansst(1:150,:); % make last year 1996 for Climate/Proxy*04/09/05
  
%save('/chinook/meteo/svr5143/data_for_science_2009/data_and_code/temp/data','meansstmm','-ascii')
save ./data/clidata meansstmm -ascii
