pro mk_week1_file, prefix, infil=infil, outfil=outfil
;
;+
;NAME:
;	mk_week1_file
;PURPOSE:
;	Make the Yohkoh formated files for:
;			GRO/BATSE event log file (GBE)
;			Nobeyama event log file (NEL)
;HISTORY:
;	Written 19-Apr-93 by M.Morrison
;-
;
progVerNo = 1.00*1000
progName = 'MK_WEEK1_FILE'
;
gbo_struct, gbo_version=gbo_version
gen_struct
obs_struct
fhead           = {file_header_rec}
orbit_header    = {obs_neworb_hd_rec}
;
case strupcase(prefix) of
    'GBE': begin
		if (n_elements(outfil) eq 0) then outfil = '$DIR_GEN_GBE/gbe000000.0000'
		log = rd_gbe_raw(infil=infil)
		instr = 'BAT'
		spacecraft='GRO'
		data_version     = gbo_version.gbe
	   end
    'NEL': begin
		if (n_elements(outfil) eq 0) then outfil = '$DIR_GEN_NEL/nel000000.0000'
		rd_nel_raw, infil, log
		instr = '???'
		spacecraft = 'NOB'
		data_version	= gbo_version.nel
	   end
endcase
;
qfirst_time     = 1
first_time      = 0
first_day       = 0
last_time       = 0
last_day        = 0
;
get_lun, lunout
rsiz = 16
;
;---------------------------------------- Get event information  --------------------
ss = sort(int2secarr(log))
log = log(ss)
n = n_elements(log)
npointers = n/20	;have a pointer every 20 records
orbit_arr       = replicate({obs_newOrbit_Rec}, npointers)
sss = indgen(npointers)*20
orbit_arr.time = log(sss).time
orbit_arr.day = log(sss).day
orbit_arr.stEntry = sss + 1		;
orbit_header.nOrbitRec = npointers
;
;---------------------------------------- Open/write to output file --------------------
open_da_file, lunout, '', '', outfil, rsiz, bytout, fpoint, /nolower

fpoint.opt_section  = bytout
rdwrt, 'W', lunout, bytout, rsiz, Orbit_header, 1
rdwrt, 'W', lunout, bytout, rsiz, Orbit_arr, 1
fpoint.data_section = bytout

rdwrt, 'W', lunout, bytout, rsiz, log, 1
totbytes = bytout

fpoint.TotBytes         = totbytes

fhead.first_Time        = log(0).time
fhead.first_Day         = log(0).day
fhead.last_Time         = log(n-1).time
fhead.last_Day          = log(n-1).day

fhead.nDataSets         = n
fhead.maxSamps          = get_nbytes(log(0))

fpoint.data_version     = data_version

wrt1p_fh, lunout, fpoint, fhead, rsiz, progName, progVerNo, ' ', strupcase(prefix), instr, spacecraft=spacecraft
close, lunout
end

