1 ## Copyright (C) 2008 Bill Denney <bill@denney.ws>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{d} =} yeardays (@var{y})
18 ## @deftypefnx {Function File} {@var{d} =} yeardays (@var{y}, @var{b})
19 ## Return the number of days in the year @var{y} with an optional basis
25 ## actual/actual (default)
39 ## actual/365 (Japanese)
41 ## actual/actual (ISMA)
49 ## @seealso{days365, days360, daysact, daysdif}
52 function d = yeardays (y, basis)
61 d = zeros (size (basis));
62 elseif isscalar (basis)
63 ## the rest of the code is much simpler if you can be sure that
64 ## basis is a matrix if y is a matrix
65 basis = basis * ones (size (y));
68 if ndims (y) == ndims (basis)
69 if ~ all (size (y) == size (basis))
70 error ("year and basis must be the same size or one must be a scalar");
75 error ("year and basis must be the same size or one must be a scalar.")
79 bact = ismember (basis(:), [0 8]);
80 b360 = ismember (basis(:), [1 2 4 5 6 9 11]);
81 b365 = ismember (basis(:), [3 7 10]);
83 badbasismask = ~ (bact | b360 | b365);
85 badbasis = unique (basis(badbasismask));
86 error ("Unsupported basis: %g\n", badbasis)
89 d(bact) = 365 + (eomday(y(bact), 2) == 29);
96 %!assert(yeardays(2000), 366)
97 %!assert(yeardays(2001), 365)
98 %!assert(yeardays(2000:2004), [366 365 365 365 366])
99 %!assert(yeardays(2000, 0), 366)
100 %!assert(yeardays(2000, 1), 360)
101 %!assert(yeardays(2000, 2), 360)
102 %!assert(yeardays(2000, 3), 365)
103 %!assert(yeardays(2000, 4), 360)
104 %!assert(yeardays(2000, 5), 360)
105 %!assert(yeardays(2000, 6), 360)
106 %!assert(yeardays(2000, 7), 365)
107 %!assert(yeardays(2000, 8), 366)
108 %!assert(yeardays(2000, 9), 360)
109 %!assert(yeardays(2000, 10), 365)
110 %!assert(yeardays(2000, 11), 360)