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 help 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) 1990 by the MathWorks, Inc.
%	All Rights Reserved.

[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

