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

OCNFRAC=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/read_nc/ncfile/cesm.nc','OCNFRAC');
m=0;
for i=37:109
    for j=62:80
        if OCNFRAC(i,j)>0.8
            m=m+1;
        end
    end
end

EOF_SSLTSF=zeros(144,96);
EOF_SSLTSF(:,:)=-999;

SSLTSF_ALL=zeros(1800,m);

n=1;
for i=37:109
    for j=62:80
        if OCNFRAC(i,j)>0.8
            SSLTSF_ALL(:,n)=SSLTSF_MONTH(i,j,:);
            n=n+1;
        end
    end
end

[e,PC_SSLTSF,expvar] = caleof(SSLTSF_ALL,1,1);
n=1;
for i=37:109
    for j=62:80
        if OCNFRAC(i,j)>0.8
            EOF_SSLTSF(i,j)=e(n);
            n=n+1;
        else
            EOF_SSLTSF(i,j)=-999;
        end
    end
end


save('SSLTSF_EOF_monthly.mat','EOF_SSLTSF','PC_SSLTSF','expvar')

nccreate('SSLTSF_EOF_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('SSLTSF_EOF_monthly.nc','lat', lat)
ncwriteatt('SSLTSF_EOF_monthly.nc','lat','units','degrees_north')
ncwriteatt('SSLTSF_EOF_monthly.nc','lat','long_name','Latitude')
nccreate('SSLTSF_EOF_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('SSLTSF_EOF_monthly.nc','lon', lon)
ncwriteatt('SSLTSF_EOF_monthly.nc','lon','units','degrees_east')
ncwriteatt('SSLTSF_EOF_monthly.nc','lon','long_name','Longitude')
nccreate('SSLTSF_EOF_monthly.nc','EOF_SSLTSF','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF_EOF_monthly.nc','EOF_SSLTSF', EOF_SSLTSF)
nccreate('SSLTSF_EOF_monthly.nc','PC_SSLTSF','Dimensions',{'month',length(month)},'Format','classic')
ncwrite('SSLTSF_EOF_monthly.nc','PC_SSLTSF', PC_SSLTSF)
ncdisp('SSLTSF_EOF_monthly.nc')
