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

Home » Public Forums » archive » Re: How to get numbers into passed structure elements (pass-by-value/reference problem).
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
Re: How to get numbers into passed structure elements (pass-by-value/reference problem). [message #58922] Thu, 28 February 2008 02:22 Go to next message
Wox is currently offline  Wox
Messages: 184
Registered: August 2006
Senior Member
On Wed, 27 Feb 2008 10:02:46 -0500, Paul van Delst
<Paul.vanDelst@noaa.gov> wrote:


> FUNCTION CRTM_Read_Atmosphere_Record, FileID , $ ; Input
> Atm , $ ; Output
> DEBUG=Debug ; Optional input
> .....
> FOR n = 0, Atm.n_Clouds-1 DO BEGIN
> result = CRTM_Read_Cloud_Record( FileID, (*Atm.Cloud)[n], DEBUG=Debug )
> ...check result....
> ENDFOR

So Atm.Cloud is a pointer to an array of structures. What if Atm.Cloud
would be a pointer to an array of pointers (each pointing to one
structure)? Than you could pass *(*Atm.Cloud)[n]

However, you would loose the ability to do something like this:
(*Atm.Cloud).Type to get all types of clouds.
Re: How to get numbers into passed structure elements (pass-by-value/reference problem). [message #59015 is a reply to message #58922] Thu, 28 February 2008 07:11 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> I find this equivalent to dynamic tying and structuring:

Whoops, should be "typing", of course.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to get numbers into passed structure elements (pass-by-value/reference problem). [message #59016 is a reply to message #58922] Thu, 28 February 2008 07:07 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul van Delst writes:

> I'll repeat my comment in my reply to David Fanning's post in this thread:
> I find it a fundamental flaw of IDL that the argument passing mechanism (reference
> or value) is so exposed to the user that they have to tailor their code to prevent
> data loss.

I find this equivalent to dynamic tying and structuring:
powerful, but dangerous. Like keeping a loaded 357 Magnum
in the drawer of the night stand. In the right hands ... etc.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to get numbers into passed structure elements (pass-by-value/reference problem). [message #59017 is a reply to message #58922] Thu, 28 February 2008 07:00 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Wox wrote:
> On Wed, 27 Feb 2008 10:02:46 -0500, Paul van Delst
> <Paul.vanDelst@noaa.gov> wrote:
>
>
>> FUNCTION CRTM_Read_Atmosphere_Record, FileID , $ ; Input
>> Atm , $ ; Output
>> DEBUG=Debug ; Optional input
>> .....
>> FOR n = 0, Atm.n_Clouds-1 DO BEGIN
>> result = CRTM_Read_Cloud_Record( FileID, (*Atm.Cloud)[n], DEBUG=Debug )
>> ...check result....
>> ENDFOR
>
> So Atm.Cloud is a pointer to an array of structures. What if Atm.Cloud
> would be a pointer to an array of pointers (each pointing to one
> structure)? Than you could pass *(*Atm.Cloud)[n]

Hello,

Yes, I could do that. I went with the "passing the entire array" approach (less pointers).

My goal was to replicate the functionality of my Fortran95 code: each little function
works just on a single structure. The "main" routine can pass in a scalar or rank-1 array
of the structures (I overloaded these such that the rank-1 form simply loops over the
elements and calls the scalar function).

It may sound complicated, but in execution it's quite simple and allows for easy unit
testing of the individual functions.

The complication with doing that in IDL is that when the actual argument to a function is
(*Atm.Cloud)[n]
and the dummmy argument is simply
Cloud
then this is sort-of (pointer components notwithstanding) equivalent to a "intent(in)"
attribute in Fortran95, i.e. you can pass it in, but you cannot modify the dummy argument
in the function.

This can be gotten around a number of ways in IDL (e.g. passing in all the elements,
*Atm.Cloud; or making it a pointer as you suggested) but the added complexity makes the
code harder to read and test. In a case like this where the structure components are a
mixture of pointer and "regular" variables, it certainly isn't intuitive. Well, it's not
to me, at least. :o)

I'll repeat my comment in my reply to David Fanning's post in this thread:
I find it a fundamental flaw of IDL that the argument passing mechanism (reference
or value) is so exposed to the user that they have to tailor their code to prevent
data loss.


cheers,

paulv


> However, you would loose the ability to do something like this:
> (*Atm.Cloud).Type to get all types of clouds.
>
>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: LOG AXIS, itools and tickmarks
Next Topic: How to get numbers into passed structure elements (pass-by-value/reference problem).

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

Current Time: Wed Oct 08 19:06:00 PDT 2025

Total time taken to generate the page: 0.00569 seconds