Home > utilities > julian2greg.m

julian2greg

PURPOSE ^

This function converts the Julian dates to Gregorian dates.

SYNOPSIS ^

function [year,month,day,hour,minu,sec,dayweek,dategreg] = julian2greg(JD)

DESCRIPTION ^

 This function converts the Julian dates to Gregorian dates.

 0. Syntax:
 [day,month,year,hour,min,sec,dayweek] = julian2greg(JD)

 1. Inputs:
     JD = Julian date.   

 2. Outputs:
     year, month, day, dayweek = date in Gregorian calendar.
     hour, min, sec = time at universal time.

 3. Example:
  >> [a,b,c,d,e,f,g,h] = julian2greg(2453887.60481)
  a = 
     2006      
  b =
     6
  c =
     1
  d =
     2
  e =
     30
  f =
     56
  g = 
     Thursday
  h =
       1     6     2006     2     30     56

 4. Notes:
     - For all common era (CE) dates in the Gregorian calendar.
     - The function was tested, using  the julian date converter of U.S. Naval Observatory and
     the results were similar. You can check it.
     - Trying to do the life... more easy with the conversions.

 5. Referents:
     Astronomical Applications Department. "Julian Date Converter". From U.S. Naval Observatory.
               http://aa.usno.navy.mil/data/docs/JulianDate.html
     Duffett-Smith, P. (1992).  Practical Astronomy with Your Calculator.
               Cambridge University Press, England:  pp. 8,9.

 Gabriel Ruiz Mtz.
 Jun-2006
 ____________________________________________________________________________________________

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [year,month,day,hour,minu,sec,dayweek,dategreg] = julian2greg(JD)
0002 % This function converts the Julian dates to Gregorian dates.
0003 %
0004 % 0. Syntax:
0005 % [day,month,year,hour,min,sec,dayweek] = julian2greg(JD)
0006 %
0007 % 1. Inputs:
0008 %     JD = Julian date.
0009 %
0010 % 2. Outputs:
0011 %     year, month, day, dayweek = date in Gregorian calendar.
0012 %     hour, min, sec = time at universal time.
0013 %
0014 % 3. Example:
0015 %  >> [a,b,c,d,e,f,g,h] = julian2greg(2453887.60481)
0016 %  a =
0017 %     2006
0018 %  b =
0019 %     6
0020 %  c =
0021 %     1
0022 %  d =
0023 %     2
0024 %  e =
0025 %     30
0026 %  f =
0027 %     56
0028 %  g =
0029 %     Thursday
0030 %  h =
0031 %       1     6     2006     2     30     56
0032 %
0033 % 4. Notes:
0034 %     - For all common era (CE) dates in the Gregorian calendar.
0035 %     - The function was tested, using  the julian date converter of U.S. Naval Observatory and
0036 %     the results were similar. You can check it.
0037 %     - Trying to do the life... more easy with the conversions.
0038 %
0039 % 5. Referents:
0040 %     Astronomical Applications Department. "Julian Date Converter". From U.S. Naval Observatory.
0041 %               http://aa.usno.navy.mil/data/docs/JulianDate.html
0042 %     Duffett-Smith, P. (1992).  Practical Astronomy with Your Calculator.
0043 %               Cambridge University Press, England:  pp. 8,9.
0044 %
0045 % Gabriel Ruiz Mtz.
0046 % Jun-2006
0047 % ____________________________________________________________________________________________
0048 
0049 error(nargchk(1,1,nargin))
0050 
0051 I = floor( JD + 0.5);
0052 Fr = abs( I - ( JD + 0.5) );     
0053 
0054 if I >= 2299160 
0055      A = floor( ( I- 1867216.25 ) / 36524.25 );
0056      a4 = floor( A / 4 );
0057      B = I + 1 + A - a4;
0058 else
0059      B = I;
0060 end 
0061 
0062 C = B + 1524;
0063 D = floor( ( C - 122.1 ) / 365.25 );
0064 E = floor( 365.25 * D );
0065 G = floor( ( C - E ) / 30.6001 );
0066 day = floor( C - E + Fr - floor( 30.6001 * G ) );
0067 
0068 if G <= 13.5 
0069     month = G - 1;
0070 else
0071     month = G - 13;
0072 end
0073 
0074 if month > 2.5
0075     year = D - 4716;
0076 else
0077     year = D - 4715;
0078 end
0079 
0080 hour = floor( Fr * 24 );
0081 minu = floor( abs( hour -( Fr * 24 ) ) * 60 );
0082 minufrac = ( abs( hour - ( Fr * 24 ) ) * 60 ); 
0083 sec = ceil( abs( minu - minufrac ) * 60);
0084 AA = ( JD + 1.5 ) / 7;
0085 nd = floor( (abs( floor(AA) - AA ) ) * 7 );
0086 dayweek ={ 'Sunday' 'Monday' 'Tuesday' 'Wednesday' 'Thursday' 'Friday' 'Saturday'};
0087 dayweek = dayweek{ nd+1};
0088 format('long', 'g');
0089 dategreg = [ day month year hour minu sec ];
0090

Generated on Wed 20-Feb-2019 16:06:01 by m2html © 2005