function  [Zcongr,output,W_hist,Zin] = PLM_Zcongr1(arg1,params,chev)

%PLM_ZCONGR1 -- Run PLMODEL1 and calculate z-probabilities correct.
%
%  Zcongr = PLM_Zcongr1(Mdata)
%  Zcongr = PLM_Zcongr1(stim,params)
%  Zcongr = PLM_Zcongr1(stim,params,chev)
%  [Zcongr,output,W_hist,Zin] = PLM_Zcongr1(...)
%
%  STIM, PARAMS, and CHEV are the same as in PLM_HEBB1, except that an
%  additional field 'blk_size' may be included in the PARAMS structure.
%  The default block size is 300.
%  ZCONGR is produced by PLM_PBLOCK1. It is a 6-by-N_blocks matrix of
%  z-transformed probabilities of correct response for each stimulus
%  type across blocks. The rows (or "conditions") in ZCONGR have the
%  following indices (see also PLM_SUMSQFIT and PLOT_PLM_FIT):
%   1: congruent Gabor, contrast 0.23
%   2: incongruent Gabor, contrast 0.23
%   3: congruent Gabor, contrast 0.15
%   4: incongruent Gabor, contrast 0.15
%   5: congruent Gabor, contrast 0.10
%   6: incongruent Gabor, contrast 0.10
%
%  See also PLM_HEBB1, PLM_PBLOCK1, PLM_SUMSQFIT, PLM_PARAMSEARCH.

%  Original coding by Alexander Petrov, UC Irvine.
%  $Revision: 2.0 $  $Date: 2003/05/30 18:55 $

%-- Call PLM_HEBB1
if (isstruct(arg1))   % a single structure with subfields
   if (nargin~=1) warning('ARG1 is a struct; I ignore the rest.') ; end
   [output,W_hist] = PLM_Hebb1(arg1) ;
   stim = arg1.stim ;
   params = arg1.params ;
else    % STIM, PARAMS, and perhaps CHEV explicitly supplied
   stim = arg1 ;
   if (nargin==2)
      [output,W_hist] = PLM_Hebb1(stim,params) ;
   else  % nargin must be 3
      [output,W_hist] = PLM_Hebb1(stim,params,chev) ;
   end
end

%-- Bottom-up input to the output unit
bottom_up = output(:,3) ;   % bottom-up input to the output unit
crit = output(:,4) ;        % current boundary b/n "Left" and "Right"

%-- Z(bottom_up + noise > crit) = Z((bottom_up-crit)/sigma > 0)
Zin = (bottom_up - crit) ./ params.out_noise ;

%-- Call PLM_PBLOCK1 to partition into blocks and conditions
Zcongr = PLM_Pblock1(stim,Zin) ; 

%-- Return ZCONGR
%%%%% End of file PLM_ZCONGR1.M
