pro add_magf,dat,source,average=average,gap_thresh=gap_thresh
if not keyword_set(source) then begin
answer = ''
source = (tnames('wi_B3 wi_B wi_Bhkp',/all))[0]
read,answer,prompt='Source of magnetic field data; (default is '+source+')? '
if keyword_set(answer) then source = answer
endif
nan=!values.f_nan
if keyword_set(average) then begin
t = dat.trange
b = tsample(source,t,/average)
endif else begin
t = (dat.time+dat.end_time)/2
b = data_cut(source,t,count=count,gap_thresh=gap_thresh)
if count eq 0 then begin
print,'Unable to determine magnetic field vector using: ',source
b = [nan,nan,nan]
endif
endelse
add_str_element,dat,'magf',b
end