	PRO MK_SUMMARY, START_TIME=TSTART, END_TIME=TEND, SHOW=SHOW, ALL=ALL
;+
; Project     :	SOHO - CDS
;
; Name        :	MK_SUMMARY
;
; Purpose     :	Produce CDS summary data
;
; Category    :	Class3, CDS, Operations
;
; Explanation :	Call MK_SYNOPTIC and WRITE_CIF to produce CDS summary data.
;		Intended to be used in an automatic cron job.  Since synoptic
;		scans are run around 0h UT, the most optimal time to run this
;		cron job would be between 12h and 18h UT.
;
; Syntax      :	MK_SUMMARY
;
; Examples    :	
;
; Inputs      :	None.
;
; Opt. Inputs :	None.
;
; Outputs     :	The summary data files are written out to the directory
;		CDS_SUMMARY_DATA_W.
;
; Opt. Outputs:	None.
;
; Keywords    :	START_TIME = Start of time range to look for synoptic scans in.
;			     If not passed, then looks for data in the last 84
;			     hours.
;
;			     Also used to pass the start time to the routine
;			     WRITE_CIF.  For that application, the default is
;			     yesterday.
;
;		END_TIME   = End of time range to look for synoptic scans in.
;			     If not passed, then defaults to now.
;
;		SHOW	   = If set, then MK_SYNOPTIC displays the image data
;			     as it is being processed.
;
;		ALL	   = If set, then MK_SYNOPTIC processes all the 
;			     the synoptic scans in the requested time range.
;
; Calls       :	LIST_MAIN, MK_SYNOPTIC, WRITE_CIF
;
; Common      :	None.
;
; Restrictions:	None.
;
; Side effects:	None.
;
; Prev. Hist. :	None.
;
; History     :	Version 1, 20-May-1996, William Thompson, GSFC
;		Version 2, 24-Jul-1996, William Thompson, GSFC
;			Make earliest synoptic, rather than latest.  This is
;			more robust. 
;		Version 3, 20-Aug-1996, William Thompson, GSFC
;			Fixed bug with sort.
;		Version 4, 29-Oct-1998, Ron Yurow, SM&A
;		        Added the keyword, ALL, to process all the synoptic
;			scans in the requested time range.
;		Version 5, 03-Dec-1998, Ron Yurow, SM&A
;			Changed the defualt time to look back when processing
;		        synoptic scans.		        
;
;
; Contact     :	WTHOMPSON
;-
;
	ON_ERROR, 2
;
;  Get the start and stop times.  If not passed, then use the last 36 hours.
;
	GET_UTC, UTC
	IF N_ELEMENTS(TSTART) EQ 0 THEN BEGIN
		START_TIME = ANYTIM2TAI(UTC) - 84.D0 * 60.D0^2
	END ELSE BEGIN
		START_TIME = ANYTIM2TAI(TSTART)
	ENDELSE
;
	IF N_ELEMENTS(TEND) EQ 0 THEN BEGIN
		END_TIME = ANYTIM2TAI(UTC)
	END ELSE BEGIN
		END_TIME = ANYTIM2TAI(TEND)
	ENDELSE
;
;  List all studies in the requested time range.
;
	LIST_MAIN, START_TIME, END_TIME, OBS, N_FOUND
;
;  Extract all the runs of the SUNOP program.
;
	IF N_FOUND GT 0 THEN BEGIN
	    W = WHERE(STRMID(OBS.OBS_PROG,0,5) EQ 'SYNOP', COUNT)
	    IF COUNT GT 0 THEN BEGIN
;
;  Sort by date
;
		OBS = OBS(W)
		IF COUNT GT 1 THEN BEGIN
		    S = SORT(OBS.OBT_TIME)
		    OBS = OBS(S)
		ENDIF

;
;  Determine how many synoptic studies to process.  If the keyword /ALL is
;  is set, then we will process all of them.  Otherwise we will only process
;  the first study.
;

	        IF NOT KEYWORD_SET (ALL) THEN COUNT = 1

;
;  Process the requested number of synoptic studies in cronological order.
;

                FOR I = 0, COUNT - 1 DO BEGIN

 		   PROG_NUM = OBS(I).PROG_NUM
		   PRINT, 'Making synoptic data from study ' + TRIM(PROG_NUM)
		   MK_SYNOPTIC, PROG_NUM, SHOW=SHOW
	        
	        ENDFOR

	    ENDIF
	ENDIF
;
;  Write out the as-run summary file.
;
	TEST = WRITE_CIF(START=TSTART, /SUMMARY)
;
	RETURN
	END
