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.

<br />
#pragma rtGlobals=1     // Use modern global access method and strict wave access.<br />
function savings (npart,niter,l,el)<br />
Variable npart  // number of par<br />
Variable niter   // number of iteration<br />
Variable l // dimension<br />
Variable el // size <br />
make /n=(npart,9) /o alleq1, alleq2, alleq3,alleq4<br />
Make /n=(npart) /o eq1,eq2,eq3,eq4<br />
Variable k,h,z<br />
z=0<br />
 for (k=-1;k<=1;k+=1)<br />
    for (h=-1;h<=1;h+=1)<br />
    four_elec (npart,niter,l,el,h,k)<br />
alleq1[ ] [z]=eq1<br />
alleq2[ ] [z]=eq2<br />
alleq3[ ] [z]=eq3<br />
alleq4[ ] [z]=eq4<br />
z+=1<br />
    endfor<br />
 endfor<br />
end<br />
 <br />
function four_elec (npart,niter,l,el,x0,y0)<br />
Variable npart  // number of par<br />
Variable niter   // number of iteration (usec)<br />
Variable l // dimensions <br />
Variable el // size <br />
Variable x0,y0  //initial position in x,y<br />
Variable D = 8e-5   // coef <br />
Variable std = sqrt(2*D)  // std<br />
Variable xval, yval<br />
Variable genx,geny<br />
 <br />
Make /n=(npart) /o eq1,eq2,eq3,eq4,knum<br />
 <br />
Variable i,j<br />
for ( j=1; j<=npart; j+=1)<br />
      i=0<br />
    xval = x0<br />
    yval = y0<br />
 <br />
    do <br />
        genx = gnoise(std)<br />
        geny = gnoise(std)<br />
        xval += genx<br />
        yval += geny<br />
        i+=1<br />
        if (xval<-l || xval>l ||yval<-l || yval>l)<br />
        xval-=genx<br />
        yval-=geny<br />
        i-=1<br />
        knum[j]+=1<br />
        endif<br />
    while((i<niter) && (xval>-l+el || yval>-l+el)&& (xval<l-el || yval>-l+el) && (xval<l-el || yval<l-el) && (xval>-l+el || yval<l-el))<br />
    if (xval<=-l+el && yval<=-l+el)<br />
    eq1[ j]=i<br />
    elseif (xval>=l-el && yval<=-l+el)<br />
    eq2[ j]=i<br />
    elseif (xval>=l-el && yval>=l-el)<br />
    eq3[ j]=i<br />
    elseif (xval<=-l+el && yval>=l-el)<br />
    eq4[ j]=i<br />
    endif  <br />
 <br />
endfor<br />
<br />
return eq1<br />
return eq2<br />
return eq3<br />
return eq4 <br />
<br />
end</span>
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.