% Last modified: 06/09/2012 by Pete

% truereac      true reaction equation of tracer in system [1,9]
% Re            Reynolds number
% randseed      rng seed for observation noise realization (set to -1 to
%               suppress addition of noise to observations)
% reac          reaction equation of tracer used in stochastic reac [1,9]

function Pete_RunStoch( truereac, Re, randseed, reac )

app.toptic = tic ;
fprintf(['Stochastic microorganism tracer system: ',...
    'stochastic model.\n'])

trunk = regexp(pwd,'.*trunk','match','once') ; Pete_src
app.tag = sprintf('tracer_truereac%d_Re%d_randseed%d', ...
    truereac, Re, randseed) ;
savemain = [trunk,'/Save/',app.tag] ;
addpath(genpath([trunk,'/Cases/Pete_tracer']))

% load parameter file generated from deterministic realization
paramfile = [ savemain, '/true/param.mat' ] ;
if ( ~exist(paramfile,'file') )
    fprintf(['Deterministic realization not found.  ',...
        'Running deterministic realization first.\n'])
    Pete_RunDet( truereac, Re, randseed )
end
load( paramfile, 'app' )

% DO PARAMETERS
app.S = 5 ;             % number of active DO modes
app.MC = 1e4 ;          % number of Monte Carlo ensemble particles
app.varscale = 1 ;      % scaling factor for initial field variance

% call stochastic solver
app.subtag = num2str(reac) ;
app.reac = reac ;
loglikes = Pete_StochSolver( app ) ;

save( sprintf('%s/loglikes%d.mat',savemain,reac), 'loglikes' )

fprintf( 'Phew! Total time = %02d:%02d.\n', ...
    floor(toc(app.toptic)/3600), floor(mod(toc(app.toptic),3600)/60) )

