Printing difference of two waves
I have two waves a,b. I want to print their difference. In other scripting languages (Python, IDL) I can say: print a - b. In Igor I need
<br />
Make /N=(10) diff = a[p] - b[p] // need to know the number of elements, Make diff = a[p] - b[p] is not good enough<br />
print diff<br />
Really?
UHe
printoperation.In any computation (programming language) something has to store the result of an operation, even if it appears as temporary or "anonymous", like so (executed at the command line):
That being said there is something inconsistent for me going on here and it may be related. Take for example the following code:
Regardless if executed in a function or at the command prompt, the following will give an error:
print diff_wave(a,b)(provided,aandbexist in the global scope when executing from the command prompt).While the
test_print()function prints the difference correctly:'_free_'[0]= {-1,-1,-1}Why can't
printtake directly the wave reference fromdiff_wave()but needs a specially defined reference as inwave c = diff_wave(a,b)?best,
_sk
March 15, 2018 at 09:50 am - Permalink
UHe
March 17, 2018 at 10:56 am - Permalink
Why can't
printtake directly the wave reference fromdiff_wave()but needs a specially defined reference as inwave c = diff_wave(a,b)?_sk[/quote]
The free wave expires outside of the function runtime context. That is, once it hits the command line, it has already been disposed.
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
March 17, 2018 at 12:22 pm - Permalink
Why can't
printtake directly the wave reference fromdiff_wave()but needs a specially defined reference as inwave c = diff_wave(a,b)?_sk[/quote]
The free wave expires outside of the function runtime context. That is, once it hits the command line, it has already been disposed.
[/quote]
I'm not sure this really answers the question.
I'd say in general that print needs a wave reference and not a function returning a wave.
If you only index a single point from the wave
print GetWave()[0]then it compiles and does what you expect.March 17, 2018 at 03:05 pm - Permalink
I'm not sure this really answers the question.
I'd say in general that print needs a wave reference and not a function returning a wave.
[/quote]
I was under the impression that
function/wavereturns a wave reference and not a wave; in other words, there is no copy.But what you point out is correct. If print gets a single value then it chugs through it.
[quote=JimProuty]
The free wave expires outside of the function runtime context. That is, once it hits the command line, it has already been disposed.
[/quote]
Even if the
/freeinmatrixopis removed (in other words,resis not cleared upon exiting thediff_wavescope) the code below still fails.While we are at it, why doesn't the following work?
While this does work:
best,
_sk
March 18, 2018 at 03:31 pm - Permalink
I'm not sure this really answers the question.
I'd say in general that print needs a wave reference and not a function returning a wave.
[/quote]
I was under the impression that
function/wavereturns a wave reference and not a wave; in other words, there is no copy.[/quote]
Sorry my wording was inaccurate. It should have been "print needs a wave reference and not a function returning a wave reference".
March 20, 2018 at 11:44 am - Permalink
I'm not sure this really answers the question.
I'd say in general that print needs a wave reference and not a function returning a wave.
[/quote]
I was under the impression that
function/wavereturns a wave reference and not a wave; in other words, there is no copy.[/quote]
Sorry my wording was inaccurate. It should have been "print needs a wave reference and not a function returning a wave reference".[/quote]
A function returning a wave reference should be equivalent to a wave reference, otherwise composability breaks. I think the reason for the error is that
print,makeneed the whole data and not a pointer to the whole data, whileduplicateapparently doesn't.These inconsistencies in operations and functions throughout Igor are a sign of evolution and cruft accumulation through the years but, overall, contribute in a negative manner to the use of the environment as a whole.
best,
_sk
March 21, 2018 at 02:33 am - Permalink
This will print to the history the difference between tokens 'a' and 'b' but it will not leave behind a wave 'ff'. If you need to use ff for some later computation you can execute:
More details (especially about /P=2) will be provided in subsequent documentation.
A.G.
WaveMetrics, Inc.
March 21, 2018 at 03:10 pm - Permalink