function get_hxt_pos, times, get_sxt=get_sxt, get_goes=get_goes, $
		helio=helio, sxt_struct=sxt_struct, status=status, $
		nouser=nouser, $
		qstop=qstop
;
;+
;NAME:
;	get_hxt_pos
;PURPOSE:
;	To get the HXT flare position address.  The options are
;		1. To read the $DIR_HXT_CAL/hxt_flare_pos.txt file to
;		   see if the time is in that list.
;		2. Use the GOES heliocentric location to determine
;		   the address
;		3. Use an SXT image index to define the address
;		4. Pass in heliocentric coordinates and convert them
;		5. Ask for user to specify HXT address directly
;	The default is to check in the order shown here until matches
;	are found.
;SAMPLE CALLING SEQUENCE:
;	hxt_pos = get_hxt_pos(times)
;	hxt_pos = get_hxt_pos('20-dec-92 3:32', helio='N32W23')
;	hxt_pos = get_hxt_pos(sxt_struct=sxt_struct)
;	hxt_pos = get_hxt_pos(times, /get_sxt)
;	hxt_pos = get_hxt_pos(times, /get_goes)
;OPTIONAL INPUTS:
;	times	- The times that the HXT address is wanted.
;OPTIONAL KEYWORD INPUTS:
;	get_sxt	- If set, then read the SXT observing log, find the PFI
;		  with the closest time, and convert from SXT coordinates
;		  to HXT coordinates.
;	get_goes - If set, then read the GOES event log and find the 
;		  heliocentric coordinates of the flare event.  Convert to
;		  HXT address
;	nouser	- If set, then do not ask the user for coordinates
;	helio	- You can pass a heliocentric coordinate and date, and it
;		  will derive the HXT address
;	sxt_struct - You can pass an SXT roadmap, index, or observing log
;		     entry and it will calculate the HXT address from it.
;OPTIONAL KEYWORD OUTPUT:
;	status	- The status of finding the hxt address
;			-1: did not make a match
;			1: found it in the HXT flare list
;			2: found from an SXT image
;			3: found from the GOES event
;			4: found from a heliocentric coordinate which was
;			   passed in.
;			5: user manually entered the value
;HISTORY:
;	Written 20-Dec-93 by M.Morrison
;-
;
if (keyword_set(sxt_struct)) then begin
    hxt = gt_center(sxt_struct, /hxt)
    status = bytarr(n_elements(hxt)/2) + 2	;sxt found it
    return, hxt
end
;
if (keyword_set(helio)) then begin
    sxt = conv_h2p(helio, times)
    hxt = conv_p2hxt(sxt)
    status = bytarr(n_elements(hxt)/2) + 4
    return, hxt
end
;
if (n_elements(times) eq 0) then begin
    print, 'GET_HXT_POS: No times passed in.  Returning...'
    status = -1
    return, 0
end
;
times0 = anytim2ints(times)
n = n_elements(times0)
status = intarr(n) - 1
out = fltarr(2, n)
;
qtry_list = 1
qtry_sxt  = 1
qtry_goes = 1
qtry_user = 1
if (keyword_set(get_sxt)) then begin
    qtry_list = 0
    qtry_goes = 0
end
if (keyword_set(get_goes)) then begin
    qtry_list = 0
    qtry_sxt  = 0
end
if (keyword_set(nouser)) then qtry_user = 0
;
;------------------------------ Check the HXT flare list file
;
if (qtry_list) then begin
    mat = hxt_flare_pos()
    for i=0,n-1 do begin
	x = int2secarr(mat, times0(i))/60./60.	;time off in hours
	minv = min(abs(x), imin)
	if (minv lt 24) then begin
	    out(0,i) = mat(imin).x0
	    out(1,i) = mat(imin).y0
	    status(i) = 1
	end
    end
end
;
;------------------------------ Now check GOES location 
;
ss = where(status eq -1, n)
if (qtry_goes and (n ne 0)) then begin
    for j=0,n-1 do begin
	i = ss(j)
	sttim = anytim2ints(times0(i), off=-60*60.)
	entim = anytim2ints(times0(i), off=60*60)
	rd_gev, sttim, entim, gev, status=status0
	if (status0 eq 0) then begin		;found some PFI data
	    x = int2secarr(gev, times0(i))/60./60.		;time off in hours
	    minv = min(abs(x), imin)
	    if (minv lt 1) then begin	;within an hour of the flare
		sxt = conv_h2p(gev(imin).location, gev(imin))
		hxt = conv_p2hxt(sxt)
		out(*,i) = hxt
		status(i) = 3
	    end
	end
    end
end
;		
;------------------------------ Now check SXT PFI location from observing log
;
ss = where(status eq -1, n)
if (qtry_sxt and (n ne 0)) then begin
    for j=0,n-1 do begin
	i = ss(j)
	sttim = anytim2ints(times0(i), off=-5*60.)
	entim = anytim2ints(times0(i), off=5*60)
	rd_obs, sttim, entim, bcs, sxtf, sxtp, /sxtp
	if (keyword_set(qstop)) then stop
	if (get_nbytes(sxtp) gt 10) then begin		;found some PFI data
	    x = int2secarr(sxtp, times0(i))/60./60.		;time off in hours
	    minv = min(abs(x), imin)
	    hxt = gt_center(sxtp(imin), /hxt)
	    out(*,i) = hxt
	    status(i) = 2
	end
    end
end
;
;------------------------------ Now ask the user
;
ss = where(status eq -1, n)
if (qtry_user and (n ne 0)) then begin
    print, 'Cannot find the HXT coordinates of the flare'
    print, 'Options are      0 = exit
    print, '                 1 = enter HXT addresses
    print, '                 2 = enter heliocentric coordinates'
    read, 'Enter your option', code
    ;
    x0 = 0.0
    y0 = 0.0
    if (code eq 1) or (code eq 2) then begin
	for j=0,n-1 do begin
	    i = ss(j)
	    print, 'Enter the coordinates for ', fmt_tim(times0(i))
	    if (code eq 1) then begin
		input, '    Enter HXT X address', x0, x0
		input, '    Enter HXT Y address', y0, y0
		out(0,i) = x0
		out(1,i) = y0
		status(i) = 5
	    end
	    if (code eq 2) then begin
		input, '    Enter N/S heliocentric coord (S is neg)', x0, x0
		input, '    Enter E/W heliocentric coord (E is neg)', y0, y0
		out(0,i) = x0
		out(1,i) = y0
		status(i) = 4
	    end
	end
    end
end
;
return, out
end

