% this file is for generating instrumental data matrix with gridpoint info
%(for screening with proxies)

clear all; close all;
load /holocene/s1/zuz10/hadcru3v/infillannt/instfilled
load /holocene/s1/zuz10/hadcru3v/enough
load /holocene/s1/zuz10/hadcru3v/toofew

% standardize sst/sat based on interval 1850-1995 for the full series(1850-2006)
  respliced=instfilled;
  [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])=respliced;
  annfull(:,[toofew])=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]); % 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('/holocene/s1/zuz10/work1/temann/data/clidata','meansstmm','-ascii')
