Home > atmlab > time > dayofyear.m

dayofyear

PURPOSE ^

DAYOFYEAR Ordinal number of day in a year.

SYNOPSIS ^

function yd = dayofyear(varargin)

DESCRIPTION ^

DAYOFYEAR Ordinal number of day in a year.

   DAYOFYEAR(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) returns the ordinal
   day number in the given year plus a fractional part depending on the
   time of day.

   Any missing MONTH or DAY will be replaced by 1.  HOUR, MINUTE or SECOND
   will be replaced by zeros.

   If no date is specified, the current date and time is used.  Gregorian
   calendar is assumed.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

dayofyear.m

SOURCE CODE ^

0001 function yd = dayofyear(varargin)
0002 %DAYOFYEAR Ordinal number of day in a year.
0003 %
0004 %   DAYOFYEAR(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) returns the ordinal
0005 %   day number in the given year plus a fractional part depending on the
0006 %   time of day.
0007 %
0008 %   Any missing MONTH or DAY will be replaced by 1.  HOUR, MINUTE or SECOND
0009 %   will be replaced by zeros.
0010 %
0011 %   If no date is specified, the current date and time is used.  Gregorian
0012 %   calendar is assumed.
0013 
0014 %   Author:      Peter J. Acklam
0015 %   Time-stamp:  2002-03-03 12:52:04 +0100
0016 %   E-mail:      pjacklam@online.no
0017 %   URL:         http://home.online.no/~pjacklam
0018 
0019    nargsin = nargin;
0020    error(nargchk(0, 6, nargsin));
0021    if nargsin
0022       argv = { 1 1 1 0 0 0 };
0023       argv(1:nargsin) = varargin;
0024    else
0025       argv = num2cell(clock);
0026    end
0027    [year, month, day, hour, minute, second] = deal(argv{:});
0028 
0029    days_in_prev_months = [0 31 59 90 120 151 181 212 243 273 304 334];
0030 
0031 
0032    % Day in given month.
0033    yd = days_in_prev_months(month) ...               % days in prev. months
0034         + ( isleapyear(year) & ( month > 2 ) ) ...   % leap day
0035         + day ...                                    % day in month
0036         + ( second + 60*minute + 3600*hour )/86400;  % part of day

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005