function [zepo,k]=zpsssd(th,ku,ky,thresh)
%ZPSSSD An auxiliary function to TH2ZP
%
%	[zepo,k]=zpsssd(th,ku,ky)
%

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

nu=th(1,3);ny=th(1,4);T=th(1,2);
if any(ku>nu),error('There are not that many inputs in the model!'),end
if any(ku<-ny),error('There are not that many noise sources in the model!'),end
if any(ky>ny) | any(ky<1),
   error('There are not that many outputs in the model!'),end
if isempty(thresh),thresh=100000;end
if isempty(ku),if nu>0,ku=1:nu;else ku=0;end,end
if isempty(ky),ky=1:ny;end
ku1=ku(find(ku>0));if any(ku==0),ku=[-ny:-1,ku1 ];end
zepo=[];k=[];
for ko=ky
    if any(ku==-ko),kku=[ku1,0];flag=1;else kku=ku1;flag=0;end
    if ~isempty(kku)
    th1=thss2th(th,ko);
    [zep,kt]=th2zp(th1,kku);
    if flag,
      zep(1,find(abs(zep(1,:)>500)))=abs(zep(1,find(abs(zep(1,:)>500))))+...
      (ko-1);
      kt(1,find(kt(1,:)>500))=kt(1,find(kt(1,:)>500))+ko-1;
    end
    zep(1,:)=(ko-1)*1000+abs(zep(1,:));
    kt(1,:)=(ko-1)*1000+kt(1,:);
    else zep=[];kt=[];end
    zepo=zpform(zepo,zep);
    k=[k kt];
end
if ~isempty(zepo),zepo(1,:)=sign(T)*zepo(1,:);end