next up previous contents
Next: Adding ``stop'' Up: Lecture -1: A first Previous: Lecture -1: A first   Contents

Passing information into the the program - a parameter

Edit your hello_world.pro file so it contains

pro hello_world, number_questions
;+
;pro hello_world
;Procedure to print ``Hello world'' to screen then ask 'Anyone there?'
;number_questions  times.
;Parameters:  number_questions - integer number of times to ask 'anyone there?'
;Keywords: none
;John Marsham, (01/11/06)
;-

print,'Hello world' ;print the line ''Hello world'' to screen

for i=1,number_questions do begin
 print,'Anyone there?'
endfor

end

Type

.compile hello_world
(otherwise IDL will just use the old version), then
hello_world,3
We are passing in the integer value 3 into the procedure, so it repeats `'Anyone there?'' there three times. number_questions is a parameter of the procedure hello_world (Note that the order that parameters are listed it matters).

Note print is a procedure built into idl. We have just passed it one parameter each time - what we want to print to the screen. He have just made another procedure that isn't built into IDL - hello_world.pro

Also note you could also use,

n_times=3
hello_world,n_times
to do exactly the same thing.



lecjm 2008-11-06