Re: A Nice (undocumented?) feature for PS plotting [message #7263] |
Sun, 27 October 1996 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Jack Harlan <jah@etl.noaa.gov > writes:
> I stumbled on a very useful feature Here's the situation:
> I need Postscript output files for my presentations... [so] I usually
> set the device to 'PS', then run my IDL [widget program].
> If I have already run the widget-using program at least once, then
> set device to 'PS', everything works fine. If I start up IDL, then set
> device to 'PS', then run my widget-using program, I'll get this error:
> "WIDGET_CONTROL: Routine is not defined for current graphics device."
> So, all I have to do is to remember to run the procedure once, *then*
> set the 'PS' device, then re-run the procedure. This means that
> I don't have to write different procedures for X and Postscript output.
> This is great! ...Maybe no one else cares about this or maybe everyone
> else already knew, but I find it very convenient.
Yes, it is very convenient, but I am afraid it is working for the wrong
reason in your program!
I am willing to bet dollars to donuts that the reason this works is that
you are not making sure you are drawing into the draw widget graphic
window in your widget program. You just assume the draw widget
window is the current window. So far, you have been absolutely
right, but this must be because you are either living right or are
fabulously lucky. (Have you purchased any lottery tickets lately?)
It is a grave mistake in widget programs to draw graphics into any
ol' window without first setting the current window in the program.
Sooner or later you will end up with another widget
program on the display at the same time as yours (perhaps written
like yours), and you will find yourself drawing graphics in the
wrong window.
But, that caveat aside, you _have_ discovered a useful technique.
I am currently working on a book about IDL programming and one
of the things I hope to show people is how to write a graphic display
routine that can be (1) displayed in a regular IDL graphic window,
or, (2) in a resizeable IDL graphic window, or (3) be sent directly
to a PostScript file, all without having to modify any of the code.
One aspect of this technique is to be sure you don't use any
WSET commands if your graphics device is the PostScript
device. Usually, this means writing your WSET commands
like this:
IF !D.NAME NE 'PS' THEN WSET, windowIndex
Another aspect of this technique is to use normalized
coordinates for your plotting routines. This allows you
to draw the plot in _any_ sized window. For example,
like this:
CONTOUR, data, POSITION=[0.15, 0.15, 0.95, 0.95]
I will be debuting a new IDL Programming web site in the
next several weeks that will elaborate on these and other
programming ideas. If you send me your e-mail address, I'll
make sure you get to have a look at it before its public debut. :-)
In the meantime, you may want to look at the program GWINDOW
that resides on my anonymous ftp site. This is a resizeable
widget graphics window that can send its output directly to
a PostScript file as true PostScript, not as a screen dump.
You will need to download the following files:
gwindow.pro -- a "smart" resizeable IDL graphics window
ps_form.pro -- an interactive form for configuring the PS device
xcolors.pro -- a more flexible (in widget programs, at least) XLOADCT
The files are on the machine ftp.frii.com in the directory
/pub/dfanning/outgoing/idl_examples. (The gwindow and
ps_form files have been updated just today to add some
features and flexibility.)
To see an example of how it can be used (including with your
own IDL programs), compile gwindow.pro and type "example"
at the IDL command line, like this:
IDL> .compile gwindow
IDL> example
All the graphics windows that you open are resizeable
and can send their contents to a PostScript file. If you
fix your WSET command, it is likely that your program
will work directly in the GWINDOW graphics window!
Enjoy!
David
--
David Fanning, Ph.D.
Phone: 970-221-0438
Fax: 970-221-4728
E-Mail: davidf@fortnet.org
|
|
|