multidimensional Wave

Hi,

I have written a function ('savings') which calls my other function ('four_elec') for many times (say 9 times). The purpose of writing the function 'Savings' is to call the function 'four_elec' and saves the returning waves of that into a multidimensional wave for further use. Each time that 'four_elec' is called returns some completely NEW waves.
The function 'four_elec' is working great by itself. However, I am having hard time to save the waves in into a new multidimensional wave. Would appreciate if you advise me how to do that. hereunder you may find my code. Thanks.


#pragma rtGlobals=1 // Use modern global access method and strict wave access.
function savings (npart,niter,l,el)
Variable npart // number of par
Variable niter // number of iteration
Variable l // dimension
Variable el // size
make /n=(npart,9) /o alleq1, alleq2, alleq3,alleq4
Make /n=(npart) /o eq1,eq2,eq3,eq4
Variable k,h,z
z=0
for (k=-1;k<=1;k+=1)
for (h=-1;h<=1;h+=1)
four_elec (npart,niter,l,el,h,k)
alleq1[ ] [z]=eq1
alleq2[ ] [z]=eq2
alleq3[ ] [z]=eq3
alleq4[ ] [z]=eq4
z+=1
endfor
endfor
end

function four_elec (npart,niter,l,el,x0,y0)
Variable npart // number of par
Variable niter // number of iteration (usec)
Variable l // dimensions
Variable el // size
Variable x0,y0 //initial position in x,y
Variable D = 8e-5 // coef
Variable std = sqrt(2*D) // std
Variable xval, yval
Variable genx,geny

Make /n=(npart) /o eq1,eq2,eq3,eq4,knum

Variable i,j
for ( j=1; j<=npart; j+=1)
i=0
xval = x0
yval = y0

do
genx = gnoise(std)
geny = gnoise(std)
xval += genx
yval += geny
i+=1
if (xval<-l || xval>l ||yval<-l || yval>l)
xval-=genx
yval-=geny
i-=1
knum[j]+=1
endif
while((i-l+el || yval>-l+el)&& (xval-l+el) && (xval-l+el || yval if (xval<=-l+el && yval<=-l+el)
eq1[ j]=i
elseif (xval>=l-el && yval<=-l+el)
eq2[ j]=i
elseif (xval>=l-el && yval>=l-el)
eq3[ j]=i
elseif (xval<=-l+el && yval>=l-el)
eq4[ j]=i
endif

endfor

return eq1
return eq2
return eq3
return eq4

end
You are using eq1, eq2, eq3 and eq4 as temporary waves to convey data from four_elec to the calling routine, savings.

Since four_elec makes eq1, eq2, eq3 and eq4, there is no need for savings to make these waves so you can remove that Make command.

After calling four_elec you can create wave references pointing to eq1, eq2, eq3 and eq4, like this:

	...
	four_elec (npart,niter,l,el,h,k)	// This makes eq1, eq2, eq3 and eq4
	// Create wave references to access eq1, eq2, eq3 and eq4 in this function
	Wave eq1, eq2, eq3, eq4
	alleq1[ ] [z]=eq1
	alleq2[ ] [z]=eq2
	alleq3[ ] [z]=eq3
	alleq4[ ] [z]=eq4
	...


To read about wave references execute this:
DisplayHelpTopic "Wave References"

It is also a good idea to read the rest of the Programming help file or the equivalent chapters in the PDF manual starting with Volume IV chapters 1 through 5.