	SUBROUTINE OPNHD(lo,li)
	INTEGER lo,li
C---------------------------------------------------------------------------
C Subroutine to open the hard copy graphics device
C---------------------------------------------------------------------------
	COMMON /SETCRT/ CRTOPEN
	LOGICAL CRTOPEN

	CHARACTER*11 LGPRC/'LNM$PROCESS'/
C	CHARACTER*7 LGJOB/'LNM$JOB'/
	LOGICAL GET_LOGICAL,flag
	CHARACTER H_FILE*50,H_DEV*20,H_STRING*60
	INTEGER HD_len,HF_len
C for DECWINDOWS, if there is window open, close it
	IF (CRTOPEN) THEN
	  CRTOPEN = .false.
	  call pgend
	ENDIF

C get logical definitions for hardcopy devices
	flag = GET_LOGICAL('PS_HFILE',H_FILE,50,HF_len,lgprc)
	flag = GET_LOGICAL('PS_HDEV',H_DEV,20,HD_len,lgprc)
	IF (hd_len .gt. 1) then 
	  H_STRING = H_FILE(1:HF_len) // '/' // H_DEV(1:HD_len)
	else
	  H_STRING = '?'
	endif
	CALL PGBEGIN(0,H_STRING,1,1)
c If no logical has been set, get the current settings from PGPLOT and 
C save them 
	IF (hd_len .le. 1) then 
	  call pgqinf('DEVICE',h_file,hf_len)
c Drop the file version number, if any
	  do i=hf_len,2,-1
	   if(h_file(i:i) .eq. ';') then 
	     hf_len = i-1
	     goto 10
	    endif
	  enddo
10	  flag = DEF_LOGICAL('PS_HFILE',H_file(1:HF_LEN),hf_len,1,lgprc)
	  call pgqinf('type',h_dev,hd_len)
C remove trailing comments from device string
	  DO I=hd_len,2,-1
	    if (h_dev(I:I) .eq. ' ') hd_len = I-1
	  ENDDO
	  flag = DEF_LOGICAL('PS_HDEV',H_dev(1:HD_LEN),hd_len,1,lgprc)
	ENDIF
	RETURN
	END
C---------------------------------------------------------------------------
	SUBROUTINE CLHD(lo,li)
	INTEGER lo,li
C---------------------------------------------------------------------------
C Subroutine to close the hard copy graphics device and possibly spool the
C output.  Logical name PS_HF_LAST is defined with the output file name 
C and PS_HD_LAST is defined with the file type.
C---------------------------------------------------------------------------
	CHARACTER*11 LGPRC/'LNM$PROCESS'/
	CHARACTER*7 LGJOB/'LNM$JOB'/
	LOGICAL GET_LOGICAL,flag,DEF_LOGICAL
	CHARACTER H_COM*200
	INTEGER HC_len
 
C get from PGPLOT the name of the open output file
	call pgqinf('DEVICE',h_com,hc_len)
	flag = DEF_LOGICAL('PS_HF_LAST',H_COM(1:HC_LEN),hc_len,1,lgprc)
C get from PGPLOT the name of the plot type
	call pgqinf('type',h_com,hc_len)
	flag = DEF_LOGICAL('PS_HD_LAST',H_COM(1:HC_LEN),hc_len,1,lgprc)
C close out the plot
	CALL PGEND
C check for a command to process the file
	hc_len = 0
	flag = GET_LOGICAL('PS_HCOM',H_COM,200,HC_len,lgprc)
C now queue the file, if PS_HCOM has been defined
	if (hc_len .gt. 1 .and. flag) call lib$spawn(h_com(1:hc_len))
	RETURN
	END
