Smart Commons, Was: can i place a job advert [message #28125] |
Mon, 26 November 2001 09:15 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
William Thompson (thompson@orpheus.nascom.nasa.gov) writes:
> You obviously don't belong to the right religion. ;^)
Amen to that! :-)
> The main objections to common blocks have been:
>
> 2. In widget programs, common blocks restrict you to only one copy of the
> widget at any one time. I think this is sometimes overemphasized, but is
> certainly a true disadvantage.
I used to believe this. In fact, I may be the main
culprit in overemphasing this point.
But, ....
As I was reading this post it suddenly occurred to
me how to have a COMMON block in a program AND to
have multiple versions of the program running at
the same time, all working with their own data.
I just tried the idea in my MPI_PLOT program and
I was *shocked* that it worked!
A bit of history.
Typically, in a widget program the kinds of things
you would put in a common block (or into an info
structure) are widget identifiers, data to display,
etc. If two programs use the same common block to
store this information, then the data, identifiers,
etc. of the first program is overwritten by the
second program and the first program doesn't work
anymore. So, we "protect" the common block by
making sure only one widget program can run at
any one time. (This is typically done with XREGISTERED.)
I have the same problem with MPI_PLOT. I want
to "overplot" on the plot displayed in the program
graphics window. Do do this, I have to know what
"data" is already in the window, and, in fact, which
window to draw into, etc. All of this information is
stored in an info pointer, that I placed in a common
block.
But, I realized this morning, if I could just substitute
one pointer for another, I could draw into any open MPI_PLOT
window I liked. But how to switch windows? Well, the window
I want to draw into is the one I have forward on my display,
the one I am *looking* at, the one I *selected* to draw into.
Bingo!
All I had to do was set the Keyboard Focus Events for the
top-level base, and when the keyboard focus changes load
the proper info pointer in the common block. Yikes! Now
I can overplot data into any window that I simply select
with my mouse.
I'm a convert. You are going to see common blocks
everywhere. :-)
Cheers,
David
P.S. Give me a half-hour or so to update the documentation
on this program and you can have a look yourself.
http://www.dfanning.com/programs/mpi_plot.zip
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|