
function/wave and return

ChrLie
I wonder if there is a recommended procedure for the following case:
function main() wave w = sub() return sum(w) end function/wave sub() wave/Z WaveMayNotExist if(!WaveExists(WaveMayNotExist)) // this may also be another condition that causes the function to not run through // what's best to return now? A non-existing wave? Make/N=1 w=NaN; return w? return NaN endif Make/N=(numpnts(WaveMayNotExist)) output // more code return output end
Obviously "return NaN" is inconsistent with the function type although it compiles but gives an unexpected result (at least for me):
print main() 0
I would recommend to return
$""
this is an invalid wave reference. The code then bugs out at
Wave w = sub()
which is what you expect or?
August 27, 2019 at 08:40 am - Permalink
August 27, 2019 at 09:24 am - Permalink
In reply to Wave w = sub() if … by johnweeks
John, yes, main() should contain something like this but I was just puzzled what to return from sub() in case it aborts.
Thanks Thomas! That works for me and is what I was looking for!
Cheers
Christian
August 27, 2019 at 10:42 pm - Permalink
If the wave may not exist, you should use /Z, like this:
Without the /Z, if you are running with debugging enabled and "NVAR SVAR WAVE Checking" turned on, which is recommended during development, Igor will break into the debugger to let you know you are using a NULL wave reference.
With /Z, Igor will not break into the debugger, because /Z tells Igor "I know that this wave reference may be NULL".
For details, execute:
DisplayHelpTopic "Accessing Global Variables And Waves"
and especially the section "Runtime Lookup Failure".
August 29, 2019 at 01:26 pm - Permalink
Woops. I intended to include the /Z in my post above.
August 29, 2019 at 04:22 pm - Permalink