	FUNCTION MOD_PLAN, OLD_DEF, NEW_DEF, INSTRUMENT=INSTRUMENT, $
		ERRMSG=ERRMSG
;+
; Project     :	SOHO - CDS
;
; Name        :	MOD_PLAN()
;
; Purpose     :	Modifies an entry in the science plan database.
;
; Explanation :	Modifies an entry in the science plan database.  The old entry
;		is removed, and the new entry is added.
;
; Use         :	Result = MOD_PLAN( OLD_DEF, NEW_DEF )
;
;		IF NOT MOD_PLAN(OLD_DEF,NEW_DEF) THEN ...
;
; Inputs      :	OLD_DEF	= Previous entry.  This is a structure such as that
;			  returned by GET_PLAN, and has the tags:
;
;			SCI_OBJ      = Science objective from the daily science
;				       meeting
;			SCI_SPEC     = Specific science objective from meeting
;			NOTES	     = Further notes about the observation
;			START_TIME   = Date/time of beginning of observation,
;				       in TAI format
;			END_TIME     = Date/time of end of observation, in TAI
;				       format
;			OBJECT	     = Code for object planned to be observed
;			OBJ_ID	     = Object identification
;			PROG_ID	     = Program ID, linking one or more studies
;				       together
;			CMP_NO	     = Campaign number
;			XCEN	     = Center(s) of instrument FOV along X
;				       axis, given as a character string.
;			YCEN	     = Center(s) of instrument FOV along Y
;				       axis, given as a character string.
;			DISTURBANCES = Description of any disturbances
;
;		NEW_DEF = New entry.  It has the same structure as OLD_DEF.
;			  Any field can be changed, including the start and end
;			  times.
;
; 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    :	INSTRUMENT = Instrument to modify plan entry for.  Can be
;			     passed either as the instrument name or as a
;			     single character code value.  Normally, this
;			     routine is used for modifying CDS records.
;			     However, the use of the INSTRUMENT keyword allows
;			     it to be used with the SOC planning tool.
;
;		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 = MOD_PLAN( ERRMSG=ERRMSG, ... )
;				IF ERRMSG NE '' THEN ...
;
; Calls       :	DEL_PLAN, ADD_PLAN
;
; Common      :	None.
;
; Restrictions:	The INSTRUMENT keyword must *only* be used with the SOC
;		planning tool.  Its use disables some CDS-specific checks.
;
; Side effects:	None.
;
; Category    :	Planning, Databases.
;
; Prev. Hist. :	None.
;
; Written     :	William Thompson, GSFC, 17 November 1994
;
; Modified    :	Version 1, William Thompson, GSFC, 17 November 1994
;		Version 2, William Thompson, GSFC, 16 May 1995
;			Added keyword INSTRUMENT.
;
; Version     :	Version 2, 16 May 1995
;-
;
	ON_ERROR, 2
;
;  Check the number of parameters.
;
        IF N_PARAMS() NE 2 THEN BEGIN
		MESSAGE = 'Syntax:  MOD_PLAN, OLD_DEF, NEW_DEF'
		GOTO, HANDLE_ERROR
        ENDIF
;
;  First delete the old entry.
;
	MESSAGE = ''
	IF NOT DEL_PLAN( OLD_DEF.START_TIME, INSTRUMENT=INSTRUMENT,	$
		ERRMSG=MESSAGE) THEN GOTO, HANDLE_ERROR
;
;  Next add in the new entry.
;
	IF NOT ADD_PLAN( NEW_DEF, INSTRUMENT=INSTRUMENT, ERRMSG=MESSAGE) THEN $
			BEGIN
;
;  If you can't add in the new definition, put back the old definition.
;
		MSG = ''
		IF NOT ADD_PLAN( OLD_DEF, INSTRUMENT=INSTRUMENT, ERRMSG=MSG) $
			THEN MESSAGE = "Something's wrong--can't even ' + $
				'put back old entry"
		GOTO, HANDLE_ERROR
	ENDIF
;
;  If you got this far, you must be successful.
;
	MESSAGE = ''
	RETURN, 1
;
;  Error handling point.
;
HANDLE_ERROR:
	IF N_ELEMENTS(ERRMSG) NE 0 THEN ERRMSG = 'MOD_PLAN: ' + MESSAGE	$
		ELSE MESSAGE, MESSAGE
;
	END
