% Loads display parameters from a display index file idx_(kernel).txt into a display index structure

function display_index = load_display_index(data_path, kernel);

    filename = [data_path 'idx' kernel '.txt'];
    fid = fopen(filename,'rb');

    line = fgetl(fid);
    display_index.source_directory = line;
    
    line = fgetl(fid);
    display_index.source_filename_kernel = line;

    line = fgetl(fid);
    display_index.processed_data_directory = line;

    line = fgetl(fid);
    display_index.processed_data_kernel = line;
    
% Output file plot selection switches

    line = fgetl(fid);
   
    for i=1:8
        [value line] = strtok(line);
        display_index.selection_switch(i) = str2num(value);
    end

% Input file plot selection switches (skip over)

    line = fgetl(fid);

% Full state dimensions

    line = fgetl(fid);

    display_index.num_full_state_dimension_types = 5;
   
    for i=1:display_index.num_full_state_dimension_types
        [value line] = strtok(line);
        display_index.full_state_dimensions(i) = str2num(value);
    end
   
% Selected state dimensions

    line = fgetl(fid);
  
    for i=1:display_index.num_full_state_dimension_types
        [value line] = strtok(line);
        display_index.selected_state_dimensions(i) = str2num(value);
    end

% State selection index

    display_index.NTOT = sum(display_index.full_state_dimensions);
    display_index.N = sum(display_index.selected_state_dimensions);
    
    num_lines_to_read = floor(display_index.N/10);
    if mod(display_index.N,10) ~= 0
        num_lines_to_read = num_lines_to_read + 1;
    end
    
    count = 0;
    for j=1:num_lines_to_read    
        line = fgetl(fid);
      
        while length(line) > 0
            count = count + 1;    
            [value line] = strtok(line);
            display_index.selected_states(count) = str2num(value);
            line = deblank(line);
        end
    end

% Compare given num of selected states with number of selected states read in

    if display_index.N ~= count
        disp('Number of States in State Selection Index not equal to given N')
    end

% Full measurement dimensions

    line = fgetl(fid);

    [value line] = strtok(line);
    display_index.MDIM = str2num(value);

% Selected measurement dimensions

    [value line] = strtok(line);
    display_index.M = str2num(value);

% Measurement selection index

    num_lines_to_read = floor(display_index.M/10);
    if mod(display_index.M,10) ~= 0
        num_lines_to_read = num_lines_to_read + 1;
    end

    count = 0;
    for j=1:num_lines_to_read    
        line = fgetl(fid);
      
        while length(line) > 0
            count = count + 1;    
            [value line] = strtok(line);
            display_index.selected_measurements(count) = str2num(value);
            line = deblank(line);
        end
    end

% Compare given num of selected states with number of selected states read in

    if display_index.M ~= count
        disp('Number of measurements in Measurements Selection Index not equal to given M')
    end

   
fclose(fid);

