%2011 Copyright Nuria Ruiz-Fuentes

%This program is free software: you can redistribute it and/or modify it under the terms 
%of the GNU General Public License as published by the Free Software Foundation, either 
%version 3 of the License, or (at your option) any later version.

%This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
%without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
%See the GNU General Public License for more details.

%You should have received a copy of the GNU General Public License along with this program. 
%If not, see <http://www.gnu.org/licenses/>

N=input('Number of paths  ');
tstart=input('Start time point (T0)  ');
tend=input('End time point (T1)  ');
ns=input('Number of independent subpaths ');
p=input('Number of points ');
L=input('Intensity ');

T=[tstart];np=[];t=[];paths=[];
for i=1:p*ns
   T=[T,tstart+i*(tend-tstart)./(p*ns)];
end;

for h=1:N
    for i=1:p*ns
        npois=0;
        t1=rand;
    ttau=T(i)-log(1-t1)/L;
    while ttau<=T(i+1),
      npois=npois+1;
      t(i,npois)=ttau;
      t1=rand;
      ttau=ttau-log(1-t1)/L;
    end
      np(i)=npois;
 end
paths=[paths;mean([zeros(ns,1),cumsum(reshape(np,p,ns))'])]; %HPP
end