function []=spread(arow,acol)
%SPREAD    Spread out windows(figures) on screen.
%
%          spread(arow,acol)
%
%          arow and acol defines how many windows you'll get per row
%          and column. If no argument is given a standard placement
%          is done.
%
%          Bugs: There may be bugs due to unnoticed differences between 
%                Matlab 4.0 beta and Matlab 4.0

% Johan Nilsson 920709  Matlab4

hlist = get(0,'children');
[n,slask] = size(hlist); 

if nargin==0,
    arow=round(sqrt(n)+0.5);
    acol=round(sqrt(n)+0.5);
elseif nargin~=2,
    error('Wrong number of arguments.');
end

%screen size (pixels)
screen=get(0,'screensize');
xscreen=screen(1,3);
yscreen=screen(1,4);
top=25;

xsize=round(xscreen/arow);
%ysize=round((yscreen-acol*top)/acol);
ysize=round((yscreen-acol*top-top)/acol);
col=0;
row=0;

for i=1:n,
%    pos=[col*xsize yscreen-(row+1)*(ysize+top)+top xsize ysize];
    pos=[col*xsize yscreen-(row+1)*(ysize+top) xsize ysize];
    if  pos(1,2)<0,
        error('Not enough space...');
    end
    set(hlist(n-i+1,1),'position',pos);
    col=col+1;
    if col>(arow-1),
        col=0;
        row=row+1;
        if (row>(acol-1)) & (i~=n),
            error('Not enough space...');
        end
    end
end

    
