function ProgName=findprog(Program,DefaultPath)
% FINDPROG find a program using which or on a default path
%	ProgName=findprog(Program,DefaultPath)

Alt1=sprintf('%s/%s/%s',DefaultPath,getenv('HOSTTYPE'),Program);
Alt2=sprintf('%s/%s',DefaultPath,Program);
if exist(Alt1)==2
  ProgName=Alt1;
elseif exist(Alt2)==2
  ProgName=Alt2;
else
  [dummy,Path]=unix(sprintf('which %s',Program));
  if length(findstr(Path,' '))>0
    error(sprintf('Not able to find %s',Program));
  elseif exist(Path)==2
    ProgName=Path;
  else
    error(sprintf('Not able to find %s',Program));
  end
end
