;+
;NAME:
; thm_ui_new_wavelet
;PURPOSE:
; wrapper for wav_data for wavelet transform of the input tplot
; variable
;CALLING SEQUENCE:
; thm_ui_new_wavelet, vnames, new_names
;INPUT:
; vnames = the tplot variable names to transform
;OUTPUT:
; new_names = new variable names generated by the process
;KEYWORDS:
; polar = if set, passes the /polar keyword into the split_vec
;         procedure, new variable names for 3-d data will be polar,
;         and not '_x','_y','_z'
;HISTORY:
; 22-oct-2008, jmm, jimm@ssl.berkeley.edu
;$LastChangedBy: jimmpc $
;$LastChangedDate: 2008-10-23 17:21:46 -0700 (Thu, 23 Oct 2008) $
;$LastChangedRevision: 3801 $
;$URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/thmsoc/tags/tdas_5_1/idl/themis/thm_ui_new/utilities/thm_ui_new_wavelet.pro $
;-
Function thm_ui_new_wavelet, vnames, new_names, trange, $
                             polar = polar, _extra = _extra

vn0 = tnames(vnames)
new_names = ''
If(vn0 Eq 0) Then Begin
    otp = 'THM_UI_NEW_WAVELET: Invalid variable name'
    new_names = ''
    return, otp
Endif
n =  n_elements(vn0)
For j = 0, n-1 Do Begin
    get_data, vn0[j], data = data ;first call split_vec, if necessary
    If(is_struct(data)) Then Begin 
        ndj = n_elements(data.y[0, *])
        If(ndj Eq 3) Then Begin
            split_vec, vnames[j], polar = polar, names_out = vn_j
        Endif Else If(ndj Gt 1) Then Begin
            split_vec, vnames[j], names_out = vn_j, $
              suffix = '_'+strcompress(string(indgen(ndj)), /remove_all)
        Endif Else vn_j = vnames[j]
    Endif Else vn_j = ''
;Do the transform
    If(is_string(vn_j)) Then Begin
        nvnj = n_elements(vn_j)
        For k = 0, nvnj-1 Do Begin
;test the data first
            get_data, vn_j[k], data = d
            If (is_struct(d) && n_elements(where(finite(d.y))) ge 2) Then Begin
                ok = where(d.x Gt trange[0] And d.x Le trange[1], nok)
                If(nok Gt 500000l) Then Begin
                    message, /info, 'Warning: '+strcompress(string(nok))+$
                      ' May be too many data points'
                Endif
                wav_data, vn_j[k], trange = trange
                new_names = [new_names, vn_j[k]+'_wv_pow']
            Endif
        Endfor
    Endif
Endfor
;What are the new names?
If(n_elements(new_names) Gt 1) Then new_names = new_names[1:*]
Return
End