% process Data
if year==1 & month==1
    NPPmonthly  = zeros(POOLSequilibriumYear,12);
    respmonthly = zeros(POOLSequilibriumYear,12);
    combmonthly = zeros(POOLSequilibriumYear,12);
    herbmonthly = zeros(POOLSequilibriumYear,12);
    biofmonthly = zeros(POOLSequilibriumYear,12);
end

if year<=POOLSequilibriumYear
    NPPmonthly(year,month)  = sum(gridArea .* (perc_tree + perc_herb) .* NPP(:,month));
    respmonthly(year,month) = sum(gridArea .* (perc_tree .* wresp + perc_herb .* hresp));
    combmonthly(year,month) = sum(gridArea .* (perc_tree .* wcomb + perc_herb .* hcomb));
    herbmonthly(year,month) = sum(gridArea .* (perc_tree .* wherb + perc_herb .* hherb));
    biofmonthly(year,month) = sum(gridArea .*  perc_tree .* wbiof);
end

if year==POOLSequilibriumYear
    respEQ(:,month)        = perc_tree .* wresp + perc_herb .* hresp;
    combEQ(:,month)        = perc_tree .* wcomb + perc_herb .* hcomb;
    herbEQ(:,month)        = perc_tree .* wherb + perc_herb .* hherb;
    biofEQ(:,month)        = perc_tree .* wbiof;
end

if year==POOLSequilibriumYear & month==12
    subplot(321),imagesc(unmaskfile((perc_tree+perc_herb).*sum(NPP,2),mask)),colorbar,axis off,title('NPP [g C m^-^2]')
    subplot(322),imagesc(unmaskfile((perc_tree+perc_herb).*sum(NPP,2)-sum(respEQ+combEQ+herbEQ+biofEQ,2),mask)),colorbar,axis off,title('NEP [g C m^-^2]')
    subplot(323),imagesc(unmaskfile(sum(combEQ,2),mask)),colorbar,axis off,title('Combustion [g C m^-^2]')

    x = POOLSequilibriumYear;
    subplot(325),plot(1:x,sum(NPPmonthly,2),1:x,sum(respmonthly,2),1:x,sum(combmonthly,2),1:x,sum(herbmonthly,2), ...
                      1:x,sum(biofmonthly,2)),legend('NPP','Resp','Comb','Herb','Biof'),ylabel('g C'),xlabel('Year')

    [x,y] = size(mask);
    NH=zeros(x,y);SH=zeros(x,y);
    NH(1:x/2,:)=1;  NH=maskfile(NH,mask);
    SH(x/2+1:y,:)=1;SH=maskfile(SH,mask);
    
    NHfile=zeros(5,12);
    for i=1:12
        NHfile(1,i) = sum(gridArea .* NH .* NPP(:,i));
        NHfile(2,i) = sum(gridArea .* NH .* respEQ(:,i));
        NHfile(3,i) = sum(gridArea .* NH .* combEQ(:,i));
        NHfile(4,i) = sum(gridArea .* NH .* herbEQ(:,i));
        NHfile(5,i) = sum(gridArea .* NH .* biofEQ(:,i));
    end
    subplot(324),plot(NHfile' ),legend('NPP','Resp','Comb','Herb','Biof'),,ylabel('g C'),xlabel('Month'),title('NH fluxes')
    
    SHfile=zeros(5,12);
    for i=1:12
        SHfile(1,i) = sum(gridArea .* SH .* NPP(:,i));
        SHfile(2,i) = sum(gridArea .* SH .* respEQ(:,i));
        SHfile(3,i) = sum(gridArea .* SH .* combEQ(:,i));
        SHfile(4,i) = sum(gridArea .* SH .* herbEQ(:,i));
        SHfile(5,i) = sum(gridArea .* SH .* biofEQ(:,i));
    end
    subplot(326),plot(SHfile' ),legend('NPP','Resp','Comb','Herb','Biof'),ylabel('g C'),xlabel('Month'),title('SH fluxes')
end
