%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   
%   This program is a Matlab taster. It simply shows you
%   how to define vectors and plot things, within the context
%   of a simple energy balance model.
%
% (c) Environmental Physics, Jan. 2007.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%------------------
% 1. Definitions
%------------------

%Units
KM = 1000;
PW = 1.e15;
DAY = 24*3600;
MONTH = 30*DAY; 
YEAR = 12*MONTH;

%Planetary & Physical constants
RADIUS = 6371*KM;       %Earth Radius (m)
SIGMA = 5.67*1.e-08;    %Stefan Boltzmann (Wm-2K-4)
So = 1367*1.01;         %Solar constant (Wm-2) 
ALPHAp = .3;            %Planetary albedo (non dim.)

%------------------------------------
% 2. Model for surface temperature
%------------------------------------

T = [200:.1:350];                                     %Surface temperature (K)
ASR_pw = ones(size(T))*So*(1-ALPHAp)*pi*RADIUS^2/PW;  %Absorbed Solar Radiation (PW)
OLR_pw = SIGMA*(T.^4)*4*pi*RADIUS^2/PW;               %Outgoing Longwave Radiation (PW)

%----------
% 3. Plot 
%----------

figure(1), hold on,
plot(T,OLR_pw,'r',T,ASR_pw,'b--');
xlabel('Temperature (K)','Fontsize',15);
ylabel('Energy exchanged with Space (PW)','Fontsize',15);
grid on