---------------------------------------------------------------------------------- How to print plots from IDL ---------------------------------------------------------------------------------- Alas, RSI is in the stone age in this regard. I had thought that Markwart's library routine 'fxwindow' would do the job seamlessly. And it did, for IDL versions 5.1 and earlier. I have been in contact with him and to do this for the latest versions requires new C-code to steal internal IDL info. Alas..... ----------------------------------------------------------------------------------- So, for the nonce, here is the clunkly reality: OVERVIEW: IDL can only deal with a single graphics device at a time. Normally we are using an X-window on our screen. To get hardcopy plots, we need to open a disk file, REISSUE the same graphics commands that gave us the plot on the X window, and then explicity close the .ps file. Once this file exists, standard UNIX I/O is used to print the file. ------------------------------------------------------------------------------ THE FOLLOWING PROCEDURES CONTROL PLOT I/O ------------------------------------------------------------------------------ 1. first, make sure you have defined the Unix PSPRINTER device to the hardware. Use the command SETPRINTER: ; ; setprinter,dev select printer for hardcopy output ; -------------- ; ; ==> setprinter,dev if no device input a menu is printed ; ; setprinter,0 can specify device by integer or string ; setprinter,'lpr' both these commands do the same thing ; setprinter Select printer for hardcopy output. Sets Unix setenv PSPRINTER. Syntax: SETPRINTER,device If no device input a menu is printed. ------------------------- setprinter,0 <-- Can specify device by integer or string. setprinter,'lpr' Both these commands do the same thing. setprinter <-- Menu: (0) lp0 : Boston University department office: BW' (1) ops4050 : GBT Control Room: BW' (2) telops : GBT Control Room: color' (3) net : Jansky 234: BW' (4) lp : Reber 105: BW' (5) pslaser : Reber 105: color' (6) coltran : Reber 105: color transparency' (7) astro-hp : University of Virginia printer' Use the following command to define characteristics of the PS device or to return to other graphics devices. N.B. printon and printoff invoke this as well so you do not need to deal with SETPLOT if you are happy with the default. Default is tuned to be WYSIWYG with GBT_IDL X-term graphics plots: your hardcopy will look exactly like the screen version provided the IDL commands issued to make the plots are identical. ; setplot.pro ; ----------- ; ; Directs subsequent plot to the specified plotting device. ; Typing SETPLOT without any parameters will give a menu of ; available plotting devices. ; ; setplot ;Print menu of available graphics devices ; setplot,device_n_no ;Direct subsequent to device device_no ; setplot,device_name ;Set to device given by device_name ; THICK - controls thickness of lines and characters, by setting ; !P.CHARTHICK, !P.THICK, !X.THICK and !Y.THICK, default=1 ; For example, to make triple thickness lines on a QMS landscape plot: ; IDL->SETPLOT,'QMS',THICK=3 ; ; PURPOSE: ; To direct subsequent plot to the specified plotting device. ; Typing SETPLOT without any parameters will give a menu of ; available plotting devices. ; The user is informed of the subsequent plotting device. ; The user can either specify the device name or the ; device number. ; CALLING SEQUENCE: ; setplot ;Print menu of available graphics devices ; setplot,device_no ;Direct subsequent to device given by device_no ; setplot,device_name ;Set to device given by device_name ; INPUT: ; KEYWORDS: ; THICK - controls the thickness of the lines and characters, by setting ; !P.CHARTHICK, !P.THICK, !X.THICK and !Y.THICK, default=1 ; For example, to make triple thickness lines on a QMS landscape ; plot: ; ; IDL>SETPLOT,'QMS',THICK=3 ; REVISION HISTORY: ; Written, W. Landsman, STX Corp. February, 1987 ; Adapted to SUN IDL. M. Greason, STX, August 1990 ; Combined VAX and UNIX versions, N. Collins, STX, Nov. 27, 1990 ; Added THICK keyword to control the plot thickness W. Landsman Mar 1991 ; ; Modified by Ed Murphy for his personal preferences. ;- print,'Select device number for subsequent plotting output' print,'(0) Tektronics Terminal Screen print,'(1) X windows display' print,'(3) PostScript Landscape plot file' print,'(4) PostScript Thesis format plot file' print,'(5) Postscript full page portrait format plot file' print,'(6) Postscript default portrait format plot file' print,'(7) Postscript portrait square plot file' print,'(8) PostScript Narrow Landscape plot file' read,'Graphics device number: ',device_no 2. now here is what you need to know: printon,['fname'] defines an IDL PS device and opens file 'fname' ----------------- which must be explicity sent as a string 'myfilename' if no argument, fname='idl' IDL-->print,!plot_file /idl/idl/figs/idl.ps At startup, '/idl/idl/figs/idl.ps' is the default plot file name at BU AT GB this is'/users/tbania/idl/figs/idl.ps' <-- make sure to change in startup.idl ! N.B. printon,'bania' opens a file named: '/idl/idl/figs/bania.ps' It also resets !plot_file = '/idl/idl/figs/bania.ps' printoff,[1] closes the current PS file device ------------ THIS IS ABSOLUTELY NECESSARY -- failure to close will keep the plot device open. there will be a valid filename.ps, but it will be incomplete Command returns graphics to mode it was in before printon was executed For most instances, this is the X-window graphic display printoff -- closes PS file device printoff,1 -- closes PS file device AND prints !plot_file IDL-->print,!plot_file /idl/idl/figs/test1.ps <=== value of !plot_file IDL-->printoff,1 % PSOFF: POSTSCRIPT output not active: nothing done <== PS device already closed $ lpr -Plp0 /idl/idl/figs/test1.ps <== plotted !plot_file anyway ----- ==> this is BU specific piping of file to printer; change for GB in printoff.pro psplot,'name' plots existing .ps file 'name' ------------ ; searches for env variable PSPRINTER, else uses ; PSprinter = 'lp0' <== change this for GB !! ; if filename not input, 'idl' is assumed IDL-->psplot,'bania' $ lpr -Plp0 /data02/idl/figs/bania.ps ------------------------------------------------------------------------------------- EXAMPLE COMMAND SEQUENCE ------------------------------------------------------------------------------------- 1. you have on your X window screen a very nice looking plot that you want to save and print out. 2. printon,'H91alpha_grand_average' : this opens PS device and creates at BU a file named: '/idl/idl/figs/H91alpha_grand_average.ps' 3. now input the sequence of graphics commands that made the plot in (1.) ALL commands need to be repreated. These commands are going to the PS device, so you will see NOTHING whatsoever in the graphics screen. wonderful, eh? example: fetch,1097 show b show 4. print off,1 : this closes the PS device and prints file to default printer !plot_file='/idl/idl/figs/H91alpha_grand_average.ps' which is the explicit file name at BU from step (2.) 5. psplot,'H91alpha_grand_average' : will print (if this file exists) '/idl/idl/figs/H91alpha_grand_average.ps' on the default printer defined as Unix environment variable PSPRINTER -------------------------------------------------------------------------------- TIP FOR THE LAZY, AKA RTR -------------------------------------------------------------------------------- Obviously, for complex plots step (3.) could be really painful. One could go to the middle screen in IDLDE and capture the series of graphics commands and put them into emacs, edit appropriately so that they are valid IDL commands, and save the file as, e.g., graphics.cmds Then at step (3.) simply run this as a batch file and the commands will be inserted appropriately. For joy, you might consider using the fully qualified file name for the batch file: @/idl/idl/graphics.cmds at BU So, the sequence would be: printon,'H91alpha_grand_average' @/idl/idl/graphics.cmds printoff,1 ==> This give you a hardcopy plot and a permanent .ps file for this graphic --------------------------------------------------------------------------------- JOURNAL command --------------------------------------------------------------------------------- IDL has a JOURNAL command which makes this last technique easy to implement. JOURNAL[,ARG] provides a record of an interactive session by saving, in a file, all text entered from the terminal in response to an IDL prompt. as well as all the IDL responses to the standard output terminal. JOURNAL,fname -- starts the logging process to file=fnam JOURNAL -- if logging is enabled, this closes the file and ends logging JOURNAL,arg -- if logging is enabled, this writes ARG to the file ARG is a string Because of this, we have a system variable defined: !jrnl_file At BU the default journal file is: /idl/idl/saves/journal.dat JOURNAL is enabled automatically during execution of STARTUP.IDL.V3.1 ---------------------------------------------------------------------------------- Thus, if you have a pretty plot and want to output it, look in 'journal.dat' and capture the commands you wish to use.... To view 'journal.dat', however, you need to close this open file with: journal don't forget to start another journal afterwards: journal, '/idl/idl/saves/fname.dat' you can overwrite the existing file, /idl/idl/saves/journal.dat, via fname=!jrnl_file journal,fname ; you MUST do it this way because IDL passes system variables by value, not reference a 'feature' in the coding business...