function [annual,grow,ngrowing,diffuse,total] = treegrowth(nhmodel,volc,T1,T2,T3,T4,tmax,tmin,igrowth,ampnoise);
% (C) Michael Mann, 2011.
%
% calculate growth index both with and without diffuse light effect
% 
nyears=length(nhmodel);
%
% impose seasonal temperature cycle (daily mean temperatures)
%
zerro=1e-6;
twopi=2.0*3.1415926;
seasonamp=(tmax-tmin)/2.0;
for j=1:365
    noise=ampnoise*gasdev;
    seasonal(j)=tmin+seasonamp*(1.0-cos((j-1)*twopi/365.0));
    annual(j)=seasonal(j)+noise; % sample annual cycle w/ noise
end
%
%
for i=1:nyears
    gd=0.0;
    ngrow=0;
    for j=1:365
        noise=ampnoise*gasdev;
        tgrow=nhmodel(i)+seasonal(j)+noise;
        [response]=tresponse(tgrow,T1,T2,T3,T4,igrowth);
        if (response>zerro)
            ngrow=ngrow+1; 
            gd=gd+response;
        end
    end
    ngrowing(i)=ngrow;
    grow(i)=gd;
end
%
% now include effect of anomalous diffuse radiation
% 
diffrad=-volc;
%
% assume a linear relative increase of productivity at rate of 30% for each
% 2W/m^2 radiative forcing
% diffuse radiation
afrac=0.3/2.0;
diffuse=afrac*diffrad;
for i=1:nyears
     diffuse(i)=afrac*diffrad(i);
     total(i)=grow(i)*(1.0+diffuse(i));
end
diffuse=diffuse';
end
















      