function [x,options] = seminf(FunName, ntheta, x0, options, vlb, vub,varargin) 
%SEMINF Solves semi-infinite constrained optimization problems.
%   SEMINF has been replaced with FSEMINF.  SEMINF currently works but
%   will be removed in the future.  Use FSEMINF instead.
%       SEMINF solves problems of the form:
%
%          min { f(x) | g(x)<=0 | phi(x,w)<=0 | vlb<=x<=vub }
%            x
%       for all w in an interval. 
%
%       X=SEMINF('FUN',N,X0) starts at X0 and finds minimum to the function
%       constrained by N semi-infinite constraints in FUN (usually an 
%       M-file: FUN.M). The function 'FUN' should return two arguments: 
%       a scalar value of the function to be minimized, F, a matrix of 
%       constraints, G, and N semi-infinite constraints evaluated over 
%       an interval, PHI1, PHI2, ..: [F,G,PHI1,PHI2,...,PHIN,S]=FUN(X,S). 
%       F is minimized such that G < zeros(G), PHI1 < zeros(PHI1), ...
%       S is a recommended sampling interval which may or may not be used. 
%
%       X=SEMINF('FUN',N,X,OPTIONS) allows a vector of optional parameters to 
%       be defined. For more information type HELP FOPTIONS.
%       
%       X=SEMINF('FUN',N,X,OPTIONS,VLB,VUB) defines a set of lower and upper
%       bounds on the design variables, X, so that the solution is always in 
%       the range VLB <= X <= VUB.
%
%       X=SEMINF('FUN',N,X,OPTIONS,VLB,VUB,P1,P2,...) passes the problem-
%       dependent parameters P1,P2,... directly to the functions FUN:
%       FUN(X,P1,P2,...). Pass empty matrices for OPTIONS, VLB, and VUB 
%       to use the default values.
%
%       [X,OPTIONS]=SEMINF(...) returns the parameters used in the 
%       optimization method.  For example, options(10) contains the number 
%       of function evaluations used.
%

%   Copyright 1990-2000 The MathWorks, Inc. 
%   $Revision: 1.18 $  $Date: 2000/06/16 22:25:41 $
%       Andy Grace 7-9-90.
%       Andy Potvin 11-3-93

%       X=SEMINF('FUN',N,X,OPTIONS,VLB,VUB,P1,P2,..) allows
%       coefficients, P1, P2, ... to be passed directly to FUN:
%       [...]=FUN(X,S,P1,P2,...). Empty arguments ([]) are ignored.

%  This function is old, the current version should be used.
WarningStr=sprintf(...
['The function SEMINF is obsolete and has been replaced by\n',...
'FSEMINF.  SEMINF will be removed in a future release of the\n',...
'Optimization Toolbox.  Update your code to call FSEMINF to\n',...
'suppress this warning message.  See "Converting your code to\n',...
'Version 2 Syntax" in the Optimization Toolbox User''s Guide\n',...
'for more information.\n']);

warning(WarningStr)


if nargin < 3, error('seminf requires three input arguments'); end
if nargin < 4, options=[]; end
if nargin < 5, vlb=[]; end
if nargin < 6, vub=[]; end
options = foptions(options);
options(7) = 5; 

% Build call to the user-function:
%   [f,g,t1,...,tntheta,s]=fun(x,s,varargin{:});
% (do not use inline since variable number of output arguments)
FunStr  =  '[f, g';
for i=1:ntheta
    FunStr = [FunStr, ',t',int2str(i)];
end
FunStr = [FunStr, ', s]=', FunName '(x, s, varargin{:});'];

lenVarIn = length(varargin);
% semifun also needs ntheta and FunStr
semargs = 2;
% Convert to inline function as needed.
%  semifun is actually called directly by nlconst, but to be
%   compatible with the other calls to nlconst, call prefcnchk.
gradflag = 0;
[ffun, msg] = prefcnchk('semifun','seminf',lenVarIn+semargs,gradflag);
if ~isempty(msg)
  error(msg);
end

[x,options] = nlconstold(ffun,x0,options,vlb,vub,[],ntheta,FunStr,varargin{:});
% end seminf
