pro fl_mktext, time0, time1, otext=otext
;+
; NAME: fl_mktext
;
; PURPOSE: make near realtime text file for first_light /distribution
;
; History:
;   6-sep-1994 (SLF)
;   3-jun-1995 (SLF) - set minimum eventlog duration to 7 minutes
;-

savetext=concat_dir('$DIR_SITE_LOGS', + 'first_light.text')

now=ut_time()

if n_elements(time1) eq 0 then time1 = now
if n_elements(time0) eq 0 then time0 = $
   gt_day(anytim2ints(time1,offset= -(24.*60*60.*1.5)),/string)

file_append,/new, savetext, [ $
   "FIRST_LIGHT - Yohkoh/SXT and Ground Based Data Summary","",		$
   "Text Summary Generated at: " + now + " UT.",""			]

tpre=['gev','nar','evn']
tempfiles=concat_dir(get_logenv('HOME'),tpre + '.temp')
header=["-------------- GOES Events -----------------",		$
	"-------- NOAA Active Region Reports ---------",		$
 	"----- Yohkoh Event Log (KSC / Near Real Time Data Summary) ---"]
keywords=['','',',mindur=7.']

for i=0,n_elements(tpre)-1 do begin
   exestat=execute("pr_" + tpre(i) + keywords(i) + ",time0,time1,outfile='" + tempfiles(i) + "'")
   if file_stat(tempfiles(i),/size) gt 0 then begin
      outpr=rd_tfile(tempfiles(i))
      if n_elements(outpr) gt 3 then $
       file_append, savetext, ["",header(i),"", outpr(1:*)]
   endif
endfor

; finger
spawn,'finger campaign@isass0.solar.isas.ac.jp',out
start=where(strpos(out,'Plan:') ne -1,cnt)
if cnt gt 0 and start(0) lt n_elements(out)-1 then out=out(start(0):*)

file_append,savetext,["","--- Yohkoh Campaigns & Observing Plans ---",out,""]

otext=rd_tfile(savetext)

return
end
