Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/fn_dataext.m

raw
1 function [xdsube,Brow,Erow] = fn_dataext(Byrqm,Eyrqm,xdatae)
2 % xdsube = dataext(Byrqm,Eyrqm,xdatae)
3 % Extract subset of xdatae, given Byrqm and Eyrqm
4 %
5 % Byrqm: [year quarter(month)]: beginning year and period. If Byqm(2)=0, we get annual data.
6 % Eyrqm: [year period]: end year and period. If Byrqm(2)=0, it must be Eyrqm(2)=0.
7 % xdatae: all data (some of which may be NaN) with the first 2 columns indicating years and periods.
8 %----------
9 % xdsube: subset of xdatae.
10 % Brow: the row number in xdatee that marks the first row of xdsube.
11 % Erow: the row number in xdatee that marks the last row of xdsube.
12 %
13 % Tao Zha, April 2000
14 %
15 % Copyright (C) 1997-2012 Tao Zha
16 %
17 % This free software: you can redistribute it and/or modify
18 % it under the terms of the GNU General Public License as published by
19 % the Free Software Foundation, either version 3 of the License, or
20 % (at your option) any later version.
21 %
22 % It is distributed in the hope that it will be useful,
23 % but WITHOUT ANY WARRANTY; without even the implied warranty of
24 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 % GNU General Public License for more details.
26 %
27 % If you did not received a copy of the GNU General Public License
28 % with this software, see <http://www.gnu.org/licenses/>.
29 %
30
31
32 if (Byrqm(2)==0) & (Eyrqm(2)~=0)
33 error('If annual data, make sure both Byrqm(2) and Eyrqm(2) are zero')
34 end
35
36 Brow = min(find(xdatae(:,1)==Byrqm(1)));
37 if isempty(Brow)
38 error('Byrqm is outside the date range indicated by xdatae(:,1:2)!')
39 end
40 if Byrqm(2)>0
41 nadt=Byrqm(2)-xdatae(Brow,2);
42 if nadt<0
43 error('Byrqm is outside the date range indicated by xdatae(:,1:2)!')
44 end
45 Brow=Brow+nadt;
46 end
47 %
48 Erow = min(find(xdatae(:,1)==Eyrqm(1)));
49 if isempty(Erow)
50 error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!')
51 end
52 if Eyrqm(2)>0
53 nadt2=Eyrqm(2)-xdatae(Erow,2);
54 if nadt<0
55 error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!')
56 end
57 Erow=Erow+nadt2;
58 end
59 %
60 xdsube = xdatae(Brow:Erow,:); % with dates