function figurePos = getfgpos(width, height);
% Function to set default window for this computer
% Input is in pixel units.

%   Yama Habibzai
%   Copyright (c) 1984-98 by The MathWorks, Inc. All Rights Reserved
%   $Revision: 1.4 $  $Date: 1998/08/19 19:42:24 $

% Function to set default window for this computer

oldRootUnits = get(0,'Units');
set(0, 'Units', 'pixels'); 

figurePos=get(0,'DefaultFigurePosition');
figurePos(3:4)=[width height];
rootScreenSize = get(0,'ScreenSize');

figurePos(1:2) = figurePos(1:2)*72/96;

% Make sure the title bar of the window isn't off the screen
%rootScreenSize = get(0,'ScreenSize');

% (position is [x(from left) y(bottom edge from bottom) width height]
% check left edge and right edge
if ((figurePos(1) < 1) ...
      | (figurePos(1)+figurePos(3) > rootScreenSize(3)))
  figurePos(1) = 30;
end

% the figure 'position' does not include the menu bar or the title bar
% really, the default figure position should adjust for this, but
% for now, assume that the title and the menu bar take less than
% sixty pixels
if ((figurePos(2)+figurePos(4)+60 > rootScreenSize(4)) ...
      | (figurePos(2) < 1))
  figurePos(2) = rootScreenSize(4) - figurePos(4) - 60;
end
set(0, 'Units', oldRootUnits);
