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

PRECL_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;
            PRECL_POCL_LAT(j)=PRECL_POCL_LAT(j)+PRECL_POCL(i,j);
        end
    end
    PRECL_POCL_LAT(j)=PRECL_POCL_LAT(j)/n;
end


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



PRECL_POCL_GLOBAL=PRECL_POCL_GLOBAL/area_GLOBAL;


save('PRECL_POCL_composite_monthly_lat.mat','PRECL_POCL_LAT')

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