function mo_filelist, source=source, destination=destination, files=files, $
   prefix=prefix, mosearch=mosearch, subdirs=subdirs, pattern=pattern
;+
;   Name: mo_filelist
;
;   Purpose: return files found on currently mounted mos
;
;   Calling Sequence:
;      files=mo_filelist( /dest, prefix='SSS')
;
;   History:
;      9-Dec-1994 (SLF) 
;
;   Restrictions:
;      uses environnmentals MO_SOURCE and MO_DEST so assumes those are
;      defined at your site...
;
;-

slist=str2arr(get_logenv('MO_SOURCE'))		; top level directory
dlist=str2arr(get_logenv('MO_DEST'))            ; top level directory

type='MO_SOURCE (read mount)'

case 1 of 
   keyword_set(destination) and keyword_set(source): begin
      mlist=[slist,dlist]
      type=' anytype (read&write mount)'
   endcase
   keyword_set(destination): begin
      mlist=dlist
      type='MO_DEST (write mount)'
   endcase
   else: mlist=slist
endcase

allpre=['ada','bda','hda','sfr','spr','wda','sfd']

chklist=where(mlist ne '',gcnt)
if gcnt eq 0 then begin
   print,"NO MOs of type: " + type + " are mounted within IDL..."
   retval=''
endif else begin
   mlist=mlist(chklist)
   if n_elements(subdirs) eq 0 then $
      subdirs=[concat_dir('yohkoh','*'),'*']
   if n_elements(pattern) eq 0 then pattern='*'
   if n_elements(prefix) eq 0 then prefix=allpre   
   if keyword_set(files) then filenames = files else $
      filenames=str_perm(prefix,pattern)
   retval=file_list(concat_dir(mlist,subdirs),filenames)
endelse

return,retval
end



