Debian Codegraph @

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

raw
1 function [xdsube,Brow,Erow] = fn_dataext2(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)
33 Eyrqm(2)=0;
34 q_m1=find(xdatae(:,2)==xdatae(1,2)); % Locating quarter or month
35 if length(q_m1)<2
36 error('The matrix xdatae must at least have a cycle of q_m periods for possibly one calendar year')
37 end
38 q_m=q_m1(2)-1;
39 end
40
41 Brow = min(find(xdatae(:,1)==Byrqm(1)));
42 if isempty(Brow)
43 error('Byrqm is outside the date range indicated by xdatae(:,1:2)!')
44 end
45 if Byrqm(2)>0
46 nadt=Byrqm(2)-xdatae(Brow,2);
47 if nadt<0
48 error('Byrqm is outside the date range indicated by xdatae(:,1:2)!')
49 end
50 Brow=Brow+nadt;
51 end
52 %
53 Erow = min(find(xdatae(:,1)==Eyrqm(1)));
54 if isempty(Erow)
55 error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!')
56 end
57 if Eyrqm(2)>0
58 nadt2=Eyrqm(2)-xdatae(Erow,2);
59 if nadt<0
60 error('Eyrqm is outside the date range indicated by xdatae(:,1:2)!')
61 end
62 Erow=Erow+nadt2;
63 end
64 %
65
66 if (Byrqm(2)==0) % By calendar years.
67 if (xdatae(Brow,2)~=1) | (xdatae(Erow,2)~=1)
68 error('Calendar years extracted here must have q_m periods')
69 end
70 Erow=Erow+q_m-1;
71 end
72
73 xdsube = xdatae(Brow:Erow,:); % with dates