function  [sumstats36,stim36] = NewSpdCmp36(Mparams,N_runs)

%NEWSPDCMP36 -- Run PLM_Hebb2 on the 36-block PLExp2 protocol
%
%  [sumstats36,stim36] = NewSpdCmp36(Mparams,N_runs,verbosep)
%
%  MPARAMS is a structure array! Each parameter set is run on the same
%  stimulus sequences independently of the other parameter sets.
%  N_RUNS specifies the (even) number of stimulus sequences. Default=100
%  Set verbosep to 0 to suppress all messages. Default=1=stdout.
%  SUMSTATS32 is a structure array of the same size as MPARAMS.
%  STIM32 is a 10800-by-5-by-N_runs matrix of stimulus descriptors.
%
%  Set Mparams(:).fdbk_fract to 1 or 0 switch feedback on or off.
%
%  See also PLM_HEBB2, PLM_PARAMS, PLM_STATS, BLOCK_FROM_CACHE, PLExp2.

%  Original coding by Alexander Petrov, UC Irvine.
%  $Revision: 1.0 $  $Date: 2005/06/27 17:50 $

global PLM_CACHE

if (nargin<2)  N_runs = 100 ; end
if (nargin<3)  verbosep = 1 ; end   % print on stdout by default

%-- Change to PLExp2/modelfits directory
orig_dir = pwd ;             % restored upon exit
cd(PLM_pathstr) ; cd('..\PLExp2\modelfits') ;
load('sched36.mat') ;

%-- Generate sequences according to the 36-block PLExp2 protocol,
d1 = zeros(10800,5,N_runs/2) ;   % Group 1: schedule L-8R-...
d2 = d1 ;                        % Group 2: schedule R-8L-...
for k = 1:N_runs/2 
   d = block_from_cache(sched36_1,PLM_CACHE) ; 
   d1(:,:,k) = cat(1,d{:}) ;
   d = block_from_cache(sched36_2,PLM_CACHE) ;
   d2(:,:,k) = cat(1,d{:}) ;
end
stim36=cat(3,d1,d2);      % [10800,5,N_runs]
clear d1 d2 d
if (verbosep) fprintf(verbosep,'*') ; end

%-- Run the model on the same stimuli with different Mparams
o=zeros(10800,6,N_runs);
for p = 1:length(Mparams)
    Mp = Mparams(p) ;
    for k = 1:N_runs  
        o(:,:,k) = PLM_Hebb2(stim36(:,:,k),Mp) ; 
    end
    %st = PLM_stats2(stim36,o(:,1,:),o(:,2,:),o(:,3,:)) ;
    st = PLM_stats2(stim36,o(:,1,:)) ;      % short stats
    sumstats36(p) = PLM_summary(st) ; 
    if (verbosep) fprintf(verbosep,'.') ; end
end

cd(orig_dir) ;

%--- Return SUMSTATS36 and optionally STIM36
%%%%% End of file NEWSPDCMP32.M
