function ccd_sunc, comment=comment, update=update, history=history, $
	norange=norange
;
;+
;   Name: ccd_sunc
;
;   Purpose: maintain ccd sun center coordinate data file
;
;   Optional Keyword Parameters:
;	update - 2 element array containing new CCD SUNC coord ([EW,NS])
;	norange - bypasses range checks on update parameters 
;       comment - input or output depending on calling sequence below 
;       history - output array ALL coordinate entries (structure)
;
;   Calling Sequences:
;      Two major functions are provided
;
;      1 - Obtain most recent coordinates: 
;          coord=ccd_sunc([history=history])
;           function returns 2 element vector: [EW,NS] CCD coord SunC.
;           Optional output is vector of all entries - include
;             comments , entry dates, etc. 
;
;      2 - Update Sun Center coordinates: 
;	   coord=ccd_sunc(update=newcoord [,comment=comment])
;	     Will update the Coordinate file with new coordinates
;	     Optional comment can include reason for update (offpoint)
;	       (Name of updater and update time are included automatically in
;		entry so dont include in comment)
;
;   Method: uses generic file
;
;   History: slf, 15-April-1992
;	 5-Jun-93 (MDM) - Modified to only save the last updated value
;	18-Aug-93 (MDM) - Added "software" to authorized list
;
;   Restrictions: range check not implemented yet so be careful
;-
; Set range check?
on_error,2
; if it exists, read the current file contents
coordfile='$DIR_SXT_CALIBRATE/ccdsunc.genx'
file_found=file_exist(coordfile) 
if file_found then $
    restgen,file=coordfile, data , text=text

if n_elements(update) ne 0 then begin		; update coordinates
;  Verify current user is authorized 
   authorize=['freeland','acton','hudson','nitta','sxt','handy','sxt_co']
   authorize=[authorize,'mckenzie','lemen','slater','shirts','software']

   spawn,'whoami',whoami
   authchk=where(whoami(0) eq authorize,count)
   nowrite=count eq 0
   if nowrite then $
      message,'User ' + whoami(0) + ' not authorized to update file'

;     define file structure template
      recstr=make_str('{dummy, 	Coord:intarr(2),'	+	$
			       	'Who: "",'  		+	$
			 	'Time: "",' 	+	$
			 	'Comment:""}'		)
;     fill the structure
      if n_elements(comment) eq 0 then comment=''
      recstr.coord=update
      recstr.who=whoami(0)
      recstr.time=fmt_tim(syst2ex())
      recstr.comment=comment

;;      if file_found then begin			; concatente structures
;;	   template=data(0)
;;	   newstr=str_copy(template,recstr)
;;	   data=[data,newstr]
;;      endif else data=recstr			; brand new file
      data = recstr			;MDM - just save the latest value

      savegen,file=coordfile,data, /replace, $
	   text='CCD Sun Center Coordinate History File' 
endif else if not file_found then $
   message,'File: ' + coordfile + ' does not exist' 

history=data				; set output parameter
retval=data(n_elements(data)-1).coord   ; define return parameter 
return,retval
end
