function  Hstats = print_Hebb_stats(Hstats,fid)

%PRINT_HEBB_STATS -- Pretty-printed output of HEBB_STATS.
%
%  Hstats = print_Hebb_stats(Hstats,[fid])
%
%  HSTATS must be a structure generated by HEBB_STATS.
%  FID is a handle to a file stream. Default 1=stdout.
%
%  Example:
%   Idef=make_PLFrontend(PLM_input_params);PLM_CACHE=cache_inputs(Idef,N);
%   Mparams = PLM_params ; Hstats = Hebb_stats(Mparams);
%   print_Hebb_stats(Hstats) ; plot(Hstats.Wsame.weights,'.-') ;
%
%  See also HEBB_STATS.

%  Original coding by Alexander Petrov, UC Irvine.
%  $Revision: 1.0 $  $Date: 2003/05/28 10:12 $

if (nargin<2)  fid=1 ;  end    % print on stdout by default

hline = repmat('-',1,67) ;
ttl='Condition   dprime   bias  : mnYcon  mnYinc  :   sdY   SDcon  SDinc ';
fprintf(fid,'\n%s\n%s',ttl,hline) ;
print_one(Hstats,'Wsame',fid) ;
print_one(Hstats,'Wother',fid) ;
print_one(Hstats,'Wmix',fid) ;
print_one(Hstats,'W0step',fid) ;
print_one(Hstats,'W0lin',fid) ;
fprintf(fid,'%s\n%s\n\n',hline,ttl) ;

%--- Return HSTATS
%%%% End of the main function


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function  print_one(Hstats,field,fid)

if (~isfield(Hstats,field))  return ; end

N_contrasts = size(Hstats.mnXcon,1) ;   % = 3
if (N_contrasts==3)
   header = {'  Cp=.23','  Cp=.15','  Cp=.10','  Mean  ', '  Diff  '} ;
else
   for k=1:N_contrasts  headers{k} = ['  Con. ' int2str(k)] ; end
   header{N_contrasts+1} = '  Mean  ' ;
   header{N_contrasts+1} = '  Diff  ' ;
end

fprintf(fid,'\n%s\n',field) ;
s = getfield(Hstats,field) ;
for k=1:N_contrasts
   fprintf(fid,'%s  %7.3f %7.3f  :%7.3f %7.3f  : %6.3f %6.3f %6.3f\n',...
      header{k},s.dprime(k),s.bias(k),s.mnYcon(k),s.mnYincon(k),...
      s.sdY(k),s.sdY0con(k),s.sdY0incon(k)) ;
end
fprintf(fid,'%s+ %7.3f %7.3f  +%7.3f %7.3f  + %6.3f %6.3f %6.3f\n',...
   header{N_contrasts+1},mean(s.dprime),mean(s.bias),...
   mean(s.mnYcon),mean(s.mnYincon),...
   mean(s.sdY),mean(s.sdY0con),mean(s.sdY0incon)) ;
fprintf(fid,'%s  %7.3f          :%7.3f %7.3f  :\n',...
   header{N_contrasts+2},s.dprime(end)-s.dprime(1),...
   s.mnYcon(end)-s.mnYcon(1),s.mnYincon(end)-s.mnYincon(1) ) ;

%%%  End of subfunction PRINT_ONE

%%%%% End of file PRINT_HEBB_STATS.M
