function []=tduni_plot(res)
% PURPOSE: Generate graphic output of the BFL or Denton 
%          temporal disaggregation method
% ------------------------------------------------------------
% SYNTAX: tduni_plot(res);
% ------------------------------------------------------------
% OUTPUT: Graphic output:
%         - High and low frequency series: y vs Y
% ------------------------------------------------------------
% INPUT: res: structure generated by bfl or denton programs
% ------------------------------------------------------------
% LIBRARY: temporal_agg, copylow
% ------------------------------------------------------------
% SEE ALSO: bfl, denton_uni, tduni_plot

% written by:
%  Enrique M. Quilis
%  Macroeconomic Research Department
%  Ministry of Economy and Competitiveness
%  <enrique.quilis@mineco.es>

% 1: Generation of a 'naive' high freq. series using low freq. data
% 2: Plot of low freq. input and high freq. output (divided by sc)

n = res.N * res.sc;

Y = temporal_agg(res.y,res.ta,res.sc);

ya = copylow(Y,res.ta,res.sc);

if (res.ta == 1)
   g1=res.sc;
else
   g1=1;
end

t=1:n;
plot(t,res.y(1:end-res.pred),'b-',t,ya/g1,'r-');
axis ([0 n+1 min(res.y)*0.99 max(res.y)*1.01]);
grid off; legend (res.meth,'naive',0);
title ('High frequency and low frequency series');
xlabel ('time'); 

switch res.meth
case {'Boot-Feibes-Lisman'}
   % Do nothing
case {'Denton','Proportional Denton'}
   figure;
   t=1:n+res.pred;
   plot(t,res.y,'r-',t,res.x,'b-');
   grid off; legend ('y','x',0);
   title ('High frequency conformity');
   xlabel ('time');
   % -----------------------------------------------------------
   % High and low frequency residuals: u vs U
   %   1. Generate a high freq. time series with the low freq. data
   %   2. Plot both series (low freq. divides by g1)
   ua = copylow(res.U,res.ta,res.sc);
   figure;
   t=1:n;
   plot(t,res.u(1:end-res.pred),'r-',t,ua/g1,'b-');
   grid off; legend ('u','U',0);
   title ('High frequency and low frequency residuals');
   xlabel ('time'); 
end




   