Debian Codegraph @

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

raw
1 function [Myrqm,nMyrqm] = calyrqm(q_m,Byrqm,Eyrqm)
2 % [Myrqm,nMyrqm] = calyrqm(q_m,Byrqm,Eyrqm)
3 %
4 % Given the beginning and end years and quarters (months), export a matrix of all years and
5 % quarters (months) for these years and in between
6 %
7 % q_m: 4 if quarterly and 12 if monthly
8 % Byrqm: [year quarter(month)] -- all integers, the begining year and quarter (month)
9 % Eyrqm: [year quarter(month)] -- all integers, the end year and quarter (month)
10 %-------------------
11 % Myrqm: matrix of all years and quarters (months) between and incl. Byrqm and Eyrqm
12 % nMyrqm: number of data points incl. Byrqm and Eyrqm
13 %
14 % Tao Zha, April 2000
15 %
16 % Copyright (C) 1997-2012 Tao Zha
17 %
18 % This free software: you can redistribute it and/or modify
19 % it under the terms of the GNU General Public License as published by
20 % the Free Software Foundation, either version 3 of the License, or
21 % (at your option) any later version.
22 %
23 % It is distributed in the hope that it will be useful,
24 % but WITHOUT ANY WARRANTY; without even the implied warranty of
25 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 % GNU General Public License for more details.
27 %
28 % If you did not received a copy of the GNU General Public License
29 % with this software, see <http://www.gnu.org/licenses/>.
30 %
31
32 if ~isempty(find(Byrqm-round(Byrqm))) | (q_m-round(q_m)) | ~isempty(find(Byrqm-round(Byrqm)))
33 error('argin qm, Byrqm, or Eyrqm must of integer')
34 elseif Byrqm(1)>Eyrqm(1)
35 error('Eyrqm(1) must be equal to or greater than Byrqm(1)')
36 elseif Byrqm(1)==Eyrqm(1)
37 if Byrqm(2)>Eyrqm(2)
38 error('Eyrqm(2) must be equal to or greater than Byrqm(2) because of the same year')
39 end
40 end
41
42
43 Yr = Byrqm(1)+[0:Eyrqm(1)-Byrqm(1)]';
44
45 if length(Yr)>=2 % there are years and quarters (months) between Byrqm and Eyrqm
46 n=length(Yr)-2;
47 C=zeros(n*q_m,2);
48 C(:,1) = kron(Yr(2:end-1),ones(q_m,1));
49 C(:,2) = kron(ones(n,1),[1:q_m]');
50
51 %* initialize a matrix of years and quarters (months) including Byrqm and Eyrqm
52 Myrqm = zeros((q_m-Byrqm(2)+1)+Eyrqm(2)+n*q_m,2);
53
54 %* Years in between
55 n1=q_m-Byrqm(2)+1;
56 n2=Eyrqm(2);
57 Myrqm(n1+1:end-n2,:) = C;
58 %* Beginning year
59 for k=1:n1
60 Myrqm(k,:) = [Byrqm(1) Byrqm(2)+k-1];
61 end
62 %* End year
63 for k=1:n2
64 Myrqm(end-Eyrqm(2)+k,:) = [Eyrqm(1) k];
65 end
66 else %* all the data are in the same calendar year
67 n1=Eyrqm(2)-Byrqm(2)+1;
68 Myrqm = zeros(n1,2);
69 for k=1:n1
70 Myrqm(k,:) = [Byrqm(1) Byrqm(2)+k-1];
71 end
72 end
73
74 nMyrqm = size(Myrqm,1);