function [ms1,par1]=fixxx(ms,par,mat,arg,fixpar)
%FIXXX Subroutine for fixpar
%
%	[MS1,PAR1] = fixxx(MS,PAR,MAT,ARG,FIXPAR)
%

%	L. Ljung 15-4-90
%	Copyright (c) 1990 The MathWorks, Inc
%	All rights reserved

deff=0;
if fixpar(1)=='d', deff=1;end
[a,b,c,d,k,x0]=ssmodx9(par,-1,ms);

par1=par;
nd=length(par);%nd=sum(sum(ms==NaN)');
[rarg,carg]=size(arg);
rr=rand(1,nd);
[ar,br,cr,dr,kr,x0r]=ssmodx9(rr,-1,ms);
[as,bs,cs,ds,ks,x0s]=ssmodx9(NaN*ones(1,nd),-1,ms);
if mat=='a' | mat=='A'
	kk=[];
	for nr=1:rarg
	if deff,as(arg(nr,1),arg(nr,2))=a(arg(nr,1),arg(nr,2));
	else as(arg(nr,1),arg(nr,2))=fixpar(nr);end
	kk=[kk,find(abs(rr-ar(arg(nr,1),arg(nr,2)))<eps)];
	
	end
	kk=sort(kk);nk=length(kk);kk=kk(nk:-1:1);
	for sk=1:nk
	par1=par1([1:kk(nk)-1,kk(nk)+1:length(par1)]);
	end
end
if mat=='b' | mat=='B'

	kk=[];
	for nr=1:rarg
	if deff,bs(arg(nr,1),arg(nr,2))=b(arg(nr,1),arg(nr,2));
	else bs(arg(nr,1),arg(nr,2))=fixpar(nr);end
	kk=[kk,find(abs(rr-br(arg(nr,1),arg(nr,2)))<eps)];
	
	end
	kk=sort(kk);nk=length(kk);kk=kk(nk:-1:1);
	for sk=1:nk
	par1=par1([1:kk(nk)-1,kk(nk)+1:length(par1)]);
	end
end
if mat=='c' | mat=='C'

	kk=[];
	for nr=1:rarg
	if deff,cs(arg(nr,1),arg(nr,2))=c(arg(nr,1),arg(nr,2));
	else cs(arg(nr,1),arg(nr,2))=fixpar(nr);end
	kk=[kk,find(abs(rr-cr(arg(nr,1),arg(nr,2)))<eps)];
	
	end
	kk=sort(kk);nk=length(kk);kk=kk(nk:-1:1);
	for sk=1:nk
	par1=par1([1:kk(nk)-1,kk(nk)+1:length(par1)]);
	end
end
if mat=='d' | mat=='D'

	kk=[];
	for nr=1:rarg
	if deff,ds(arg(nr,1),arg(nr,2))=d(arg(nr,1),arg(nr,2));
	else ds(arg(nr,1),arg(nr,2))=fixpar(nr);end
	kk=[kk,find(abs(rr-dr(arg(nr,1),arg(nr,2)))<eps)];
	
	end
	kk=sort(kk);nk=length(kk);kk=kk(nk:-1:1);
	for sk=1:nk
	par1=par1([1:kk(nk)-1,kk(nk)+1:length(par1)]);
	end
end
if mat=='k' | mat=='K'

	kk=[];
	for nr=1:rarg
	if deff,ks(arg(nr,1),arg(nr,2))=k(arg(nr,1),arg(nr,2));
	else ks(arg(nr,1),arg(nr,2))=fixpar(nr);end
	kk=[kk,find(abs(rr-kr(arg(nr,1),arg(nr,2)))<eps)];
	
	end
	kk=sort(kk);nk=length(kk);kk=kk(nk:-1:1);
	for sk=1:nk
	par1=par1([1:kk(nk)-1,kk(nk)+1:length(par1)]);
	end
end
if mat=='x0' | mat=='X0'

	kk=[];
	for nr=1:rarg
	if deff,x0s(arg(nr,1),arg(nr,2))=x0(arg(nr,1),arg(nr,2));
	else x0s(arg(nr,1),arg(nr,2))=fixpar(nr);end
	kk=[kk,find(abs(rr-x0r(arg(nr,1),arg(nr,2)))<eps)];
	
	end
	kk=sort(kk);nk=length(kk);kk=kk(nk:-1:1);
	for sk=1:nk
	par1=par1([1:kk(nk)-1,kk(nk)+1:length(par1)]);
	end
end

ms1=modstruc(as,bs,cs,ds,ks,x0s);

