function [G,PV] = trfsssd(th,nnu,nny,w)
%TRFSSSD	Auxiliary routine to TH2FF
%
%	[G,PHI]=trfsssd(th)
%

%	L. Ljung 10-2-90
%	Copyright (c) 1990 by the MathWorks, Inc.
%	All Rights Reserved.

[a,b,c,d,k]=eta2ss(th); [nx,nu]=size(b);[ny,nx]=size(c);
if any(nnu>nu),error('There are not that many inputs in the model!'),end
if any(nny>ny),error('There are not that many outputs in the model!'),end
T=gett(th);
if isempty(nnu),nnu=1:nu;end
if isempty(nny),nny=1:ny;end
if length(nnu)==1,if nnu<0,nnu=1:nu;end,end
if length(nny)==1,if nny<0,nny=1:ny;end,end
lny=length(nny);

G=[];PV=[];
for ky=nny
    thbb=thss2th(th,ky);
    if nargout==1 , gy=th2ff(thbb,nnu,w);else [gy,pvy]=th2ff(thbb,nnu,w);
       pvy(1,:)=pvy(1,:)+(ky-1)*1000; PV=[PV pvy];
    end
    gy(1,:)=gy(1,:)+(ky-1)*1000;G=[G gy]; 
end
if nu==0,PV=G;end
if length(nnu)>0
     for ku=nnu
	[g,p]=trfsaux(a,b,c(nny,:),d(nny,:),ku,w,T); 
        scount=1;
	for ky=nny
	  G(2:length(w)+1,find(G(1,:)==1000*(ky-1)+ku))=g(:,scount);
	  G(2:length(w)+1,find(G(1,:)==1000*(ky-1)+20+ku))=p(:,scount);
	  scount=scount+1;
        end
     end
end

if nargout>1 | nu==0
    [par,PM,lam]=th2par(th);
    for ky=nny
       g=trfsaux(a,k,c(ky,:),ones(1,ny),ky,w,T);
       PV(2:length(w)+1,find(PV(1,:)==1000*(ky-1)))=abs(T)*(g.^2)*lam(ky,ky);
    end
end
if nu==0 G=PV;end
