	FUNCTION DEL_DETAIL, DATE_OBS, ERRMSG=ERRMSG
;+
; Project     :	SOHO - CDS
;
; Name        :	DEL_DETAIL()
;
; Purpose     :	Deletes a CDS detailed science plan record from the database
;
; Explanation :	This routine removes an entry from the CDS detailed science
;		plan database.
;
; Use         :	DEL_DETAIL, DATE_OBS
;
; Inputs      :	DATE_OBS   = A double precision number giving the date/time
;			     value corresponding to the entry in the
;			     sci_details database to be deleted.
;
; Opt. Inputs :	None.
;
; Outputs     :	The result of the function is a logical value representing
;		whether or not the operation was successful, where 1 is
;		successful and 0 is unsuccessful.
;
; 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 = ''
;                       Result = DEL_DETAIL( ERRMSG=ERRMSG, ... )
;                       IF ERRMSG NE '' THEN ...
;
;
; Calls       :	DATATYPE, DBOPEN, DBFIND, DBEXT, DBCLOSE, TRIM
;
; Common      :	None.
;
; Restrictions:	Only this routine or ADD_DETAIL can be used to add or delete
;		detailed science plan entries to or from the database.
;		Modifying the database by hand could corrupt its integrity.
;
; Side effects:	Marks records as deleted.  PRG_DETAIL must be called to really
;		delete the records.
;
; Category    :	Planning, Databases.
;
; Prev. Hist. :	None.
;
; Written     :	William Thompson, GSFC, 26 July 1994
;
; Modified    :	Version 1, William Thompson, GSFC, 3 August 1994
;               Version 2, Liyun Wang, GSFC/ARC, September 22, 1994
;                  Added the keyword ERRMSG.
;		Version 3, William Thompson, GSFC, 13 February 1995
;			Changed way pointing is handled
;		Version 4, William Thompson, GSFC, 8 May 1995
;			Modified to pay attention to DELETED field in database
;		Version 5, William Thompson, GSFC, 10 May 1995
;			Fixed bug introduced in version 4
;
; Version     :	Version 5, 10 May 1995
;-
;
	ON_ERROR, 2
;
;  Initialize RESULT to represent non-success.  If the routine is successful,
;  this value will be updated below.
;
	RESULT = 0
;
;  Check the number of parameters.
;
        IF N_PARAMS() NE 1 THEN BEGIN
           MESSAGE = 'Syntax:  DEL_DETAIL, DATE_OBS'
	   GOTO, HANDLE_ERROR
        ENDIF
;
;  Make sure that the user has privilege to write into the database.
;
	IF !PRIV LT 2 THEN BEGIN $
           MESSAGE = '!PRIV must be 2 or greater to write into the database'
           GOTO, HANDLE_ERROR
	ENDIF
;
;  Check the input parameter.
;
	IF DATATYPE(DATE_OBS,1) NE 'Double' THEN BEGIN
           MESSAGE = 'DATE_OBS must be double precision'
           GOTO, HANDLE_ERROR
	END ELSE IF N_ELEMENTS(DATE_OBS) NE 1 THEN BEGIN
           MESSAGE = 'DATE_OBS must be a scalar'
           GOTO, HANDLE_ERROR
	ENDIF
;
;  Open the database for update.
;
	DBOPEN, 'sci_details', 1
;
;  Search for the entry with the start date/time given by the user.
;
	ENTRIES = DBFIND('DATE_OBS=' + TRIM(DATE_OBS,'(F15.3)') +	$
		',DELETED=N', /SILENT)
;
;  If no entries were found, then return immediately.
;
	IF !ERR EQ 0 THEN BEGIN
           MESSAGE = 'No such entry in the database'
           GOTO, HANDLE_ERROR
	ENDIF
;
;  Delete the entry.
;
	DBUPDATE, ENTRIES, 'deleted', 'Y'
;
;  Open the pointing database and delete any associated entries.
;
	DBOPEN, 'point_details', 1
	ENTRIES = DBFIND('DATE_OBS=' + TRIM(DATE_OBS,'(F15.3)') +	$
		',DELETED=N', /SILENT)
	IF !ERR GT 0 THEN DBUPDATE, ENTRIES, 'deleted',		$
		REPLICATE('Y',N_ELEMENTS(ENTRIES))
;
;  Signal success.
;
	RESULT = 1
	GOTO, FINISH
;
;  Error handling point.
;
HANDLE_ERROR:
	IF N_ELEMENTS(ERRMSG) NE 0 THEN ERRMSG = 'DEL_DETAIL: ' + MESSAGE $
		ELSE MESSAGE, MESSAGE, /CONTINUE
;
;  Close the database, and return.
;
FINISH:
	DBCLOSE
;
	RETURN, RESULT
	END
