[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

IDL Passing Constants to a Procedure

Posted on 2006-06-05
5
Medium Priority
?
267 Views
Last Modified: 2010-04-17
This has boggled my mind for quite some time. I have a short procedure that takes in four integers and performs some simple calculations with them. We'll call this procedure "buildProfile".

I have another procedure (generateSlice) that generates four numbers, with the objective of and passing them to buildProfile.

That procedure looks like this:

Pro generateSlice, x1, x2, y1, y2
firstPoint = fix(randomu(seed, 1) * 800)
secondPoint = fix(randomu(seed, 1) * 800)

    x1 = 0      ;Constants
    x2 = 799 ;Constants
    y1 = firstPoint
    y2 = secondPoint
endelse
end

So, if I call generateSlice, a, b, c, d, I get the numbers 0, 799, and two random integers between 0 and 799, assigned to the variables a, b, c, d respectively.

However, if I then call buildProfile, a, b, c, d, the procedure does not produce the expected result. However, if I were to call buildProfile, x1, x2, 580, 700 (replacing the last two variables with constant values of my own), it works perfectly fine. Is there any reason that assigning one variable to the value of another variable might cause problems in this context?

Thanks.

0
Comment
Question by:esotericlete
  • 3
5 Comments
 
LVL 27

Assisted Solution

by:Dabas
Dabas earned 1000 total points
ID: 16840178
What language?
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 1000 total points
ID: 16841390
Has this anything to do with passing by value and passing by reference?
0
 

Author Comment

by:esotericlete
ID: 16844838
The language is IDL, and I think it may have to do with passing by value and/or reference. I tried explicitly forcing it to pass both ways, and it doesn't seem to change anything. I suspect it has to do with the lines:

    x1 = 0      ;Constants
    x2 = 799 ;Constants
    y1 = firstPoint
    y2 = secondPoint

If I change 'firstPoint' and 'secondPoint' to constants, the procedure works fine, and the passed values work as expected.
0
 

Author Comment

by:esotericlete
ID: 16844846
Also, omit the "endelse" on the second to last line, I was cutting out irrelevant parts of the code, and forgot to remove that part.
0
 

Author Comment

by:esotericlete
ID: 16845608
I figured out the solution. The function fix() attempts to convert a set of objects into integers. If you only pass one object in, it will still convert it, but the result will be an array of dimension 1, rather than a scalar.

Because two of the variables are scalars, and two are arrays, IDL becomes confused, and tries to perform multiply the array by a scalar.

The solution is:

firstPoint = fix(randomu(seed, 1) * 800)
secondPoint = fix(randomu(seed, 1) * 800)
x1 = 0      ;Constants
x2 = 799 ;Constants
y1 = firstPoint[0]
y2 = secondPoint[0]

This way, we only assign the scalar value that is desired.

Thanks for leaving a comment.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Simple Linear Regression
Progress

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question