function rd_dt_genx, file_filter, type=type, files=files, summary=summary, infil=infil
;+
;NAME:
;	rd_dt_genx
;PURPOSE:
;	To read the GENX data structures created during the MDI detune analysis
;SAMPLE CALLING SEQUENCE:
;	struct = rd_dt_genx()
;	struct = rd_dt_genx('960205*', type='obs')
;	struct = rd_dt_genx(file_filter, type=type, files=files)
;OPTIONAL INPUT:
;	file_filter - wildcard filter on which files to display
;OPTIONAL KEYWORD INPUT:
;	type	- The type of files to list (CAL or OBS)
;OPTIONAL KEYWORD OUTPUT:
;	files	- The files selected and read
;HISTORY:
;	Written 13-Feb-96 by M.Morrison
;	22-Feb-96 (MDM) - Patched the filtering option
;	 4-Mar-96 (MDM) - Added summary option
;			- Added infil option
;	 1-Apr-96 (MDM) - Changed filtering option to look for DT instead of DT20
;	 8-Apr-96 (MDM) - Corrected 1-Apr fix which broke TYPE option capability
;	 6-May-96 (MDM) - Added "/data14/detunes" to the list of directories to search
;	21-Jul-97 (MDM) - Added window creating because of IDL bug
;	27-Oct-97 (MDM) - Modified to use XMENU_SEL
;-
;
if (!d.window eq -1) then begin
    window
    wdelete
end
;
qsum = keyword_set(summary)
;
if (keyword_set(infil)) then begin
    files = infil
end else begin
    dirs = file_list(['/data13/data_eof/sci160k','/data14/data_eof/sci160k'], '9*', /cd, file=file)
    ndirs = n_elements(dirs)
    if (dirs(0) eq '') then ndirs = 0
    if (ndirs ne 0) then begin
        ss = sort(file)
        dirs = dirs(ss)
    end else begin
        dirs = ''
    end
    ;
    dirs = [dirs, '/data14/detunes']
    ;
    if (n_elements(file_filter) eq 0) then file_filter = '9*'
    if (strpos(file_filter, '*') eq -1) then file_filter = file_filter + '*'
    if (n_elements(type) ne 0) then file_filter = file_filter + 'DT*' + strupcase(type) + '*' $
			else file_filter = file_filter + 'DT*'

    ff = file_list(dirs,  file_filter)
    if (ff(0) eq '') then begin
        print, 'Cannot find any GENX files'
        return, 0
    end
    ;;ifiles = wmenu_sel(ff)
    ifiles = xmenu_sel(ff)
    if (ifiles(0) eq -1) then return, 0
    ;
    files = ff(ifiles)
end
nfile = n_elements(files)
;
for i=0,nfile-1 do begin
    restgen, out0, file=files(i)
    if (qsum) then begin
	nx = n_elements(out0.xtune)
	if (i eq 0) then out00 = {label: ' ', when: ' ', version: ' ', xtune: fltarr(nx), ftfit: {rd_dt_genx_struct2, a:fltarr(9)}}
	for j=0,2 do out00.(j) = out0.(j)	;copy label, when, version
	out00.xtune = out0.xtune
	for j=0,8 do out00.ftfit.a(j) = total( out0.ftfit.a(j) ) / n_elements( out0.ftfit.a(j) )
	out0 = out00
    end
    ;
    if (nfile eq 1) then begin
	out = temporary(out0)
    end else begin
	if (i eq 0) then out = replicate(out0, nfile)
	out(i) = str_copy_tags(out(i), out0)
    end
end
;
return, out
end