PRO gui_closeFile, top

;;-----------------------------------------------------------------------------
;; PURPOSE:
;;	Closes the open file that is being calibrated
;;
;; CALLING SEQUENCE:
;;	gui_closeFile, top, opts
;;
;; REQUIRED INPUTS:
;;	top - The top widget of the application
;;
;; OUTPUTS:
;;
;; OPTIONAL INPUT KEYWORDS:
;;
;; EXAMPLE:
;;      IDL> gui_closeFile, top
;;
;; PROCEDURES USED (i.e. called directly!):
;;
;; MODIFICATION HISTORY:
;;   2004-07-30  M. Desnoyer    Created
;;
;;-----------------------------------------------------------------------------

;; if top is invalid, just close
IF NOT widget_info(top, /valid_id) THEN RETURN

;; Get the current options
widget_control, top, get_uvalue=opts
preview = opts.previewWnd
calWnd = opts.calWnd

;; Make sure a file is actually open
IF opts.infn EQ '' THEN RETURN

;; Update the opts structure
opts.infn = ''
opts.det = -1
opts.previewWnd = 0
opts.calWnd = [0,0]
opts.doBatch=0
widget_control, top, set_uvalue=opts

;; Remove the fits header viewer
hdrview = widget_info(top, find_by_uname='hdrview')
IF hdrview NE 0 THEN widget_control, hdrview, /destroy

;; Remove the image preview window
IF preview NE 0 THEN widget_control, preview, /destroy

;; Remove the calibrated image window
IF calWnd[0] NE 0 THEN widget_control, calWnd[0], /destroy
IF calWnd[1] NE 0 THEN widget_control, calWnd[1], /destroy

gui_updateoptpane, top
gui_updatemodlist, top

RETURN

END