XOP free wave question

Hi!

I am writing a XOP operation where I would like to create a temporary (i.e. free) WAVE which needs to be accessible from the calling user function in IGOR. It should work similar to local variables/strings but for WAVEs. Can somebody point me to the right direction how to proceed?

I already tried creating a free wave using MDMakeWave and the dataFolderHandle input parameter set to -1, but then I cannot access this free wave from inside the user function which called this custom XOP operation (I guess the free wave is killed after the operation finishes and thus never gets to the calling function in IGOR) ...

Thank you for your help!

Gregor
[Update: There is another more natural way to do this - see the next post]

The only way to pass a wave handle from an external operation back to the calling user-defined function is through a waveHndl field in a structure.

You need to declare a structure parameter in your operation template. You then need to define a structure in the procedure file, create an instance of it in the user-defined function, and pass the structure to the external operation as a parameter.

The external operation must set the waveHndl field in the structure and call HoldWave on it. When the external operation returns to the user-defined function, the function can access the wave through the waveHndl field.

When the function terminates, the instance of the structure goes out of scope and the wave referenced by the waveHndl field, if it is a free wave, should be automatically killed.

To learn about structures in procedures, execute:
DisplayHelpTopic "Structures In Functions"

To learn about structure parameters in external operations, see Structure Parameters in Chapter 5 of the XOP Toolkit manual.

A simpler alternative is to create a global (not free) wave in the current data folder with a specific wave name and have the user-defined function access it through a wave reference variable and then explicitly kill it.
On further review, there is another more natural way to return a free wave from an external operation. You add /DEST and /FREE flags to the operation template. When the caller uses /DEST=<destWave>, you call GetOperationDestWave which creates the destination wave and SetOperationWaveRef which creates a wave reference for the destination wave in the calling user-defined function.

For details, see DataFolderAndName Parameters in Chapter 5 of the XOP Toolkit manual. The subsection DataFolderAndName Destination Wave Example shows how to handle /DEST but does not include the code for creating a free wave. To create a free wave, add the /FREE flag and, if it is present, add the kOpDestWaveMakeFreeWave constant to the options variable before calling GetOperationDestWave.
Thanks a lot Howard for your help! I think I will implement your last suggestion.

Gregor

--
Gregor Kladnik
ALOISA beamline @ Elettra synchrotron