1function fn_mseriesgraph(ydate,keyindx,rnum,cnum,q_m,xlab,ylab,tlab)
2% fn_mseriesgraph(ydate,keyindx,rnum,cnum,q_m,xlab,ylab,tlab)
3%   Graph actual series or point forecasts or both (annual or monthly or quarterly)
4%     with multiple series in one subplot.
5%
6% ydate:  T-by-n+2-by-h series data with dates in the first 2 columns in the order of year and month (or quarter).
7%           T: the length of an individual series.
8%           n+2:  n series plus the first 2 columns indicating dates.
9%           h:    the number of sereies on the 3rd dimension, put in the same subplot as in each of the n series.
10%                  Thus, the first 2 columns in the 3rd dimension can be NaN while
11%                  some elements are also allowed to be NaN if no data are available.
12% keyindx:  index for the variables to be graphed
13% rnum:  number of rows in subplot
14% cnum:  number of columns in subplot
15% q_m:  if 4 or 12, quarterly or monthly data
16% xlab:  1-by-1 x-axis label for what conditions imposed; e.g., conlab = 'All bar MS shocks inspl'
17% ylab:  string array for the length(keyindx)-by-1 variables
18% tlab:  1-by-1 title label for (e.g., as of time of forecast)
19%-------------
20% No output argument for this graph file
21%  See fn_foregraph.m, fn_forerrgraph.m.
22%
23% Tao Zha, September 2000
24%
25% Copyright (C) 1997-2012 Tao Zha
26%
27% This free software: you can redistribute it and/or modify
28% it under the terms of the GNU General Public License as published by
29% the Free Software Foundation, either version 3 of the License, or
30% (at your option) any later version.
31%
32% It is distributed in the hope that it will be useful,
33% but WITHOUT ANY WARRANTY; without even the implied warranty of
34% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
35% GNU General Public License for more details.
36%
37% If you did not received a copy of the GNU General Public License
38% with this software, see <http://www.gnu.org/licenses/>.
39%
40
41
42vyrs = ydate(:,1);     % vector column
43hornum = cell(length(vyrs),1);    % horizontal year (number)
44count=0;
45for k=vyrs'
46   count=count+1;
47   jnk=num2str(k);
48   if length(jnk)==4   % years
49      hornum{count}=jnk(3:4);   % e.g., with '1990', we have '90'
50   else
51      hornum{count}=jnk;   % e.g., with '1', '2', ...
52   end
53end
54
55if rnum*cnum<length(keyindx)
56   disp(' ')
57   warning('The total number of subplots must be greater that the number of selected series for graphing!')
58   disp('Press ctrl-c to abort')
59   pause
60end
61
62count=0;
63for i = keyindx
64   count = count+1;
65   subplot(rnum,cnum,count)
66   plot(ydate(:,1)+ydate(:,2)/q_m,squeeze(ydate(:,2+i,:)),...
67        ydate(:,1)+ydate(:,2)/q_m,zeros(length(vyrs),1),'-')
68
69   if (ydate(1,2)==0) & (length(num2str(ydate(1,1)))==4)      % only for annual growth rates (not for, say, monthly annualized rates)
70      set(gca,'XLim',[vyrs(1) vyrs(end)])
71      set(gca,'XTick',vyrs)
72      set(gca,'XTickLabel',char(hornum))
73   end
74
75   if i==keyindx(1)
76      title(tlab)
77   elseif i>=length(keyindx)   %i>=length(keyindx)-1
78      xlabel(xlab)
79   end
80   %
81   grid
82   ylabel(char(ylab(i)))
83end
84