%This is a function for resource dynamics of nospec species and one resource
function res2plot(nospec,specpara,supply1,loss1,supply2,loss2,nostep)
% species parameters
% growth1,2: growth per unit resource 1 and 2
% uptake1,2: uptake per unit growth
% mortality
% n0 initial size

%resource parameters:
%           supply1, 2: resource 1 and 2 supply 
%           loss1, 2: rate at which resource 1 and 2 is removed

colour = ['y','b','g','m','c'];
   
   n = res2(nospec,specpara,supply1,loss1,supply2,loss2,nostep);
   
   r1=specpara(:,5)./specpara(:,1);
   r2=specpara(:,5)./specpara(:,2);
   maxx=max(max(1.2*max(n(1,:)),r1*1.1));
   maxy=max(max(1.2*max(n(2,:)),r2*1.1));
   
   scrsz = get(0,'ScreenSize');
   
   %state plot
   figure('Position',[10 scrsz(4)/2-30 scrsz(3)/2 scrsz(4)/2-30])
   hold on;
   fig1 = gcf;
   axis([0, maxx,0, maxy])
   xlabel('Resource 1')
   ylabel('Resource 2')
   for i=1:nospec
      plot([r1(i),r1(i),maxx],[maxy,r2(i),r2(i)],colour(rem(i,5)+1));
   end
   
   %vs.-time plot
   figure('Position',[13*scrsz(4)/20 scrsz(4)/2-30 scrsz(3)/2 scrsz(4)/2-30])
   hold on;
   fig2 = gcf;
   maxx1=nostep;
   maxy1=1.2*max(max(n));
   axis([0, maxx1,0, maxy1]);  
   
   for t=1:nostep-1
      figure(fig1);
      plot(n(1,t:t+1),n(2,t:t+1),'r')
      
      figure(fig2);
      plot(t:t+1,n(1,t:t+1),'r')
      plot(t:t+1,n(2,t:t+1),'r:')
      for i=1:nospec
         plot(t:t+1,n(2+i,t:t+1),colour(rem(i,5)+1))
      end
      
      pause(0.2)
   end
   
