%This is a function for resource dynamics of nospec species and one resource
function res1_plot_rsp(specpara,supply,loss,lag,nostep, animation)
% species parameters
% 1 growth: growth per unit biomass (u)
% 2 uptake: uptake per unit growth (w)
% 3 mortality (d)
% 4 initial size (n0)

%resource parameters:
%           supply: resource supply (S)
%           loss: rate at which resource is removed (a)

   nobin =100;
   n = res1(1,specpara,supply,loss,lag,nostep);
   hold on;
   Nstar = (supply - loss*specpara(1,3)/specpara(1,1)) / (specpara(1,2) * specpara(1,3));
   Rstar = specpara(1,3)/specpara(1,1);
   Rfree = supply/loss;
   maxx = 1.2*max([n(1,:) Rstar]);
   maxy = 1.2*max(n(2,:));
   if Nstar > 0
      maxy = min([maxy 2*Nstar]);
   end
   text = sprintf('Rfree %7.2f  Rstar %7.2f   Nstar  %7.2f', Rfree,Rstar,Nstar)
   plot([Rstar, Rstar],[0 maxy]);
   axis([0, maxx, 0, maxy])
   xlabel('Resource');
   ylabel('Species');
   title(text);
   
   xhyp=[];
   yhyp=[];
   for t=supply/(loss*nobin):supply/(loss*nobin):supply/loss;
      xhyp=[xhyp t];
      yhyp=[yhyp (supply - loss*t)/(specpara(1,2)*specpara(1,1)*t)];
   end
   plot(xhyp,yhyp,'g');
   
   
   for t=1:nostep-1
      plot(n(1,t:t+1),n(2,t:t+1),'r')
      if (animation)
         pause(0.1)
      end
      
   end
   
