%% temptruh.m calls the FORTRAN code from the IRI for the
%% Truhlik et al. electron temperature model. For each 
%% point it returns the temperature at 550km, 900km, 1500km
%% and 2500km. For input of size m x n the output array is
%% (mxn) x 4, where the four columns correspond to the
%% above altitudes respectively. 
%%

function tmpe=temptruh(latmatm,timmlt,dno,f107,seas,f107s)

% latmatm = geomagnetic latitude of points of interest (rads).
% timmlt = magnetic local time of points of interest (fractional hours). 
% dno = day number of points of interest.
% f107 = F10.7 of points of interest (ignored if f107s==0)
% seas = include seasonal asymmetry effects (0 = no, 1 = yes) (scalar)
% f107s = include F107 effects (0 = no, 1 = yes) (scalar)
% 
% tmpe = electron temperatures at point of interest (K).

cd iri2000

%Save to file the required parameters
fid=fopen('data.txt','w');       
fprintf(fid,'%d %d\r\n',f107s,seas);                     
fprintf(fid,'%d %f %e %e\r\n',[dno(:)';latmatm(:)';timmlt(:)';f107(:)']);
fclose(fid);

%call Fortran subrountine in IRI directory to calculate temperatures using Truhlik et al. electron temperature model.
!pwtruhtp                     

%load in results from IRI
fid=fopen('res.txt','r');
tmpe=fscanf(fid,'%e %e %e %e',[4 inf]);
fclose(fid);

delete res.txt 

tmpe=tmpe';                           %required electron temperatures  
                  
cd ..
