function[] = createshootfiles( n, ne, ni)

%	createshootfiles( n, ne, ni)
%  
% This reads in the user's objective functions either from a file problem.m
% or the prompt and creates intermediate FUN.m files to be used in the NBI
% code or Paretolincomb code.

response = input('Do you want to enter the functions and the constraints at the prompt (1/0) ?  ');
if response == 1,


fid1 = fopen('FUN1.m', 'w+'); % NEEDED will contain objfcns to find F*
fid2 = fopen('Fequn.m', 'w+'); % Needed for solving F(x) = Phi*w
fid3 = fopen('FUN.m', 'w+'); % file for testing feasibility 
fid4 = fopen('Fns.m', 'w+'); % contains function for evaluating F - F*
%fid5 = fopen('objectives.m', 'w+'); % contains subroutine to evaluate indiv f
fid6 = fopen('lincombFUN.m', 'w+');% returns f,g for minimizing wTF(x)
fid7 = fopen('shadowParetoFUN.m', 'w+'); % point closest to shadow min

fprintf(fid1, 'function [f,g] = FUN1(x)\n');
fprintf(fid1, 'global F_index\n');
fprintf(fid1, '   \n');

fprintf(fid2, 'function [F] = Fequn(x)\n');
fprintf(fid2, 'global n shadowMin qpp_pt\n');
fprintf(fid2, '   \n');
fprintf(fid2, 'F = zeros(%i,1);\n', n);

fprintf(fid3, 'function [f, ce, ci] = FUN(x)\n');
fprintf(fid3, '   \n');

fprintf(fid4, 'function [F] = Fns(x)\n');
fprintf(fid4, 'global shadowMin\n');
fprintf(fid4, 'F = zeros(%i,1);\n', n); % makes F a column
fprintf(fid4, '   \n');

%fprintf(fid5, 'function [f] = objectives(x, index)\n');
%fprintf(fid5, '   \n');

fprintf(fid6, 'function [f, g] = lincombFUN(x)\n');
fprintf(fid6, '   \n');
fprintf(fid6, 'global w\n');
fprintf(fid6, 'F = zeros(%i,1);\n', n);

fprintf(fid7, 'function [f, g] = shadowParetoFUN(x)\n');
fprintf(fid7, 'global shadowMin\n');
fprintf(fid7, 'F = zeros(%i,1);\n', n);

%fprintf(fid8, 'function [f, g] = max_tFUN(x_t)\n');% NOT NEEDED, INDP OF PROBLEM
%fprintf(fid8, '   \n');
%fprintf(fid8, 'global Phi w normal nvars\n');
%fprintf(fid8, 't = x_t(nvars+1);\n');
%fprintf(fid8, 'x = x_t(1:nvars);\n');
%fprintf(fid8, 'f = -t;\n');
%fprintf(fid8, '   \n');
%fprintf(fid8, 'funcs = Fns(x) - (Phi*w + t*normal);\n');
%fprintf(fid8, '[fdummy, ce, ci] = FUN(x);\n');
%fprintf(fid8, 'g = [ce;funcs;ci];');

%  That's all that is required for max_tFUN.m

 disp('Enter functions and constraints as character strings enclosed in quotes')
	Fchar = input('Enter first function  ');

	fprintf(fid2, 'F(1) = %s;\n', Fchar );

	fprintf(fid4, 'F(1) = %s;\n', Fchar );

	fprintf(fid6, 'F(1) = %s;\n', Fchar );

	fprintf(fid7, 'F(1) = %s;\n', Fchar );


	fprintf(fid1, 'if F_index == 1, \n');
	fprintf(fid1, '   f = %s ;\n', Fchar );
	fprintf(fid1, 'end \n');

%	fprintf(fid5, 'if index == 1, \n');
%	fprintf(fid5, '   f = %s ;\n', Fchar );
%	fprintf(fid5, 'end \n');


	for i = 2:n
	   Fchar = input('Enter next function  ');

	   fprintf(fid2, 'F(%i) = %s ; \n', i, Fchar);

	   fprintf(fid4, 'F(%i) = %s ; \n', i, Fchar);

	   fprintf(fid6, 'F(%i) = %s ; \n', i, Fchar);

	   fprintf(fid7, 'F(%i) = %s ; \n', i, Fchar);

% writing conditionals in FUN1.m to evaluate appropriate function

	   fprintf(fid1, 'if F_index == %i, \n', i);
	   fprintf(fid1, '   f = %s ; \n', Fchar);
	   fprintf(fid1, 'end \n');

%	   fprintf(fid5, 'if index == %i, \n', i);
%	   fprintf(fid5, '   f = %s ; \n',  Fchar);
%fid5 = fopen('objectives.m', 'w+'); % contains subroutine to evaluate indiv f
%	   fprintf(fid5, 'end \n');

	end


fprintf(fid3, 'f = 1;\n');
fprintf(fid2, 'F = F - shadowMin - qpp_pt;\n');

fprintf(fid4, 'F = F - shadowMin ;\n');

 fprintf(fid6, 'f = sum(w.*F);\n\n'); %can't write w'*F, 
				     % hence using this alternative
fprintf(fid7, 'F = F - shadowMin ;\n');
fprintf(fid7, 'f = (norm(F))^2;\n');

fprintf(fid1, '   \n');

fprintf(fid3, '   \n'); 
%

fprintf(fid1, 'g = ones(%i,1);\n',ne+ni);
 fprintf(fid6, 'g = ones(%i,1);\n',ne+ni); 
fprintf(fid7, 'g = ones(%i,1);\n',ne+ni); 

% Now getting constraints
	if ne > 0,
	   Fchar = input('Enter equality constraints, omit the = 0 at the end ');

	   fprintf(fid1, 'g(1) = %s; \n', Fchar);
	   fprintf(fid6, 'g(1) = %s; \n', Fchar);
	   fprintf(fid7, 'g(1) = %s; \n', Fchar);

	   fprintf(fid3, 'ce = ones(%i,1); \n',ne);
	   fprintf(fid3, 'ce(1) = %s; \n', Fchar);
          if ne > 1,
	      for i = 2:ne
	       Fchar = input('Enter next equality constraint   ');

	       fprintf(fid1, 'g(%i) = %s; \n', i, Fchar);
	       fprintf(fid6, 'g(%i) = %s; \n', i, Fchar);
		fprintf(fid7, 'g(%i) = %s; \n', i, Fchar);

	       fprintf(fid3, 'ce(%i) = %s; \n', i, Fchar);
	      end 
	  end
        end
	if ne == 0,
	     fprintf(fid3, 'ce = []; \n');
	end

	fprintf(fid3, 'ci = ones(%i,1); \n', ni);
	if ni > 0,
	   Fchar = input('Enter inequality constraints, omit the <= 0 at the end ');
	   ineq1 = ne + 1;

	   fprintf(fid1, 'g(%i) = %s; \n', ineq1, Fchar);
	   fprintf(fid6, 'g(%i) = %s; \n', ineq1, Fchar);
	   fprintf(fid7, 'g(%i) = %s; \n', ineq1, Fchar);

	   fprintf(fid3, 'ci(1) = %s; \n', Fchar);
          if ni > 1,
	      for i = (ne + 2):(ne + ni)
	       Fchar = input('Enter next inequality constraint   ');

	       fprintf(fid1, 'g(%i) = %s; \n', i, Fchar);
		 fprintf(fid6, 'g(%i) = %s; \n', i, Fchar);
		fprintf(fid7, 'g(%i) = %s; \n', i, Fchar);

		fprintf(fid3, 'ci(%i) = %s; \n', i - ne, Fchar);
	      end 
	  end
        end
% 
	neplusni = ne + ni;
	if neplusni == 0,
	   fprintf(fid1, 'g = []; \n');
	   fprintf(fid6, 'g = []; \n');

	end

end %response == 1



return
