% EBM Future Projections w/ variable sensitivity
%
% (C) Michael Mann, 2011.
%
% specify NH temperature simulation options
%
% ioption=0:   " use AJSBT07 volcanic forcing
% ioption=1:   " use Gao et al volcanic forcing series in place of AJSBT07
% ioption=2:   " use Crowley et al Volcanic series in place of AJSBT07
ioption=0;
%
% specify volcanic optical depth scaling
%
% iscaling=0: Assume optical depth scales linearly with loading
% iscaling=1: assume 2/3 power law scaling
iscaling=1;
%
% specify solar scaling
%
% isolar=0: Assume 0.1% Maunder Min-Present change in solar output
% isolar=1: Assume 0.25% Maunder Min-Present change in solar output
isolar=0;
%
% specify equilibrium 2XCO2 sensitivity for EBM 
% standard value is mid-range IPCC sensitivity of 3C/2xCO2
sens1=3.0;
sens2=2.5;
sens3=2.0;
sens4=1.5;
sens5=4.5;
%
%
%
%%%%%%%%%%%%%%%%%%%%
%
year=(850:2012)'; % full analysis interval is AD 850-1999
nyears=1163;
yearext = (850:2100);
nyearsext = 1251;
%
% Get forcing series AD 850-1999
[v1,s1,a1,f1,c1] = getforcings(ioption,iscaling,isolar);
%
% specify asymptotic CO2 level in ppm
c0=450.0;
% specify aerosol scenioar 
% iaero=0 means keep aerosol burden constant at current level
% iaero=1 means ramp down aerosols over next century w/ specified e-folding
iaero=1;
%
[volc,solar,aer,cotwo,forcingcotwo] = stabilizeforcings(v1,s1,a1,f1,c1,c0,iaero);
% Run EBM simulation 
% (or alternatively use AJSBT07 NH simulated series if indicated)
[surftemp1]  = EBM(volc,solar,aer,forcingcotwo,sens1); 
[surftemp2]  = EBM(volc,solar,aer,forcingcotwo,sens2); 
[surftemp3]  = EBM(volc,solar,aer,forcingcotwo,sens3); 
[surftemp4]  = EBM(volc,solar,aer,forcingcotwo,sens4); 
[surftemp5]  = EBM(volc,solar,aer,forcingcotwo,sens5); 
%
% read in instrumental record (NH mean temp)
% 
% use HadCRUT4 from AD 1850-2012 
%
load Data/HadCRUT4_annual_nh.dat
yearHadCRU=HadCRUT4_annual_nh(:,1);
nhHadCRU=HadCRUT4_annual_nh(:,2);
%
% use Berkeley Earth (BEST) temperature record to establish pre-industrial (AD 1750-1849) mean 
%
load Data/BEST_annual_nh.dat
yearBEST=BEST_annual_nh(:,1);
nhBEST=BEST_annual_nh(:,2);
%
% do variance adjustment to account for land bias in BEST (use overlap
% period of 1850-2011);
stdBEST=std(nhBEST(101:262));
stdHadCRU=std(nhHadCRU(1:162));
nhBEST=(stdHadCRU/stdBEST)*nhBEST;
%
%
% define pre-industrial baseline based on mean of (BEST) NH mean
% temperature series from AD 1750-1849.
%
baselinepre=mean(nhBEST(1:100)); % AD 1750-1849
nhBEST=nhBEST-baselinepre;
%
% now realign HADCRUT3 NH mean record to have same mean as BEST
% during common (1961-1990) overlap period
%
ModMeanBEST=mean(nhBEST(212:241)); % AD 1961-1990
ModMeanHadCRU=mean(nhHadCRU(112:141)); %AD 1961-1990
nhHadCRU=nhHadCRU+ModMeanBEST-ModMeanHadCRU;
%
% align model simulations to have same mean as instrumental record
% over overlap period of 1850-2012
%
nhmodel1=surftemp1-mean(surftemp1(1001:1163)); % EBM simulation #1
nhmodel1=nhmodel1+mean(nhHadCRU(1:163));
nhmodel2=surftemp2-mean(surftemp2(1001:1163)); % EBM simulation #2
nhmodel2=nhmodel2+mean(nhHadCRU(1:163));
nhmodel3=surftemp3-mean(surftemp3(1001:1163)); % EBM simulation #3
nhmodel3=nhmodel3+mean(nhHadCRU(1:163));
nhmodel4=surftemp4-mean(surftemp4(1001:1163)); % EBM simulation #4
nhmodel4=nhmodel4+mean(nhHadCRU(1:163));
nhmodel5=surftemp5-mean(surftemp5(1001:1163)); % EBM simulation #5
nhmodel5=nhmodel5+mean(nhHadCRU(1:163));
%
% compare simulated and observed NH series over historical era
%
figure(1);
hold
yearbaseline=(1750:1849);
nhbaseline(1:100)=0.0;
yearthresh=(1750:2100);
nhthresh(1:351)=2.0;
plot(yearbaseline,nhbaseline,'k--');
plot(yearthresh,nhthresh,'r--');
plot(yearext(1001:nyearsext),nhmodel1(1001:nyearsext),'r'); 
plot(yearext(1001:nyearsext),nhmodel2(1001:nyearsext)); 
plot(yearext(1001:nyearsext),nhmodel3(1001:nyearsext),'cyan'); 
plot(yearext(1001:nyearsext),nhmodel4(1001:nyearsext),'y'); 
plot(yearext(1001:nyearsext),nhmodel5(1001:nyearsext),'-'); 
plot(yearHadCRU(1:nyears-1000),nhHadCRU(1:nyears-1000),'k');
%     