function [surftemp]  = EBM(volc,solar,aer,forcingcotwo,sens);
% (C) Michael Mann, 2011.
%
% define constants
%
S0 = 1370; % define solar constant in W/m^2 
cp = 2.08E+08; % in J/m^2 dec C
dt0 = 0.1;  % in years
dt = dt0*365.25*24*3600; % in seconds
%
% calculate relaxation 
%
% set parameters
%
% default albedo
A0 = 0.3;
%
% we use linearized form of the energy balance
% Cp dT/dt = (1-A0)*S/4 - sigma T^4
%
% choose graybody parameter approx:
% sigma T^4 = A + B (T-T0)
% where T0=0C.
% default Gray Body Parameters
% A = 221.3 W/m^2  % constant term for realistic global mean temperature
A = 221.3; 
% B = 1.236 W/m^2K 
% corresponds to mid-range IPCC sensitivity of 3C for 2xCO2 forcing
B = 5.35*log(2)/sens; 
% calculate relaxation time constant
taus = cp/B;  % in seconds
tau = taus/(365.25*24*3600); % in years
%
% now calculate total forcing 
longwave = forcingcotwo;
shortwave=aer+volc+(1-A0)*(S0+solar)/4.0;
%
% impose the combined shortwave + longwave forcing as an effective increase in downward shortwave
% radiation
forcingrad = shortwave+longwave;
forcingtot=forcingrad;
%
% specifiy length and resolution of time integration
ntot = length(forcingrad);
ntot0=ntot/dt0;
nspace=1/dt0;
%
% define initial temperature as equilibrium for initial instantaneous
% forcing
%
surftemp0 = (forcingrad(1)-A)/B;
Told=surftemp0;
%
% interpolate annual forcing to appropriate temporal resolution
for i=1:ntot0;
    yearinterp(i)=850.0+i*dt0;
end
for i=1:ntot0-1
    istart=floor(i*dt0);
    forcinterp(i)=forcingtot(istart+1);
end
forcinterp(ntot0-nspace+1:ntot0)=forcingtot(ntot);
%
% now integrate the EBM forward (sub-annual time step)
%
for i=1:ntot0
    Tnew = Told + (1/cp)*(forcinterp(i)-A-B*Told)*dt;
    %
    surfhighres(i)=Tnew;
    Told=Tnew;
end
surfhighres=surfhighres';
%
% form annually averaged EBM NH series
%
ii=0;
sum=0.0;
jcount=0;
for i=1:ntot0
    ii=ii+1;
    sum=sum+surfhighres(i);
    if (ii==nspace)
        jcount=jcount+1;
        surftemp(jcount)=sum/nspace;
        sum=0.0;
        ii=0;
    end
end
surftemp=surftemp';
end


















      