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

EOF_WIND_ANN=zeros(144,96);
EOF_WIND_DJF=zeros(144,96);
EOF_WIND_MAM=zeros(144,96);
EOF_WIND_JJA=zeros(144,96);
EOF_WIND_SON=zeros(144,96);
EOF_WIND_JAN=zeros(144,96);
EOF_WIND_JUL=zeros(144,96);

WIND_ANN_ALL=zeros(150,144*96);
WIND_DJF_ALL=zeros(150,144*96);
WIND_MAM_ALL=zeros(150,144*96);
WIND_JJA_ALL=zeros(150,144*96);
WIND_SON_ALL=zeros(150,144*96);
WIND_JAN_ALL=zeros(150,144*96);
WIND_JUL_ALL=zeros(150,144*96);
n=1;
for i=1:144
    for j=1:96
        WIND_ANN_ALL(:,n)=WIND_ANN(i,j,:);
        WIND_DJF_ALL(:,n)=WIND_DJF(i,j,:);
        WIND_MAM_ALL(:,n)=WIND_MAM(i,j,:);
        WIND_JJA_ALL(:,n)=WIND_JJA(i,j,:);
        WIND_SON_ALL(:,n)=WIND_SON(i,j,:);
        WIND_JAN_ALL(:,n)=WIND_JAN(i,j,:);
        WIND_JUL_ALL(:,n)=WIND_JUL(i,j,:);
        n=n+1;
    end
end

[e,PC_WIND_ANN,expvar_ANN] = caleof(WIND_ANN_ALL,1,1);
n=1;
for i=1:144
    for j=1:96
        EOF_WIND_ANN(i,j)=e(n);
        n=n+1;
    end
end

[e,PC_WIND_DJF,expvar_DJF] = caleof(WIND_DJF_ALL,1,1);
n=1;
for i=1:144
    for j=1:96
        EOF_WIND_DJF(i,j)=e(n);
        n=n+1;
    end
end

[e,PC_WIND_MAM,expvar_MAM] = caleof(WIND_MAM_ALL,1,1);
n=1;
for i=1:144
    for j=1:96
        EOF_WIND_MAM(i,j)=e(n);
        n=n+1;
    end
end

[e,PC_WIND_JJA,expvar_JJA] = caleof(WIND_JJA_ALL,1,1);
n=1;
for i=1:144
    for j=1:96
        EOF_WIND_JJA(i,j)=e(n);
        n=n+1;
    end
end

[e,PC_WIND_SON,expvar_SON] = caleof(WIND_SON_ALL,1,1);
n=1;
for i=1:144
    for j=1:96
        EOF_WIND_SON(i,j)=e(n);
        n=n+1;
    end
end

[e,PC_WIND_JAN,expvar_JAN] = caleof(WIND_JAN_ALL,1,1);
n=1;
for i=1:144
    for j=1:96
        EOF_WIND_JAN(i,j)=e(n);
        n=n+1;
    end
end

[e,PC_WIND_JUL,expvar_JUL] = caleof(WIND_JUL_ALL,1,1);
n=1;
for i=1:144
    for j=1:96
        EOF_WIND_JUL(i,j)=e(n);
        n=n+1;
    end
end


save('WIND_EOF.mat','EOF_WIND_ANN','PC_WIND_ANN','expvar_ANN','EOF_WIND_DJF','PC_WIND_DJF','expvar_DJF','EOF_WIND_MAM','PC_WIND_MAM','expvar_MAM','EOF_WIND_JJA','PC_WIND_JJA','expvar_JJA','EOF_WIND_SON','PC_WIND_SON','expvar_SON','EOF_WIND_JAN','PC_WIND_JAN','expvar_JAN','EOF_WIND_JUL','PC_WIND_JUL','expvar_JUL')

nccreate('WIND_EOF.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('WIND_EOF.nc','lat', lat)
ncwriteatt('WIND_EOF.nc','lat','units','degrees_north')
ncwriteatt('WIND_EOF.nc','lat','long_name','Latitude')
nccreate('WIND_EOF.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('WIND_EOF.nc','lon', lon)
ncwriteatt('WIND_EOF.nc','lon','units','degrees_east')
ncwriteatt('WIND_EOF.nc','lon','long_name','Longitude')
nccreate('WIND_EOF.nc','EOF_WIND_ANN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('WIND_EOF.nc','EOF_WIND_ANN', EOF_WIND_ANN)
nccreate('WIND_EOF.nc','PC_WIND_ANN','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('WIND_EOF.nc','PC_WIND_ANN', PC_WIND_ANN)
nccreate('WIND_EOF.nc','EOF_WIND_DJF','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('WIND_EOF.nc','EOF_WIND_DJF', EOF_WIND_DJF)
nccreate('WIND_EOF.nc','PC_WIND_DJF','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('WIND_EOF.nc','PC_WIND_DJF', PC_WIND_DJF)
nccreate('WIND_EOF.nc','EOF_WIND_MAM','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('WIND_EOF.nc','EOF_WIND_MAM', EOF_WIND_MAM)
nccreate('WIND_EOF.nc','PC_WIND_MAM','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('WIND_EOF.nc','PC_WIND_MAM', PC_WIND_MAM)
nccreate('WIND_EOF.nc','EOF_WIND_JJA','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('WIND_EOF.nc','EOF_WIND_JJA', EOF_WIND_JJA)
nccreate('WIND_EOF.nc','PC_WIND_JJA','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('WIND_EOF.nc','PC_WIND_JJA', PC_WIND_JJA)
nccreate('WIND_EOF.nc','EOF_WIND_SON','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('WIND_EOF.nc','EOF_WIND_SON', EOF_WIND_SON)
nccreate('WIND_EOF.nc','PC_WIND_SON','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('WIND_EOF.nc','PC_WIND_SON', PC_WIND_SON)
nccreate('WIND_EOF.nc','EOF_WIND_JAN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('WIND_EOF.nc','EOF_WIND_JAN', EOF_WIND_JAN)
nccreate('WIND_EOF.nc','PC_WIND_JAN','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('WIND_EOF.nc','PC_WIND_JAN', PC_WIND_JAN)
nccreate('WIND_EOF.nc','EOF_WIND_JUL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('WIND_EOF.nc','EOF_WIND_JUL', EOF_WIND_JUL)
nccreate('WIND_EOF.nc','PC_WIND_JUL','Dimensions',{'year',length(year)},'Format','classic')
ncwrite('WIND_EOF.nc','PC_WIND_JUL', PC_WIND_JUL)
ncdisp('WIND_EOF.nc')
