Viewing contents of file '../idllib/sdss/allpro/endplot.pro'
;+
; NAME:
;	ENDPLOT	
;
; PURPOSE:
;
;	Closes and saves the current plotfile.  By default, the file
;	is then spooled to the printer using the unix 'lpr -r'
;	command. Keywords are available to name the plotfile and
;	inhibit spooling.
;
;	See also BEGPLOT and KILLPLOT.
;
; CATEGORY:
;
;	Misc.
;
; CALLING SEQUENCE:
;
;	ENDPLOT
;
;	There are no user defined inputs.
;
; INPUTS:
;
;	None.
;
; KEYWORD PARAMETERS:
;
;	NOPRINT: Set to prevent spooling.
;
;	P: Name (string) of printer to spool plotfile to.  'lpr -r
;          -Pprintername' is used.
;
;       SHELL: Set to use an intervening shell process for the
;                'spawn, "lpr..."' call.  By default, the 
;                /NOSHELL keyword to spawn is used.
;
; OUTPUTS:
;
;	None.
;
; COMMON BLOCKS:
;
;	PLOTFILE_COM:  See the documentation for BEGPLOT.
;
; EXAMPLE:
;
;	See the documentation for BEGPLOT.
;
; COPYRIGHT NOTICE:
;
;	Copyright 1993, The Regents of the University of California. This
;	software was produced under U.S. Government contract (W-7405-ENG-36)
;	by Los Alamos National Laboratory, which is operated by the
;	University of California for the U.S. Department of Energy.
;	The U.S. Government is licensed to use, reproduce, and distribute
;	this software. Neither the Government nor the University makes
;	any warranty, express or implied, or assumes any liability or
;	responsibility for the use of this software.
;
; MODIFICATION HISTORY:
;
; 	Based on ENDPLT by Phil Klingner, NIS-3, LANL.
;
;	Modified and renamed ENDPLOT. Michael J. Carter, NIS-1, LANL,
;	March, 1994.
;
;       Added /noshell keyword in call to 'spawn' to speed up printing.
;       Use the /shell keyword to 'endplot' to override. <mjc - April, 1995>
;
;-

PRO Endplot, noprint=noprint, p=p, shell=shell, help=help

;; Procedure to close out and print current or named plot file
   
   COMMON Plotfile_com, plotfile, save_device, spool
   
   IF keyword_set(help) THEN BEGIN
      doc_library, 'endplot'
      return
   ENDIF
   
   sv = size(plotfile)
   IF sv(sv(0)+1) EQ 0 THEN plotfile = 'null'
   sv = size(save_device)
   IF sv(sv(0)+1) EQ 0 THEN save_device = !D.name
   
   IF keyword_set(p) THEN $
    parg = '-P' + strtrim(string(p), 2) $
   ELSE $
     parg = ''
   
   message, 'Closing current plot file ' + plotfile, /continue
   IF !D.name NE 'X' THEN device, /close
   set_plot, save_device
      
   IF ((NOT keyword_set(noprint)) AND (spool EQ 1)) THEN BEGIN
       IF keyword_set(shell) THEN BEGIN
           spawncmd = 'lpr -h -r' + ' ' + parg + ' ' + plotfile
           spawn, spawncmd
       ENDIF ELSE BEGIN
           IF parg EQ '' THEN $
             spawncmd = ['lpr', '-h', '-r', plotfile] $
           ELSE $
             spawncmd = ['lpr', '-h', '-r', parg, plotfile]
           spawn, spawncmd, /noshell
       ENDELSE 
       message, plotfile+' sent to printer', /continue
   ENDIF

   plotfile = 'null'
   
END