function [perct, turb_out, x_axis, z_axis]=pdf_maker(input_data, type_pdf, top_height)
% input_data.param : which variable do I want to have the CFAD for?
% input_data.tke =0: variable is contained in the *vert.w files
%input_data.tke=1: variable is contained in the *vert_vrrms.w files


turb_out=[];
max_bin=15;
min_bin=-12;
bins=min_bin:max_bin;
bins=[-inf bins inf];
x_axis=min_bin-0.5:1:max_bin + 1.5;
turb=[];
turb_r1=[];
turb_r2=[];
turb_r3=[];
turb_r4=[];
turb_r0=[];
turb_r5=[];

if strcmp(type_pdf,'CFAD_rmw_interp')~=1
    disp('processing one day of the storm')
    file_dir=dir(['C:\Documents and Settings\sylvie.lorsolo\My Documents\research\HRD research\Gamache_soft\wfiles\',input_data.hurricane,'\',input_data.jour,'\*.w']) ;
    M=length(file_dir);
    
    for file_number = 1:M
        input_data.file_number=file_number;
        [ws,radwin,tgwind,w,dbz, x_fill, y_fill, z_fill, type_data]=read_w_files(input_data);
        
        param=eval(input_data.param);
        
        
        u_z=find(z_fill <=top_height);
        h1=(u_z(end));
        z_axis=z_fill(1:h1);
        temp_rmw20ou=NaN*ones(14,h1);
        temp_rmw40ou=NaN*ones(14,h1);
        temp_rmw60ou=NaN*ones(14,h1);
        temp_rmw80ou=NaN*ones(14,h1);
        temp_rmw_in=NaN*ones(64,h1);
        [li_int,col_int]=size(param);
        
        if (type_data == 0 & strcmp(type_pdf,'CFAD_rmw')==1)
            filename=[file_dir(input_data.file_number).name(1:16),'_flt'];
            path1=['C:\Documents and Settings\sylvie.lorsolo\My Documents\research\HRD research\Gamache_soft\wfiles\',input_data.hurricane,'\',input_data.jour(1:2),'\'];
            [flight_data]=flight_level_data(path1,filename);
            [rmw,rmw_pos]=rmw_find(flight_data, tgwind, x_fill,z_axis);
            rmw;
        end
        if (type_data ~= 0 & input_data.tke==1)
            
            
            
            
            turb=[turb;(param(:,1:h1))];
            if strcmp(type_pdf,'CFAD_radius')==1
                
                
                turb_r1=[turb_r1;(param(2:15,1:h1))];
                turb_r2=[turb_r2;(param(16:29,1:h1))];
                turb_r3=[turb_r3;(param(30:43,1:h1))];
                turb_r4=[turb_r4;(param(44:57,1:h1))];
                
                rad(1).turb=turb_r1;
                rad(2).turb=turb_r2;
                rad(3).turb=turb_r3;
                rad(4).turb=turb_r4;
            elseif strcmp(type_pdf,'CFAD_rmw')==1
                
                
                for colo=1:h1
                    continue_lower=1;
                    check_length=rmw_pos(colo)+13;
                    if check_length < li_int
                        temp_rmw20ou(:,colo)=(param(rmw_pos(colo): rmw_pos(colo)+13,colo));   %13 in range is 19.5 km distance, we want 19.5 km from rmw or from ~20km to 40 km, etc...
                    else
                        continue_lower=0;
                    end
                    
                    if continue_lower==1
                        temp_rmw_in(1:rmw_pos(colo)-1,colo)=(param(2:rmw_pos(colo),colo));
                    end
                    
                    check_length=rmw_pos(colo)+(13*2)+1;
                    if check_length < li_int
                        temp_rmw40ou(:,colo)=(param(rmw_pos(colo)+13+1:rmw_pos(colo)+(13*2)+1,colo));
                    elseif check_length >= li_int & continue_lower==1
                        reste=check_length-li_int;
                        temp_rmw40ou(1:14-reste,colo)=(param(rmw_pos(colo)+13+1:li_int,colo));
                        continue_lower=0;
                    end
                    
                    check_length=rmw_pos(colo)+(13*3)+2;
                    if check_length < li_int
                        temp_rmw60ou(:,colo)=(param(rmw_pos(colo)+(13*2)+2:rmw_pos(colo)+(13*3)+2,colo));
                    elseif check_length >= li_int & continue_lower==1
                        reste=check_length-li_int;
                        temp_rmw60ou(1:14-reste,colo)=(param(rmw_pos(colo)+(13*2)+2:li_int,colo));
                        continue_lower=0;
                    end
                    
                    check_length=rmw_pos(colo)+(13*4)+3;
                    if check_length < li_int
                        temp_rmw80ou(:,colo)=(param(rmw_pos(colo)+(13*3)+3:rmw_pos(colo)+(13*4)+3,colo));
                    elseif check_length >= li_int & continue_lower==1
                        reste=check_length-li_int;
                        temp_rmw80ou(1:14-reste,colo)=(param(rmw_pos(colo)+(13*3)+3:li_int,colo));
                    end
                    
                    
                end
                turb_r0=[turb_r0;temp_rmw_in];
                turb_r1=[turb_r1;temp_rmw20ou];
                turb_r2=[turb_r2;temp_rmw40ou];
                turb_r3=[turb_r3;temp_rmw60ou];
                turb_r4=[turb_r4;temp_rmw80ou];
                rad(2).turb=turb_r1;
                rad(3).turb=turb_r2;
                rad(4).turb=turb_r3;
                rad(5).turb=turb_r4;
                rad(1).turb=turb_r0;
            end
        elseif (type_data == 0 & input_data.tke==0)
            
            
            
            turb=[turb;(param(:,1:h1))];
            disp('check point')
            if strcmp(type_pdf,'CFAD_radius')==1
                
                
                turb_r1=[turb_r1;(param(2:15,1:h1))];
                turb_r2=[turb_r2;(param(16:29,1:h1))];
                turb_r3=[turb_r3;(param(30:43,1:h1))];
                turb_r4=[turb_r4;(param(44:57,1:h1))];
                
                rad(1).turb=turb_r1;
                rad(2).turb=turb_r2;
                rad(3).turb=turb_r3;
                rad(4).turb=turb_r4;
            elseif strcmp(type_pdf,'CFAD_rmw')==1
                
                
                for colo=1:h1
                    continue_lower=1;
                    check_length=rmw_pos(colo)+13;
                    if check_length < li_int
                        temp_rmw20ou(:,colo)=(param(rmw_pos(colo): rmw_pos(colo)+13,colo));   %13 in range is 19.5 km distance, we want 19.5 km from rmw or from ~20km to 40 km, etc...
                    else
                        continue_lower=0;
                    end
                    
                    if continue_lower==1
                        temp_rmw_in(1:rmw_pos(colo)-1,colo)=(param(2:rmw_pos(colo),colo));
                    end
                    
                    check_length=rmw_pos(colo)+(13*2)+1;
                    if check_length < li_int
                        temp_rmw40ou(:,colo)=(param(rmw_pos(colo)+13+1:rmw_pos(colo)+(13*2)+1,colo));
                    elseif check_length >= li_int & continue_lower==1
                        reste=check_length-li_int;
                        temp_rmw40ou(1:14-reste,colo)=(param(rmw_pos(colo)+13+1:li_int,colo));
                        continue_lower=0;
                    end
                    
                    check_length=rmw_pos(colo)+(13*3)+2;
                    if check_length < li_int
                        temp_rmw60ou(:,colo)=(param(rmw_pos(colo)+(13*2)+2:rmw_pos(colo)+(13*3)+2,colo));
                    elseif check_length >= li_int & continue_lower==1
                        reste=check_length-li_int;
                        temp_rmw60ou(1:14-reste,colo)=(param(rmw_pos(colo)+(13*2)+2:li_int,colo));
                        continue_lower=0;
                    end
                    
                    check_length=rmw_pos(colo)+(13*4)+3;
                    if check_length < li_int
                        temp_rmw80ou(:,colo)=(param(rmw_pos(colo)+(13*3)+3:rmw_pos(colo)+(13*4)+3,colo));
                    elseif check_length >= li_int & continue_lower==1
                        reste=check_length-li_int;
                        temp_rmw80ou(1:14-reste,colo)=(param(rmw_pos(colo)+(13*3)+3:li_int,colo));
                    end
                    
                    
                end
                turb_r0=[turb_r0;temp_rmw_in];
                turb_r1=[turb_r1;temp_rmw20ou];
                turb_r2=[turb_r2;temp_rmw40ou];
                turb_r3=[turb_r3;temp_rmw60ou];
                turb_r4=[turb_r4;temp_rmw80ou];
                rad(2).turb=turb_r1;
                rad(3).turb=turb_r2;
                rad(4).turb=turb_r3;
                rad(5).turb=turb_r4;
                rad(1).turb=turb_r0;
            end
            
        end
    end
    [li_turb,col_turb]=size(turb);
    if strcmp(type_pdf,'full_pdf')==1
        turb_out=turb;
        temp=reshape(turb, li_turb*col_turb,1);
        u_nan=find(isnan(temp)~=1);
        perct=((histc(temp, bins))/length(u_nan))*100;
    elseif strcmp(type_pdf,'CFAD_height')==1
        turb_out=turb;
        distri=histc(turb, bins);
        for col=1:col_turb
            if sum(distri(:,col))~=0
                perct(:,col) = (distri(:,col)./sum(distri(:,col)))*100;
            else
                perct(:,col)=zeros(length(bins),1);
            end
        end
    elseif  strcmp(type_pdf,'CFAD_radius')==1 
        
        for ii=1:4
            turb_out=rad;
            distri=histc(rad(ii).turb, bins);
            
            for col=1:col_turb
                if sum(distri(:,col))~=0
                    perct1(:,col) = (distri(:,col)./sum(distri(:,col)))*100;
                else
                    perct1(:,col)=zeros(length(bins),1);
                end
            end
            perct(ii).perct1=perct1;
        end
        
    elseif strcmp(type_pdf,'CFAD_rmw')==1
        turb_out=rad;
        for ii=1:5
            distri=histc(rad(ii).turb, bins);
            
            for col=1:col_turb
                if sum(distri(:,col))~=0
                    perct1(:,col) = (distri(:,col)./sum(distri(:,col)))*100;
                else
                    perct1(:,col)=zeros(length(bins),1);
                end
            end
            perct(ii).perct1=perct1;
        end
        
        
        
    end
    
else
    [results]=rmw_scaling_interp(input_data);
    %u_interv=find(results(1).xaxis >= 0.5 & results(1).xaxis <0.75);
    %delta_r=length(u_interv);
    h1=length(results(1).zaxis);
    z_axis=results(1).zaxis;
    param_scaled=results(1).param_scaled;
    turb_r1=[turb_r1;(param_scaled(11:15,:,1:h1))];
    turb_r2=[turb_r2;(param_scaled(16:20,:,1:h1))];
    turb_r3=[turb_r3;(param_scaled(21:25,:,1:h1))];
    turb_r4=[turb_r4;(param_scaled(26:30,:,1:h1))];
    
    turb_r5=[turb_r5;(param_scaled(31:length(results(1).xaxis),:,1:h1))];
    [li1,col1, profond1]=size(turb_r1);
    turb_r1=reshape(turb_r1,li1*col1,profond1);
    turb_r2=reshape(turb_r2,li1*col1,profond1);
    turb_r3=reshape(turb_r3,li1*col1,profond1);
    turb_r4=reshape(turb_r4,li1*col1,profond1);
    [li1,col1, profond1]=size(turb_r5);
    turb_r5=reshape(turb_r5,li1*col1,profond1);
    rad(1).turb=turb_r1;
    rad(2).turb=turb_r2;
    rad(3).turb=turb_r3;
    rad(4).turb=turb_r4;
    rad(5).turb=turb_r5;
    turb_out=rad;
    [li_turb,col_turb]=size(turb_r1);
    for ii=1:5
        
        distri=histc(rad(ii).turb, bins);
        
        for col=1:col_turb
            if sum(distri(:,col))~=0
                perct1(:,col) = (distri(:,col)./sum(distri(:,col)))*100;
            else
                perct1(:,col)=zeros(length(bins),1);
            end
        end
        perct(ii).perct1=perct1;
    end
    
end