function [G,PV] = trfss(th,nnu,nny,w)
%TRFSS	Auxiliary routine to TRF
%
%	[G,PV] = trfss(th,nnu,nny,w)
%

%	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
lny=length(nny);
if length(nnu)>0
G=[];G1=zeros(1+length(w),3*lny);
for ku=nnu
if ku>0, [g,p]=trfsaux(a,b,c(nny,:),d(nny,:),ku,w,T); 
G1(1,1:3:3*lny)=1000*(nny-1)+100+ku;
G1(1,2:3:3*lny)=1000*(nny-1)+ku;
G1(1,3:3:3*lny)=1000*(nny-1)+20+ku;
G1(2:length(w)+1,[1:3:3*lny 2:3:3*lny 3:3:3*lny])=[w'*ones(1,length(nny)) g p];
G=[G G1];
end ,end,end
if nargout>1 | nu==0
PV=[]; [par,PM,lam]=th2par(th);
for ky=nny
	g=trfsaux(a,k,c(ky,:),ones(1,ny),ky,w,T);
PV1(1,1:2)=[(ky-1)*1000+100,(ky-1)*1000];
PV1(2:length(w)+1,[1:2])=[w' abs(T)*(abs(g).^2)*lam(ky,ky)];	
PV=[PV PV1];
end
end
if nu==0 G=PV;
end