function theta=ms2th(ms,cd,parval,lambda,T)
%MS2TH  Packages standard state-space parameterizations into the IDSS format.
%   OBSOLETE function. Use IDSS instead.
%
%   THETA = MS2TH(MS,CD,PARVAL,LAMBDA,T)
%
%   THETA: The resulting matrix in the IDSS model format. 
%
%   MS: The model structure. Specifies which state-space matrix coeff-
%   icients that are free and which are fixed (Generated by (See also)
%   MODSTRUC or CANFORM)
%
%   CD: CD='c' means a continuous-time model. CD='d' denotes a discrete
%   time model (default CD='d'). For continuous time models there are
%   two options: CD='czoh' (default) assumes the input to be piecewise
%   constant between the samples (u(t)=u(kT) for kT<=t<kT+T)) while
%   CD='cfoh' assumes the input to be piecewise linear between the
%   samples (u(t) obtained by linear interpolation of the sampled values)
%   (Note that, unlike 'foh' in c2dm in the CSTB, no extra delay is
%   introduced in this case.)
%
%   PARVAL: The values of the free parameters (Default zeros)
%   LAMBDA: The covariance matrix of the innovations (Default Identity)
%   T: The sampling interval (Default 1). For continuous time models this
%   is the sampling interval of the data to be used for the fit in pem.
%   See also ARX2TH, MF2TH, PEM.

%   L. Ljung 10-2-1990,10-10-93
%   Copyright 1986-2000 The MathWorks, Inc.
%   $Revision: 1.8 $ $Date: 2000/08/24 12:53:36 $

if nargin < 1
   disp('Usage: TH = MS2TH(MS)')
   disp('       TH = MS2TH(MS,CD,PARAMETERS,LAMBDA,T)')
   disp('       CD is one of ''d'', ''c'', ''czoh'', ''cfoh''.')
   return
end

if nargin<5, T=[];end
if nargin<4, lambda=[];end
if nargin<3, parval=[];end
if nargin<2, cd=[];end
if isempty(T),T=1;end
MM = [ms.as,ms.bs,ms.cs',ms.ks,ms.x0s];

d1=sum(sum(isnan(MM))')+sum(sum(isnan(ms.ds))');
if isempty(parval),parval=zeros(1,d1);end
if isempty(cd), cd='d';end,cd=lower(cd);
if cd(1)~='c' & cd(1)~='d',
  error('CD must start with either ''c''(ontinuous) or ''d''(iscrete)')
end
if strcmp(lower(cd),'cfoh')
   disp(sprintf('To obtain First Order Hold sampling when adjusting the model \n',...
      'to data, set the Data property ''InterSample'' to ''foh''.'))
end

if cd(1)=='c' %% This does not support czoh and cfoh
   T1 = 0;
else
   T1 = T;
end

theta = idss;
set(theta,'As',ms.as,'Bs',ms.bs,'Cs',ms.cs,'Ds',ms.ds,'Ks',ms.ks,'X0s',ms.x0s,...
   'ParameterVector',parval(:),'Ts',T1,'NoiseVariance',lambda);
if T1==0
   ut = pvget(theta,'Utility');%gsutil(theta,0,'g');
   ut.Tsdata = T;
   theta = pvset(theta,'Utility',ut);%gsutil(theta,ut,'s');
end


 
