This file is indexed.

/usr/share/dynare/matlab/@dates/subsref.m is in dynare-common 4.4.1-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
function B = subsref(A,S) % --*-- Unitary tests --*--

% Overload the subsref method for dates objects.
%
% INPUTS 
%  o A     dates object.
%  o S     matlab's structure.
%
% OUTPUTS 
%  o B     dates object.
%
% REMARKS 
%  See the matlab's documentation about the subsref method.

% Copyright (C) 2011-2013 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.

switch S(1).type
  case '.'
    switch S(1).subs
      case {'time','freq','ndat'}% Access public members.
        if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
            error(['dates::subsref: ' S(1).subs ' is not a method but a member!'])
        end
        B = builtin('subsref', A, S(1));
      case {'sort','unique','double','isempty','length'}% Public methods (without arguments)
        B = feval(S(1).subs,A);
        if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
           S = shiftS(S);
        end
      case {'append','pop'}% Public methods (with arguments).
        if isequal(S(2).type,'()')
            B = feval(S(1).subs,A,S(2).subs{:});
            S = shiftS(S);
        else
            error('dates::subsref: Something is wrong in your syntax!')
        end
      otherwise
        error('dates::subsref: Unknown public member or method!')
    end
  case '()'
    if isempty(A)
        if isempty(A.freq)
            % Populate an empty dates object with time member (freq is not specified). Needs two or three inputs. First input is an integer
            % scalar specifying the frequency. Second input is either the time member (a n*2 array of integers) or a column vector with n
            % elements (the first column of the time member --> years). If the the second input is a row vector and if A.freq~=1 a third input
            % is necessary. The third input is n*1 vector of integers between 1 and A.freq (second column of the time member --> subperiods).
            B = dates();
            % First input is the frequency.
            if isfreq(S(1).subs{1})
                if ischar(S(1).subs{1})
                    B.freq = string2freq(S(1).subs{1});
                else
                    B.freq = S(1).subs{1};
                end
            else
                error('dates::subsref: First input must be a frequency!')
            end
            if isequal(length(S(1).subs),2)
                % If two inputs are provided, the second input must be a n*2 array except if frequency is annual.
                [n, m] = size(S(1).subs{2});
                if m>2
                    error('dates::subsref: Second input argument array cannot have more than two columns!')
                end
                if ~isequal(m,2) && ~isequal(B.freq,1)
                    error('dates::subsref: Second argument has to be a n*2 array for non annual frequency!')
                end
                if ~all(all(S(1).subs{2}))
                    error('dates::subsref: Second argument has be an array of intergers!')
                end
                if m>1 && ~issubperiod(S(1).subs{2}(:,2),B.freq)
                    error(['dates::subsref: Elements in the second column of the first input argument are not legal subperiods (should be integers betwwen 1 and ' num2str(B.freq) ')!'])
                end
                if isequal(m,2)
                    B.time = S(1).subs{2};
                elseif isequal(m,1)
                    B.time = [S(1).subs{2}, ones(n,1)];
                else
                    error(['dates::subsref: This is a bug!'])
                end
                B.ndat = rows(B.time);
            elseif isequal(length(S(1).subs),3)
                % If three inputs are provided, the second and third inputs are column verctors of integers (years and subperiods).
                if ~iscolumn(S(1).subs{2}) && ~all(isint(S(1).subs{2}))
                    error('dates::subsref: Second input argument must be a column vector of integers!')
                end
                n1 = size(S(1).subs{2},1);
                if ~iscolumn(S(1).subs{3}) && ~issubperiod(S(1).subs{3}, B.freq)
                    error(['dates::subsref: Third input argument must be a column vector of subperiods (integers between 1 and ' num2str(B.freq) ')!'])
                end
                n2 = size(S(1).subs{3},1);
                if ~isequal(n1,n2)
                    error('dates::subsref: Second and third input arguments must have the same number of elements!')
                end
                B.time = [S(1).subs{2}, S(1).subs{3}];
                B.ndat = rows(B.time);
            else
                error('dates::subsref: Wrong calling sequence!')
            end
        else
            % Populate an empty dates object with time member (freq is already specified).
            % Needs one (time) or two (first and second columns of time for years and subperiods) inputs.
            B = A;
            if isequal(length(S(1).subs),2)
                if ~iscolumn(S(1).subs{1}) && ~all(isint(S(1).subs{1}))
                    error('dates::subsref: First argument has to be a column vector of integers!')
                end
                n1 = size(S(1).subs{1},1);
                if ~iscolumn(S(1).subs{2}) && ~issubperiod(S(1).subs{2}, B.freq)
                    error(['dates::subsref: Second argument has to be a column vector of subperiods (integers between 1 and ' num2str(B.freq) ')!'])
                end
                n2 = size(S(1).subs{2},1);
                if ~isequal(n2,n1)
                    error('dates::subsref: First and second argument must have the same number of rows!')
                end
                B.time = [S(1).subs{1}, S(1).subs{2}];
                B.ndat = rows(B.time);
            elseif isequal(length(S(1).subs),1)
                [n, m] = size(S(1).subs{1});
                if ~isequal(m,2) && ~isequal(B.freq,1)
                    error('dates::subsref: First argument has to be a n*2 array!')
                end
                if ~all(isint(S(1).subs{1}(:,1)))
                    error('dates::subsref: First column of the first argument has to be a column vector of integers!')
                end
                if m>1 && issubperiod(S(1).subs{1}(:,1), B.freq)
                    error(['dates::subsref: The second column of the first input argument has to be a column  vector of subperiods (integers between 1 and ' num2str(B.freq) ')!'])
                end
                if isequal(m,2)
                    B.time = S(1).subs{1};
                elseif isequal(m,1) && isequal(B.freq,1)
                    B.time = [S(1).subs{1}, ones(n,1)];
                else
                    error(['dates::subsref: This is a bug!'])
                end
                B.ndat = rows(B.time);
            else
                error('dates::subsref: Wrong number of inputs!')
            end
        end
    else
        % dates object A is not empty. We extract some dates
        if isvector(S(1).subs{1}) && all(isint(S(1).subs{1})) && all(S(1).subs{1}>0) && all(S(1).subs{1}<=A.ndat)
            B = dates();
            B.freq = A.freq;
            B.time = A.time(S(1).subs{1},:);
            B.ndat = rows(B.time);
        else
            error(['dates::subsref: indices has to be a vector of positive integers less than or equal to ' int2str(A.ndat) '!'])
        end
    end
  otherwise
    error('dates::subsref: Something is wrong in your syntax!')
end

S = shiftS(S);
if ~isempty(S)
    B = subsref(B, S);
end

%@test:1
%$ % Define a dates object
%$ B = dates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
%$
%$ % Try to extract a sub-dates object.
%$ d = B(2:3);
%$
%$ if isa(d,'dates')
%$     t(1) = 1;
%$ else
%$     t(1) = 0;
%$ end
%$
%$ if t(1)
%$     t(2) = dyn_assert(d.freq,B.freq);
%$     t(3) = dyn_assert(d.time,[1950 2; 1950 3]);
%$     t(4) = dyn_assert(d.ndat,2);
%$ end
%$ T = all(t);
%@eof:1

%@test:2
%$ % Define a dates object
%$ B = dates('1950Q1'):dates('1960Q3');
%$
%$ % Try to extract a sub-dates object and apply a method
%$ 
%$ d = B(2:3).sort ;
%$
%$ if isa(d,'dates')
%$     t(1) = 1;
%$ else
%$     t(1) = 0;
%$ end
%$
%$ if t(1)
%$     t(2) = dyn_assert(d.freq,B.freq);
%$     t(3) = dyn_assert(d.time,[1950 2; 1950 3]);
%$     t(4) = dyn_assert(d.ndat,2);
%$ end
%$ T = all(t);
%@eof:2

%@test:3
%$ % Define a dates object
%$ B = dates('1950Q1'):dates('1960Q3');
%$
%$ % Try to extract a sub-dates object and apply a method
%$
%$ d = B(2:3).sort() ;
%$
%$ if isa(d,'dates')
%$     t(1) = 1;
%$ else
%$     t(1) = 0;
%$ end
%$
%$ if t(1)
%$     t(2) = dyn_assert(d.freq,B.freq);
%$     t(3) = dyn_assert(d.time,[1950 2; 1950 3]);
%$     t(4) = dyn_assert(d.ndat,2);
%$ end
%$ T = all(t);
%@eof:3

%@test:4
%$ % Define a dates object
%$ B = dates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
%$
%$ % Try to extract a sub-dates object.
%$ d = B(2);
%$
%$ if isa(d,'dates')
%$     t(1) = 1;
%$ else
%$     t(1) = 0;
%$ end
%$
%$ if t(1)
%$     t(2) = dyn_assert(d.freq,B.freq);
%$     t(3) = dyn_assert(d.time,[1950 2]);
%$     t(4) = dyn_assert(d.ndat,1);
%$ end
%$ T = all(t);
%@eof:4

%@test:5
%$ % Define an empty dates object with quaterly frequency.
%$ qq = dates('Q');
%$
%$ % Define a ranges of dates using qq.
%$ try
%$     r1 = qq(1950,1):qq([1950, 3]);
%$     t(1) = 1;
%$ catch
%$     t(1) = 0;
%$ end
%$ if t(1)
%$     try
%$         r2 = qq([1950, 1; 1950, 2; 1950, 3]);
%$         t(2) = 1;
%$     catch
%$         t(2) = 0;
%$     end
%$ end
%$ if t(1) && t(2)
%$     try
%$         r3 = qq(1950*ones(3,1), transpose(1:3));
%$         t(3) = 1;
%$     catch
%$         t(3) = 0;
%$     end
%$ end
%$
%$ if t(1) && t(2) && t(3)
%$     t(4) = dyn_assert(isequal(r1,r2),1);
%$     t(5) = dyn_assert(isequal(r1,r3),1);
%$ end
%$ T = all(t);
%@eof:5

%@test:6
%$ % Define an empty dates object with quaterly frequency.
%$ date = dates();
%$
%$ % Define a ranges of dates using qq.
%$ try
%$     r1 = date(4,1950,1):date(4,[1950, 3]);
%$     t(1) = 1;
%$ catch
%$     t(1) = 0;
%$ end
%$ if t(1)
%$     try
%$         r2 = date(4,[1950, 1; 1950, 2; 1950, 3]);
%$         t(2) = 1;
%$     catch
%$         t(2) = 0;
%$     end
%$ end
%$ if t(1) && t(2)
%$     try
%$         r3 = date(4,1950*ones(3,1), transpose(1:3));
%$         t(3) = 1;
%$     catch
%$         t(3) = 0;
%$     end
%$ end
%$
%$ if t(1) && t(2) && t(3)
%$     t(4) = dyn_assert(isequal(r1,r2),1);
%$     t(5) = dyn_assert(isequal(r1,r3),1);
%$ end
%$ T = all(t);
%@eof:6