pro lists2matrix, filenames, num_slots=num_slots, num_people=num_people, outfile=outfile
;+
;NAME:
;       lists2matrix
;PURPOSE:
;	This takes a list of files that have mailing list 'rosters', and it
;	then produces a chart showing which mailing lists each address
;	belong to.
;SAMPLE CALLING SEQUENCE:
;       lists2matrix, ['/usr2/majordom/lists/sxi_test', '/usr2/majordom/lists/trace_ops'], outfile='test.txt'
;PARAMETERS
;	An array containing the names of all address list files to be used.
;	'num_slots' is the maximum # of people per file, and 'num_people' is the
;	maximum # of people total.  They default to 150 and 500 respectively.
;	'outfile' is the file to print to; default is terminal.
;DETAILS:
;	Use data in /usr2/major*/lists
;
;	NOTE:  If one address is XXX@XXX.space.lockheed.com, and an address on a
;	different list is XXX@XXX, the program realizes that the two addresses
;	are identical.  The address will be listed the way it was first encountered.
;	
;	This also alphabetizes the entries, and it's not case sensitive.
;HISTORY:
;       Created 23-Oct-97 J.Abrehamson
;-

num_files = n_elements(filenames)

if n_elements(num_slots) EQ 0 then num_slots = 150
if n_elements(num_people) EQ 0 then num_people = 500
if n_elements(outfile) EQ 0 then begin
	lun = -1
endif else begin
	get_lun, lun
	openw, lun, outfile
endelse

file = REPLICATE(' ', num_files, num_slots)
num_names = INTARR(num_files)
cut_filename = STRARR(num_files)
longest_filelength = 0

for index = 0, num_files-1 do BEGIN
	num_names(index) = n_elements(rd_tfile(filenames(index)))
	file(index, 0:num_names(index)-1) = rd_tfile(filenames(index))
	cut_filename(index) = (STR_SEP(filenames(index), '/'))(n_elements(STR_SEP(filenames(index), '/'))-1)
	if (strlen(cut_filename(index)) GT longest_filelength) then begin
		longest_filelength = strlen(cut_filename(index))
	endif
endfor

names = {name: ' ', status:STRARR(num_files)}
names = REPLICATE(names, num_people)
names.status = '.'
names(0:num_names(0)-1).name = strlowcase(REFORM(file(0, 0:num_names(0)-1)))
last_nameindex = num_names(0) - 1


for index = 0, num_files - 1 do BEGIN
	for name_index = 0, num_names(index)-1 do BEGIN
		name_found = 0
		
		for check_index = 0, last_nameindex do BEGIN
			if ((names(check_index).name EQ strlowcase(file(index, name_index))) OR $
				(names(check_index).name EQ strlowcase(file(index, name_index))+'.space.lockheed.com') OR $
				(names(check_index).name+'.space.lockheed.com' EQ strlowcase(file(index, name_index)))) then BEGIN
					names(check_index).status(index) = 'X'
					name_found = 1			
			ENDIF 
		ENDFOR
		
		if (name_found EQ 0) then BEGIN
			last_nameindex = last_nameindex + 1
			names(last_nameindex).name = strlowcase(file(index, name_index))
			names(last_nameindex).status = '.'
			names(last_nameindex).status(index) = 'X'
		ENDIF
	ENDFOR	
ENDFOR

order = sort(strupcase(names(0:last_nameindex).name))
nameout = STRARR(num_files, longest_filelength)
nameout(*,*) = ' '
for index = 0, num_files - 1 do BEGIN
	offset = longest_filelength - strlen(cut_filename(index))
	for index2 = 0, (strlen(cut_filename(index))-1) do begin
		nameout(index, index2+offset) = STRMID(cut_filename(index), index2, 1)
	endfor 
endfor

format_string = '("                                              ",' + string(num_files) + '(A, "  "))'
for index = 0, longest_filelength-1 do begin
	printf, lun, FORMAT = format_string, nameout(*, index)
endfor

printf, lun, ''
printf, lun, ''
 
for index = 0, last_nameindex do BEGIN
	temp='                                             '
	STRPUT, temp, names(order(index)).name, 0
	format_string = '(A, " ", ' + string(num_files) + '(A, "  "))' 
	printf, lun, FORMAT = format_string, temp, names(order(index)).status
ENDFOR

if lun NE -1 then free_lun, lun
END

list = FILE_LIST('/usr2/majordom/lists', 'trace*')
break_file, list, dummy, dummy, dummy, extentions
lists2matrix, list(WHERE(extentions EQ '')), outfile='/usr2/majordom/lists/trace_chart.txt'

list = FILE_LIST('/usr2/majordom/lists', 'sxi*')
break_file, list, dummy, dummy, dummy, extentions
lists2matrix, list(WHERE(extentions EQ '')), outfile='/usr2/majordom/lists/sxi_chart.txt'

list = FILE_LIST('/usr2/majordom/lists', '*')
break_file, list, dummy, dummy, dummy, extentions
lists2matrix, list(WHERE(extentions EQ '')), outfile='/usr2/majordom/lists/all_chart.txt'
END