[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
Medium Priority
267 Views
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
Question by:esotericlete
• 3

LVL 27

Assisted Solution

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

LVL 65

Accepted Solution

ID: 16841390
Has this anything to do with passing by value and passing by reference?
0

Author Comment

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

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

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

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
###### Suggested Courses
Course of the Month18 days, 14 hours left to enroll