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

PRECT_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;
            PRECT_POCL_LAT(j)=PRECT_POCL_LAT(j)+PRECT_POCL(i,j);
        end
    end
    PRECT_POCL_LAT(j)=PRECT_POCL_LAT(j)/n;
end


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



PRECT_POCL_GLOBAL=PRECT_POCL_GLOBAL/area_GLOBAL;


save('PRECT_POCL_composite_monthly_lat.mat','PRECT_POCL_LAT')

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