Pointers and Heap Variables
IDL> p_1 = ptr_new(50.)
If you don't give value, the pointer will point to the special null_value, used for example to specify the end of a tree:
You can see the difference between the pointer and the heap_variable.
The <PtrHeapVar1> is the value of the pointer, and 50.0000 is the value of the heap_variable on which it points.
You can define pointers everywhere, also into structures. Here follows an example of defining a structure str1 containing, as a second tag, a pointer equal to the already defined p_1 pointer (that is, pointing on the same heap_variable).
You can access the value of the heap_variable in the same way as before, just putting a * in front of the name.
You can modify the value of the heap_variable, and of course all the pointers pointing on this variable will take this modification into account (The heap_variable is defined once, but you can define a lot of pointers pointing on it).
You can also define a pointer pointing on a structure, then you have to take care of the *s and brackets:
p_str1 = ptr_new(str1)
There are other functions to play with pointers, have a look at the man pages.
The pointers and the structures are an (best) alternative solution to common blocks. You just have to define a structure containing all the parameters you need in form of pointers, and pass it, as parameter, to the procedure. Contrary to the common blocks, where you cannot put the same variable into 2 or more commons, with the pointers, you can define a lot of structures corresponding to the set of variables you need for specific applications, and containing pointers to the same variables.
The pointers allow you to change dynamically the value or even the type/size of the variable on which the pointer is pointing.
See the David Fanning examples on widgets. Address in the reference page.
IDL courses C. Morisset © 2004 IA/UNAM V 2.2