Wave dependency in user-defined functions

euaruksakul
Posts: 12
Joined: 2015-01-26
Location: United Kingdom

I try to use wave dependency in my function so that when Wave1 is changed, Wave2 will be updated automatically.

Function Dependency_test1()
	make /O/N=5 wave1
	wave1={1,2,3,4,5}
	make /O /N=5 wave2
	wave2:=wave1
End

but always get an error "Can't use local variables in dependency formula" during compile.

This seems to work in the command line. I am not sure what I am doing wrong?

Thank you!


KurtB
Posts: 145
Joined: 2013-01-16
Location: United Kingdom

This appears to work:

Function Dependency_test1()
	make /O/N=5 wave1
	wave1={1,2,3,4,5}
	make /O /N=5 wave2
	SetFormula wave2,  "wave1"
End

When I use Edit root:wave1,root:wave2 I can change values in wave1 and those in wave2 change automagically.

Hope this helps,
Kurt


euaruksakul
Posts: 12
Joined: 2015-01-26
Location: United Kingdom

SetFormula does the trick. Thank you!


Posts: 1966
Joined: 2007-06-29
Location: United States

To be fully safe with liberal names and data folders, you need to do something like this:

Function Dependency_test1()
 
// stupid example to make this point...
	String wname = "liberal name for my wave"
	make /O/N=5 $wname
	WAVE wave1 = $wname
	wave1={1,2,3,4,5}
 
// now create the dependency
	make /O /N=5 wave2
	String wave1name = GetWavesDataFolder(wave1, 2)
	SetFormula wave2, wave1name
End

If you now run this function, then go to Misc->Object Status you will see that wave2 depends on wave1 via this formula: "root:'liberal name for my wave'". Note the data folder path, and special quoting for the liberal name.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com


Back to top