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 #58951] Wed, 27 February 2008 07:56 Go to next 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:
>
>> So, I realise this is one of those pass-by-reference or pass-by-value things, but how does
>> one get around it? Do I:
>> a) make the Type component of the Cloud structure a pointer? (Yuk!)
>> b) change the way I pass the Cloud structure into the CRTM_Read_Cloud_Record() fn?
>> i.e. not reference the cloud structure array via the index [n].
>>
>> I would much prefer (b), but will that entail copying entire structures? The number of
>> "Clouds" associated with any particular "Atm[m]" profile is variable.
>
> Too much misdirection for me to follow this early in the morning,
> but if you pass a structure array in by reference, what are you
> copying?

Well I meant if I do this:

FOR n = 0, Atm.n_Clouds-1 DO BEGIN
; Need to store data into (*Atm.Cloud)[n]
result = CRTM_Read_Cloud_Record( FileID, Cloud, DEBUG=Debug )
...Copy Cloud into (*Atm.Cloud)[n]
ENDFOR

> I think you are only "copying" if you pass something in
> by value. I would go with (b).

I just completed an experiment where I passed the entire pointer array and looped over
clouds in my reader,

result = CRTM_Read_Cloud_Record( FileID, *Atm.Cloud, DEBUG=Debug )

since it was passing (*Atm.Cloud)[n] that was buggering me up.

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 understand why it's there, but even Fortran has moved beyond it (for about 18(!) years now).

cheers,

paulv
Re: How to get numbers into passed structure elements (pass-by-value/reference problem). [message #58955 is a reply to message #58951] Wed, 27 February 2008 07:25 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul van Delst writes:

> So, I realise this is one of those pass-by-reference or pass-by-value things, but how does
> one get around it? Do I:
> a) make the Type component of the Cloud structure a pointer? (Yuk!)
> b) change the way I pass the Cloud structure into the CRTM_Read_Cloud_Record() fn?
> i.e. not reference the cloud structure array via the index [n].
>
> I would much prefer (b), but will that entail copying entire structures? The number of
> "Clouds" associated with any particular "Atm[m]" profile is variable.

Too much misdirection for me to follow this early in the morning,
but if you pass a structure array in by reference, what are you
copying? I think you are only "copying" if you pass something in
by value. I would go with (b).

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 #59021 is a reply to message #58951] Thu, 28 February 2008 02:23 Go to previous message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
On 27 fév, 16:56, Paul van Delst <Paul.vanDe...@noaa.gov> wrote:
> David Fanning wrote:
>> Paul van Delst writes:
>
>>> So, I realise this is one of those pass-by-reference or pass-by-value things, but how does
>>> one get around it? Do I:
>>>    a) make the Type component of the Cloud structure a pointer? (Yuk!)
>>>    b) change the way I pass the Cloud structure into the CRTM_Read_Cloud_Record() fn?
>>>       i.e. not reference the cloud structure array via the index [n].
>
>>> I would much prefer (b), but will that entail copying entire structures? The number of
>>> "Clouds" associated with any particular "Atm[m]" profile is variable.
>
>> Too much misdirection for me to follow this early in the morning,
>> but if you pass a structure array in by reference, what are you
>> copying?
>
> Well I meant if I do this:
>
>    FOR n = 0, Atm.n_Clouds-1 DO BEGIN
>      ; Need to store data into (*Atm.Cloud)[n]
>      result = CRTM_Read_Cloud_Record( FileID, Cloud, DEBUG=Debug )
>      ...Copy Cloud into (*Atm.Cloud)[n]
>    ENDFOR
>
>> I think you are only "copying" if you pass something in
>> by value. I would go with (b).
>
> I just completed an experiment where I passed the entire pointer array and looped over
> clouds in my reader,
>
>    result = CRTM_Read_Cloud_Record( FileID, *Atm.Cloud, DEBUG=Debug )
>
> since it was passing (*Atm.Cloud)[n] that was buggering me up.
>
> 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 understand why it's there, but even Fortran has moved beyond it (for about 18(!) years now).
>
> cheers,
>
> paulv

Since IDL pointers point to variables which are global in scope and
IDL structures are
global too, I would suggest, in any of your function, to just pass a
pointer on the used instance
of CRTM_Atmosphere...
alx
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Inverse Map Projection Help
Next Topic: LOG AXIS, itools and tickmarks

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

Current Time: Wed Oct 08 13:54:59 PDT 2025

Total time taken to generate the page: 0.00740 seconds