Dear tb6pham,
The problem here is that you are running the looping index one more element than it should be. Basically, the following code will run correctly:
FUNCTION GetInput, myArray, nElements
myArray=MAKE_ARRAY(nElements,/INTEGER ,value=0)
FOR i=0, nElements-1 DO BEGIN
READ, myArray[i]
ENDFOR
T = myArray
RETURN, T
END
PRO Display
T=getInput(myArray,5)
FOR i=0,4 DO BEGIN
PRINT, T[i]
ENDFOR
END
You can see here that the index in the loop in the procedure "Display" and in the function "GetInput" runs now one less element.
In the calling procedure:
FOR i=0,4 DO BEGIN ...
and in the function:
FOR i=0, nElements-1 DO BEGIN ...
That was the problem.
Let me know if you need anything else.
Cheers,
Fernando
|