%% timml2lon.m converts from local magnetic time to magnetic longitude.
%% Magnetic local time is defined as (in degrees)  MLT = 180 + geomagnetic
%% longitude of point - geomagnetic longitude of subsolar point. To 
%% determine the subsolar point, calculate the solar declination and from
%% that determine its magnetic longitude. 
%% 

function lonmatm=timml2lon(timmat,timmlt,dno)

% timmat = univerisal time
% dno = day number matrix
% timmlt = local magnetic time
% lonmatm = magnetic longitude (rads)

lonmats=longch(pi-(pi/12)*timmat);           %geographic longitude of subsolar point 
dec=soco2(lonmats,timmat,dno);               %solar declination angle 
lonmatms=geo2mag3(lonmats,dec);              %magnetic longitude of subsolar point
lonmatm=(pi/12)*(timmlt-12)+lonmatms;        %magnetic longitude of point of interest     
lonmatm=longch(lonmatm);                     %correct magnetic longitude to -pi -> pi

