function Q = ann2qtr(A,s,method)
% QTR2ANN   reads in data in matrix A at an annual frequency and converts
%           it to a quarterly frequency via log-linear interpolation
%           if method=0 (default) or linear interpolation if method=1.
%           Q = qtr2ann(A,s) assumes that the first column of matrix 
%           A is the years of the sample period. The first column of
%           Q is in the form 1990.3 where 1990 is the year and 3 is the
%           quarter.  The annual number is used for the sth quarter of 
%           of each year.  The default is s=4.
%              

%           Ellen McGrattan, 12-31-08

[m,n]    = size(A);
if (s<1 | s>4); disp('WARNING: s should be equal to 1, 2, 3, or 4'); end;
if nargin<2;
  s      = 4;
  method = 0;
end;
if (method==0);
  A(:,2:n) = log(A(:,2:n));
end;

Q        = zeros(4*m,n);
t        = ones(4,1)*A(:,1)'+[.1;.2;.3;.4]*ones(1,m);
Q(:,1)   = t(:);

for j=2:n;
  for i=2:m;
    tem                  = linspace(A(i-1,j),A(i,j),5);   
    Q(4*i+s-7:4*i+s-4,j) = tem(2:5);
  end;
  tem              = linspace(2*A(1,j)-A(2,j),A(1,j),5);
  Q(1:s,j)         = tem(6-s:5);
  tem              = linspace(A(m,j),2*A(m,j)-A(m-1,j),5);
  Q(4*m+s-3:4*m,j) = tem(s+1:4);
end;
if (method==0);
  Q(:,2:n) = exp(Q(:,2:n));
end;
