function [j]=mjulian(y,m,d,h,force_true_julian) %JULIAN Converts Gregorian calendar dates to corresponding % modified Julian day numbers. % % Although the formal definition % holds that Julian days start and end at noon, here % Julian days start and end at midnight. % % In this convention, "true" Julian day 2440000 began at 0000 hours, May 23, 1968. % and modified Julian day 40000 began at 0000 hours, May 23, 1968. % % note that passing dates prior to Nov 17, 1858 will likely generate many % unreasonable errors % % Usage: [j]=julian(y,m,d,h) or [j]=julian([y m d hour min sec]) % % OR (as of 15 May 2006, bfleming) % % [j]=julian(y,m,d,h,force_true_julian) % % OR % % [j]= [j]=julian([y m d hour min sec],force_true_julian) % % so in summary: % nargs=1: [y,m,d,hr,mn,sc] --assume modified julian day wanted % nargs=2: [y,m,d,hr,mn,sc],force__true_julian --true julian day wanted % nargs=4: y,m,d,hr assume modified julian day wanted % nargs=5: y,m,d,hr,force_true_julian --true julian day returned % ************************************************************ % % d.... day (1-31) component of Gregorian date % m.... month (1-12) component % y.... year (e.g., 1979) component % j.... decimal Julian day number % h.... decimal hours (assumed 0 if absent) % force_true_julian (any value-not just any non-zero value-passed will do) % % ************************************************************ % recoded for MATLAB by Rich Signell, 5-15-91 % % some alteration to allow for modified julian dates rather than % the (larger) julian date, RJF 5/15/2005 % % NOTE: should really reduce complexity and restrict input to % one or two args, array + optional "force_true_julian". true_julian=0; switch nargin case {1,2}; h=hms2h(y(:,4),y(:,5),y(:,6)); d=y(:,3); m=y(:,2); y=y(:,1); if nargin==2 true_julian=1; end; case 3; h=0.; case 5; true_julian=1; end mo=m+9; yr=y-1; i=(m>2); mo(i)=m(i)-3; yr(i)=y(i); c = floor(yr/100); yr = yr - c*100; j = floor((146097*c)/4) + floor((1461*yr)/4) + ... floor((153*mo +2)/5) +d +1721119; % If you want julian days to start and end at noon, % replace the following line with: % j=j+(h-12)/24; j=j+h/24; %oldj=j; if ~true_julian; j=j-2400001; % or if starting at noon, %j=j-2400000.5; end; %save ~/julstate;