A question about subrange notation of wave

I am wondering whether the subrange notation of wave can be regarded as a new wave? I mean whether like testwave[][1] can be regarded as a new 1D wave and directly used in functions and operations. I know some operation like FuncFit can support subrage notation but not universal, right? I am also wondering whether it is possible to assign a wave reference to a portion of an existing wave like:

Wave test=wave_existed[][1]

I hope to find some ways to avoid large amount of wave duplicating and making waves in my program. Any suggestion or comment is truly appreciated.
With some exceptions like MatrixOp, you cannot use subrange notation directly. However, as of Igor 6.1 you can create a function which returns wave references. Thus, you can create a function like this:

function /wave column(w,n)
  wave w
  variable n // column number
  matrixop /free myColumn=col(w,n)
  return myColumn
end


Then, when you want to access as single column, you can simply replace any wave named "wave_existed" with column(wave_existed,n), to operate on the Nth column of that wave. Similarly, you can create a wave reference:
wave test=column(wave_existed,1)


Note that if you want to create a permanent instance of that new wave, e.g. for graphing purposes, replace "matrixop /free" with "matrixop /o" in the function definition so that it creates a non-free, global wave instead. For intermediate operations though, free waves work nicely and are automatically disposed of when they are no longer in use. Using functions like the one written above, you can access arbitrary pieces or modifications of waves for use in single line commands.

Rick
Dear Rick,

Thanks for your valuable suggestions. I would try your idea.

Yu-Hung
Dear Rick,

I tried to follow the statements of matrixop and free wave in the manual and had some questions about them. First, it looks like matrixop still duplicate the wave according to Igor manual V-366, right? Secondly, could I expect free wave as some normal wave but it is hidden by Igor and it would be automatically discarded by Igor when the function is done?

I am also wondering whether Igor support C-like pointer in its programming language.

Yu-Hung Lien
YHLien wrote:
I tried to follow the statements of matrixop and free wave in the manual and had some questions about them. First, it looks like matrixop still duplicate the wave according to Igor manual V-366, right? Secondly, could I expect free wave as some normal wave but it is hidden by Igor and it would be automatically discarded by Igor when the function is done?
Yu-Hung Lien


I'm not sure if the manual is as up-to-date as my suggestion. If you use MatrixOp or MatrixOp /o, you will get a new, global wave, visible in the data browser. If you use MatrixOp /free, you will get a free wave, invisible, unplottable, and usable only within the function or in any functions to which it is returned. Either way, it takes up memory, but for a free wave, that memory is freed, and the wave disposed, when it is no longer needed. One of the Igor programmers might be able to tell you when exactly the memory is truly freed.

YHLien wrote:
I am also wondering whether Igor support C-like pointer in its programming language.

All waves are passed by reference, so when you pass a wave as an argument to a function, it is like passing a pointer to the wave. Variable and strings are passed by value by default, but you can pass them by reference instead if you put a & symbol in front of the variable name in its declaration at the beginning of the function, e.g.:
function smith(var1)
  variable &var1
end

Also, data folder references (dfref) are passed by reference. Other than that, the only other concept of pointers in Igor is waves of wave references (or waves of data folder references); you can make a wave that contains references to other waves, using Make /wave, or references to data folders using Make /df. All of this is Igor >= 6.1, preferably the latest version.

Rick
You can also have pass-by-reference function input parameters. Not like a C pointer that can be used to iterate through memory, but at least you can set the value of the variable and have the changed value passed back to the calling function.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com