% ***************************************************************************
% COPYRIGHT BY DAVE JEWELL AND T.E. MARLIN 1994
% FILNAME : GRAPH.M
% Version 2.0
% LAST UPDATED : December 1994
% DISCRIPTION OF FILE :
% THIS M-FILE IS ACCESSED FROM "sim_2by2.m" AND PLOTS THE DATA ACCORDING TO THE
% PAIRING OF THE CONTROLLED VARIABLE AND ITS MANIPULATED VARIABLE
% ***************************************************************************
L=length(nstart-1:nmax)-1;
%dt=tend/L;
tendx = - delt*(nstart-nmax);  % ensure that size of variables and 
time=0:delt:tendx;           % time are consistent, regardless of rounding
clg;

subplot(2,2,1),plot(time,sp1(nstart-1:nmax-1),'--r',time,cv1(nstart-1:nmax-1),'-g');
title(['IAE = ',num2str(IAE1),' ISE = ',num2str(ISE1)]);
%xlabel('Time');
ylabel(cv1name);

subplot(2,2,2),plot(time,sp2(nstart-1:nmax-1),'--r',time,cv2(nstart-1:nmax-1),'-g');
title(['IAE = ',num2str(IAE2),' ISE = ',num2str(ISE2)]);
%xlabel('Time');
ylabel(cv2name);

if conalgo == 2       % Plot CV1 above MV1 and CV2 above MV2
    config(1,1) = 1;  % when controller is DMC
end

if config(1,1)==1

[xsample,ysample1] = stairs (mv1(nstart-1:nmax-1));
subplot(2,2,3),plot  (delt*xsample, ysample1, '-g');
title(['SAM = ',num2str(SAM1),' SSM = ',num2str(SSM1)]);
xlabel('Time');ylabel(mv1name);

[xsample, ysample2] = stairs (mv2(nstart-1:nmax-1));
subplot(2,2,4),plot(delt*xsample, ysample2,'-g');
title(['SAM = ',num2str(SAM2),' SSM = ',num2str(SSM2)]);
xlabel('Time');ylabel(mv2name);

else

[xsample,ysample1] = stairs (mv2(nstart:nmax));
subplot(2,2,3),plot  (delt*xsample, ysample1, '-g');
title(['SAM = ',num2str(SAM2),' SSM = ',num2str(SSM2)]);
xlabel('Time');ylabel(mv2name);

[xsample, ysample2] = stairs (mv1(nstart:nmax));
subplot(2,2,4),plot(delt*xsample, ysample2,'-g');
title(['SAM = ',num2str(SAM1),' SSM = ',num2str(SSM1)]);
xlabel('Time');ylabel(mv1name);

figure (1)
end
pause;

close all

if SAVEGRAPH==1                        %SAVEGRAPH always =~ 1 in windows version
     eval(['meta ',graphname]);        % SAVES GRAPH in  DOS version
end
SAVEGRAPH=0;                            % RESETS SAVING GRAPH TOGGLE (0=OFF)
