function [epoch] = htoe(year, jday, hour, min, sec, msec)
% converts time in year, julian day, hour, minute, second, millisecond format
% to time in seconds after midnight, January 1, 1970.
%
% input:
%          year, an integer, e.g. 2010
%          julian, an integer, the day of the year, where January  1 is 1
%          hour, an integer, the hour of the day, starting with 0
%          minute, an integer, the minute of the hour, starting with 0
%          sec, an integer, the second of the minute, starting with 0
%          msec, an integer, the milliseconds of the second, starting with 0
% output:
%          epoch, the number of secobds after midnight, January 1, 1970.
%
% example: January 10, 2010 at 01:02:03.040
%          e = htoe( 2010, 10, 1, 2, 3, 40)
%
% Note 1: the julian() script can calculate julian day from year-month-day
%
% Note 2: The calculation does not include leap seconds.  It will give correct
% epoch times for GPS and TIA clock standards, but will be off for the UTC standard.
% When two epoch times are subtracted to calculate a time interval, the length
% of the interval could be incorrect by as much as 2 seconds per year.

epoch=0.0;

if( year<1970 )
    sprintf('sorry: cant handle pre-1970 data')
    return;
end

days=0;
if( year > 1970 )
    for i = [1970:year-1]
        days=days+365;
        if( isleap(i) )
            days=days+1;
        end
    end
end

days=days+(jday-1);
epoch = (86400.0*days) + (hour*3600.0) + (min*60.0) + sec + msec/1000.0;

return


