Home > utilities > greg2julian.m

greg2julian

PURPOSE ^

This function converts the Gregorian dates to Julian dates.

SYNOPSIS ^

function [JD,julianday] =greg2julian(year,month,day,hour,min,sec)

DESCRIPTION ^

 This function converts the Gregorian dates to Julian dates.

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

 1. Inputs:
     year, month, day = date in Gregorian calendar.
     hour,min,sec = time at universal time.

 2. Outputs:
     JD = Julian date.
     julianday = day of week.

 3. Example:
  >> [a,b] = greg2julian(2006,5,30,2,30,28)
  a =

           2453885.60449074
  b =

  Tuesday

  4. Notes:
     - For all common era (CE) dates in the Gregorian calendar, and for more
     information, check the referents.
     - 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. 9.
     Seidelmann, P. K. (1992). Explanatory Supplement to the Astronomical Almanac.
               University Science Books, USA.  pp. 55-56.
      Weisstein, Eric W.  "Julian Date".  From World of Astronomy--A Wolfram Web Resource.
               http://scienceworld.wolfram.com/astronomy/JulianDate.html

 Gabriel Ruiz Mtz.
 May-2006

 Modifications:
 04/06/06: To find the days, it was only changed the loop to a cell array. Thanks to Jerome.
 2014-07-29 Fix input arguments check (Pierre Cazenave, Plymouth Marine
   Laboratory).
 ------------------------------------------------------------------------------------------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [JD,julianday] =greg2julian(year,month,day,hour,min,sec)
0002 % This function converts the Gregorian dates to Julian dates.
0003 %
0004 % 0. Syntax:
0005 % [JD,julianday] = juliandate(year,month,day,hour,min,sec)
0006 %
0007 % 1. Inputs:
0008 %     year, month, day = date in Gregorian calendar.
0009 %     hour,min,sec = time at universal time.
0010 %
0011 % 2. Outputs:
0012 %     JD = Julian date.
0013 %     julianday = day of week.
0014 %
0015 % 3. Example:
0016 %  >> [a,b] = greg2julian(2006,5,30,2,30,28)
0017 %  a =
0018 %
0019 %           2453885.60449074
0020 %  b =
0021 %
0022 %  Tuesday
0023 %
0024 %  4. Notes:
0025 %     - For all common era (CE) dates in the Gregorian calendar, and for more
0026 %     information, check the referents.
0027 %     - The function was tested, using  the julian date converter of U.S. Naval Observatory and
0028 %     the results were similar. You can check it.
0029 %     - Trying to do the life... more easy with the conversions.
0030 %
0031 % 5. Referents:
0032 %     Astronomical Applications Department. "Julian Date Converter". From U.S. Naval Observatory.
0033 %               http://aa.usno.navy.mil/data/docs/JulianDate.html
0034 %     Duffett-Smith, P. (1992).  Practical Astronomy with Your Calculator.
0035 %               Cambridge University Press, England:  pp. 9.
0036 %     Seidelmann, P. K. (1992). Explanatory Supplement to the Astronomical Almanac.
0037 %               University Science Books, USA.  pp. 55-56.
0038 %      Weisstein, Eric W.  "Julian Date".  From World of Astronomy--A Wolfram Web Resource.
0039 %               http://scienceworld.wolfram.com/astronomy/JulianDate.html
0040 %
0041 % Gabriel Ruiz Mtz.
0042 % May-2006
0043 %
0044 % Modifications:
0045 % 04/06/06: To find the days, it was only changed the loop to a cell array. Thanks to Jerome.
0046 % 2014-07-29 Fix input arguments check (Pierre Cazenave, Plymouth Marine
0047 %   Laboratory).
0048 % ------------------------------------------------------------------------------------------------------------
0049 
0050    narginchk(6,6)
0051    timeut = hour + ( min / 60 ) + ( sec / 3600 );
0052 
0053    %For common era (CE), anno domini (AD)
0054    JD = ( 367 * year ) - floor ( 7 * ( year + floor( ( month + 9 ) / 12 ) ) / 4 ) - ...
0055                      floor( 3 * ( floor( ( year + ( month - 9 ) / 7 ) / 100 ) + 1 ) / 4 ) + ...
0056                      floor( ( 275 * month ) / 9 ) + day + 1721028.5 + ( timeut / 24 );
0057    a = ( JD + 1.5 ) / 7;
0058    frac = a - floor(a);
0059    n = floor(frac * 7) ;
0060    julianday ={ 'Sunday' 'Monday' 'Tuesday' 'Wednesday' 'Thursday' 'Friday' 'Saturday'};
0061    julianday = julianday{n+1};
0062 
0063

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