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

Home » Public Forums » archive » Very basic IDL vector question
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
Very basic IDL vector question [message #93148] Mon, 02 May 2016 23:27 Go to next message
kubota is currently offline  kubota
Messages: 5
Registered: May 2016
Junior Member
I am trying to understand the operation of an IDL program. There are several lines using vectors which I do not understand.

The first line is:

fc = call_function(fun,xc)

Here, xc is a vector.

Is fc a scalar or vector, being that xc is a vector?
If fc is a scalar, which element of xc is being used for the function calculation?
If fc is a vector, does that mean that the vector fc is filled with all the function evaluations of the x values in xc?

Thanks for any assistance.
Re: Very basic IDL vector question [message #93150 is a reply to message #93148] Tue, 03 May 2016 01:35 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Tuesday, May 3, 2016 at 7:27:53 AM UTC+1, kubota wrote:
> I am trying to understand the operation of an IDL program. There are several lines using vectors which I do not understand.
>
> The first line is:
>
> fc = call_function(fun,xc)
>
> Here, xc is a vector.
>
> Is fc a scalar or vector, being that xc is a vector?
> If fc is a scalar, which element of xc is being used for the function calculation?
> If fc is a vector, does that mean that the vector fc is filled with all the function evaluations of the x values in xc?
>
> Thanks for any assistance.

Hi,
the call_function() function calls a function called with the name of your string (I suppose) "fun" and passes xc as a parameter. The return value of the function will be put into fc.

Consider these two functions:

function testTotal, arr
return, total(arr)
end

function testDouble, arr
return, arr*2
end

If you now call:
fun = 'testTotal'
xc = findgen(10)
fc = call_function(fun,xc)

then you will get a single value (scalar) in fc equal to the total of xc (in this case 45.0).
If you call:

fun = 'testDouble'
xc = findgen(10)
fc = call_function(fun,xc)

Then in fc you get an array:
IDL> print, fc
0.000000 2.00000 4.00000 6.00000 8.00000 10.0000 12.0000 14.0000 16.0000 18.0000

I hope it helps.

Cheers,
Helder
Re: Very basic IDL vector question [message #93153 is a reply to message #93148] Tue, 03 May 2016 05:08 Go to previous messageGo to next message
kubota is currently offline  kubota
Messages: 5
Registered: May 2016
Junior Member
Hi Helder, you've made the two possible answers for fc (scalar or vector) very clear by your two examples. Thank you.

Continuing on, if the two function calls were, for some reason, called in reverse order, with the testDouble call done first, then fc will become an array with values, 0, 2, 4,.. 18.
If we then call testTotal with the same xc values (0 to 9), how does fc deal with the scalar result given that it is (currently) an array? Does fc change from an array to a scalar, with the result 45? If so, I presume all the previous (0,2,4, .. 18) 10 array values are lost at that moment?

Thanks again.
Re: Very basic IDL vector question [message #93154 is a reply to message #93153] Tue, 03 May 2016 05:32 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Tuesday, May 3, 2016 at 1:08:11 PM UTC+1, kubota wrote:
> Hi Helder, you've made the two possible answers for fc (scalar or vector) very clear by your two examples. Thank you.
>
> Continuing on, if the two function calls were, for some reason, called in reverse order, with the testDouble call done first, then fc will become an array with values, 0, 2, 4,.. 18.
> If we then call testTotal with the same xc values (0 to 9), how does fc deal with the scalar result given that it is (currently) an array? Does fc change from an array to a scalar, with the result 45? If so, I presume all the previous (0,2,4, .. 18) 10 array values are lost at that moment?
>
> Thanks again.

I think that the question you're asking is "is the parameter xc passed by reference or value?"
What this asks is if the function you're calling will in the process affect the original data contained in xc (passed by reference) or not (passed by value).

Have a look at this article for clarification:
http://www.harrisgeospatial.com/docs/parameter_passing_mecha n.html

If you're unsure, test like this:

fun = 'testTotal'
xc = findgen(10)
print, 'before', xc
fc = call_function(fun,xc)
print, 'after', xc

of course for both functions.

Cheers,
Helder
Re: Very basic IDL vector question [message #93156 is a reply to message #93148] Tue, 03 May 2016 06:22 Go to previous message
kubota is currently offline  kubota
Messages: 5
Registered: May 2016
Junior Member
My intention is to maintain xc, a 10 element array (0 to 9), with the 10 values of 0,1,2,..9.
Then by calling testDouble, fc becomes a 10 element array (0 to 9) with the 10 values of 0,2,4,6, .. 18 as before.
Now a call is made to testTotal using the same xc values as above. What is the resulting (new) state of fc? Does fc change from being a 10-element array to a scalar (45)? I presume the xc values will not be affected by these two calls.
With my thanks
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Help - IDL Basic Question
Next Topic: syntax for calling parent class _overloadPlus method

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

Current Time: Wed Oct 08 13:38:01 PDT 2025

Total time taken to generate the page: 0.00620 seconds