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
KillWaves/Zignores a wave that is in use or missing.KillDataFoldertakes the whole folder and everything under it.- A free wave needs none of this, which is the argument for using one.
Keywords and builtins used here
EndFunctionItemsInListKillDataFolderKillWavesPrintfStringVariableWAVEWaveExistsWaveListendforendifforiif
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.
Step 4 of 4 in Waves, step 4 of 18 in Language basics.