pro tvectot,name,remove=remove,newname=newname,tot=tot
COMPILE_OPT idl2
names = tnames(name)
n_type = size(newname,/type)
t_type = size(tot,/type)
if names[0] eq '' then begin
dprint,'No valid tplot variables with name: ' + name,dlevel=2
return
endif
n_bool = 0
t_bool = 0
a_bool = 0
if n_type eq 7 then n_bool = 1 $
else if n_type ne 0 then begin
dprint,'newname is set but it is not of type string, returning',dlevel=2
return
endif
if t_type eq 7 then t_bool = 1 $
else if arg_present(tot) then a_bool = 1
if (n_bool eq 1 || t_bool eq 1 || a_bool eq 1) && n_elements(names) gt 1 then begin
dprint,'newname or tot are set and regex is being used, returning',dlevel=2
return
endif
for i = 0,n_elements(names)-1 do begin
name_i = names[i]
get_data,name_i,data=d,dlimits=dl
if not keyword_set(d) then begin
dprint,'Data element of: ' + name_i + ' not set',dlevel=2
return
endif
size_d = size(d.y,/dimensions)
ele_d = n_elements(size_d)
if(ele_d ne 2) then begin
dprint,'Data of ' + name_i + ' has the wrong number of elements',dlevel=2
return
endif
if not keyword_set(remove) then begin
mag = sqrt(total(d.y^2,2))
new_y = transpose([transpose(d.y),reform(mag,1,n_elements(mag))])
new_v = indgen(size_d[1]+1)+1
new_d = {x:d.x,y:new_y,v:new_v}
new_color = [(indgen(size_d[1])+1)*2,0]
if keyword_set(dl) then begin
str_element,dl,'colors',success=s
if s then $
str_element,dl,'colors',new_color,/add
str_element,dl,'labels',success=s
if s then $
str_element,dl,'labels',[dl.labels,'mag'],/add
endif
if n_bool eq 1 then $
store_data,newname,data=new_d,dlimits=dl $
else if t_bool eq 1 then begin
mag_d = {x:d.x,y:mag}
store_data,tot,data=mag_d
endif else if a_bool eq 1 then tot = mag else $
store_data,name_i,data=new_d,dlimits=dl
endif else begin
new_y = d.y[*,0:size_d[1]-2]
new_v = d.v[0:size_d[1]-2]
new_d = {x:d.x,y:new_y,v:new_v}
if keyword_set(dl) then begin
str_element,dl,'colors',success=s
if s then begin
new_color = dl.colors[0:n_elements(dl.colors)-2]
str_element,dl,'colors',new_color,/add
endif
str_element,dl,'labels',success=s
if s then begin
new_labels = dl.labels[0:n_elements(dl.labels)-2]
str_element,dl,'labels',new_labels,/add
endif
endif
if n_bool eq 1 then $
store_data,newname,data=new_d,dlimits=dl $
else $
store_data,name_i,data=new_d,dlimits=dl
endelse
endfor
end