function [x_cg_eng_in,x_cg_eng_out,x_cg_prop,y_cg_eng_in,y_cg_eng_out,y_cg_prop,z_cg_eng]...
   =engine_xyz(tiltwing,w_max,c_r_wing,tc_avg_wing,sweep_wing,taper_wing,AR_wing,b_wing,D_eng,L_eng)

% note: tiltwing is a flag variable -- 1 = tiltwing, other # = fixed wing

% do not use for tiltwing yet (some values set to zero)

sweep_le = atan(tan(sweep_wing*pi/180) + 4*.25*(1-taper_wing)/(AR_wing*(1+taper_wing)));
D_engine = D_eng;
L_engine = L_eng;


if tiltwing == 1
% set turboprop dimensions
   D_nacelle_max = 1.1 * D_engine;		% calculate nacelle diameter
   L_inlet_cowl = 0.6 * D_nacelle_max;	% inlet cowl length ahead of engine fan face 
   space_ideal = D_nacelle_max/3;		% ideal distance between engines -- in feet
   x_cg_eng_ideal=L_engine/4-L_engine/2;						% for each pair of engine -- measured from leading edge
   y_cg_eng_out= b_wing/2 - D_nacelle_max/2;
   x_cg_eng_out= x_cg_eng_ideal - tan(sweep_le)*y_cg_eng_out;
   y_cg_eng_in= y_cg_eng_out - D_nacelle_max/2 - space_ideal - D_nacelle_max/2;
   x_cg_eng_in= x_cg_eng_ideal - tan(sweep_le)*y_cg_eng_in;			% sweep taken into account
   
   x_cg_prop_ideal=x_cg_eng_ideal + L_engine/2 + (18.92-(2.1+3.7))/12;		% in feet
   y_cg_prop=(y_cg_eng_out+y_cg_eng_in)/2;
   x_cg_prop = x_cg_prop_ideal - tan(sweep_le)*y_cg_prop;   
   z_cg_eng=-D_engine/2;								% measured from top of wing

else
   % set turbofan dimensions
   D_engine =41.7/12;
   L_engine =58.56/12;
   D_nacelle_max = 1.1 * D_engine;		% calculate nacelle diameter
   L_inlet_cowl = 0.6 * D_nacelle_max;	% inlet cowl length ahead of engine fan face 
   % find distances between engines and fuselage
   space = 2;									% distance between engines -- in feet
   dist_fuse = 2;								% distance between fuselage and first engine
      
   x_cg_eng_ideal=L_engine/2 - 0.3*c_r_wing;		% ideal case -- measured from leading edge
   y_cg_eng_in=w_max/2 + dist_fuse + D_nacelle_max/2;	% for each pair of engine -- measured from centerline
   x_cg_eng_in = x_cg_eng_ideal - tan(sweep_le)*y_cg_eng_in;			% sweep taken into account
   y_cg_eng_out=y_cg_eng_in + D_nacelle_max/2 + space + D_nacelle_max/2;
   x_cg_eng_out= x_cg_eng_ideal - tan(sweep_le)*y_cg_eng_out;	
   z_cg_eng=D_nacelle_max/2 - 1.1*tc_avg_wing*c_r_wing ;	% measured from top of wing
   x_cg_prop=0;y_cg_prop=0;			% pass back dummy values 
end
