% Copyright 1997 Thomas Mc Avoy
function [KC,TR]=cascpi(KC,TR)
loop=1;
while loop==1
disp(' ')
disp(' CURRENT INNER LOOP')
disp('CONTROLLER PARAMETERS 	    KC               TR')
for i=1:10
		if i==1
			s=sprintf('	D-FLOW 		          %5.2e',KC(i));
		elseif i==2
			s=sprintf('	E-FLOW 		          %5.2e',KC(i));
		elseif i==3
			s=sprintf('	A-FLOW 		          %5.2e',KC(i));
		elseif i==4
			s=sprintf('	C-FLOW 		          %5.2e',KC(i));
		elseif i==5
			s=sprintf('	PURGE-FLOW 		      %5.2e',KC(i+1));
		elseif i==6
			s=sprintf('	SEP EXIT-FLOW 		  %5.2e',KC(i+1));
		elseif i==7
			s=sprintf('	PRODUCT-FLOW 		  %5.2e',KC(i+1));
		elseif i==8
			s=sprintf('	STEAM-FLOW 		      %5.2e',KC(i+1));
		elseif i==9
			s=sprintf('	REACTOR CW TEMP 	  %5.2e',KC(i+1));
		elseif i==10
			s=sprintf('	COND CW TEMP 		  %5.2e',KC(i+1));
		end
		if i>4
			ii=i+1;
		else
			ii=i;
		end

	s1=sprintf('  		%5.2f',TR(ii));
	disp([s,s1])
end
disp(' ')
	disp(' ')
	disp('SPECIFY THE INNER LOOP NUMBER FOR PI PARAMETERS WILL BE ENTERED.')
	disp('	ENTER 0 TO TERMINATE')
	disp(' ')
	disp('	LOOP-1: THE D-FEED FLOW')
	disp('	LOOP-2: THE E-FEED FLOW')
	disp('	LOOP-3: THE A-FEED FLOW') 
	disp('	LOOP-4: THE C-FEED FLOW')
	disp('	LOOP-6: THE PURGE FLOW')
	disp('	LOOP-7: THE SEPARATOR EXIT FLOW')
	disp('	LOOP-8: THE PRODUCT FLOW')
	disp('	LOOP-9: THE STEAM FLOW')
	disp('	LOOP-10: THE REACTOR CW TEMP')
	disp('	LOOP-11: THE CONDENSER CW TEMP')
	disp(' ')
	k=input(' ');
	if k>0&k<12&k~=5
		disp(' ')
		s=sprintf('INPUT THE CONTROLLER GAIN FOR LOOP %3.0f',k);
		disp(s)
		temp=input(' ');
		while (isempty(temp)==1)
			disp('PLEASE ENTER KC AGAIN')
			disp(s)
			temp=input(' ');
		end
		KC(k)=temp;
		disp(' ')
		s=sprintf('INPUT THE RESET TIME (min) FOR LOOP %3.0f',k);
		disp(s)
		temp=input(' ');
		while (isempty(temp)==1)
			disp('PLEASE ENTER TR AGAIN')
			disp(s)
			temp=input(' ');
		end
		TR(k)=temp;
	end	
	if k==0
		loop=0;
	end
end
for i=1:12
	if TR(i)==0
		TR(i)=1.e6;% can't have TR=0
	end
end;
	
	
