

pro testfilelist,filelist,detail=detail



; =================================================================
; check through filelist and determine which files have to be merged
; =================================================================

if (n_elements(filelist) lt 1) then begin
    filelist = '*.dat'
    print,'** WARNING : empty filelist ! Will try to merge all .dat files. **'
endif


filenames = ''
for i=0,n_elements(filelist)-1 do  $
    filenames = [ filenames, findfile(expand_path(filelist(i))) ]

print,'FILENAMES contains ',n_elements(filenames),' elements !'

; first test for all files not found
ind = where(filenames eq '')
if (n_elements(ind) gt 1) then print,n_elements(ind)-1,' filenames empty !'

; now get valid names
ind = where(filenames ne '')
if (ind(0) lt 0) then begin
    print,'** ERROR : Could not find any files in filelist ! Return. **'
    return
endif
filenames = filenames(ind)


; loop through valid filenames and check if file exists
if (keyword_set(detail)) then begin
   for i=0,n_elements(filenames)-1 do begin
       if file_exist(filenames(i)) then print,'file ',filenames(i),' found.' $
       else print,'file ',filenames(i),' NOT  found.'
   endfor
   print
endif

return
end



