function [index_final] = find_index(fileList,time_tr)
    % GATHERARCHIVE Extracts a variable with a given name from a list of .h5 files
    %
    % Inputs:
    %   - fileList: A cell array of strings representing the file names or paths
    %               of the .h5 files to extract the variable from
    %   - variableName: A string representing the name of the variable to extract
    %
    % Output:
    %   - varData: A cell array of matrices representing the values of the
    %              variable in each of the .h5 files

    % Initialize the output variable
    % Loop through ecach file in the list

    index_final = cell(length(fileList), 1);

    for i = 1:length(fileList)
        drop_file = fileList{i};
        drop_times = time_tr{i};
        [path, filename, ext] = fileparts(drop_file);
        %Extract matching HSRL indices to profile
        coin_path = strrep(path, '/PBLH','/profiles/Coincidence_idx_files/');
        coin_file = strcat(filename,'_P3B_HSRL_idx.mat');
        full_path_coin = strcat(coin_path,coin_file);                
        coincident = load(full_path_coin);
        HSRL_times_array = coincident.P3B_HSRL_idx(:,5);
        %Find indices in corresponding .h5 file 
        h5_path = strrep (path, '/PBLH', '/Archive_ml/');
        h5_file = strcat(filename, '.h5');
        full_path_h5 = strcat(h5_path,h5_file);
        gps_time = h5read(full_path_h5, '/ApplanixIMU/gps_time');
        %indices = zeros(size(HSRL_times_array));
        index = cell(length(HSRL_times_array),1);
        for j = 1:length(HSRL_times_array)
            HSRL_times = HSRL_times_array{j};
            if ~isempty(HSRL_times)
                indices = zeros(length(HSRL_times),1); 
                for k = 1:length(HSRL_times)
                    [~,idx] = min(abs(gps_time - HSRL_times(k)));
                    indices(k) = idx;
                end
                index{j} = indices;
            end 
        end
        index_final{i} = index;
             
         
        
    end 
      
end






