% TITLE: GRPH2.M
% DONE BY : RENO CIPOLLA
% DATE: DEC/93
% VERSION 2.0
% REVISED : January 1995
% COPYRIGHT 1995 by T. Marlin and R. Cipolla
% This program plots the results of the simulations.
% This is called from the main program, the Simulation menu and the 
% optimization menu.
% ****************************************************************

while 1
 if save_graph == 1 
   disp('')
   if usegrh == 2 
    clc
    disp('')
    disp('')
    disp('')
    disp(' No graph has been created !!! ')
    disp('')
    disp(' Press any key to continue....')
    pause
    break
   end
 end

echo off
if usegrh == 0
 h=3;
elseif usegrh ==1
 h=1;
end
 for g=1:h
  if save_graph == 1
   clc
   disp('')
   disp('')
   graph_nm = input('Enter filename (no extension) to be saved: ','s');
   if isempty(graph_nm), break; end
  end  
  if g == 1   % nominal model

  clf
  subplot(2,2,1),plot(t,Xmis(:,g),'-',t,set,'--')
  title (['       IAE= ',num2str(Qp(g,1)),';ISE= ',num2str(Qp(g,2)),';ITAE= ',num2str(Qp(g,3)),'']);
%  xlabel ('time ');
  ylabel ('CV');

  subplot(2,2,3),plot(t,vpmis(:,g),t,bd);
  title (['MV_Violation = ',num2str(violates(g)),'  '])
  xlabel ('time ');
  ylabel ('MV');

  subplot(2,2,2),plot(t,distg)               
  title('Disturbance');
  xlabel('time ');
  ylabel(' D ');


   subplot(2,2,4)
   text(0.5,0.5,'Nominal Case ','sc');
   axis('off')    

  end 
  

  if g==2

  clf
  subplot(2,2,1),plot(t,Xmis(:,g),'-',t,set,'--')
  title (['       IAE= ',num2str(Qp(g,1)),';ISE= ',num2str(Qp(g,2)),';ITAE= ',num2str(Qp(g,3)),'']);
%  xlabel ('time ');
  ylabel ('CV');

  subplot(2,2,3),plot(t,vpmis(:,g),t,bdpos);
  title (['MV_Violation = ',num2str(violates(g)),'  '])
  xlabel ('time ');
  ylabel ('MV');

  subplot(2,2,2),plot(t,distg)               
  title('Disturbance');
  xlabel('time ');
  ylabel(' D ');


   subplot(2,2,4)
   text(0.5,0.5,'+ Model Error Case ','sc');
   axis('off')

  end
  
  
  if g == 3 

  clf
  subplot(2,2,1),plot(t,Xmis(:,g),'-',t,set,'--')
  title (['       IAE= ',num2str(Qp(g,1)),';ISE= ',num2str(Qp(g,2)),';ITAE= ',num2str(Qp(g,3)),'']);
%  xlabel ('time ');
  ylabel ('CV');

  subplot(2,2,3),plot(t,vpmis(:,g),t,bdneg);
  title (['MV_Violation = ',num2str(violates(g)),'  '])
  xlabel ('time ');
  ylabel ('MV');

  subplot(2,2,2),plot(t,distg)               
  title('Disturbance');
  xlabel('time ');
  ylabel(' D ');

   subplot(2,2,4)
   text(0.5,0.5,'- Model Error Case ','sc');
   axis('off')

  end
  
  if save_graph == 1
   pause(3)
   clc
   eval(['meta ',graph_nm]);
   disp('')
   disp('')
   disp('')
   disp('')
   disp([' SAVING TO.... ',num2str(graph_nm),'.met'])
   pause(3)
  else
   figure (1)
   pause
   close all
  end
 end
 break
end
save_graph = 0; 






