function nss1970 = nosecsince1970(year,month,day,a,b,c)

% function nss1970 = nosecsince1970(year,month,day,a,b,c)
%
% compute the number of seconds since Jan. 1, 1970 0 UT
% 
% input time can be in Year, Month, Day, Hour, Minute, Second
%                   or Year, Month, Day, fractional time since 0UT

% Main equation:
% nss1970 = nds1970*spd + nss0ut
% #seconds since 1970 = (# days since 1970)*(seconds per day) + 
%   (# seconds since 0UT)

% nds1970

nds1970 = 0;   % total number of days since 1970

% compute # days in years leading up to current year
if year > 1970
	Y = (1970 : 1 : year - 1)';
	for i = 1:length(Y)
		if rem(Y(i),4)==0;
			nds1970 = nds1970 + 366;
		else
			nds1970 = nds1970 + 365;
		end
	end
end

% compute # days in months from 1st of year to current month
dpm = [31 28 31 30 31 30 31 31 30 31 30 31]; %days per month (non-leap yr)
if month > 1
	M = (1 : 1 : month - 1)';
	for i = 1:length(M)
		if M(i)==2 & rem(year,4)==0 % if February & leap year
			nds1970 = nds1970 + 29;
		else
			nds1970 = nds1970 + dpm(M(i));
		end
	end
end

% compute # days from 1st of month to current day
if day > 1
	D = (1 : 1 : day - 1)';
	nds1970 = nds1970 + length(D);
end

%disp([num2str(nds1970) ' days since 1970'])

% now compute # seconds since 0UT for the last day
if nargin == 6
	hour = a;
	minute = b;
	second = c;
	nss0ut = hour*60*60 + minute*60 + second;
elseif nargin == 4
	ft = a;
	nss0ut = ft*24*60*60;
end
%disp([num2str(nss0ut) ' seconds since 0UT'])

nss1970 = nds1970*24*60*60 + nss0ut;

