function evar = getevar(varname,ii_warn);
% Call: evar = getevar(varname);
% Return environmental variable
%
% 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<2, ii_warn=1; end
%
if (isunix)
    !printenv>temp___file
    delcom='!/bin/rm ';
elseif strcmp(computer,'PCWIN')
    !set>temp___file
    delcom='!del ';
else
    error('Unknown computer system')
end
fid=fopen('temp___file');
lv=length(varname);
while 1
    tline = fgetl(fid);
    if ~ischar(tline), break,end
    if strcmpi(tline(1:lv),varname) &strcmp(tline(lv+1),'=')
        evar=tline(lv+2:end);
        fclose(fid);
        eval([delcom  'temp___file']);
        return;
    end
end
evar=[];
if ii_warn, disp([varname ' not found']); end
fclose(fid);
