Home > air_sea > greg2.m

greg2

PURPOSE ^

GREG2: converts decimal yearday to standard Gregorian time.

SYNOPSIS ^

function [gtime]=greg2(yd,yr)

DESCRIPTION ^

 GREG2: converts decimal yearday to standard Gregorian time.
 [gtime]=GREG2(yd,yr) converts decimal yearday to corresponding 
 Gregorian calendar dates.  In this convention, Julian day 2440000 
 begins at 0000 UT May 23 1968. 

  INPUT:   yd - decimal yearday (e.g., 0000 UT Jan 1 is 0.0)
           yr - year (e.g., 1995)

  OUTPUT:  gtime is a six component Gregorian time vector
                gtime=[year mo da hr mi sec]
            
     Example: [1995 01 01 12 00 00] = greg2(0.5, 1995)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001   function [gtime]=greg2(yd,yr)
0002 % GREG2: converts decimal yearday to standard Gregorian time.
0003 % [gtime]=GREG2(yd,yr) converts decimal yearday to corresponding
0004 % Gregorian calendar dates.  In this convention, Julian day 2440000
0005 % begins at 0000 UT May 23 1968.
0006 %
0007 %  INPUT:   yd - decimal yearday (e.g., 0000 UT Jan 1 is 0.0)
0008 %           yr - year (e.g., 1995)
0009 %
0010 %  OUTPUT:  gtime is a six component Gregorian time vector
0011 %                gtime=[year mo da hr mi sec]
0012 %
0013 %     Example: [1995 01 01 12 00 00] = greg2(0.5, 1995)
0014 
0015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0016 % 3/10/97: version 1.0
0017 % 4/7/99: version 1.2 (simplified by AA)
0018 % 8/5/99: version 2.0
0019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0020 
0021 js = julianmd(yr,01,01,00);
0022 julian = js + yd;
0023 julian=julian+5.e-9;  % kludge to prevent roundoff error on seconds
0024 
0025 %      if you want Julian Days to start at noon...
0026 %      h=rem(julian,1)*24+12;
0027 %      i=(h >= 24);
0028 %      julian(i)=julian(i)+1;
0029 %      h(i)=h(i)-24;  Otherwise,....
0030 
0031 secs=rem(julian,1)*24*3600;
0032 
0033 j = floor(julian) - 1721119;
0034 in = 4*j -1;
0035 y = floor(in/146097);
0036 j = in - 146097*y;
0037 in = floor(j/4);
0038 in = 4*in +3;
0039 j = floor(in/1461);
0040 d = floor(((in - 1461*j) +4)/4);
0041 in = 5*d -3;
0042 m = floor(in/153);
0043 d = floor(((in - 153*m) +5)/5);
0044 y = y*100 +j;
0045 mo=m-9;
0046 yr=y+1;
0047 i=(m<10);
0048 mo(i)=m(i)+3;
0049 yr(i)=y(i);
0050 [hour,min,sec]=s2hms(secs);
0051 gtime=[yr(:) mo(:) d(:) hour(:) min(:) sec(:)];
0052 
0053

Generated on Thu 26-Apr-2007 12:23:13 by m2html © 2003