gregoria.m
changeset 0 0a450563f904
equal deleted inserted replaced
-1:000000000000 0:0a450563f904
       
     1 function [gtime]=gregorian(julian)
       
     2 %GREGORIAN  Converts Julian day numbers to corresponding
       
     3 %       Gregorian calendar dates.  Although formally, 
       
     4 %       Julian days start and end at noon, here Julian days
       
     5 %       start and end at midnight for simplicity.
       
     6 %     
       
     7 %       In this convention, Julian day 2440000 begins at 
       
     8 %       0000 hours, May 23, 1968.
       
     9 %
       
    10 %     Usage: [gtime]=gregorian(julian) 
       
    11 %
       
    12 %        julian... input decimal Julian day number
       
    13 %
       
    14 %        gtime is a six component Gregorian time vector
       
    15 %          i.e.   gtime=[yyyy mo da hr mi sec]
       
    16 %                 gtime=[1989 12  6  7 23 23.356]
       
    17  
       
    18 %        yr........ year (e.g., 1979)
       
    19 %        mo........ month (1-12)
       
    20 %        d........ corresponding Gregorian day (1-31)
       
    21 %        h........ decimal hours
       
    22 %
       
    23 %  calls S2HMS
       
    24  
       
    25       julian=julian+5.e-9;    % kludge to prevent roundoff error on seconds
       
    26 
       
    27 %      if you want Julian Days to start at noon...
       
    28 %      h=rem(julian,1)*24+12;
       
    29 %      i=(h >= 24);
       
    30 %      julian(i)=julian(i)+1;
       
    31 %      h(i)=h(i)-24;
       
    32 
       
    33       secs=rem(julian,1)*24*3600;
       
    34 
       
    35       j = floor(julian) - 1721119;
       
    36       in = 4*j -1;
       
    37       y = floor(in/146097);
       
    38       j = in - 146097*y;
       
    39       in = floor(j/4);
       
    40       in = 4*in +3;
       
    41       j = floor(in/1461);
       
    42       d = floor(((in - 1461*j) +4)/4);
       
    43       in = 5*d -3;
       
    44       m = floor(in/153);
       
    45       d = floor(((in - 153*m) +5)/5);
       
    46       y = y*100 +j;
       
    47       mo=m-9;
       
    48       yr=y+1;
       
    49       i=(m<10);
       
    50       mo(i)=m(i)+3;
       
    51       yr(i)=y(i);
       
    52       [hour,min,sec]=s2hms(secs);
       
    53       gtime=[yr(:) mo(:) d(:) hour(:) min(:) sec(:)];
       
    54 %=======================================================
       
    55 function [hour,min,sec]=s2hms(secs)
       
    56 %S2HMS converts seconds to integer hour,minute,seconds
       
    57 %
       
    58 sec=round(secs);
       
    59 hour=floor(sec/3600);
       
    60 min=floor(rem(sec,3600)/60);
       
    61 sec=round(rem(sec,60));
       
    62