same string and wave name in function

Function diurnal_hr()
variable i
wave d_int
string word = "diurnal_"
for(i=0;i<24;i+=1)
string di = word + num2str(i)
Make/ N = 974 $di
$di = d_int[p*24+i]
endfor
End

This is my function. I tried to separate the wave d_int into 24 waves. However, the wave name is in form of string. So when i compile, the 8th line, "$di = d_int[p*24+i]", was error.

Thanks so much
nicha wrote: However, the wave name is in form of string. So when i compile, the 8th line, "$di = d_int[p*24+i]", was error.


You have to use a wave reference here:
Function diurnal_hr()
	variable i
	wave d_int
	string word = "diurnal_"
	for(i=0;i<24;i+=1)
		string di = word + num2str(i)
		Make/N = 974 $di
		wave ww = $di
		ww = d_int[p*24+i]
	endfor
End

A.
And if you're using 6.12 or later (I think that's when this feature was added) you can combine the WAVE declaration with the Make command:

Function diurnal_hr()
	variable i
	wave d_int
	string word = "diurnal_"
	for(i=0;i<24;i+=1)
		string di = word + num2str(i)
		Make/N = 974 $di/WAVE=ww
		ww = d_int[p*24+i]
	endfor
End


John Weeks
WaveMetrics, Inc.
support@wavemetrics.com