	PRO FIX_MAIN_TIMES
;+
; Project     :	SOHO - CDS
;
; Name        :	FIX_MAIN_TIMES
;
; Purpose     :	Fixes start and stop times in the MAIN catalog
;
; Category    :	Class5, Operations, Catalog
;
; Explanation :	Sometimes the start and stop times in the MAIN catalog get out
;		of sync with the entries in the EXPERIMENT catalog.  These
;		anomalous entries are signalled by having OBT_TIME=0.  This
;		routine will set the time parameters in such cases to resync
;		the databases.
;
;		Only for use by experts.
;
; Syntax      :	FIX_MAIN_TIMES
;
; Examples    :	
;
; Inputs      :	None.
;
; Opt. Inputs :	None.
;
; Outputs     :	None.
;
; Opt. Outputs:	None.
;
; Keywords    :	None.
;
; Calls       :	DBOPEN, GET_MAIN, LIST_EXPER, MOD_MAIN
;
; Common      :	None.
;
; Restrictions:	!PRIV must be GE 2 to write into the database.
;
; Side effects:	None.
;
; Prev. Hist. :	None.
;
; History     :	Version 1, 10-Apr-1996, William Thompson, GSFC
;
; Contact     :	WTHOMPSON
;-
;
	ON_ERROR, 2
;
;  Make sure that the user has privilege to write into the database.
;
	IF NOT PRIV_ZDBASE(/CAT) THEN MESSAGE,	$
		'No privilege to write into the MAIN database'
;
;  Check that !PRIV is set correctly.
;
	IF !PRIV LT 2 THEN MESSAGE,	$
		'!PRIV must be 2 or greater to write into the database'
;
;  Open the MAIN database, and extract all the program numbers and OBT_TIME
;  values.
;
	DBOPEN, 'main'
	DBEXT, -1, 'prog_num,obt_time', PROG_NUM, OBT_TIME
	DBCLOSE
;
;  Find all the values with OBT_TIME set to zero.
;
	W = WHERE(OBT_TIME EQ 0, COUNT)
	IF COUNT EQ 0 THEN BEGIN
		MESSAGE, /CONTINUE, 'No corrections need to be made.'
		RETURN
	ENDIF
;
;  For each anomalous time, get the complete entry, and list all the
;  experiments associated with that program.
;
	FOR I = 0,COUNT-1 DO BEGIN
	    GET_MAIN, PROG_NUM(W(I)), MAIN
	    LIST_EXPER, PROG_NUM(W(I)), EXPER, N_FOUND
	    IF N_FOUND GT 0 THEN BEGIN
		MAIN.DATE_OBS = EXPER(0).DATE_OBS
		MAIN.DATE_END = EXPER(0).DATE_END
		MAIN.OBT_TIME = EXPER(0).OBT_TIME
		MAIN.OBT_END  = EXPER(0).OBT_END
		TEST = MOD_MAIN(MAIN)
		IF N_FOUND GT 1 THEN FOR J = 1,N_FOUND-1 DO BEGIN
		    MAIN.DATE_OBS = MAIN.DATE_OBS < EXPER(0).DATE_OBS
		    MAIN.DATE_END = MAIN.DATE_END > EXPER(0).DATE_END
		    MAIN.OBT_TIME = MAIN.OBT_TIME < EXPER(0).OBT_TIME
		    MAIN.OBT_END  = MAIN.OBT_END  > EXPER(0).OBT_END
		    TEST = MOD_MAIN(MAIN)
		ENDFOR
	    ENDIF
	ENDFOR
;
	RETURN
	END
