PRO get_page, File, $ printfile = PrintFile , $ keepfile = KeepFile , $ killfile = KillFile , $ color = Color , $ freezedev = FreezeDev , $ png = png , $ gif = gif , $ bmp = bmp , $ jpg = jpg , $ eps = eps , $ silent = silent , $ zbuffer = zbuffer , $ display = display , $ printer = printer , $ new = new , $ notwin = notwin , $ logo = logo ;+ ; NAME: ; get_page ; PURPOSE: ; Complete output procedure set up with href=set_page=. ; Submit PostScript or HP file to print queue ; CATEGORY: ; Plotting ; CALLING SEQUENCE: ; get_page [,File, /color] Close device & print & delete ; get_page [,File, /killfile] Close device & delete ; get_page [,File, /keepfile ,/color] Close device & keep ; get_page [,File, /keepfile, /printfile ,/color] ; Close device & print & keep ; OPTIONAL INPUTS: ; File scalar; type: string; default: !ThePlotFile ; file name to be used for plot filefile name. In general the common block ; default should be use. Primarily useful for /gif and /bmp ouput. ; /keepfile ; keepfile=KeepFile ; scalar; type: string or byte ; (HP only) the plot file will be saved ; If KeepFile is a valid file name it is used for the saved plot file. ; (this option is only set up for the HP printer on CASS01 and depends ; on the LIBPRN command procedure). ; /printfile (HP and PS) ; if set the plot file is submitted for printing ; This is the default for HP and PS ; /killfile (HP, PS and EPS) ; closes the plot device, and deletes the plot file ; /freezedev by default the plot device is set back to !TheTerminal. ; If /freezedev is set the device will remain at the setting found when ; get_page was called (usually the printer device !ThePrinter) ; /color plot in color (only for PS files) ; ; /gif ; /png ; /jpg ; /bmp can be used in combination with the File argument to save the ; content of the current window into a GIF or BMP file. ; If File has the extension .gif or .bmp then the keyword does not need ; to be specified. ; /silent suppresses a bunch of informational messages ; INCLUDE: @compile_opt.pro ; On error return to caller ; CALLS: ; IsType, InitVar, SetFileSpec, GetFileSpec, do_file, filepath, reset_colors ; hide_env, put_logo ; SEE ALSO: ; set_page ; PROCEDURE: ; set_page and get_page are supposed to be used together: set_page starts the ; output procedure, get_page completes it. get_page uses the file name save in ; common block 'devices' to determine what kind of output to produce (EPS, GIF, BMP, ; HP, PS, etc.). ; ; For the PRINTER device no plot file is created but instead output is send directly ; to the printer. Hence none of the keywords are useful. get_page will always close ; the PRINTER device (effectively forcing the printer to start printing). ; ; For EPS a file name is selected using 'set_page'. The file name is saved in common ; block 'devices'. Here the EPS file is just closed. ; ; For GIF and BMP a tvrd() is executed, and the return value is written into a file ; with the name in !ThePlotFile. Alternatively the File argument is used to specify a ; file name. If the name does not have extension .gif or .bmp then the keyword /gif ; or /bmp must be set explicitly. ; MODIFICATION HISTORY: ; Based on PSPLOT, written DMZ (ARC, Aug'90) ; July 1991, Paul Hick (ARC) ; 1992, Paul Hick (UCSD/CASS); added option for plotting to HP printer ; 2006, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Added logo keyword ;- InitVar, printer , /key InitVar, display , /key InitVar, zbuffer , /key InitVar, true , /key IF NOT zbuffer AND NOT printer AND NOT display THEN BEGIN printer = IsPrinter() display = IsDisplay() zbuffer = !d.name EQ 'Z' ENDIF ; Check KeepFile keyword. If it is a valid file name use it for the plot file. IF IsType(KeepFile, /string) THEN BEGIN SetFileSpec, KeepFile, /parse, status=tmp IF tmp THEN SaveFile = KeepFile ENDIF InitVar, KeepFile , /key InitVar, PrintFile , /key InitVar, KillFile , /key InitVar, Color , /key InitVar, FreezeDev , /key InitVar, silent , 0 InitVar, zbuffer , /key InitVar, notwin , /key InitVar, File , !ThePlotFile ; Set by set_page. PrintFile = PrintFile OR 1-KeepFile InitVar, png, /key InitVar, gif, /key InitVar, bmp, /key InitVar, jpg, /key InitVar, eps, /key IF total([gif,png,bmp,jpg,eps]) EQ 0 THEN BEGIN SetFileSpec, File type = strlowcase(GetFileSpec(part='type')) gif = type EQ '.gif' png = type EQ '.png' bmp = type EQ '.bmp' jpg = type EQ '.jpg' eps = type EQ '.eps' IF silent LE 0 THEN $ IF type NE '.z' AND type NE '.x' THEN $ message, /info, hide_env(File) ENDIF old_device = !d.name Terminal = ([!TheTerminal,'Z'])[zbuffer] CASE 1 OF gif: BEGIN ; Save as GIF file and bail IF !d.name NE Terminal THEN set_plot, Terminal IF File NE '' THEN BEGIN img = tvrd() put_logo, img, logo=logo, /match_background write_gif, File, img ENDIF goto, BAIL END png: BEGIN ; Save as PNG file and bail IF !d.name NE Terminal THEN set_plot, Terminal IF File NE '' THEN BEGIN true_color = !d.n_colors GT 256 img = tvrd(true=true_color) IF NOT true_color THEN BEGIN tvlct, /get, r, g, b img = SuperArray(img, 3, /lead) img[0,*,*] = r[img[0,*,*]] img[1,*,*] = g[img[1,*,*]] img[2,*,*] = b[img[2,*,*]] ENDIF put_logo, img, logo=logo write_png, File, img ENDIF goto, BAIL END bmp: BEGIN ; Save as BMP file and bail IF !d.name NE Terminal THEN set_plot, Terminal IF File NE '' THEN BEGIN img = tvrd() put_logo, img, logo=logo, /match_background write_bmp, File, img ENDIF goto, BAIL END jpg: BEGIN ; Save as JPG file and bail IF !d.name NE Terminal THEN set_plot, Terminal IF File NE '' THEN BEGIN true_color = !d.n_colors GT 256 img = tvrd(true=true_color) IF NOT true_color THEN BEGIN tvlct, /get, r, g, b img = SuperArray(img, 3, /lead) img[0,*,*] = r[img[0,*,*]] img[1,*,*] = g[img[1,*,*]] img[2,*,*] = b[img[2,*,*]] ENDIF put_logo, img, logo=logo write_jpeg, File, img ENDIF goto, BAIL END zbuffer: BEGIN IF !d.name NE Terminal THEN set_plot, Terminal img = tvrd() tvlct, /get, r, g, b IF !d.name NE !TheTerminal THEN set_plot, !TheTerminal true_color = !d.n_colors GT 256 CASE true_color OF 0: BEGIN put_logo, img, logo=logo, /match_background tvlct, r, g, b END 1: BEGIN img = SuperArray(img, 3, /trail) img[*,*,0] = r[img[*,*,0]] img[*,*,1] = g[img[*,*,1]] img[*,*,2] = b[img[*,*,2]] put_logo, img, logo=logo loadct, 0, /silent END ENDCASE IF NOT notwin THEN twin, xsize=(size(img, /dim))[0],ysize=(size(img, /dim))[1], /show, new=new tv, img, true=3*true_color goto, BAIL END display: BEGIN IF !d.name NE Terminal THEN set_plot, Terminal twin, /show;, new=new goto, BAIL END eps: BEGIN IF !d.name NE 'PS' THEN set_plot, 'PS' !p.font = -1 END printer: BEGIN IF !d.name NE !ThePrinter THEN set_plot, !ThePrinter IF !d.name EQ 'PRINTER' THEN BEGIN ; No print file: output to printer and bail device, /close_document goto, BAIL ENDIF END ENDCASE File = (file_search(File))[0] IF File EQ '' THEN BEGIN ; Check whether file exists IF silent LE 0 THEN message, /info, !d.name+' file does not exist' goto, BAIL ENDIF device, /close IF KillFile THEN BEGIN CMD = do_file( File, /delete ) goto, BAIL ENDIF CASE strupcase(!d.name) OF 'PS': BEGIN IF NOT eps AND PrintFile THEN BEGIN tmp = 'print'+(['/delete',''])[KeepFile] + $ ; Delete file ?? (['/setup=(psi)','/que=color$script'])[Color]+' '+File; Print command IF silent LE 0 THEN message, /info, tmp spawn, tmp ; Print plot file ENDIF END 'HP': BEGIN CASE !version.os OF 'vms': tmp = '@$COM:LIBPRN IDLPLOT '+File+(['',' /print'])[PrintFile] ELSE : tmp = filepath(root=getenv('SSW_SMEI_UCSD'), $ subdir=['gen','exe','linux'],'idlprint')+' '+File ; Linux ;ELSE: tmp = 'idlprint '+File+(['',' -print'])[PrintFile] ENDCASE IF KeepFile THEN BEGIN tmp = tmp+' /keep' IF IsType(SaveFile, /defined) THEN tmp = tmp+'='+SaveFile ENDIF IF silent LE 0 THEN message, /info, hide_env(tmp) spawn, tmp ; Print plot file END ELSE: message, 'No plot instructions available for device '+!d.name ENDCASE BAIL: !ThePlotFile = '' CASE FreezeDev OF 0: BEGIN IF !d.name NE !TheTerminal THEN set_plot, !TheTerminal reset_colors END 1: IF !d.name NE old_device THEN set_plot, old_device ENDCASE IF silent LE 0 THEN message, /info, '!D.NAME='+!d.name RETURN & END