function gtab_file, itab0, ientry0, dir=dir, table=table, itab=itab, ientry=ientry, fid=fid, headline=headline
;
;+
;NAME:
;       gtab_file
;PURPOSE:
;       Determine what file is needed and read the SXT seqeuence table.  It 
;	also returns the entry table that is used.
;CALLING SEQUENCE:
;       print, gtab_pfi(150)
;       print, gtab_pfi(roadmap(0))
;INPUT:
;       itab0   - Table number to display
;                       (or)
;                 A structure which has the sequence table and entry table
;                 that is used for a particular image.  The index, roadmap
;                 or observing log entries can be used.
;		  If an array is passed in, it only looks at the first structure.
;			(or)
;		  A string time representation
;       ientry0 - Entry table to display.  If a structure is passed, this
;                 value is ignored.
;OPTIONAL INPUT:
;	dir	- The directory where the SXT tables are stored.  If
;		  not specified, $DIR_SXT_TABLES is used
;       fid	- The user can specify a specific table by passing the fileid
;OUTPUT:
;       returns - The file name of the table needed
;	table	- The matrix containing the complete SXT table dump
;	itab	- The table number selected, since the information
;		  might be inside the structure passed.
;	ientry	- The entry table used, since it might be inside the
;		  structure passed.
;	headline- A 3 element string array with the header line for the table
;HISTORY:
;       Written Sep-91 by M.Morrison
;	21-Nov-91 (MDM) - Added "fid" option
;	 6-Dec-91 (MDM) - Changed so that when the structure is passed,
;			  the "fid" option is used (generate a time string
;			  and do not rely on the sequence table number - 
;			  it was not reliable)
;	25-Mar-92 (MDM) - Added option of passing time as a string
;	 7-Jul-92 (MDM) - Added "headline"
;	28-Aug-92 (MDM) - Added /SEC switch to ex2fid - it was grabbing the
;			  incorrect table (rounding down to 0 sec)
;	 6-May-93 (MDM) - Modified to work with VMS (used CONCAT_DIR)
;	 4-Jan-94 (MDM) - Modified so that when converting the header 
;			  information to string type, to check that the
;			  ASCII value is less than 126.  Some garbage characters
;			  were hanging up the terminal when displaying them.
;-
;
if (not keyword_set(dir)) then dir = '$DIR_SXT_TABLES'
;
if (n_elements(itab0) ne 0) then begin
    siz = size(itab0)
    typ = siz(siz(0)+1)
    case typ of
	7: begin		;string - time
		itab = 0
		ientry = 0
		fid = ex2fid( anytim2ex( itab0 ), /sec )
	   end
	8: begin		;structure - index or roadmap
		itab = gt_seq_tab(itab0(0))		;Removed on 6-Dec and replaced with FID option - more acurate
		ientry = gt_entry(itab0(0))
		int2ex, gt_time(itab0(0)), gt_day(itab0(0)), tarr
		fid = string(tarr(6), tarr(5), tarr(4), '.', tarr(0:2), FORMAT = '(3i2.2,a,3i2.2)')
	    end
	else: begin
		itab = itab0
		ientry = 0
	    end
    end
    if (n_elements(ientry0) ne 0) then ientry = ientry0		;do not need entry number for common block dumps
    ;
    if (n_elements(itab) ne 1) then begin
	print, 'Input was an array - Only looking at first element', string(7b)
	itab = itab(0)
	ientry = ientry(0)
    end
end
;
itab = get_seq_tab(itab, fileid=fileid, fid=fid)		;itab is overwritten if the FID option is used
infil = concat_dir(dir, 'btb' + fileid)
;
if (keyword_set(fid) and (n_elements(itab) eq 0)) then itab = dummy
if (keyword_set(fid) and (n_elements(ientry) eq 0)) then ientry = 0
if (n_elements(ientry0) ne 0) then ientry = ientry0
;
headline = strarr(3)
;
ff = findfile(infil)
if (ff(0) eq '') then begin
    print, 'GTAB_FILE: Cannot find file: ', infil
    return, ''
end
;
table = bytarr(64*64)
openr, lun, infil, /get_lun
readu, lun, table
free_lun, lun
;
headline(0) = '****** Table # ' + strtrim(itab,2) + ' (File: ' + infil + ')'
headline(1) = '****** '+ string(table(2816:2879)<126B)
headline(2) = '****** '+ string(table(2880:2943)<126B)
;
return, infil
end
