% [Cl_da]=Cl_da(S_w,AR_w,ca_cw,eta_ia,eta_oa,beta,kappa,....
%		Lambda_c4,lambda_w,tc_w,Cl_alpha_w)
%
%  Cl_da - Variation of Rolling Moment Coefficient with  
%           Aileron Deflection 
%
%	[Ref.2]	Jan Roskam
%		Methods for Estimating
%		Stability and Control Derivatives
%		of Conventional Subsonic Airplanes  -  1977
%
%		S_w			- Wing Area [ft^2]
%		AR_w			- Aspect Ratio of wing
%		ca_cw			- Ratio of aileron chord to wing chord
%		eta_ia		- Percent span position of outboard edge of aileron
%		eta_oa		- Percent span position of inboard edge of aileron
%		tc_w			- Thickness to chord of wing
%		beta			- Compressibility correction factor
%		kappa 		- Ratio of wing 2D lift curve slope to 2pi
%		Lambda_c4   - Wing sweep angle at 1/4chord [rad]
%		lambda_w		- Wing taper ratio
%		Cl_alpha_w	- wing 2D lift curve slope

function [Cl_da]=Cl_da(S_w,AR_w,ca_cw,eta_ia,eta_oa,beta,kappa, ...
   Lambda_c4,lambda_w,tc_w,Cl_alpha_w)


AR_cor=beta*AR_w/kappa;
Lambda_beta = atan(tan(Lambda_c4/beta));  % Eqn 11.1 [Ref 2]

% Figure 11.1 [Ref 1]
eta_fig = [0	0.1	0.2	0.3	0.4	0.5	0.6	0.7	0.8	0.9	1];
Lambda_beta_fig = [-40 0 40 60];
AR_cor_fig = [8 4 2];
lambda_fig = [0 0.5 1];

Cl_delta_prime_cor_fig1(:,:,1) = ...
[0.0000	0.0052	0.0305	0.0800	0.1448	0.2095	0.2743	0.3352	0.3948	0.4462	0.4871; ...
0.0000	0.0114	0.0405	0.0924	0.1643	0.2519	0.3524	0.4443	0.5276	0.5905	0.6295; ...
0.0000	0.0114	0.0471	0.1081	0.1872	0.2819	0.3776	0.4657	0.5448	0.5905	0.6133; ...
0.0000	0.0114	0.0471	0.1081	0.1838	0.2576	0.3267	0.3910	0.4443	0.4752	0.4862];										
Cl_delta_prime_cor_fig1(:,:,2) = ...										
[0.0000	0.0066	0.0265	0.0564	0.0953	0.1433	0.1956	0.2435	0.2910	0.3310	0.3650; ...
0.0000	0.0066	0.0303	0.0659	0.1124	0.1718	0.2374	0.3001	0.3642	0.4174	0.4444; ...
0.0000	0.0066	0.0303	0.0659	0.1167	0.1794	0.2454	0.3138	0.3756	0.4174	0.4415; ...
0.0000	0.0066	0.0303	0.0640	0.1087	0.1618	0.2207	0.2749	0.3204	0.3500	0.3645];					
Cl_delta_prime_cor_fig1(:,:,3) = ...
[0.0000	0.0051	0.0150	0.0319	0.0565	0.0891	0.1255	0.1633	0.1969	0.2224	0.2450; ...
0.0000	0.0051	0.0188	0.0376	0.0655	0.0991	0.1426	0.1861	0.2248	0.2589	0.2820; ...
0.0000	0.0051	0.0188	0.0376	0.0655	0.1033	0.1487	0.1913	0.2315	0.2627	0.2820; ...
0.0000	0.0051	0.0188	0.0376	0.0632	0.0957	0.1369	0.1775	0.2158	0.2432	0.2592];
Cl_delta_prime_cor_fig2(:,:,1) = ...
[0.0000	0.0092	0.0351	0.0743	0.1258	0.1911	0.2726	0.3703	0.4803	0.5809	0.6638; ...
0.0000	0.0159	0.0527	0.1085	0.1824	0.2777	0.3944	0.5139	0.6249	0.7230	0.8031; ...
0.0000	0.0159	0.0527	0.1156	0.1905	0.2810	0.3877	0.4873	0.5788	0.6603	0.7299; ...
0.0000	0.0159	0.0527	0.1033	0.1662	0.2373	0.3102	0.3798	0.4447	0.5038	0.5549];
Cl_delta_prime_cor_fig2(:,:,2) = ...										
[0.0000	0.0068	0.0261	0.0586	0.1012	0.1518	0.2143	0.2949	0.3688	0.4314	0.4796; ...
0.0000	0.0097	0.0346	0.0739	0.1254	0.1861	0.2614	0.3463	0.4260	0.4904	0.5396; ...
0.0000	0.0097	0.0346	0.0739	0.1254	0.1861	0.2614	0.3396	0.4107	0.4718	0.5158; ...
0.0000	0.0068	0.0284	0.0658	0.1131	0.1699	0.2338	0.2949	0.3508	0.3971	0.4320];									
Cl_delta_prime_cor_fig2(:,:,3) = ...
[0.0000	0.0044	0.0147	0.0294	0.0500	0.0753	0.1069	0.1399	0.1744	0.2032	0.2189; ...
0.0000	0.0044	0.0179	0.0350	0.0582	0.0845	0.1172	0.1492	0.1850	0.2128	0.2320; ...
0.0000	0.0044	0.0179	0.0350	0.0582	0.0845	0.1172	0.1492	0.1787	0.2050	0.2278; ...
0.0000	0.0044	0.0179	0.0350	0.0543	0.0802	0.1104	0.1438	0.1744	0.1968	0.2136];
Cl_delta_prime_cor_fig3(:,:,1) = ...
[0.0000	0.0085	0.0351	0.0726	0.1201	0.1891	0.2851	0.4017	0.5197	0.6287	0.7248; ...
0.0000	0.0147	0.0498	0.1045	0.1777	0.2724	0.3909	0.5165	0.6540	0.7730	0.8524; ...
0.0000	0.0147	0.0498	0.1102	0.1853	0.2810	0.3933	0.5012	0.6026	0.6930	0.7662; ...
0.0000	0.0085	0.0398	0.0926	0.1553	0.2281	0.3042	0.3789	0.4531	0.5196	0.5795];
Cl_delta_prime_cor_fig3(:,:,2) = ...										
[0.0000	0.0075	0.0313	0.0641	0.1073	0.1620	0.2234	0.3020	0.3862	0.4524	0.5028; ...
0.0000	0.0075	0.0313	0.0698	0.1226	0.1859	0.2587	0.3463	0.4363	0.5062	0.5595; ...
0.0000	0.0075	0.0313	0.0698	0.1226	0.1859	0.2563	0.3344	0.4115	0.4743	0.5252; ...
0.0000	0.0075	0.0313	0.0698	0.1116	0.1639	0.2258	0.2886	0.3467	0.3999	0.4456];										
Cl_delta_prime_cor_fig3(:,:,3) = ...										
[0.0000	0.0023	0.0165	0.0377	0.0670	0.1077	0.1474	0.1919	0.2415	0.2826	0.3082; ...
0.0000	0.0056	0.0222	0.0462	0.0798	0.1176	0.1616	0.2075	0.2553	0.2935	0.3167; ...
0.0000	0.0056	0.0222	0.0462	0.0798	0.1176	0.1564	0.2018	0.2496	0.2883	0.3110; ...
0.0000	0.0056	0.0222	0.0462	0.0755	0.1077	0.1474	0.1900	0.2335	0.2708	0.2925];

Cl_delta_prime_cor_ia1=interlim3(eta_fig,Lambda_beta_fig,AR_cor_fig,Cl_delta_prime_cor_fig1,eta_ia,Lambda_beta,AR_cor);
Cl_delta_prime_cor_oa1=interlim3(eta_fig,Lambda_beta_fig,AR_cor_fig,Cl_delta_prime_cor_fig1,eta_oa,Lambda_beta,AR_cor);
Cl_delta_prime_cor_ia2=interlim3(eta_fig,Lambda_beta_fig,AR_cor_fig,Cl_delta_prime_cor_fig2,eta_ia,Lambda_beta,AR_cor);
Cl_delta_prime_cor_oa2=interlim3(eta_fig,Lambda_beta_fig,AR_cor_fig,Cl_delta_prime_cor_fig2,eta_oa,Lambda_beta,AR_cor);
Cl_delta_prime_cor_ia3=interlim3(eta_fig,Lambda_beta_fig,AR_cor_fig,Cl_delta_prime_cor_fig3,eta_ia,Lambda_beta,AR_cor);
Cl_delta_prime_cor_oa3=interlim3(eta_fig,Lambda_beta_fig,AR_cor_fig,Cl_delta_prime_cor_fig3,eta_oa,Lambda_beta,AR_cor);

Cl_delta_prime_cor_ia=interlim1(lambda_fig,[Cl_delta_prime_cor_ia1 Cl_delta_prime_cor_ia2 Cl_delta_prime_cor_ia3],lambda_w);
Cl_delta_prime_cor_oa=interlim1(lambda_fig,[Cl_delta_prime_cor_oa1 Cl_delta_prime_cor_oa2 Cl_delta_prime_cor_oa3],lambda_w);
                    
Cl_delta_prime_cor = Cl_delta_prime_cor_oa-Cl_delta_prime_cor_ia;           
                    
Cl_d_prime=kappa/beta*Cl_delta_prime_cor;  % Eqn 11.2 [Ref 2]

% Figure 10.5  -  Reference 2
cf_c_fig = [0.05 0.1 0.15 0.2 0.25 0.3 0.4 0.5];
t_c_fig = [0.15 0.12 0.10 0.08 0.06 0.04 0.02 0];
Cl_delta_theory_fig = ...
   	[1.81	2.57	3.09	3.44	3.82	4.61	5.33	5.96 	;...
		1.81	2.55	3.11	3.48	3.88	4.54	5.21	5.8	;...
		1.8	2.53	3.13	3.57	3.97	4.46	5.12	5.7	;...
		1.8	2.51	3.16	3.52	4.03	4.41	5.03	5.57	;...
		1.79	2.5	3.19	3.6	4.08	4.35	4.95	5.47	;...
		1.79	2.49	3		3.63	4.14	4.29	4.86	5.36	;...
		1.78	2.48	3.04	3.73	4.19	4.23	4.78	5.24	;...
      1.78	2.47	3.07	3.69	3.93	4.16	4.7	5.14	];
Cl_delta_theory=interlim2(cf_c_fig,t_c_fig,Cl_delta_theory_fig,ca_cw,tc_w);

% Figure 10.6  -  Reference 2
cf_c_fig = [0.05 0.1 0.15 0.2 0.25 0.3 0.4 0.5];
Cl_alpha_ratio_fig = [1 .98 .96 .94 .92 .9 .88 .86 .84 .82 .8 .78 .76 .74 .72 .7];
Cl_delta_ratio_fig = ...
		[1.00	1.00	1.00	1.00	1.00	1.00	1.00	1.00	;...	
		0.952	0.961	0.965	0.965	0.966	0.968	0.971	0.973	;...	
		0.91	0.92	0.928	0.932	0.935	0.939	0.944	0.95	;...
		0.863	0.882	0.894	0.9	0.905	0.909	0.917	0.923	;...
		0.825	0.846	0.858	0.865	0.871	0.878	0.891	0.901	;...
		0.782	0.809	0.824	0.835	0.846	0.85	0.863	0.875	;...
		0.739	0.771	0.786	0.8	0.81	0.819	0.835	0.848	;...
		0.699	0.733	0.751	0.765	0.778	0.789	0.805	0.818	;...
		0.656	0.695	0.714	0.731	0.744	0.756	0.777	0.793	;...
		0.616	0.654	0.673	0.691	0.706	0.72	0.742	0.762	;...
		0.574	0.613	0.636	0.655	0.671	0.684	0.709	0.729	;...
		0.527	0.566	0.59	0.611	0.627	0.642	0.67	0.693	;...
		0.483	0.52	0.547	0.567	0.587	0.602	0.631	0.656	;...
		0.441	0.471	0.497	0.521	0.543	0.562	0.593	0.616	;...
		0.398	0.427	0.452	0.476	0.497	0.515	0.549	0.582	;...
      0.354	0.384	0.408	0.431	0.453	0.471	0.509	0.545	];
Cl_alpha_ratio=Cl_alpha_w/(2*pi);
Cl_delta_ratio=interlim2(cf_c_fig,Cl_alpha_ratio_fig,Cl_delta_ratio_fig,ca_cw,Cl_alpha_ratio);

% Figure 11.3
eta_fig = [0 0.2 0.4 0.6 0.8 0.9];
AR_fig = [3 4 6 8];
lambda_fig = [1.0 0.75 0.5 0.25];
K_fig(:,:,1) = ...
   	[-0.3615	-0.3615	-0.3615	-0.3615	-0.3615	-0.3615; ...
		-0.2620	-0.2671	-0.2797	-0.2963	-0.3164	-0.3270; ... 
		-0.1825	-0.1906	-0.2017	-0.2198	-0.2494	-0.2720; ...
		-0.1450	-0.1506	-0.1592	-0.1753	-0.2029	-0.2255];									
K_fig(:,:,2) = ...
   	[-0.3266	-0.3261	-0.3297	-0.3418	-0.3879	-0.4294; ...
		-0.2612	-0.2607	-0.2643	-0.2804	-0.3075	-0.3235 ; ...
		-0.1801	-0.1807	-0.1843	-0.1994	-0.2250	-0.2406; ...
		-0.1382	-0.1388	-0.1424	-0.1575	-0.1830	-0.1976];			
K_fig(:,:,3) = ...
   	[-0.3373	-0.3364	-0.3373	-0.3424	-0.3554	-0.3654; ...
		-0.2496	-0.2491	-0.2521	-0.2582	-0.2712	-0.2807; ...
		-0.1699	-0.1694	-0.1729	-0.1815	-0.2030	-0.2206; ...
		-0.1303	-0.1303	-0.1323	-0.1373	-0.1584	-0.1774];
K_fig(:,:,4) = ...
   	[-0.2850	-0.2772	-0.2744	-0.2806	-0.2988	-0.3157; ...
		-0.2330	-0.2237	-0.2164	-0.2191	-0.2268	-0.2302; ...
		-0.1600	-0.1522	-0.1434	-0.1446	-0.1603	-0.1746; ...
		-0.1200	-0.1157	-0.1084	-0.1051	-0.1238	-0.1421];
K = interlim3(eta_fig,AR_fig,lambda_fig,K_fig,eta_ia,AR_w,lambda_w);

Cl_delta=Cl_delta_ratio*Cl_delta_theory;  	% Eqn 11.5 [Ref 2]
Cl_da=Cl_delta/Cl_alpha_w*Cl_d_prime;			% Eqn 11.3 [Ref 2]

return