pro mk_orb_file, year, week, clobber=clobber, dirout=dirout, asca=asca
;
;+
;NAME:
;	mk_orb_file
;PURPOSE:
;	To create the ORB file containg spacecraft position
;INPUT:
;	year
;	week
;OPTIONAL INPUT:
;	clobber
;	dirout
;HISTORY:
;	Written Aug-96 by R.D.Bentley
;-
;
progName = 'MK_ORB_FILE'
progVerNo = 1.00*1000
;
;;dirout = '/ydb/ref_scratch'   ;???

if (keyword_set(asca)) then begin
    if (n_elements(dirout) eq 0) then dirout = '$DIR_ASCA_ORB'
end else begin
    if (n_elements(dirout) eq 0) then dirout = '$DIR_GEN_ORB'
end

filnam = 'orb' + string(year,'_', week, 'a.', fix(progverno/1000.), format='(i2.2,a,i2.2,a,i2.2)') 
outfil = concat_dir(dirout, filnam)
print, 'Making new file: ', outfil
;
rsiz = 16
get_lun, lun
open_da_file, lun, '', '', outfil, rsiz, bytout, fpoint, /nolower
gen_struct, file_header=fhead

;
fpoint.data_section     = bytout
fpoint.data_version	= 0

;
mk_orb_week, year, week, orb_data, asca=asca
ndset = n_elements(orb_data)

rdwrt, 'W', lun, bytout, rsiz, orb_data, 1

fpoint.TotBytes         = bytout

fhead.first_Time        = orb_data(0).time
fhead.first_Day         = orb_data(0).day
fhead.last_Time         = orb_data(ndset-1).time
fhead.last_Day          = orb_data(ndset-1).day

fhead.nDataSets         = ndset
fhead.maxSamps          = 0

file_id = ' '

if (keyword_set(asca)) then spacecraft='ASC'
wrt1p_fh, lun, fpoint, fhead, rsiz, progName, progVerNo, file_id, 'ORB', 'All', spacecraft=spacecraft
free_lun, lun
;
spawn, 'chmod 666 ' + outfil
end
