%  function EPSA = calc_EPSA(Ts,Ta,RHa,CO2,BlackBody)
%
% Computes the emissivity of atmospheric column at 
% average temperature Ta (K) and surface temperature Ts (K),
% CO2 concentration CO2 (in ppm), assuming fixed relative humidity.
%
% EPSA = 1 - exp(-TAUinf) = emissivity of a gray layer
% TAUinf = ALPHA*CO2 + GAMMA*Qa = optical depth
% ref values: ALPHA = .001  (CO2 in ppm)
%             GAMMA = .7   (Qa in g/kg)
% will produce TAUinf~2 for Ts=288K, Ta=255K, RH=0.5 and CO2=280ppm
%
% Ref: Emanuel, 2002.

   function EPSA = calc_EPSA(Ts,Ta,RHa,CO2,BlackBody)
   
   if BlackBody == 1
   
       EPSA = 1; return;
   
   else
       
     % Read Parameter
     TwoBox_Param;
    
     % Computes (low level) specific humidity 
     Pa = 750; %low level pressure (mb)
     [Esat,Qsat] = Clausius_Clapeyron((Ts+Ta)/2,Pa);
     Qa = 1000*RHa * Qsat; %in g/kg
   
     % Test
     %ALPHA*CO2, GAMMA*Qa, ' **'
   
     % Computes optical depth
     TAUinf = ALPHA*CO2 + GAMMA*Qa;
   
     % Computes emissivity
     EPSA = 1-exp(-TAUinf);
   
   end