pro rbsp_detrend,tnames,sec
tn = tnames(tnames)
if ~keyword_set(sec) then sec = 60.
for j=0,n_elements(tn)-1 do begin
get_data,tn[j],data=dat
sz = size(dat.y,/n_dimensions)
if sz eq 2 then begin
nvec = size(dat.y,/dimensions)
nvec = nvec[1]
endif else nvec = 1
if is_struct(dat) then begin
sr = 1/(dat.x[1]-dat.x[0])
n_samples = sr*sec
num = n_elements(dat.x)/n_samples
width = floor(sec * sr)
dat_smoothed = dat.y
for q=0,nvec-1 do dat_smoothed[*,q] = smooth(dat.y[*,q],width,/nan)
store_data,tn[j] + '_smoothed',data={x:dat.x,y:dat_smoothed}
store_data,tn[j] + '_detrend',data={x:dat.x,y:dat.y - dat_smoothed}
endif else print,'NO TPLOT VARIABLE ' + tn[j]
endfor
end