PRO GetPrintParams, lpr, dest
  
Spawn, "which pdpr", lpr
 
if ((strmid(lpr,0,1))(0) eq '/') then begin
  lpr=lpr+' -p '
endif else begin
  Spawn, "which lpr", lpr
  lpr = lpr + ' -P'
endelse

dest = StrArr(7)
dest(0) = GetEnv( 'LPDEST' )
dest(1) = GetEnv( 'LPDEST1' )
dest(2) = GetEnv( 'LPDEST2' )
dest(3) = GetEnv( 'LPDEST3' )
dest(4) = GetEnv( 'LPDEST4' )
dest(5) = GetEnv( 'LPDEST5' )
dest(6) = GetEnv( 'LPDEST6' )

END

PRO PrintInterface, status, file, PRINT = print, MDISP=mdisp

;+
; NAME:
;       PrintInterface
; PURPOSE:
;       Interface for generating postscript files from ragview.
; CALLING SEQUENCE:
;       PrintInterface, status
;       ... commands such as plot, etc...
;       PrintInterface, status, /PRINT
; OUTPUT:
;       status:  the number of the printer that has been chosen
;                in the menu. status is output parameter if the 
;                keyword PRINT is not set
; INPUT:
;       status:  the number of the printer that has been chosen
;                in the menu in the previous call of printinterface.
;                status is input parameter if the 
;                keyword PRINT is set
;       file: the file to print (only whith association with the PRINT
;             keyword). 
; NOTICE:
;       This interface is extendable. If you have more than one
;       printer, you can add it by assigning it to LPDEST1, lPDEST2,
;       ... LPDEST6 (up to 7 printers can be declared)
; KEYWORDS:
;       PRINT: Sends the file to the printer
;              If not set, the menu interface is displayed
; MODIFICATION HISTORY:
;       Created in 1991 by A.Csillaghy, csillag@astro.phys,ethz.ch
;       Modified for IDL5/ssw/Ragview ACs, March 1998
;       Modified for Advanced Printing System, P.Messmer, July 2000
;-


GetPrintParams, lpr, dest
IF N_Elements( file ) EQ 0 THEN file =  'ragview'

IF NOT Keyword_Set( PRINT ) THEN BEGIN

    menuP = 'Print on file'
    i = 0
    WHILE dest(i) NE '' AND i NE 7 DO BEGIN
        menuP = [ menuP, ['Print on ' + dest(i) + ' printer']]
        i = i+1
    ENDWHILE

  status = General_Menu( menuP,'Choose an Option' )


ENDIF ELSE BEGIN

    ext = '.ps'
    IF N_Elements( status ) EQ 0 THEN BEGIN
        Print, 'Cannot print: the status variable should be defined...'
        RETURN
    ENDIF

    IF status GT 1 THEN BEGIN
;        Spawn, lpr + ' -P' + dest(status-2) + ' ' + file + ext
        Spawn, lpr + dest(status-2) + ' ' + file + ext
    ENDIF

ENDELSE

END; printer interface
