Function temp_time2file, time_in, no_u = no_u
  t0 = time_string(time_in)
  yyyy = strmid(t0, 0, 4)
  mo = strmid(t0, 5, 2)
  dd = strmid(t0, 8, 2)
  hh = strmid(t0, 11, 2)
  mm = strmid(t0, 14, 2)
  ss = strmid(t0, 17, 2)
  If(keyword_set(no_u)) Then Return, yyyy+mo+dd+hh+mm+ss $
  Else Return, yyyy+mo+dd+'_'+hh+mm+ss
End

;+
;NAME:
; tplot2ascii
;PURPOSE:
; Dumps a tplot variable into an ascii file
;CALLING SEQUENCE:
; tplot2ascii, varname, filename = filename, filepath = filepath
;INPUT:
; varname = a tplot variable name
;KEYWORDS:
; filename = a filename, if not set the default is to use the variable
;            name appended with the start time of the data
; filepath = a path for the filename, the default is to dump it into
;            the current working directory.
;OUTPUT:
; None, it writes a file
;HISTORY:
; 24-apr-2007, jmm, jimm@ssl.berkeley.edu
;
;$LastChangedBy$
;$LastChangedDate$
;$LastChangedRevision$
;$URL$
;-
Pro tplot2ascii, varname, filename = filename, $
                 filepath = filepath, _extra = _extra

;Catch errors here
  err_xxx = 0
  catch, err_xxx
  If(err_xxx Ne 0) Then Begin
    catch, /cancel
    message, /info, 'tplot2ascii failed'
    help, /last_message, output = err_msg
    For j = 0, n_elements(err_msg)-1 Do print, err_msg[j]
    Return
  Endif
;First, be sure that there is data in the variable
  get_data, varname, data = data, dlimit = dlimit, limit = limit
  If(is_struct(data) Eq 0) Then message, 'No Data in: '+varname
;Ok, now create the filename
  If(keyword_set(filename)) Then filex = filename Else Begin
    ndx = n_elements(data.x)
    t0 = temp_time2file(data.x[0], /no_u)
    t1 = temp_time2file(data.x[ndx-1], /no_u)
    filex = varname+'_'+t0+'_'+t1
  Endelse
  If(keyword_set(filepath)) Then filex = filepath+'/'+filex
;Open the file for writing
  openw, unit, filex, /get_lun
;Some header information
  printf, unit, 'FILE: '+filex
  printf, unit, 'Created by tplot2ascii: '+!stime
  printf, unit, 'Variable Name: '+varname
  printf, unit, 'Time Range: '+time_string(data.x[0])+' -- '+$
    time_string(data.x[ndx-1])
  xdd = float(data.x-data.x[0]) ;this should be ok
  str_element, data, 'x', /delete
  data = add_tag(data, xdd, 'x', /no_copy)
;blindly charge through
  printf, unit, 'Data Structure:'
  struct2ascii, data, lun = unit
  printf, unit, 'Dlimits Structure:'
  struct2ascii, dlimit, lun = unit
  printf, unit, 'Limits Structure:'
  struct2ascii, dlimit, lun = unit
;Done
  printf, unit, 'End of FILE:'
  free_lun, unit
  Return
End