%%%%%%%%%%%%%%%%%%%%%%
% Rayjan Wilson
% Marcos Hasebe
% AAE 421
% Stability and Control Derivatives
% from geometric analysis of 
% Orion Aerospace SID-5
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%********************************
%*altered and used for the Boiler Express by Jeremy Davis, Jake Grasmick
%* Dan Squibb, Andy Wiratama, Sean McElroy and Amanda Allen  04/01
%**********************************
%%%%%%%%%%5%%%%%%%%%%%%%%%%%%%%%%%%

clear all
close all

%open inputfile and read constants
sid5

%Calculations follow

%%open('boilerconst.m')
diary boilerconst

%%take biplane info out to calculate for the Boiler Express

%biplane to equivalent monoplane
%still needs improvement
%[Cdi,deda,k]=bi2mono(AR_w,lam_w,hh,l_h,b_w,CL_w,S_w,gap)

%3.2 CLa
[CLa_w,Kwb,CLa_wb,CLa_h,CLa,CLa_v]=CLa2(AR_w,AR_h,AR_v_eff,Kap,Kap2,Lam2_w,Lam2_h,Lam2_v,d,b_w,eta_h,S_h,S_w,deda,Beta)

%3.3 Cma 
[Xw,Xh,Xac_LE,Xac,Xac_wb,Xac_w,Xac_h,XacP_c_h,XacP_c_w,Xbar]=Cma2(q,c_w,S_w,CLa_w,eta_h,S_h,deda,CLa_h,CLa_wb,xLE,Xcg)

%4.1 CDu
CDu=CDu2(M,dCDdM); %eqn 4.1

%4.2 CLu
CLu=CLu2(M,CL_wb);		%eqn 4.2

%4.3 Cmu
Cmu=Cmu2(CL_wb,dXacdm);	%eqn 4.3

%5.1 CDq
CDq=0;

%5.2 CLq
[CLq_w_MO,CLq_w_M,CLq_w,V_h,CLq_h,CLq]=CLq2(Xw,B,c_w,c_h,CLa_w,Cla_h,AR_w,Lamq_w,Xh,S_h,S_w,eta_h)

%5.3 Cmq
[Cmq_w_MO,Cmq_w,Cmq_h,Cmq]=Cmq2(AR_w,Lamq_w,Xw,c_w,Cla_w,CLa_h,eta_h,V_h,Xh,c_h,B);

%6.2 CLadot
[CL_adot_w, CL_adot_h,CLadot]=Cladot2(XacP_c_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c_w,B,Clp_w,a,Clp,CL_w,dCnpTheta,Theta,dCnp_add,adelf,delf,b_v,l_v,Z_v,CyB_v)

%9.1 Cyr
[Cyr_v,Cyr]=Cyr2(CLa_v,Xh,b_v,eta_v,S_v,S_w)

%9.2 Clr
%for wing
[ClrCL_M, dClrGam,Clr_w,Clr_v,Clr]=Clr2(a,AR_w,CL_w,B,b_w,b_v,l_v,Z_v,Lamq_w,ClrCL_M0,Gam_w,dClrTheta,Theta,dClradelfdelf,adelf,delf,CyB_v)

%9.3 Cnr
[Cnr_w,Cnr_v,Cnr]=Cnr2(CnrCL2,CL_w,CnrCDo,CDo,b_v,l_v,a,Z_v,CyB_v)

%10.1 CLdF
[CLaM,CldF,ClaM,CLdF]=CLdF2(CLa_w,CldCldth,Cldth,Kprime,Cla_w,M,adCLadCl,Kb)

%10.2 CmdF
%beyond the scope of this text

%10.3 CLi_h
[CLi_h]=CLi_h2(CLa_h,S_h,S_w)

%10.4 Cmi_h
Cmi_h=Cmi_h2(CLa_h,V_h)

%10.5 CLdE
[taue,CLdE]=CLdE2(CLdF,S_h,S_w)

%10.6 CmdE
CmdE=CmdE2(CLdE,l_h,c_w)

%11.1 Cyda  -  Usually zero
Cyda=0;   						% eqn 11.1  

%11.2 Clda
[LamB,CldPr,Cld,ad,dA,CldA,Cl]=CldA2(Lamq_w,Beta,Kap,BCldPrKap,CldCldth,Cldth,Cla_w,dl,dr,CldL,CldR)

%11.3 Cnda 
Cnda=Cnda2(K,CL_w,CldA)

%12.1 CydR 
CydR=CydR2(CLa_v,adCLadCl,adCl,Kprime,Kb,S_v,S_w)

%12.2  CldR  
%CldR=CldR2(CydR,l_v,a,Z_v,b_v)
CldR=0;

%12.3 CndR 
CndR=CndR2(CydR,l_v,a,Z_v,b_v)

diary off