Wave Reference Review

Wave statements are used in user-defined functions. They look like this:
Wave w = wave0
Wave w = root:wave0
String name = "wave0"
Wave w = $name


Once you have a wave reference you can act on the referenced wave. For example:
w += 1              // Add 1 to each point
Display w           // Display in graph
Variable avg = mean(w)      // Use in arithmetic expression


Wave references do three things:

1. Tell Igor that a symbol (w in this case) refers to a wave rather than some other object (global numeric variable, global string variable or data folder)

2. Tell Igor the type of the referenced wave (/T for text, /C for complex, no flags for real)

3. Set the reference (w) to the address in memory of the specified wave

Items 1 and 2 occur at compile time, when the function is compiled. They give the Igor compiler the information it needs to compile the function.

Item 3 occurs at runtime, when the function executes. It is called "runtime lookup" and is needed so that the compiled code can access the specified wave.

NOTE: In order for item 3 to work, the wave must exist at the point that the wave statement occurs.

WRONG
String name = "wave0"
Wave w = $name      // Wrong - wave does not yet exist
Make $name


RIGHT
String name = "wave0"
Make $name
Wave w = $name      // Right - wave exists so Igor can store its address in w


One more twist...

In a Make or Duplicate statement, if the destination is a simple name then Igor automatically creates a wave reference:

Make wave0          // Make automatically creates a wave reference named wave0
Make root:wave0         // No automatic wave reference is created
String name = "wave0"
Make $name          // No automatic wave reference is created


For more execute:
DisplayHelpTopic "Accessing Global Variables And Waves"
DisplayHelpTopic "Wave References"