% ***************************************************************************
% COPYRIGHT BY DAVE JEWELL AND T.E. MARLIN 1995
% FILNAME : DMC_MOD
% Version 2.0
% LAST UPDATED : January 1995
% DISCRIPTION OF FILE :
% THIS M-FILE IS ACCESSED FROM "DMC_MENU.M" ALLOWS THE USER TO ENTER THE 
% PARAMETERS FOR THE CONTROLLER MODEL
% ***************************************************************************

clc;
while 1
clc;
if TFM == 1
i=1;j=1;
elseif TFM == 2
i=1;j=2;
elseif TFM == 3
i=2;j=1;
elseif TFM == 4
i=2;j=2;
end
disp('*********************************************************************')
disp('*                                                                   *')
disp('*                DMC MODEL TRANSFER FUNCTION EDITING                *')
disp('*                                                                   *')
disp('*                        CV(s)    Km(T1s+1)exp(-Ds)                 *')
disp('*                Gm(s) = ----- = -------------------                *')
disp('*                        MV(s)     (T2s+1)(T3s+1)                   *')
disp('*********************************************************************')

disp('WHAT PARAMETER WOULD YOU LIKE TO UPDATE ?')
disp('                                          Present Values')
fprintf('1) Process Gain (Km)                           %-g\n',Kp_m(i,j))
fprintf('2) Lead Time Constant (T1)                     %-g\n',tauA_m(i,j))
fprintf('3) Dead Time (D)                               %-g\n',DT_m(i,j))
fprintf('4) Lag Time Constant (T2)                      %-g\n',tau1_m(i,j))
fprintf('5) Lag Time Constant (T3)                      %-g\n',tau2_m(i,j))
fprintf('6) Edit Another Transfer Function              Gm%-g%-g\n',i,j)
disp('7) Previous Menu')
mm = input('PLEASE ENTER A SELECTION : ');
if isempty(mm)==1
break
end
mm = round(mm);                          % round off selection
if (mm<1) | (mm>6)
	disp('')                       % selection validation
	disp('NOT A VALID SELECTION')
	disp('')
	disp('PRESS ENTER TO CONTINUE')
	pause;
end

% A SERIES OF PROMPTS FOR CONTROLLER TUNING 
if mm == 1
TEMP = input('Km : ');
    if isempty(TEMP)~=1
	Kp_m(i,j)=TEMP;
    end
	
elseif mm == 2
TEMP = input('T1 : ');
    if isempty(TEMP)~=1
%        if tauA_m(i,j)<0
%          disp('Time Constant CANNOT be less than 0, Press enter to continue')
%          pause;
%        else
	  tauA_m(i,j)=TEMP;
%        end
    end


elseif mm == 3
TEMP = input('D : ');
    if isempty(TEMP)~=1
	if TEMP < 0
	  disp('Dead Time CANNOT be less than 0, Press enter to continue')
	  pause;
	else
	  DT_m(i,j)=TEMP;
	end
    end

elseif mm == 4
TEMP = input('T2 : ');
    if isempty(TEMP)~=1
	if TEMP < 0
	  disp('Time Constant CANNOT be less than 0, Press enter to continue')
	  pause;
	else
	  tau1_m(i,j)=TEMP;
	end
    end


elseif mm == 5
TEMP = input('T3 : ');
    if isempty(TEMP)~=1
	if TEMP < 0
	  disp('Time Constant CANNOT be less than 0, Press enter to continue')
	  pause;
	else
	  tau2_m(i,j)=TEMP;
	end
    end

elseif mm == 6
TEMP=input('Which MODEL Transfer Function - (1) Gm11 (2) Gm12 (3) Gm21 (4) Gm22 : ');
TEMP=round(TEMP);

if isempty(TEMP)~=1
    if (TEMP<1) | (TEMP>4)      % VALIDATES SELECTION
	disp('')
	disp('NOT A VALID SELECTION, MUST BE BETWEEN 1 AND 4')
	disp('PRESS ENTER TO CONTINUE')
	pause;
    else
	TFM=TEMP;
    end
end

elseif mm == 7
return
end     % if
end     % while



