function figurePos = figpos(width, height)
%FIGPOS - Get a figure Position which is independent of the 
%         Screen Resolution
% 
% Inputs:
%   Width  - Figure's width
%   Height - Figure's height
%
% Output:
%   figurePos - A four element vector with the Figure's position.

%   Author(s): P. Pacheco
%   Copyright 1988-2000 The MathWorks, Inc.
%   $Revision: 1.2 $  $Date: 2000/06/13 21:23:04 $ 

% Cache sizes and spacing used in the GUI.
sz = gui_sizes;

% Figure out screen resolution.
oldRootUnits = get(0,'Units');
set(0, 'Units', 'pixels');
pixfactor = sz.pixf;

% Calculate figure position according to resolution.
figurePos = get(0,'DefaultFigurePosition');
figurePos(3:4) = [width height];
figurePos = figurePos * pixfactor;

% 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

% Make sure top of figure is not off the screen.
if ((figurePos(2) < 1) ...
      | (figurePos(2)+figurePos(4) > rootScreenSize(4)))
   figurePos(2) = figurePos(2)-((figurePos(2)+figurePos(4)+100)-rootScreenSize(4));
end

set(0, 'Units', oldRootUnits);
