function n = distr(type,par_a,par_b,pool_size)
% This function generates some abundance distributions 
% It returns proportions of abundances

  no_rep =100;  % constant
  switch type
  case 1 %geometric 
     abund(1)= par_a;
     for i=2:pool_size 
        abund(i) = abund(i - 1) * par_a; 
     end
  
  case 2 %lognormal 
     abund=zeros(pool_size,1)';
     for k=1:no_rep
        for i=1:pool_size
           sd = randn(1);
           xabund(i) = exp(par_b + par_a * sd);
        end
        xabund=fliplr(sort(xabund));
        abund = abund + xabund;              
     end
     abund = abund / no_rep;
  case 3 %broken stick
     abund=zeros(pool_size,1)';
     for k=1:no_rep
        xabund =[1];
        for i=1:pool_size-1
           s=size(xabund);
           r=ceil(s(2).*rand(1));
           r1=rand(1);
           xabund(r) = xabund(r)*r1;
           xabund=[xabund xabund(r).*(1-r1)];
        end
        xabund = fliplr(sort(xabund));
        abund = abund + xabund;              
     end
     abund = abund / no_rep;
  case 4 %random
     abund=zeros(pool_size,1)';
     for k=1:no_rep
        xabund = rand(pool_size,1);
        xabund = flipud(sort(xabund))';
        abund = abund + xabund;              
     end
     abund = abund / no_rep;
  
  otherwise
     return 
  end
 
 abund=abund/sum(abund);
 %n=cumsum(abund);
 n=abund;
