function [x_km,flt_tke_final,tke_radar_final]=flt_vs_radar(input_data)
rappel=input_data.file_number;
filename=dir(['C:\Documents and Settings\lorsolette\My Documents\Research\',input_data.hurricane,'\',input_data.jour,'\*.w']) ;
fichier=filename(input_data.file_number).name
tke_radar_final=[];
file_flight=dir([['C:\Documents and Settings\lorsolette\My Documents\Research\',input_data.hurricane,'\',input_data.jour(1:2)],'\flight_data\*']) 

[temp_t, temp_lat, temp_lon,temp_rad, temp_wd, temp_ws, temp_w, temp_GS]=textread(['C:\Documents and Settings\lorsolette\My Documents\Research\',input_data.hurricane,'\',input_data.jour(1:2),'\flight_data\',fichier(1:7)],'%f %f %f %f %f %f %f %f', 'headerlines',4,'bufsize', 8191);



file_info=dir([['C:\Documents and Settings\lorsolette\My Documents\Research\',input_data.hurricane,'\',input_data.jour(1:2)],'\*',fichier(10:13),'*leg*']) 
fichier2=['C:\Documents and Settings\lorsolette\My Documents\Research\',input_data.hurricane,'\',input_data.jour(1:2),'\',file_info.name];

leg_data=textread(fichier2,'%s','bufsize', 8191);

inb_az=str2num(cell2mat(leg_data(17)))
t0=str2num(cell2mat(leg_data(1)))
t1=str2num(cell2mat(leg_data(4)))
tc=str2num(cell2mat(leg_data(7)))


u_t=find(temp_t>=t0 & temp_t <= t1);
wsi=temp_ws(u_t);
wdi=temp_wd(u_t);
w_insti=temp_w(u_t);
lati=temp_lat(u_t);
loni=-temp_lon(u_t);
ti=temp_t(u_t);
alt_radi=temp_rad(u_t);
[u_insti,v_insti]=wind_decomposition(wdi,wsi);
L=length(u_t);
u_center=find(ti==tc);



lat0=repmat(lati(u_center),L,1);
lon0=repmat(loni(u_center),L,1);
xaxisi=distdim(distance(lat0, lon0, lati, loni),'deg','m');
i_center=u_center(1);
xaxisi(i_center:L)=-xaxisi(i_center:L);


x_inb_leg=flipud((750:1500:xaxisi(1)+700)');
x_oub_leg=(-750:-1500:xaxisi(L)-750)';
x_leg=[x_inb_leg;x_oub_leg];


figure
axesm('mercator','MapLatLimit',[min(lati)-15 max(lati)+15],'MapLonLimit',[min(loni)-15 max(loni)+15]);
plotm(lati,loni);

reply = input('Did they circle in the center? y/n [y]: ','s');
if strcmp(reply,'y')==1
    
    disp('first start point')
    [start_lat,start_long]=inputm(1);%find((diff(xaxis))>0);
    disp('now end point')
    [end_lat,end_long]=inputm(1);
    dist_up=distdim(distance(lat0(1,1), lon0(1,1), start_lat,start_long),'deg','m');
    dist_down=distdim(distance(lat0(1,1), lon0(1,1), end_lat,end_long),'deg','m');
    no_looping=find(xaxisi > dist_up | xaxisi < -dist_down);
    
    
    xaxis2=xaxisi(no_looping);%[xaxis(1:start_pt(1));xaxis(u_neg(length(u_neg)):length(xaxis))];
    u_inst2=u_insti(no_looping);
    v_inst2=v_insti(no_looping);
    w_inst2=w_insti(no_looping);
    alt_rad2=alt_radi(no_looping);
else
    u_inst2=u_insti;
    v_inst2=v_insti;
    w_inst2=w_insti;
    xaxis2=xaxisi;
    alt_rad2=alt_radi;
end
close all
u_zeros=find((diff(xaxis2))~=0);

if length(u_zeros) > 0
    u_inst=u_inst2(u_zeros);
    v_inst=v_inst2(u_zeros);
    w_inst=w_inst2(u_zeros);
    xaxis=xaxis2(u_zeros);
    alt_rad=alt_rad2(u_zeros);
end

temp=[xaxis;x_leg];
xi=flipud(sort(temp));
u_leg=interp1(xaxis,u_inst,xi);
v_leg=interp1(xaxis,v_inst,xi);
w_leg=interp1(xaxis,w_inst,xi);

for i=1:length(x_leg)-1
    
    u_1500=find(xi<=x_leg(i) & xi > x_leg(i+1));
    stdu(i,1)=var(u_leg(u_1500));
    stdv(i,1)=var(v_leg(u_1500));
    stdw(i,1)=var(w_leg(u_1500));
    x_km(i,1)=(x_leg(i)-750)/1000;
    
    if length(u_1500)==1
        stdu(i,1)=NaN;
        stdv(i,1)=NaN;
        stdw(i,1)=NaN;
    end
    
end

flt_tke=0.5*((stdu) + (stdv) + (stdw));
u_0_abs=find(x_km == 0);
x_km(u_0_abs)=[];
flt_tke(u_0_abs)=[];
u_bound_abs=find(x_km > 0);
x_km_inb=x_km(u_bound_abs);
flt_inb_tke=flt_tke(u_bound_abs);
u_bound_abs=find(x_km < 0);
x_km_outb=x_km(u_bound_abs);
flt_outb_tke=flt_tke(u_bound_abs);
figure
plot(x_km,flt_tke,'--','LineWidth',2)
hold on

temp_k=input_data.file_number;

for k=temp_k:2:temp_k+2
    input_data.file_number=k;
    r_final=[];
    indice=[];
    [ws,radwind,tangwind,w,dbz, x_fill, y_fill, z_fill,L]=read_w_files(input_data);
    fichier=filename(input_data.file_number).name
    
    low_data=min(alt_rad);
    high_data=max(alt_rad);
    u_z=find(z_fill >=low_data-150 & z_fill <= high_data +150);
    
    
    
    
    
    plot((x_fill)/1000,nanmean((dbz(:,u_z(1):u_z(end)).^2)'),'r')
    xlabel('Radius (km)')
    ylabel('TKE (m^2.s^{-2})')
    title(['Comparison with flight level data for ', input_data.hurricane(6:length(input_data.hurricane)-1), ' ', input_data.jour(1:2), ' ' ,fichier(10:13)])
    legend('Flight Level Data','Radar Data')
    %          saveas(gcf,['C:\Documents and Settings\lorsolo\My Documents\research\HRD research\Gamache_soft\wfiles\TKE\profiles\flt_comp_',input_data.hurricane(5:length(input_data.hurricane)),'_',input_data.jour(1:2),'_',input_data.jour(4:end),'_',fichier(10:13),'.fig']);
    %          saveas(gcf,['C:\Documents and Settings\lorsolo\My Documents\research\HRD research\Gamache_soft\wfiles\TKE\profiles\flt_comp_',input_data.hurricane(5:length(input_data.hurricane)),'_',input_data.jour(1:2),'_',input_data.jour(4:end),'_',fichier(10:13),'.png']);
    % %  
    
    tke_radar_all=nanmean((dbz(:,u_z(1):u_z(end)).^2)');
    if length(findstr(fichier,'inbound'))==1
        u_x=find(x_km > 0);
        xx=x_km(u_x);
        tke_radar=flipud(tke_radar_all(1:length(xx))');
        
        
        for bias=0:8
            temp_flt_tke=[flt_inb_tke;NaN*ones(bias,1)];
            temp_tke_radar=[NaN*ones(bias,1);tke_radar];
            u_nan=find(isnan(temp_tke_radar)==1);
            temp_tke_radar(u_nan)=[];
            temp_flt_tke(u_nan)=[];
            u_nan=find(isnan(temp_flt_tke)==1);
            temp_flt_tke(u_nan)=[];
            temp_tke_radar(u_nan)=[];
            temp_r=corrcoef(temp_tke_radar, temp_flt_tke);
            r_final=[r_final;temp_r(1,2)];
            indice=[indice;bias];
        end
        
        
        for bias=1:8
            temp_flt_tke=[NaN*ones(bias,1);flt_inb_tke];
            temp_tke_radar=[tke_radar;NaN*ones(bias,1)];
            u_nan=find(isnan(temp_tke_radar)==1);
            temp_tke_radar(u_nan)=[];
            temp_flt_tke(u_nan)=[];
            u_nan=find(isnan(temp_flt_tke)==1);
            temp_flt_tke(u_nan)=[];
            temp_tke_radar(u_nan)=[];
            temp_r=corrcoef(temp_tke_radar, temp_flt_tke);
            r_final=[r_final;temp_r(1,2)];
            indice=[indice;-bias];
        end
        [max_corr,index_max]=max(r_final);
        
        
        final_shift_inb=indice(index_max);
        
        if final_shift_inb >0
            flt_tke_final_inb=[flt_inb_tke;NaN*ones(final_shift_inb,1)];
            tke_radar_final_inb=[NaN*ones(final_shift_inb,1);tke_radar];
            u_nan=find(isnan(tke_radar_final_inb)==1);
            tke_radar_final_inb(u_nan)=[];
            flt_tke_final_inb(u_nan)=[];
            u_nan=find(isnan(flt_tke_final_inb)==1);
            flt_tke_final_inb(u_nan)=[];
            tke_radar_final_inb(u_nan)=[];
            corrcoef(tke_radar_final_inb, flt_tke_final_inb)
        else
            flt_tke_final_inb=[NaN*ones((-final_shift_inb),1);flt_inb_tke];
            tke_radar_final_inb=[tke_radar;NaN*ones((-final_shift_inb),1)];
            u_nan=find(isnan(tke_radar_final_inb)==1);
            tke_radar_final_inb(u_nan)=[];
            flt_tke_final_inb(u_nan)=[];
            u_nan=find(isnan(flt_tke_final_inb)==1);
            flt_tke_final_inb(u_nan)=[];
            tke_radar_final_inb(u_nan)=[];
            
            corrcoef(tke_radar_final_inb, flt_tke_final_inb)
        end
        
        
        
        
        
        
        
        
        
    elseif length(findstr(fichier,'outbound'))==1
        u_x=find(x_km < 0);
        xx=x_km(u_x);
        tke_radar=tke_radar_all(1:length(xx))';
        
        
        for bias=0:8
            temp_flt_tke=[flt_outb_tke;NaN*ones(bias,1)];
            temp_tke_radar=[NaN*ones(bias,1);tke_radar];
            u_nan=find(isnan(temp_tke_radar)==1);
            temp_tke_radar(u_nan)=[];
            temp_flt_tke(u_nan)=[];
            u_nan=find(isnan(temp_flt_tke)==1);
            temp_flt_tke(u_nan)=[];
            temp_tke_radar(u_nan)=[];
            temp_r=corrcoef(temp_tke_radar, temp_flt_tke);
            r_final=[r_final;temp_r(1,2)];
            indice=[indice;bias];
        end
        
        
        for bias=1:8
            temp_flt_tke=[NaN*ones(bias,1);flt_outb_tke];
            temp_tke_radar=[tke_radar;NaN*ones(bias,1)];
            u_nan=find(isnan(temp_tke_radar)==1);
            temp_tke_radar(u_nan)=[];
            temp_flt_tke(u_nan)=[];
            u_nan=find(isnan(temp_flt_tke)==1);
            temp_flt_tke(u_nan)=[];
            temp_tke_radar(u_nan)=[];
            temp_r=corrcoef(temp_tke_radar, temp_flt_tke);
            r_final=[r_final;temp_r(1,2)];
            indice=[indice;-bias];
        end
        [max_corr,index_max]=max(r_final);
        
        
        final_shift_outb=indice(index_max);
        
        if final_shift_outb >0
            flt_tke_final_outb=[flt_outb_tke;NaN*ones(final_shift_outb,1)];
            tke_radar_final_outb=[NaN*ones(final_shift_outb,1);tke_radar];
            u_nan=find(isnan(tke_radar_final_outb)==1);
            tke_radar_final_outb(u_nan)=[];
            flt_tke_final_outb(u_nan)=[];
            u_nan=find(isnan(flt_tke_final_outb)==1);
            flt_tke_final_outb(u_nan)=[];
            tke_radar_final_outb(u_nan)=[];
            corrcoef(tke_radar_final_outb, flt_tke_final_outb)
        else
            flt_tke_final_outb=[NaN*ones((-final_shift_outb),1);flt_outb_tke];
            tke_radar_final_outb=[tke_radar;NaN*ones((-final_shift_outb),1)];
            u_nan=find(isnan(tke_radar_final_outb)==1);
            tke_radar_final_outb(u_nan)=[];
            flt_tke_final_outb(u_nan)=[];
            u_nan=find(isnan(flt_tke_final_outb)==1);
            flt_tke_final_outb(u_nan)=[];
            tke_radar_final_outb(u_nan)=[];
            
            corrcoef(tke_radar_final_outb, flt_tke_final_outb)
        end
        
        
        
    end
    
end

tke_radar_final=[tke_radar_final_inb;tke_radar_final_outb];
flt_tke_final=[flt_tke_final_inb;flt_tke_final_outb];


figure
plot(x_km,flt_tke,'--','LineWidth',2)
hold on
temp_k=rappel;
for k=temp_k:2:temp_k+2
    input_data.file_number=k;
    
    [ws,radwind,tangwind,w,dbz, x_fill, y_fill, z_fill,L]=read_w_files(input_data);
    fichier=filename(input_data.file_number).name
    
    low_data=min(alt_rad);
    high_data=max(alt_rad);
    u_z=find(z_fill >=low_data-150 & z_fill <= high_data +150);
    
    if k==temp_k
        final_shift=final_shift_inb;
    else
        final_shift=final_shift_outb;
    end
    plot((x_fill-final_shift*1500)/1000,nanmean((dbz(:,u_z(1):u_z(end)).^2)'),'r')
    xlabel('Radius (km)')
    ylabel('TKE (m^2.s^{-2})')
    title(['Comparison with flight level data for ', input_data.hurricane(6:length(input_data.hurricane)-1), ' ', input_data.jour(1:2), ' ' ,fichier(10:13)])
    legend('Flight Level Data','Radar Data')
end