Home > RPSstuff > gregorian.m

gregorian

PURPOSE ^

GREGORIAN: Converts Julian day numbers to Gregorian calendar.

SYNOPSIS ^

function [gtime]=gregorian(jd)

DESCRIPTION ^

 GREGORIAN:  Converts Julian day numbers to Gregorian calendar.

 USAGE:      [gtime]=gregorian(jd) 

 DESCRIPTION:  Converts decimal Julian days to Gregorian dates using the
               astronomical convension, but with time zero starting
               at midnight instead of noon.  In this convention, 
               Julian day 2440000 begins at 0000 hours, May 23, 1968.
               The Julian day does not have to be an integer, and with
               Matlab's double precision, the accuracy of decimal days
               is about 0.1 milliseconds.  


 INPUT:   jd  = decimal Julian days 
     
 OUTPUT:  gtime = six column Gregorian time matrix, where each row is
                  [yyyy mo da hr mi sec]. 
                   yyyy = year (e.g., 1979)
                        mo = month (1-12)
                           da = day (1-31)
                              hr = hour (0-23)
                                 mi = minute (0-59) 
                                     sec = decimal seconds 
                example: [1990 12 12 0 0 0] is midnight on Dec 12, 1990.

 AUTHOR: Rich Signell  (rsignell@usgs.gov)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [gtime]=gregorian(jd)
0002 % GREGORIAN:  Converts Julian day numbers to Gregorian calendar.
0003 %
0004 % USAGE:      [gtime]=gregorian(jd)
0005 %
0006 % DESCRIPTION:  Converts decimal Julian days to Gregorian dates using the
0007 %               astronomical convension, but with time zero starting
0008 %               at midnight instead of noon.  In this convention,
0009 %               Julian day 2440000 begins at 0000 hours, May 23, 1968.
0010 %               The Julian day does not have to be an integer, and with
0011 %               Matlab's double precision, the accuracy of decimal days
0012 %               is about 0.1 milliseconds.
0013 %
0014 %
0015 % INPUT:   jd  = decimal Julian days
0016 %
0017 % OUTPUT:  gtime = six column Gregorian time matrix, where each row is
0018 %                  [yyyy mo da hr mi sec].
0019 %                   yyyy = year (e.g., 1979)
0020 %                        mo = month (1-12)
0021 %                           da = day (1-31)
0022 %                              hr = hour (0-23)
0023 %                                 mi = minute (0-59)
0024 %                                     sec = decimal seconds
0025 %                example: [1990 12 12 0 0 0] is midnight on Dec 12, 1990.
0026 %
0027 % AUTHOR: Rich Signell  (rsignell@usgs.gov)
0028 %
0029 
0030 % Add 0.2 milliseconds before Gregorian calculation to prevent
0031 % roundoff error resulting from math operations on time
0032 % from occasionally representing midnight as
0033 % (for example) [1990 11 30 23 59 59.99...] instead of [1990 12 1 0 0 0]);
0034 % If adding a 0.2 ms to time (each time you go back and forth between
0035 % Julian and Gregorian) bothers you more than the inconvenient representation
0036 % of Gregorian time at midnight you can comment this line out...
0037 
0038       jd=jd+2.e-9;    
0039                             
0040 
0041 %      if you want Julian Days to start at noon...
0042 %      h=rem(jd,1)*24+12;
0043 %      i=(h >= 24);
0044 %      jd(i)=jd(i)+1;
0045 %      h(i)=h(i)-24;
0046 
0047       secs=rem(jd,1)*24*3600;
0048 
0049       j = floor(jd) - 1721119;
0050       in = 4*j -1;
0051       y = floor(in/146097);
0052       j = in - 146097*y;
0053       in = floor(j/4);
0054       in = 4*in +3;
0055       j = floor(in/1461);
0056       d = floor(((in - 1461*j) +4)/4);
0057       in = 5*d -3;
0058       m = floor(in/153);
0059       d = floor(((in - 153*m) +5)/5);
0060       y = y*100 +j;
0061       mo=m-9;
0062       yr=y+1;
0063       i=(m<10);
0064       mo(i)=m(i)+3;
0065       yr(i)=y(i);
0066       [hour,min,sec]=s2hms(secs);
0067       gtime=[yr(:) mo(:) d(:) hour(:) min(:) sec(:)];

Generated on Wed 30-Nov-2005 14:45:02 by m2html © 2003