Viewing contents of file '../idllib/astron/contrib/varosi/code/allpro/apxsec_hardcopy.pro'
;+
; NAME:
;	ApXsec_Hardcopy
; PURPOSE:
;	Create hardcopy of the graph of currently selected cross-section
;	with approximation points overplotted.
; CALLING:
;	ApXsec_Hardcopy, HC_request
; INPUTS:
;	HC_request = string array (optional).
; OUTPUTS:
;	Writes graphics to a file.
; COMMON BLOCKS:
;	common Modion_Widget, modion_widget
;	also see: modion_common.pro
; EXTERNAL CALLS:
;	function N_struct
; HISTORY:
;	Written: Frank Varosi NASA/GSFC 1995.
;-

pro ApXsec_Hardcopy, ELevel, HC_request

@modion_common
   common Modion_Widget, modion_widget

	if N_struct( ELevel ) LE 0 then return
	HCspec = { HCX, comment:"", file:"", mode:"", back:"", encap:0 }

	if N_elements( HC_request ) GE 3 then begin
		HCspec.mode = strlowcase( HC_request(0) )
		HCspec.back = strlowcase( HC_request(2) )
		if N_elements( HC_request ) GE 4 then begin
			if HC_request(3) EQ "encapsulated" then HCspec.encap=1
		   endif
	 endif else begin
		HCspec.mode = "black"
		HCspec.back = "white"
	  endelse

	if max( tag_names( ELevel ) EQ "MERGED" ) then $
		Levid = "g=" + strtrim( ELevel.group, 2 ) $
	  else	Levid = SLP_char( SLP=ELevel.islp ) + "_" $
			 + strtrim( ELevel.ilv, 2 )

	HCspec.file = get_text_input( "PostScript graphics file name ?", $
					DEF = ion_info.name + "_" + Levid )

	if strlen( HCspec.file ) LE 0 then return
	HCspec.comment = get_text_input( "comments ?" )

    	Widget_Control, /HOURGLASS
	if (HCspec.encap NE 0) then ftype = ".eps" else ftype = ".ps"

	HCspec.file = find_dir( "ps" ) + HCspec.file + $
			"-" + strmid( HCspec.mode,0,1 ) + $
			strmid( HCspec.back,0,1 ) + ftype

	if (HCspec.mode EQ "abort") then return
	if (HCspec.mode EQ "color") then HC_mode=1 else HC_mode=0

	psport,/SQUARE, FILE=HCspec.file
	device, COLOR=HC_mode, BITS=(8*(HC_mode<1))>1, ENCAP=HCspec.encap
	erase

	if (HCspec.back EQ "black") AND (HCspec.mode EQ "color") then begin
		!P.color = !D.table_size-1
		tv, bytarr( 16, 16 ), 0,0, Xsize=1.05, Ysize=1.05, /NORM
	   endif

	Levinfo = get_words( Level_info( ELevel ) )

	Plot_Xsec, ELevel,/NOERASE,/FANCY, COLOR=HC_mode, $
		TITLE=ion_info.name + ":   " + strconcat( Levinfo(0:2) + "   " )

	xyouts, 0.1, -0.1, /NORM, HCspec.comment, COL=0
	xyouts, 0.1, -0.15, /NORM, COL=0, $
			"( Z=" + strtrim(ion_info.NZ,2) + $
			", ne=" + strtrim(ion_info.NEL,2) + " )" + $
			strlowcase( strconcat( "   " + Levinfo(3:*) ) )
	psclose

	if (HCspec.encap NE 0) then begin
		print," encapsulated PS written to file: ", HCspec.file
	 endif else if (HCspec.mode EQ "color") then begin
		print," color PS written to file: ", HCspec.file
	  endif else if (!version.os NE "vms") then begin
		spawn, ["lpr","-h","-s",HCspec.file], /NOSHELL
		print," PS file: ", HCspec.file,"  queued to printer"
	   endif else print," PS written to file: ", HCspec.file
end