typestar

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

  1. Parameters in square brackets are optional; ParamIsDefault tells you.
  2. An & parameter is passed by reference, so the function can write to it.
  3. That is how one call returns several numbers.

Keywords and builtins used here

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.

Type this snippet

Step 3 of 3 in Variables & functions, step 7 of 18 in Language basics.

← Previous Next →