pro mtcmd, dev, rewind=rewind, fsf=fsf, bsf=bsf, fsr=fsr, bsr=bsr, $
    offline=offline, cmds=cmds, nospawn=nospawn, background=background
;
; ----------- tape name OR drive number are allowed for dev ---------------
; ----------- (tape name system dependence done via def_tap) --------------
if data_chk(dev,/string) then begin
   if (strlen(strtrim(dev,2)))(0) gt 1 then tapd=dev else tapd=def_tapd(dev)
endif else tapd=def_tapd(dev)
; --------------------------------------------------------------------------

; --------------------------------------------------------------------------
if strupcase(!version.os eq 'VMS' ) then begin
   message,/info,"UNIX only for now, use mt.pro
endif else begin
;  ---------------------- system dependent mt qualifiers ------------------
   mtoff=[' offline',' unload']
   mtdevq=[' -f ',' -t ']
   mtost=['IRIX']
   mtcmd='mt' + mtdevq(is_member(!version.os,mtost,/ignore_case)) + tapd
   mtosoff=mtoff(is_member(!version.os,mtost,/ignore_case))
;  -------------------------------------------------------------------------
   cmds=''
;  ---------------- determine requested action(s) ---------------------------   
   if keyword_set(rewind) then  cmds=[cmds,mtcmd + ' rewind']
   if keyword_set(fsf) then     cmds=[cmds,mtcmd + ' fsf ' + strtrim(fsf,2)]
   if keyword_set(bsf) then     cmds=[cmds,mtcmd + ' bsf ' + strtrim(bsf,2)]
   if keyword_set(fsr) then     cmds=[cmds,mtcmd + ' fsr ' + strtrim(fsr,2)]
   if keyword_set(bsr) then     cmds=[cmds,mtcmd + ' bsr ' + strtrim(bsr,2)]
   if keyword_set(offline) then cmds=[cmds,mtcmd + mtosoff]
;  ---------------------------------------------------------------------------
   gcmds=where(cmds ne '',gcnt)
   if gcnt gt 0 then begin
;     
;     add background symbol if requested
      bgs=['',' &']
      cmds=cmds + bgs(keyword_set(background))
      cmds=cmds(gcmds)
      if not keyword_set(nospawn) then begin
;           ---------- Must close OPEN file units if name = tapd --------
        fs=fstats(name=tapd)            ; check all open units
        if data_chk(fs,/struct) then begin      ; open unit found
           message,/info,"Closing OPEN tape drive" + tapd + " on unit# " $
          + strcompress(arr2str(string(fs.unit)),/remove)
                for i=0,n_elements(fs)-1 do free_lun,fs.unit
        endif
;           --------------------------------------------------------------
;           -------------------- now spawn commands ----------------------
            for i=0,n_elements(cmds)-1 do begin
               message,/info, cmds(i)
               spawn,cmds(i),out
            endfor         
;           ---------------------------------------------------------------
        endif
   endif else begin
     message,/info,"No actions specified...
     message,/info,"(Actions are: /rewind, fsf=N, bsf=N, /offline)
   endelse
endelse

return
end