Home > bobstuff > greg2.m

greg2

PURPOSE ^

GREG2 converts year day numbers to corresponding Gregorian calendar dates.

SYNOPSIS ^

function [gtime]=greg2(yrday,yr)

DESCRIPTION ^

 GREG2 converts year day numbers to corresponding Gregorian calendar dates.

 [gtime]=GREG2(yrday,yr) converts year day numbers to corresponding 
 Gregorian calendar dates.  In this convention, Julian day 2440000 
 begins at 0000 Z, May 23, 1968. 

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

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 ver. 1: 5/15/91 (RS)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Thu 01-Dec-2005 07:46:03 by m2html © 2003