% Copyright 1997 Thomas Mc Avoy
% MATLAB Routine to determine which change to make to test plantwide scheme

function [kk,d,titl1]=pltst(con,conlbl,conlbl1)

% MATLAB routine to bump test loops in TE process.  Bump tests can be carried
% out on cascade setpoints, recycle and agitator, or level setpoints. 
kk=1;
loop1=0;
while 1
while 1
	disp(' ')
	disp('SELECT FROM THE FOLLOWING MENU')
	disp('    1.  DISPLAY A LIST OF VARIABLES THAT CAN BE CHANGED')
	disp('    2.  SELECT A VARIABLE TO CHANGE')
	k=input(' ');
	if k==1|k==2
		break
	end
end
	if k==1
	disp(' ')
	disp('	1.: IDV(1) A/C RATIO IN C FEED')
	disp('	2.: IDV(2) B COMPOSITION IN C FEED')
	disp('	3.: IDV(3) D FEED TEMPERATURE') 
	disp('	4.: IDV(4) REACTOR CW INLET TEMPERATURE')
	disp('	5.: IDV(5) CONDENSER CW INLET TEMPERATURE')
	disp('	6.: IDV(6) A FEED LOSS')
	disp('	7.: IDV(7) DROP IN C HEADER PRESSURE')
	disp('	8.: IDV(8) A,B,C COMPOSITION OF C FEED')
	disp('	9.: IDV(9) D FEED TEMPERATURE')
	disp('	10.: IDV(10) C FEED TEMPERATURE')
	disp('	11.: IDV(11) REACTOR CW INLET TEMPERATURE')
	disp('	12.: IDV(12) CONDENSER CW INLET TEMPERATURE')
	disp('	13.: IDV(13) REACTION KINETICS')
	disp('	14.: IDV(14) REACTION CW VALVE')
	disp('	15.: IDV(15) CONDENSER CW VALVE')
	disp('	16.: PRODUCTION RATE CHANGE OF -15%')
	disp('	17.: PRODUCT MIX CHANGE 50 G/50 H TO 40 G/60 H')
	disp('	18.: REACT. OPERATING PRESSURE CHANGE OF -60 kPa')
	disp('	19.: PURGE B COMPOSITION INCREASE OF +2%')
	[n,m]=size(con);
	if con(1,1)~=0
	for i=1:n
		s=sprintf('	%2.0f',i+19);
		disp([s,sprintf('.: SET POINT OF LOOP %3.0f',i),[': '],conlbl(i,:),['-'],conlbl1(i,:)])
	end
	end
	disp(' ')
	elseif k==2
		while 1
			disp('INPUT NUMBER OF VARIABLE TO BE CHANGED')
			temp=input(' ');
			while (isempty(temp)==1)|temp<1
				disp('PLEASE ENTER VARIABLE AGAIN')
				temp=input(' ');
			end
			kk=temp;
			break
		end
	end
		disp(' ')
		if kk==1
			s=('	IDV(1) A/C RATIO IN C FEED');
		elseif kk==2
			s=('	IDV(2) B COMPOSITION IN C FEED');
		elseif kk==3
			s=('	IDV(3) D FEED TEMPERATURE');
		elseif kk==4
			s=('	IDV(4) REACTOR CW INLET TEMPERATURE');
		elseif kk==5
			s=('	IDV(5) CONDENSER CW INLET TEMPERATURE');
		elseif kk==6
			s=('	IDV(6) A FEED LOSS');
		elseif kk==7
			s=('	IDV(7) DROP IN C HEADER PRESSURE');
		elseif kk==8
			s=('	IDV(8) A,B,C COMPOSITION OF C FEED');
		elseif kk==9
			s=('	IDV(9) D FEED TEMPERATURE');
		elseif kk==10
			s=('	IDV(10) C FEED TEMPERATURE');
		elseif kk==11
			s=('	IDV(11) REACTOR CW INLET TEMPERATURE');
		elseif kk==12
			s=('	IDV(12) CONDENSER CW INLET TEMPERATURE');
		elseif kk==13
			s=('	IDV(13) REACTION KINETICS');
		elseif kk==14
			s=('	IDV(14) REACTION CW VALVE');
		elseif kk==15
			s=('	IDV(15) CONDENSER CW VALVE');
		elseif kk==16
			s=('	PRODUCTION RATE CHANGE OF -15%');
		elseif kk==17
			s=('	PRODUCT MIX CHANGE 50 G/50 H TO 40 G/60 H');
		elseif kk==18
			s=('	REACTOR OPERATING PRESSURE CHANGE OF -60 kPa');
		elseif kk==19
			s=('	PURGE B COMPOSITION INCREASE OF +2%');
		elseif kk>19
			if con(1,1)~=0
				s=['	',sprintf(' SET POINT OF LOOP %3.0f',kk-19)];
			else
				s=[' NONE CONTROL ARCHITECTURE NEEDS TO BE SPECIFIED'];
				loop1=1;
			end
		end
		ss=['VARIABLE TO BE CHANGED - ',s];

		if k==2
			disp(ss)
			disp(' ')
			if kk>19
				s1=['	',conlbl(kk-19,:),['-'],conlbl1(kk-19,:)];
				disp(s1)
			end
			break
		end
	end
if kk<=19
	d=0;
end;
titl1=s;
loop=0;
while loop==0&loop1==0&kk>19
	d=input ('INPUT PERCENT (UP TO 5%) CHANGE IN SET POINT: ');
	while (isempty(d)==1)
		disp('PLEASE ENTER % PERTURBATION (UP TO 5%) AGAIN. ')
		d=input ('INPUT PERCENT (%) PERTURBATION: ');
	end
	if (d>5|d<0)          % Only 5% steps or less allowed
       disp(' ')
       disp('NOT A VALID SELECTION, PERTURBATION TOO LARGE') 
	   disp('PLEASE START OVER')
       disp('PRESS ENTER TO CONTINUE AND INPUT % PERTURBATION')
       pause;
	else;
	d=d/100;
	loop=1;
	end
end










