;+
; Project     : SOHO - CDS     
;                   
; Name        : LIST_TM()
;               
; Purpose     : Produce a list of available TM files.
;               
; Explanation : Returns and optionally lists the available TM files in 
;               the official directory or user's own directory.
;               
; Use         : IDL> ff = list_tm([filter, /own])
;    
; Inputs      : None
;               
; Opt. Inputs : filter - string which returned file names must contain.
;               
; Outputs     : Function returns a string array
;               
; Opt. Outputs: None
;               
; Keywords    : OWN   -  if present the current directory is searched rather
;                        than the official $CDS_TM_DATA
;               QUIET -  if present the results are not listed to the screen
;
; Calls       : None
;
; Common      : None
;               
; Restrictions: None
;               
; Side effects: None
;               
; Category    : Help, telemetry
;               
; Prev. Hist. : None
;
; Written     : C D Pike, RAL, 24-Nov-95
;               
; Modified    : 
;
; Version     : Version 1, 24-Nov-95
;-            

function list_tm, filter, own=own, quiet=quiet

;
;  check have correct evar
;
if (not keyword_set(own)) and (getenv('CDS_TM_DATA') eq '') then begin
   print,'$CDS_TM_DATA is not defined.'
   return,''
endif

;
;  get files
;
if keyword_set(own) then begin
   ff = findfile('tm.*',count=count)
endif else begin
   ff = findfile(concat_dir('$CDS_TM_DATA','tm.*'),count=count)
endelse   

;
;  apply filter if given
;
if n_params() eq 1 then begin
   if datatype(filter,1) eq 'String' then begin
      n = where(strpos(ff,filter) ge 0, count)
      if count gt 0 then ff = ff(n)
   endif else begin
      bell
      print,'File name filter must be a string - ignored.'
   endelse
endif
   
;
;  report if not silenced
;
if not keyword_set(quiet) then begin
   if count gt 0 then begin
      print_str,ff,/num
   endif else begin
      bell
      print,'No files found.'
   endelse
endif

;
;  return with list
;
return,ff

end

