%% tempaeros.m calculates the electron temperature at 600km
%% using the MATLAB version of the IRI code. The equation
%% is based on AEROS satellite data. Only the mean day and 
%% night temperatures are calculated.
%%

function [tmped,tmpen]=tempaeros(latmatm)

% latmatm = magnetic latitude of point of interest (rads)
% tmepd = day temperature (K)
% tmepn = night temperature (K)

latd=rad2deg(latmatm);
ett=exp(-latd/11.35);
tmped=2900-5600*ett./((ett+1).^2);
tmpen=839+1161./(1+exp(-(abs(latd)-45)/5));

%Add in a correction so the that day and night values agree at latmatm=pi/2. 
%Use a sine weighting for points above sL>0.8.
sl=sin(latmatm).^2;
poic=sl>0.8;
if any(any(poic))
 tmped0=tmped;
 tmpen0=tmpen;
 wt=sin(((sl(poic)-0.8)/0.4).*(pi/2)).^2;
 tmped(poic)=(1-wt).*tmped0(poic)+wt.*tmpen0(poic);
 tmpen(poic)=(1-wt).*tmpen0(poic)+wt.*tmped0(poic);
end
