Optional and by-reference parameters in Igor Pro
Igor has no overloading; optional parameters and by-reference outputs do that work.
Function Stats(WAVE w, Variable &mean, Variable &sd)
WaveStats/Q w
mean = V_avg
sd = V_sdev
End
Function Report(WAVE w, [String title])
if (ParamIsDefault(title))
title = NameOfWave(w)
endif
Variable mean, sd
Stats(w, mean, sd)
Printf "%s: %g +/- %g\r", title, mean, sd
End
How it works
- Parameters in square brackets are optional;
ParamIsDefaulttells you. - An
¶meter is passed by reference, so the function can write to it. - That is how one call returns several numbers.
Keywords and builtins used here
EndFunctionNameOfWaveParamIsDefaultPrintfStringVariableWAVEWaveStatsendififmean
The run, in numbers
- Lines
- 15
- Characters to type
- 275
- Tokens
- 70
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 60 seconds.
Step 3 of 3 in Variables & functions, step 7 of 18 in Language basics.