function plot_size(gcax,unit,width,height,xoff,yoff,iifig_size,iidiag)
% Call plot_size(gca,unit,width,height,xoff,yoff,iifig_size);
% where unit = 'cm','in','pix'.
% For width or height < 0, dimension is calculated as -w*(axmax-axmin), e.g. specify -w as inches/km
%
% To match the dimensions of an existing plot set width = -(existing width)/(existing data range);
%
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
if nargin<5 | isempty(xoff), xoff=1.15; end
if nargin<6 | isempty(yoff), yoff=0.75; end
if nargin<7 | isempty(iifig_size), iifig_size=1; end
if nargin<8, iidiag=1; end
%
figno=get(gcax,'Parent');
if strcmp(unit(1:2),'cm'),
	set(gcax,'Units','centimeters');
	set(figno,'Units','centimeters');
elseif strcmp(unit(1:2),'in'),
	set(gcax,'Units','inches');
	set(figno,'Units','inches');
elseif strcmp(unit(1:3),'pix'),
	set(gcax,'Units','pixels');
	set(figno,'Units','pixels');
else
	error('Units must be cm, in, or pix');
end
%
iiprop=0;
if width<0, 
    ax=axis; iiprop=1; w=-width*abs(ax(2)-ax(1)); %%disp([ax(1),ax(2),width,w]); 
    if w<12 & w>.2, width=w; else, disp(['Bad proportional dimension calc: width set to 5']); width=5; end
end
if height<0, 
    ax=axis; iiprop=1; h=-height*abs(ax(4)-ax(3)); 
    if h<9 & h>.2, height=h; else, disp(['Bad proportional dimension calc: height set to 5']); height=3; end
end
if iiprop & iidiag, disp(['Proportional dimensions computed to be: ',num2str([width,height])]); end
%
set(gcax,'Position',[xoff yoff width height]);
%
if iifig_size<=0, 
    return;
end
%
pos=get(figno,'Position');
fig_size=[width+2.25 height+1.85];
max_size=[12.5,9];		% Max size of screen;
%offset=min(max_size - fig_size,pos(1:2);
if pos(1)+fig_size(1)>max_size(1) | pos(2)+fig_size(2)>max_size(2),
    hoff=min(max_size(1) - fig_size(1),pos(1));
    voff=min(max_size(2) - fig_size(2),pos(2));
else
    hoff=pos(1); voff=pos(2);
end
set(figno,'Position',[hoff voff fig_size]);
%%set(figno,'Position',[pos(1) pos(2) width+2 height+1.75]);
