function CLmax=CLfun3(x) 
% x(1)=Hi(j)  Indicated altitude, feet
% x(2)=Vi(j)  Indicated arispeed at stall, knots
% x(3)=Wt(j)  Weight, pounds
% x(4)=flap   Flap setting flap=0 for no flap %flap=0.5 for half flap %flap=1 for full flap
% x(5)=S      Wing area, ft^2
Hi=x(1);
Vi=x(2);
Wt=x(3);
flap=x(4);
S=x(5);
Hcalibrated=ALTBaron58(Hi,Vi,flap); % Altitude units are feet.
Vcalibrated=AS1Baron58(Vi,flap); % Airspeed units are KNOTS.
[temp,p,rho,Hgeopvector]=atmosphere4(Hcalibrated,0);
[Vequivalent,qcOverp0,qcOverp]=AS2(Vcalibrated,p); % Knots
[Vtrue,M,aknots,rho,sigma]=AS3(Vequivalent,temp,Hcalibrated); % knots
Vtfps=1.687808*Vtrue; % convert knots to ft/sec
CLmax=2*Wt/(rho*Vtfps*Vtfps*S); % Scalar operations are used here.

% Alternate solution method
% Vefps=1.687808*Vequivalent; % convert knots to ft/sec
% CLmax=2*Wt/(0.00237691267925741*Vefps*Vefps*S); % Scalar operations are used here.
