function Vcalibrated=AS1Warrior3(Vindicated,flap)
% function Vcalibrated=AS1Warrior3(Vindicated,flap)
% Correct indicated airspeed for instrument error and static position error.
% Data is extracted from Piper Warrior III Information Manual, page 5-12.
% It is assumed that the Warrior III has zero instrument correction.
% Therefore 
%             Vinstrumentcorrected (Vic) = Vindicated (Vi)
% Given below are the position error corrections to get Vcalibrated. 
% They are a function of Vindicated and flap position.
%             Vcalibrated=f(Vindicated,flap)
%                   flap=0   for no flap
%                   flap=0.5 for half flap (20 degrees for Warrior)
%                   flap=1   for full flap (40 degrees for Warrior)
% Vindicated and Vcal are a row vectors.
% Half flap data is linearly interpolated between no flap and full flap data.
% Units are KNOTS.
% Range of applicability:  43.2<Vi<160 knots
%
% PA-28-161 Flaps up airspeed calibration
%              Vic         Vc   (knots)
dat_no_flap=[43.15563	51.75851 % add first point for interpolation to slow airapeeds 
             49.85750	57.49308
             59.85085	64.85054
             79.96288	80.95924
             99.94673	98.84158
             120.05716	116.72404
             140.04089	134.73306
             160.27768	152.86903];


% PA-28-161 Flaps Down airspeed calibration (40 degrees fo flap)
%            Vic         Vc   (knots)
dat_flap=[43.15563	49.75851
          57.07040	60.03355
          65.92485	67.00989
          79.96449	79.18549
          91.98041	89.58550
          103.99633	99.98552
          160.27768	150.86903]; % last point added so no airspeed is out of range for the interpolation.
Vi_noflap=dat_no_flap(:,1);
[r,c]=size(Vi_noflap);
Vc_noflap=dat_no_flap(:,2);
Vi_flap=dat_flap(:,1);
Vc_flap=dat_flap(:,2);

% YI = INTERP1(X,Y,XI)
VcNF=interp1(Vi_noflap,Vc_noflap,Vindicated);
VcF=interp1(Vi_flap,Vc_flap,Vindicated);
Vcalibrated=(1-flap).*VcNF+flap.*VcF;
 