function [par,P,lam]=th2par(th);
%TH2PAR converts the theta-format to parameters and covariance matrix.
%	[PAR,P,LAM] = TH2PAR(TH)
%
%	TH: The model defined in the THETA-format (see also THETA).
%
%	PAR: The parameter vector in THETA (nominal or estimated
%	     values of the free parameters)
%	P:   The covariance matrix of the estimated parameters
%	LAM: The variance (covariance matrix) of the innovations

%	L. Ljung 10-2-90
%	Copyright (c) 1986-95 by the MathWorks, Inc.
%	$Revision: 1.4 $  $Date: 1995/05/16 09:01:05 $

if nargin<1
  disp('Usage: [PARs,PAR_COV_MATRIX,NOISE_COV_MATRIX] = TH2PAR(TH)')
  return
end
[nr,nc]=size(th);
if isthss(th), nd=th(1,5);else nu=th(1,3);
nd=th(1,4)+sum(th(1,5:4+nu))+th(1,5+nu)+th(1,6+nu)+sum(th(1,7+nu:6+2*nu));end

par=th(3,1:nd);

if nr>=3+nd,P=th(4:3+nd,1:nd);else P=[];end
if isthss(th), rarg=th(1,6);
lam=th(4+nd+rarg:nr,1:th(1,4)); else lam=th(1,1);end

