% str_var = 'MVGC';
% 
% str_varname = 'pValmvgc';
% str_bartitle = 'Winterhalder2005 variant: ';
% str_suptitle = 'MVGC';


% set(h2,'PaperUnits','inches');
% set(h2,'PaperSize',[5 5]);
hboxplot=figure;
set(hboxplot,'NumberTitle','off','MenuBar','none', ...
    'Name',[str_bartitle ' ' str_var]);
%suptitle(str_suptitle)

% String of variables list to boxplot in matrix lay-out.
                
% Process iPDC p-values(f) extracting the peak value of
% -log10(p-valuesiPDC(f))

%str_varname

if ~isempty(strfind(lower(str_varname),lower('iPDC'))) | ...
        ~isempty(strfind(lower(str_varname),lower('iDTF'))),
    str_varname = [str_varname 'min'];
end;
%str_varname
for kFile = 1:M,
    skF = int2str(kFile);
    for i=1:N,
        for r=1:mm,
            for s=1:mm,
                eval(['tmp=' str_varname skF '(i,r,s);'])
                if tmp == 0
                    eval([str_varname skF '(i,r,s) = eps;'])
                else
                    eval([str_varname skF '(i,r,s)=tmp;'])
                end;
            end;
        end;
    end;
end;


varlist=[];
for k=1:length(K),
    varlist=[varlist '-log10(' str_varname int2str(k) '(:,r,s)) '];
end;
%varlist
hbp = randn(mm,mm);
tmpwidht = hbp; tmpheight = hbp; tmpx=hbp; tmpy=hbp;
for r=1:mm,
    for s=1:mm,
            hbp(r,s) = subplot2(mm,mm,s+mm*(r-1));
        if r==s,
            text(0.5,0.5,int2str(r),'FontSize',18,...
                                    'HorizontalAlignment','center', ...
                                    'VerticalAlignment','middle')
            axis off
            set(gca,'xtick',[],'ytick',[],'layer','bottom','box','off')
        else
            tmp=get(hbp(r,s),'Position'); 
            tmpx(r,s) = tmp(1); tmpy(r,s) = tmp(2); 
            tmpwidth(r,s)=tmp(3); tmpheight(r,s)=tmp(4);
            
            set(gca, 'FontName', 'Helvetica','FontSize',8)
            eval(['boxplot([' varlist '],''notch'',''on'',''outliersize'',6)']);
            text_h = findobj(gca, 'Type', 'text');
            if r == mm && s == 1,
                labelfontSize = 8;
                % label, change fontsize
                % y-axis
                set(gca, 'FontSize', [8])               
                % x-labels for lower left corner plot
                rotation = 45; % in degree
                for k = 1:length(text_h)
                    set(text_h(k), 'FontSize', labelfontSize,...
                        'FontName','Helvetica', ... 
                        'FontWeight','bold', ...
                        'Rotation', rotation, ...
                        'String', K{length(K)-k+1}, ...
                        'HorizontalAlignment', 'right', ...
                        'VerticalAlignment','bottom')
                end
            else
                % remove x-labels
                for k = 1:length(text_h)
                    set(text_h(k), 'String', '')
                end
            end;
            
            set(gca, 'FontName', 'Helvetica','FontSize',7,'FontWeight','bold')
            grid;
            xx=axis;
            if xx(4) > 15,
                xx(4) = 18;
            elseif xx(4) < 4.25,
                xx(4) = 4.25;
            else
                xx(4) = 1.05*xx(4);
            end;
            xx(3) = -0.2*xx(4)/4;
            axis(xx);

%            axis([xx(1) xx(2) 0 xx(4)]);
            hold('on');
            plot([xx(1) xx(2)], [2 2],'--b', 'LineWidth',[1.011])
        end;
    end;
end;

% Correcting boxplot subplots dimensions and alignments
mdnx = median(tmpx);  %row-wise median
mdny = median(tmpy'); %column-wise median
mdnwidth = median(median(tmpwidth)); % subplots width median value
mdnheight = median(median(tmpheight)); % subplots height median value
for r=1:mm,
    for s=1:mm,
        if r ~= s,
            set(hbp(r,s),'Position',[mdnx(s) mdny(r) mdnwidth mdnheight]); 
        end;
    end;
end;

   if flgReport,
      str_SupTitle = [str_bartitle ' ' str_var]; 
%       h3 = suptitle(str_SupTitle);
%       set(h3,'FontSize',6,'FontWeight','normal')
      
      [ax,h3]=suplabel(str_SupTitle,'t');
      set(h3,'FontSize',10) 
   end;

% y-axis variable of boxplot
supAxes=[.12 .10 .84 .84];
[ax,h2]=suplabel(['-log_{10} (p_{' str_var '})'],'y',supAxes);
set(h2,'FontName', 'Helvetica', 'FontSize',[14])
shg

%clear tmp tmpx tmpy tmpwidth tmpheight mdnwidth mdnheight hbp xx 
