function [x,xlb,xub,y,ylb,yub,optS,hEq,gEq] = mpecinit(modelname,contype)
%    [x,xlb,xub,y,ylb,yub,optS,hEq,gEq] = mpecinit('modelname',3)
% or [x,xlb,xub,y,ylb,yub,optS,gEq]     = mpecinit('modelname',2)
% or [x,xlb,xub,y,ylb,yub,optS,hEq]     = mpecinit('modelname',1)
% or [x,xlb,xub,y,ylb,yub,optS]         = mpecinit('modelname',0)
% optS = 1 -> maximization,  optS = -1 -> minimization
% Eq[k] = -1    relation is <=
% Eq[k] =  0    relation is =
% Eq[k] =  1    relation is >=
% h involves just x
% g can involve x and y

% note that contype == 0 (no side constraints)
% note that contype == 1 (just h(x) constraints)
% note that contype == 2 (just g(x,y) constraints)
% note that contype == 3 (split up h(x) and g(x,y) constraints)

cmdline = sprintf(' 			%s %s','checkScratch.pl',modelname);
[status,result] = unix(cmdline);
if nargin < 2 
  contype = 0;
end
if (status == 0 | status == 10)
  switch nargout
    case 7, [x,xlb,xub,y,ylb,yub,optS] = mpecfunc(modelname,contype);
    case 8, [x,xlb,xub,y,ylb,yub,optS,hEq] = mpecfunc(modelname,contype);
    case 9, [x,xlb,xub,y,ylb,yub,optS,hEq,gEq] = mpecfunc(modelname,contype);
    otherwise, error('wrong number of outputs to mpecinit');
  end
  return;
else
  fprintf('%s',result);
  error('cannot generate appropriate problem directory');
end
