;+
; NAME        : EIT_SUB_SC_PIXEL
;
; PURPOSE     : Read EIT S/C pixel file return latest X and Y S/C pix, w/date
;
; CATEGORY    :
;
; EXPLANATION : 
;
; SYNTAX      : 
;
; EXAMPLES    : none
; 
; CALLED BY   :
;
; CALLS TO    : none
;
; ARGUMENTS   :	none
;
; KEYWORDS    : OLD_POINT 	if set, use pre recentering (sun more north) coords
;
; OUTPUTS     : none
;
; COMMON      : none
;
; RESTRICTIONS: none
;
; SIDE EFFECTS: none
;
; PROJECT     : SOHO - EIT
;
; HISTORY     : V1,  Elaine Einfalt (HSTX)
;		1998 Jan - added old_point keyword for doing coords
;			   on pre-center images.
;		2004-Jun-02 - einfalt - added getenv call to get stat_dir
;					modified to read last line smarter
;					and other mac related conversions
; CONTACT     : eit@xanado.nascom.nasa.gov
;-

function EIT_SUB_SC_PIXEL, xcen, ycen, date, old_point=old_point

 ok = 1					; haven't put in error handling
 if strupcase(!version.os) eq 'VMS' then delim = ':' else delim = '/'

 if not(keyword_set(old_point)) then begin
    stat_dir = getenv('EIT_SUB')

    if stat_dir ne '' then begin	; there is a environment for the file

       sc_file = RD_TFILE(stat_dir +delim+ 'EIT_SC_PIXEL.DAT') 

    endif else begin
       print, '   '       
       print, '    NOTE:
       print, '          There was no environment set for EIT_SUB '
       print, '          so the file EIT_SC_PIXEL.DAT can''t be located.'     
       print, '          (a possible solution might be to define'
       print, '          setenv EIT_SUB $SSWDB/soho/eit/planning/subfield)'
       print, '   '
       print, '     Code is defaulting to center pixel pointing of (505,516).'
       print, '   '       
       sc_file = '505, 516, 2000/07/24 19:48:24'

    endelse


 endif else begin 
    sc_file = '507, 437, 1996/01/02 13:15:00'
    print,'%EIT_SUB_SC_PIXEL, Using pre-center pointing.'
 endelse

 last_line = n_elements(sc_file)        ; could have blank lines at end of file
 repeat begin 				; just back up the strarr until get real
   last_line = last_line - 1
   stuff = str_sep(sc_file(last_line),',')
 endrep until (stuff(0) ne '')

 xcen = fix(stuff(0))				; x pixel num from left, 0-1024
 ycen = fix(stuff(1))				; y pixel num from bottom,  0-1024
 data = stuff(2) 				; ECS format

return, ok
end
