load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/SSLTSF/ncfile/SSLTSF.mat
year=1:150;

EOF_SSLTSF_ANN=zeros(144,96);

SSLTSF_ANN_ALL=zeros(150,144*(64-33+1));

n=1;
for i=1:144
    for j=33:64
        SSLTSF_ANN_ALL(:,n)=SSLTSF_ANN(i,j,:);
        n=n+1;
    end
end

[e,PC_SSLTSF_ANN,expvar_ANN] = caleof(SSLTSF_ANN_ALL,1,1);
n=1;
for i=1:144
    for j=33:64
        EOF_SSLTSF_ANN(i,j)=e(n);
        n=n+1;
    end
end


save('SSLTSF_EOF.mat','EOF_SSLTSF_ANN','PC_SSLTSF_ANN','expvar_ANN')

nccreate('SSLTSF_EOF.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('SSLTSF_EOF.nc','lat', lat)
ncwriteatt('SSLTSF_EOF.nc','lat','units','degrees_north')
ncwriteatt('SSLTSF_EOF.nc','lat','long_name','Latitude')
nccreate('SSLTSF_EOF.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('SSLTSF_EOF.nc','lon', lon)
ncwriteatt('SSLTSF_EOF.nc','lon','units','degrees_east')
ncwriteatt('SSLTSF_EOF.nc','lon','long_name','Longitude')
nccreate('SSLTSF_EOF.nc','EOF_SSLTSF_ANN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF_EOF.nc','EOF_SSLTSF_ANN', EOF_SSLTSF_ANN)
nccreate('SSLTSF_EOF.nc','PC_SSLTSF_ANN','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('SSLTSF_EOF.nc','PC_SSLTSF_ANN', PC_SSLTSF_ANN)
ncdisp('SSLTSF_EOF.nc')
