Home > matlab > @dynDate > colon.m

colon

PURPOSE ^

@info:

SYNOPSIS ^

function sp = colon(a,b)

DESCRIPTION ^

@info:
! @deftypefn {Function File} {@var{sp} =} colon (@var{a},@var{b})
! @anchor{@dynDate/colon}
! @sp 1
! Overloads the colon operator for the Dynare Dates class (@ref{dynDate}). Creates a @ref{dynTime} object.
! @sp 2
! @strong{Inputs}
! @sp 1
! @table @ @var
! @item a
! Dynare date object instantiated by @ref{dynDate}, initial date.
! @item b
! Dynare date object instantiated by @ref{dynDate}, last date.
! @end table
! @sp 1
! @strong{Outputs}
! @sp 1
! @table @ @var
! @item c
! Dynare Time object instantiated by @ref{dynTime}.
! @end table
! @sp 2
! @strong{This function is called by:}
! @sp 2
! @strong{This function calls:}
! @ref{dynTime}, @ref{@@dynTime/setFreq}, @ref{@@dynTime/setTime}, @ref{@@dynTime/setSize}
!
! @end deftypefn
@eod:

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function sp = colon(a,b)
0002 
0003 %@info:
0004 %! @deftypefn {Function File} {@var{sp} =} colon (@var{a},@var{b})
0005 %! @anchor{@dynDate/colon}
0006 %! @sp 1
0007 %! Overloads the colon operator for the Dynare Dates class (@ref{dynDate}). Creates a @ref{dynTime} object.
0008 %! @sp 2
0009 %! @strong{Inputs}
0010 %! @sp 1
0011 %! @table @ @var
0012 %! @item a
0013 %! Dynare date object instantiated by @ref{dynDate}, initial date.
0014 %! @item b
0015 %! Dynare date object instantiated by @ref{dynDate}, last date.
0016 %! @end table
0017 %! @sp 1
0018 %! @strong{Outputs}
0019 %! @sp 1
0020 %! @table @ @var
0021 %! @item c
0022 %! Dynare Time object instantiated by @ref{dynTime}.
0023 %! @end table
0024 %! @sp 2
0025 %! @strong{This function is called by:}
0026 %! @sp 2
0027 %! @strong{This function calls:}
0028 %! @ref{dynTime}, @ref{@@dynTime/setFreq}, @ref{@@dynTime/setTime}, @ref{@@dynTime/setSize}
0029 %!
0030 %! @end deftypefn
0031 %@eod:
0032 
0033 % Copyright (C) 2011 Dynare Team
0034 % stephane DOT adjemian AT univ DASH lemans DOT fr
0035 %
0036 % This file is part of Dynare.
0037 %
0038 % Dynare is free software: you can redistribute it and/or modify
0039 % it under the terms of the GNU General Public License as published by
0040 % the Free Software Foundation, either version 3 of the License, or
0041 % (at your option) any later version.
0042 %
0043 % Dynare is distributed in the hope that it will be useful,
0044 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0045 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0046 % GNU General Public License for more details.
0047 %
0048 % You should have received a copy of the GNU General Public License
0049 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0050 
0051 if nargin~=2
0052     error('dynTime::colon: I need exactly two input arguments!')
0053 end
0054 
0055 if ~( isa(a,'dynDate') && isa(b,'dynDate'))
0056     error(['dynTime::colon: Input arguments ' inputname(1) 'and ' inputname(2) ' have to be a dynDate objects!'])
0057 end
0058 
0059 if a.freq~=b.freq
0060     error(['dynTime::colon: Input arguments ' inputname(1) 'and ' inputname(2) ' must have common frequency!'])
0061 end
0062 
0063 if a>b
0064     error(['dynTime::colon: ' inputname(1) ' must precede ' inputname(2) '!' ])
0065 end
0066 
0067 if a==b% Time range with only one date.
0068     sp = dynTime();
0069     sp = sp.setFreq(a.freq);
0070     sp = sp.setSize(n+1);
0071     sp = sp.setTime(1,a.time);
0072 else
0073     n = b-a;
0074     sp = dynTime();
0075     sp = sp.setFreq(a.freq);
0076     sp = sp.setSize(n+1);
0077     sp = sp.setTime(1,a.time);
0078     for t=2:n+1
0079         a = +a;
0080         sp = sp.setTime(t,a.time);
0081     end
0082 end
0083 
0084 %@test:1
0085 %$ addpath ../matlab
0086 %$
0087 %$ % Define two dates
0088 %$ date_1 = '1950Q2';
0089 %$ date_2 = '1951Q4';
0090 %$
0091 %$ % Define expected results.
0092 %$ e.freq = 4;
0093 %$ e.time = [1950 2; 1950 3; 1950 4; 1951 1; 1951 2; 1951 3; 1951 4];
0094 %$
0095 %$ % Call the tested routine.
0096 %$ d1 = dynDate(date_1);
0097 %$ d2 = dynDate(date_2);
0098 %$ d3 = d1:d2;
0099 %$
0100 %$ % Check the results.
0101 %$ t(1) = dyn_assert(d3.time,e.time);
0102 %$ t(2) = dyn_assert(d3.freq,e.freq);
0103 %$ T = all(t);
0104 %@eof:1

Generated on Fri 18-May-2012 02:41:00 by m2html © 2005