load ~/NC/grid.mat
load ~/NC/area_1.9_2.5.mat
load ~/Aerosol_Variaiton/IRUN/PRECT/ncfile/PRECC_POCL_composite_monthly.mat
load ~/NC/OCNFRAC.mat
month=1:1800;

PRECC_POCL_LAT=zeros(96,1);
for j=1:length(lat)
    n=0;
    for i=1:length(lon)
        if OCNFRAC(i,j)>0.9
            n=n+1;
            PRECC_POCL_LAT(j)=PRECC_POCL_LAT(j)+PRECC_POCL(i,j);
        end
    end
    PRECC_POCL_LAT(j)=PRECC_POCL_LAT(j)/n;
end


area_GLOBAL=0;
PRECC_POCL_GLOBAL=0;
for j=17:80
    for i=1:length(lon)
        if OCNFRAC(i,j)>0.9
            PRECC_POCL_GLOBAL=PRECC_POCL_GLOBAL+PRECC_POCL(i,j).*area(i,j);
            area_GLOBAL=area_GLOBAL+area(i,j);
        end
    end
end



PRECC_POCL_GLOBAL=PRECC_POCL_GLOBAL/area_GLOBAL;


save('PRECC_POCL_composite_monthly_lat.mat','PRECC_POCL_LAT')

nccreate('PRECC_POCL_composite_monthly_lat.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('PRECC_POCL_composite_monthly_lat.nc','lat', lat)
ncwriteatt('PRECC_POCL_composite_monthly_lat.nc','lat','units','degrees_north')
ncwriteatt('PRECC_POCL_composite_monthly_lat.nc','lat','long_name','Latitude')
nccreate('PRECC_POCL_composite_monthly_lat.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('PRECC_POCL_composite_monthly_lat.nc','lon', lon)
ncwriteatt('PRECC_POCL_composite_monthly_lat.nc','lon','units','degrees_east')
ncwriteatt('PRECC_POCL_composite_monthly_lat.nc','lon','long_name','Longitude')
nccreate('PRECC_POCL_composite_monthly_lat.nc','PRECC_POCL_LAT','Dimensions',{'lat',96},'Format','classic')
ncwrite('PRECC_POCL_composite_monthly_lat.nc','PRECC_POCL_LAT', PRECC_POCL_LAT)
ncdisp('PRECC_POCL_composite_monthly_lat.nc')
