PRO FXBCLOSE, UNIT, ERRMSG=ERRMSG ;+ ; NAME: ; FXBCLOSE ; Purpose : ; Close a FITS binary table extension opened for read. ; Explanation : ; Closes a FITS binary table extension that had been opened for read by ; FXBOPEN. ; Use : ; FXBCLOSE, UNIT ; Inputs : ; UNIT = Logical unit number of the file. ; Opt. Inputs : ; None. ; Outputs : ; None. ; Opt. Outputs: ; None. ; Keywords : ; ERRMSG = If defined and passed, then any error messages will be ; returned to the user in this parameter rather than ; depending on the MESSAGE routine in IDL. If no errors are ; encountered, then a null string is returned. In order to ; use this feature, ERRMSG must be defined first, e.g. ; ; ERRMSG = '' ; FXBCLOSE, ERRMSG=ERRMSG, ... ; IF ERRMSG NE '' THEN ... ; ; Calls : ; None. ; Common : ; Uses common block FXBINTABLE--see "fxbintable.pro" for more ; information. ; Restrictions: ; The file must have been opened with FXBOPEN. ; Side effects: ; None. ; Category : ; Data Handling, I/O, FITS, Generic. ; Prev. Hist. : ; W. Thompson, Feb. 1992. ; Written : ; William Thompson, GSFC, February 1992. ; Modified : ; Version 1, William Thompson, GSFC, 12 April 1993. ; Incorporated into CDS library. ; Version 2, William Thompson, GSFC, 21 June 1994 ; Added ERRMSG keyword. ; Version 3, William Thompson, GSFC, 23 June 1994 ; Modified so that ERRMSG is not touched if not defined. ; Version : ; Version 3, 23 June 1994 ; Converted to IDL V5.0 W. Landsman September 1997 ;- ; @fxbintable ON_ERROR, 2 ; ; Check the number of parameters. ; IF N_PARAMS() NE 1 THEN BEGIN MESSAGE = 'Syntax: FXBCLOSE, UNIT' IF N_ELEMENTS(ERRMSG) NE 0 THEN BEGIN ERRMSG = MESSAGE RETURN END ELSE MESSAGE, MESSAGE ENDIF ; ; Find the index of the file. ; ILUN = WHERE(LUN EQ UNIT,NLUN) ILUN = ILUN[0] IF NLUN EQ 0 THEN BEGIN MESSAGE = 'Unit ' + STRTRIM(UNIT,2) + ' not opened properly' IF N_ELEMENTS(ERRMSG) NE 0 THEN BEGIN ERRMSG = MESSAGE RETURN END ELSE MESSAGE, MESSAGE ENDIF ; ; Make sure the file was opened for read access. ; IF STATE[ILUN] NE 1 THEN BEGIN MESSAGE = 'Unit ' + STRTRIM(UNIT,2) + $ ' not opened for read access' IF N_ELEMENTS(ERRMSG) NE 0 THEN BEGIN ERRMSG = MESSAGE RETURN END ELSE MESSAGE, MESSAGE ENDIF ; ; Close the file, and mark it as closed. ; FREE_LUN,UNIT STATE[ILUN] = 0 ; IF N_ELEMENTS(ERRMSG) NE 0 THEN ERRMSG = '' RETURN END