%% Search files for extra bb's
clc
clear all
close all
nficheiros = 0;
nfile_inicial = 0;
for i=0:1190
    
    nfile = nfile_inicial + i*5;
    Fusion_Algorithm_infimagereset_1p3_file_txt=sprintf('/media/Novo volume/bags_tese_results/bag_2_sensor_fusion_10image_reset_txts/%d.txt',nfile);
    fileID_Fusion_infimagereset_1p3_Algorithm = fopen(Fusion_Algorithm_infimagereset_1p3_file_txt, 'r');
    A_Fusion_infimagereset_1p3_Algorithm = fscanf(fileID_Fusion_infimagereset_1p3_Algorithm,'%f');
    
    bbs_reshape_fusion_infimage_1p3 = reshape(A_Fusion_infimagereset_1p3_Algorithm,[5 size(A_Fusion_infimagereset_1p3_Algorithm,1)/5])';
    bbs_reshape_fusion_infimage_1p3_1 = bbs_reshape_fusion_infimage_1p3;
    if (A_Fusion_infimagereset_1p3_Algorithm(1) ~= 0 && A_Fusion_infimagereset_1p3_Algorithm(2) ~= 0)
        
        ola1 = [];
        ola1 = zeros(1,size(bbs_reshape_fusion_infimage_1p3,1));
        for qwer=0:(size(bbs_reshape_fusion_infimage_1p3,1)-1)
            ola3 = bbs_reshape_fusion_infimage_1p3(qwer+1, 1) + bbs_reshape_fusion_infimage_1p3(qwer+1, 3);
            if (bbs_reshape_fusion_infimage_1p3(qwer+1, 1) > 1250 || ola3 <= 50)
                ola1(qwer+1) = 1;
            end
        end
        for qwert=(size(bbs_reshape_fusion_infimage_1p3,1)-1):-1:0
            if (ola1(qwert+1) == 1)
                bbs_reshape_fusion_infimage_1p3(qwert+1,:) = [];
            end
            nficheiros=nficheiros+1;
        end
        
        if(size(bbs_reshape_fusion_infimage_1p3,1)==0)
            bbs_reshape_fusion_infimage_1p3= [0, 0, 0, 0, 0.01430226];
        end
        
    end
        
    
    
    fclose(fileID_Fusion_infimagereset_1p3_Algorithm);
    
    Fusion_Algorithm_infimagereset_1p3_file_txt_1=sprintf('/media/Novo volume/bags_tese_results/bag_2_sensor_fusion_10image_reset_txts_1/%d.txt',nfile);
    fileID_Fusion_infimagereset_1p3_Algorithm_1 = fopen(Fusion_Algorithm_infimagereset_1p3_file_txt_1, 'w');
    
    for qwer=0:(size(bbs_reshape_fusion_infimage_1p3,1)-1)
        fprintf(fileID_Fusion_infimagereset_1p3_Algorithm_1,'%4d   %4d   %4d   %4f  %2.6f\n', bbs_reshape_fusion_infimage_1p3(qwer+1, :));
    end
    
    fclose(fileID_Fusion_infimagereset_1p3_Algorithm_1);
end