function DIF_index = readDIFpath( DIF_path, bldg_struct )

DIF_index = struct([]);

if ~exist('DIF_path') || isempty(DIF_path)
    % Load pathname for DIF file used in last analysis, if available, otherwise create empty string:
    if exist('tmp_DIF_path.mat','file'), load('tmp_DIF_path'); end
    if ~exist('DIF_path','var') || ~isstr(DIF_path), DIF_path = ''; end
    tmp_path = uigetdir(DIF_path,'Select folder for storing DIF files');
    if any(tmp_path~=0)
        DIF_path = tmp_path;
        save('tmp_DIF_path','DIF_path');
    else
        err = errordlg('DIF folder selection cancelled by user.', 'Error selecting DIF Folder');
        uiwait(err); return;
    end
end

force_units = bldg_struct.force_units;
length_units = bldg_struct.length_units;
terrain = bldg_struct.terrain;
frame_coords = bldg_struct.frame_coords;
d0 = bldg_struct.d0;
resp_names = bldg_struct.resp_names;
resp_units = bldg_struct.resp_units;
n_r = length(resp_names);

tol = 10^-3;
dir_listing = dir(DIF_path);
dir_files = dir_listing(find([dir_listing(:).isdir]==0)); % eliminate directories from list
DIF_count = 0; % initialize index for counting the number of DIF results files opened
interpDIF_count = 0; % initialize index for counting the number of interpolated DIF files opened
err_count = 0; % initialize index for counting the number of files that give errors
err_file_list{1} = 'Errors were encountered in reading the following files; these files cannot be used in their present form:';
for i = 1:length(dir_files)
    filename = dir_files(i).name; 
    if length(filename)<7
        continue;
    elseif ~strcmp(filename(1:3),'DIF')
        continue;
    elseif ~strcmp(lower(filename(end-3:end)),'.csv')
        continue;
    end
    DIF_struct = readDIFfile( fullfile(DIF_path,filename), 'index' );
    if isfield( DIF_struct, 'error')
        err_count = err_count+1;
        err_file_list{err_count+1} = filename;
        continue; % error in reading bldg file
    elseif ~strcmp(force_units,DIF_struct.force_units)
        continue;
    elseif ~strcmp(length_units,DIF_struct.length_units)
        continue;
%    elseif ~strcmp(terrain,DIF_struct.terrain)
%        continue;
    elseif any(size(frame_coords)~=size(DIF_struct.frame_coords)) || max(max(abs(frame_coords-DIF_struct.frame_coords)))>tol
        continue;
    elseif max(max(abs(d0-DIF_struct.d0)))>tol
        continue;
    end
    DIF_count = DIF_count+1;
    DIF_index(DIF_count).filename = filename;
    DIF_index(DIF_count).DIF_struct = DIF_struct;
    if strcmp(DIF_struct.terrain,'Open_Country')
        if size(DIF_struct.d,1)==1
            DIF_index(DIF_count).panel = 1;
        else
            DIF_index(DIF_count).panel = 3;
        end
    else
        if size(DIF_struct.d,1)==1
            DIF_index(DIF_count).panel = 2;
        else
            DIF_index(DIF_count).panel = 4;
        end
    end
end

err_file_list{length(err_file_list)+1} = ['The selected folder contains ' num2str(DIF_count) ...
    ' valid files matching the selected building dimensions.'];

if err_count
    err_dlg = errordlg(err_file_list,'Error reading DIF files');
    uiwait(err_dlg); return;
end


