;
pro tek_print, delete_file, version_number=v, filename=fnm, queue=q

common tek_common, lun, tekfile, use_screen, sc_device, hard_device, queue

q_in = exist(q)
; Set queue if not already set.  This will be remembered for rest of session
;checkvar, queue, 'net$print'
checkvar, queue, 'eaf_post1'
checkvar, q, queue
queue=q

; set plot device temporarily back to the printer device so that we can close
; it.  At end of TEK_PRINT, we will reset plot device to the current device.
old_device = !d.name
set_plot,hard_device
device,/close

checkvar,fnm,tekfile,'TEKPLOT'
defaults,fnm,'','','.' + strlowcase(hard_device)
;
;-------------   TEKTRONIX BLOCK   ------------------

if hard_device eq 'TEK' then begin

    free_lun,lun
    use_screen = 1 ; restore use_screen to default value for next call
    checkvar,v,''  ; set version to latest if not set
    if strpos(fnm,';') eq -1 then fnm=fnm+';'
    fnm=fnm+strtrim(v,2)
    if (n_params(0) eq 0) then delete_file = 'N'

    if ((delete_file eq 'D') or (delete_file eq 'd')) then begin
        command_string = "$ PRINT /SETUP=TEK /QUEUE = " + $
            QUEUE + "/DELETE " + fnm
    endif else begin
        command_string = "$ PRINT /SETUP=TEK /QUEUE = " + $
            QUEUE + " "+fnm 
    endelse

    print, command_string
    spawn, command_string
endif 

;---------------  POSTSCRIPT BLOCK  ----------------


if hard_device eq 'PS' THEN begin

    checkvar,delete_file,' '
    checkvar,v,0
    checkvar,fnm,tekfile
;        if not q_in then queue = ''
    if strupcase(delete_file) eq 'D' THEN $
        PSPLOT, V, queue=queue, /DELETE, FILENAME=fnm ELSE $
        PSPLOT, V, queue=queue, FILENAME = fnm

endif

set_plot,old_device  ;restore plot device to current screen device

return & end