typestar

Cleaning up in Igor Pro

An experiment fills with scratch waves; the kill operations are how a script tidies after itself.

Function Cleanup(String prefix)
    String list = WaveList(prefix + "*", ";", "")
    Variable i, n = ItemsInList(list)

    for (i = 0; i < n; i += 1)
        WAVE/Z w = $StringFromList(i, list)
        if (WaveExists(w))
            KillWaves/Z w
        endif
    endfor

    KillDataFolder/Z root:Scratch
    Printf "cleaned %d waves\r", n
End

How it works

  1. KillWaves/Z ignores a wave that is in use or missing.
  2. KillDataFolder takes the whole folder and everything under it.
  3. A free wave needs none of this, which is the argument for using one.

Keywords and builtins used here

The run, in numbers

Lines
14
Characters to type
287
Tokens
74
Three-star pace
70 tpm

At the three-star pace of 70 tokens a minute, this run takes about 63 seconds.

Type this snippet

Step 4 of 4 in Waves, step 4 of 18 in Language basics.

← Previous Next →