
Return a complex variable help

BMangum
I thought I understood this, but I am having trouble somehow.
The real part works just fine, but the imaginary part is not being returned.
Any help with the code below would be appreciated.
FYI - I am using Igor Version 6.3.1.2 on Windows 7, maybe a bug?
#pragma rtGlobals=3 // Use modern global access method and strict wave access. Function tester(sam, bill) Variable sam Variable bill Variable/C dummy = cmplx(sam + 2, bill + 3) Return dummy End Function Check() Make/C/O/N = 100 wave0 Variable i for(i = 0; i < 100; i += 1) wave0[i] = tester(i, i*2) endfor End
April 9, 2013 at 05:58 pm - Permalink
April 10, 2013 at 06:28 am - Permalink
Thanks, this gets around having to mess with complex variables all together.
April 10, 2013 at 09:04 am - Permalink
April 10, 2013 at 09:06 am - Permalink
The typical syntax is something like {out_object1,out_object2, ...} = funcname(inobject1,inobject2,...)
where out_object1, etc. could be anything (variable, wave, string, structure,...) and {...} is a list
This gets around the whole dance of using complex numbers (which only works for 2 numerical variables), which is a bad kluge (only works in 1 case, uses complex numbers for things that have nothing to do with complex numbers, etc.). Using global variables is also a bad solution, as it is far too easy to lose track of such objects, to overwrite them inappropriately, etc.
Pass by reference is a slightly better method but still far inferior to the straightforward solution proposed above. The issues are that there is no distinction in the syntax of calling, etc. between the input and output objects, making it less clear and more prone to programming slip ups.
The proposed solution also gets around the problem of creating programmatic names (extracting the NameofWave, creating a wave using $(), then creating a wave reference) and
leads to much cleaner code. In other words, you could write
rather than
Sorry for the rant, but this is one area of Igor that badly needs improvement.
April 10, 2013 at 11:14 am - Permalink