;	(9-mar-92)
pro mk_orbit_sum,start_time,stop_time,time_step,	$
	file=file,orbit_file=orbit_file,delete=delete,	$
	full=full,nosaa=nosaa,contacts=contacts
;+
; NAME:
;   mk_orbit_sum
;
; PURPOSE:
;   Generate ascii file containing summary of Yohkoh Day times (*.summ)
;   Optionally generate *.sum2 file for use by contacts.
;
; CALLING SEQUENCE:
;   mk_orbit_sum	; Will prompt for start/stop and delete option.
;   mk_orbit_sum,start_time,stop_time,time_step,	$
;	file=file,orbit_file=orbit_file [,/delete,/full,/nosaa,/contacts]
;
;   Examples:
;   mk_orbit_sum,/del,/contacts			; Will prompt for start/stop
;   mk_orbit_sum,'1-apr-92','3-apr-92',/del	; Default = 60s, no *.sum2 file
;
; INPUTS:
;   start_day	Start day in string (dd-mmm-yy hh:mm) format
;   stop_day	Stop  day in string (dd-mmm-yy hh:mm) format
;   time_step	The time step in sec.  If not present, default will be 60s
;
; OPTIONAL INPUT KEYWORDS:
;   orbit_file = The file name containing the orbital state vector.
;		 If not supplied, then the closest file in time will
;		 be chosen by run_dsnfil.pro.
;   delete     = If set to 1, will delete the *.ascii file.
;
; OPTIONAL INPUT KEYWORDS FOR *.summ FILE CONTROL:
;   full       = If set to 1, will cause (*.summ) summary file to be verbose.
;   nosaa      = If set to 1, will exclude daylight times outside of saa.
;		 Only has an effect if full is not set to 1.
;
; OPTIONAL INPUT KEYWORDS FOR *.sum2 (Contacts) FILE CONTROL:
;   contacts   = If set to 1, will call pr_orbit_sum2 to write *.sum2 file
;		 for use by contacts.
;
; OPTIONAL OUTPUT KEYWORDS:
;  file = The output summary file.
;
; SIDE EFFECTS:
;  mk_orbit_sum will call run_dsnfil to create an *.ascii file containing
;  the raw orbital information.  Next pr_orbit_sum will be called to
;  create the summary file.
;
; MODIFICATION HISTORY:
;  9-mar-92, Written, J. R. Lemen
;-

if n_elements(start_time) eq 0 then start_time = ' '
if n_elements(stop_time)  eq 0 then stop_time  = ' '

if strlen(strtrim(start_time)) eq 0 then begin
   input,'* Enter the start time (dd-mmm-yy [hh:mm])', start_time, start_time
   input,'* Enter the stop  time (dd-mmm-yy [hh:mm])', stop_time,  stop_time
endif

if n_elements(time_step) eq 0 then begin
  step = 60 
  print,'* Will default to ',strtrim(step,2),'s time step'
endif else step = time_step

start_arr = timstr2ex(start_time)
stop_arr  = timstr2ex(stop_time)

Num = addtime(stop_arr,diff=start_arr)*60. / step + 1

; ---  Call run_dsnfil to spawn dsnfil_***  ---

print,'------- Starting to run dsnfil '
cmd = string(start_arr([6,5,4,0,1,2]),step,num,format='(6i5,2i10)')
print,cmd		;***
run_dsnfil,cmd,file=file,orbit_file=orbit_file

break_file,file,disk_log,dir,filnam,ext


; --- Read the ascii file ---

print,'------- Reading ',file
rd_orbit_event,file,orbit,orbit_params=orbit_params

; -- Write the summary file ---

file_sum = filnam+'.summ'		; Create the summary filename
print,'------- Writing ',file_sum
pr_orbit_sum,orbit,file_sum,orbit_params=orbit_params,full=full,nosaa=nosaa

; -- Optionally write the summary file ---
  
if keyword_set(contacts) then begin
  file_sum2 = filnam+'.sum2'		; Create the sum2 filename
  print,'------- Writing ',file_sum2
  pr_orbit_sum2,orbit,file_sum2,orbit_params=orbit_params
endif

; -- Optionally delete the *.ascii file --

if keyword_set(delete) then ans = 1 else $
	yesnox,'* Delete the ascii file?', ans, 'Y'
if ans then begin
  print,'  Deleting file ',  file
  cmd = 'rm -f '+file
  spawn,cmd
endif

return
end
