comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » IDL objects (not object graphics) tutorial?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
IDL objects (not object graphics) tutorial? [message #46457] Wed, 23 November 2005 18:33 Go to next message
Richard French is currently offline  Richard French
Messages: 173
Registered: December 2000
Senior Member
I'd like to learn how to make use of IDL objects. I'm not ready for object
graphics yet, because I'd like to understand INITS and SELF and classes and
methods before worrying about viewports and plots disappearing because I am
not using the correct projection scheme. I've scoured the web in vain
looking for a simple tutorial on how and when to use objects in IDL. I've
found a few generic tutorials praising the virtues of object-oriented
programming, but almost none of the examples give me any sense of why one
would go to the trouble. For example, one tutorial describes an object that
can return constants such as the speed of light or Planck's constant, but it
isn't obvious to me why this is superior to a simple function that returns
clight() or PlancksConst().

What I am looking for is something with a simple application or two in which
it is both clear why using objects is superior AND which explains what is
meant by self and methods and classes. Without some specific examples to
look at, I am having a hard time making sense of the nomenclature or of the
value of the approach.

This is prompted in part by David's nifty little pixmap object that I've
already made use of in a new program - thanks, David.

Someone must be out there just waiting to get rich writing a book on this
topic. The second volume can be about object graphics - I'd settle for the
first volume for now - a gentle introduction to objects in IDL. Any
suggestions? Thanks!

Dick French
Re: IDL objects (not object graphics) tutorial? [message #46546 is a reply to message #46457] Thu, 24 November 2005 01:04 Go to previous messageGo to next message
b_gom is currently offline  b_gom
Messages: 105
Registered: April 2003
Senior Member
Hi Richard,

Not knowing what your background is, I'll aim low..


Richard G. French wrote:

> I've scoured the web in vain
> looking for a simple tutorial on how and when to use objects in IDL. I've
> found a few generic tutorials praising the virtues of object-oriented
> programming, but almost none of the examples give me any sense of why one
> would go to the trouble.

'How' is covered reasonably well in the IDL manuals. 'When' is another
question altogether.


> What I am looking for is something with a simple application or two in which
> it is both clear why using objects is superior AND which explains what is
> meant by self and methods and classes. Without some specific examples to
> look at, I am having a hard time making sense of the nomenclature or of the
> value of the approach.

Let me try to summarize in a simple-mined, 1:00 AM kind of way:

Think of what problem you want to solve. If it is something like
'calculate such-and-such' or 'perform operation X on an array', then
you probably want a simple function of procedure. If you can think of
your problem as if it were some sort of abstracted machine or 'object'
(like a kitchen appliance or a tree or something), then you probably
want to make an Object.

Most IDL widget applications fall into the latter category. Although
they can almost always be written using non-OOP techniques, there are
often times when the little extra effort to write them as objects pays
off. It's hard to actually get a feel for this without trying both
techniques first.

Here are two excercises that should illustrate some advantages of OOP:

Q) write a program that acts like a stack of 'things', where a thing is
any IDL variable or type. The program should allow you to add things to
the stack, pop them off the stack, tell you how many things are on the
stack, etc. Also you need to be able to have multiple different stacks
of things all co-existing at the same time.

A) Look at the 'linkedlist' object on David Fannings webpage for an
object-oriented solution. If you come up with a non-object-oriented
solution, let me know.

Q) write a program that acts like a dynamic plot of some data. You need
to be able to add lines to the plot, remove them, zoom, change colors,
annotate, etc, and all interactively at run-time. Also, your program
needs to be simple enough so that other people can call it from their
program with a few simple lines of code, and have serveral plots open
at one time.

A) Try the non-OOP approach for 15 minutes, then look at David's site.
There's probably an object there that has most of what you need, and in
15 minutes you can probably add on a few custom methods to extend the
functionality to do the rest. Chances are, after a few years, you'll
still be adding features to your object and it will do just about
everything you can think of. But, here's the key: after all these
changes, the other programs you wrote that call the object years ago
will still work, and you or others will still be able to extend the
object further or adapt it for other uses.


> Someone must be out there just waiting to get rich writing a book on this
> topic.

Back in 1999, a good general introduction to OOP was being written up.
It's now available here:
http://mindview.net/Books/TICPP/ThinkingInCPP2e.html
This is for C++, but the general principles apply to IDL.


Brad
Re: IDL objects (not object graphics) tutorial? [message #46611 is a reply to message #46457] Fri, 02 December 2005 08:30 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
David Fanning wrote:
> Paul Van Delst writes:
>
>
>> Your webpage is great! The one new thing I learned:
>>
>> self.ptr=ptr_new(/allocate)
>>
>> can be used to subsequently point to anything without further allocation!? E.g. from your
>> tutorial:
>>
>> a->set,image
>> or
>> a->set,!d
>>
>> where in the set method, the value is simply assigned:
>> *(self.ptr)=value
>>
>> Excuse my brain-deadedness, but how is this possible? I looked at the IDL docs but there
>> is (surprise, surprise) no elaboration about this little nugget of information regarding
>> PTR_NEW. Wouldn't susbsequent calls like the above cause a memory leak, e.g.
>>
>> IDL> image=findgen(512,512)
>> IDL> a=obj_new('data') ;-- create object variable a
>> IDL> a->set,image ;-- insert image
>> IDL> a->set,!d
>>
>> What would happen to the "image" data?
>
>
> The deep answers are all contained in the Pointer Tutorial:
>
> http://www.dfanning.com/misc_tips/pointers.html

Ahhh! It's just like a regular IDL variable. D'oh! - now why didn't assume that to be the
case in the first place?!

Very cool. I was treating this sort of thing like I do in Fortran95 where the pointers are
typed (i.e. they can only point to certain data types, kinds, and ranks) and that leads to
a lot of code bloat.

This changes everything. <monty>Excellent</monty> :o)

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Re: IDL objects (not object graphics) tutorial? [message #46612 is a reply to message #46457] Fri, 02 December 2005 08:11 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul Van Delst writes:

> Your webpage is great! The one new thing I learned:
>
> self.ptr=ptr_new(/allocate)
>
> can be used to subsequently point to anything without further allocation!? E.g. from your
> tutorial:
>
> a->set,image
> or
> a->set,!d
>
> where in the set method, the value is simply assigned:
> *(self.ptr)=value
>
> Excuse my brain-deadedness, but how is this possible? I looked at the IDL docs but there
> is (surprise, surprise) no elaboration about this little nugget of information regarding
> PTR_NEW. Wouldn't susbsequent calls like the above cause a memory leak, e.g.
>
> IDL> image=findgen(512,512)
> IDL> a=obj_new('data') ;-- create object variable a
> IDL> a->set,image ;-- insert image
> IDL> a->set,!d
>
> What would happen to the "image" data?

The deep answers are all contained in the Pointer Tutorial:

http://www.dfanning.com/misc_tips/pointers.html

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: IDL objects (not object graphics) tutorial? [message #46614 is a reply to message #46457] Fri, 02 December 2005 07:46 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
dzarro@yahoo.com wrote:
> Hi,
>
> I have a tutorial at http://orpheus.nascom.nasa.gov/~zarro/idl/objects
> that I developed at NASA/GSFC.

Your webpage is great! The one new thing I learned:

self.ptr=ptr_new(/allocate)

can be used to subsequently point to anything without further allocation!? E.g. from your
tutorial:

a->set,image
or
a->set,!d

where in the set method, the value is simply assigned:
*(self.ptr)=value

Excuse my brain-deadedness, but how is this possible? I looked at the IDL docs but there
is (surprise, surprise) no elaboration about this little nugget of information regarding
PTR_NEW. Wouldn't susbsequent calls like the above cause a memory leak, e.g.

IDL> image=findgen(512,512)
IDL> a=obj_new('data') ;-- create object variable a
IDL> a->set,image ;-- insert image
IDL> a->set,!d

What would happen to the "image" data?

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Re: IDL objects (not object graphics) tutorial? [message #46628 is a reply to message #46457] Wed, 30 November 2005 18:36 Go to previous message
Richard French is currently offline  Richard French
Messages: 173
Registered: December 2000
Senior Member
On 11/29/05 11:20 PM, in article
1133324446.805496.278980@g44g2000cwa.googlegroups.com, "dzarro@yahoo.com"
<dzarro@yahoo.com> wrote:

> Hi,
>
> I have a tutorial at http://orpheus.nascom.nasa.gov/~zarro/idl/objects
> that I developed at NASA/GSFC.
>
> Dominic
>
>


Thanks very much, Dominic! I think I'll be able to make use of pieces of
your OO routines in a new image analysis program I'm working on.
Dick
Re: IDL objects (not object graphics) tutorial? [message #46645 is a reply to message #46457] Tue, 29 November 2005 20:20 Go to previous message
dzarro is currently offline  dzarro
Messages: 1
Registered: November 2005
Junior Member
Hi,

I have a tutorial at http://orpheus.nascom.nasa.gov/~zarro/idl/objects
that I developed at NASA/GSFC.

Dominic



Richard G. French wrote:
> I'd like to learn how to make use of IDL objects. I'm not ready for object
> graphics yet, because I'd like to understand INITS and SELF and classes and
> methods before worrying about viewports and plots disappearing because I am
> not using the correct projection scheme. I've scoured the web in vain
> looking for a simple tutorial on how and when to use objects in IDL. I've
> found a few generic tutorials praising the virtues of object-oriented
> programming, but almost none of the examples give me any sense of why one
> would go to the trouble. For example, one tutorial describes an object that
> can return constants such as the speed of light or Planck's constant, but it
> isn't obvious to me why this is superior to a simple function that returns
> clight() or PlancksConst().
>
> What I am looking for is something with a simple application or two in which
> it is both clear why using objects is superior AND which explains what is
> meant by self and methods and classes. Without some specific examples to
> look at, I am having a hard time making sense of the nomenclature or of the
> value of the approach.
>
> This is prompted in part by David's nifty little pixmap object that I've
> already made use of in a new program - thanks, David.
>
> Someone must be out there just waiting to get rich writing a book on this
> topic. The second volume can be about object graphics - I'd settle for the
> first volume for now - a gentle introduction to objects in IDL. Any
> suggestions? Thanks!
>
> Dick French
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: map_proj_inverse and map_proj_init IDL 6.2
Next Topic: Data General Floating Point format?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:34:50 PDT 2025

Total time taken to generate the page: 0.00747 seconds