Skip to main content

5.3) Single Variable Functions (cont'd)


Functions need to be complied before they can be used. You can compile the function using:

.compile rad_to_deg

You can then use the function as you would any built-in IDL function, either within another program or at the command line.

degrees = rad_to_deg(!pi/2.)

This will call the function using !pi/2. as the input to the function and store the output in the variables "degrees". Now try:

print, degrees

You should get the answer "90.0000".

If you save the function with the same filename (.pro) as the function, then providing the file is in the current working directory or in a directory listed in "!path", then there is no need to compile the function first, as IDL will find the file and compile it automatically when you use it.