function help

Dear users:

i am a newbie want to make a table automaticlly, like one step movement.

it works in two columns,but fails in three columns. If somebody can give me advise,that would be nice

This would be not very difficult,thanks anyway

the twopcolumn function as below:
*************************************************
variable i=0, j=0, k=0, l=0, m=0, n=0,o=0,p=0,q=0
variable d1n, d2n, d3n
Prompt xstart, "Start value X position:"
Prompt ystart, "Start value Y position:"
Prompt xend, "End value X position:"
Prompt yend, "End value Y position:"
Prompt xstep, "Step size of X direction:"
Prompt ystep, "Step size of Y dirction:"

DoPrompt "Enter position parameters (in m)", xstart, ystart, xend, yend, xstep, ystep
if (V_Flag)
return -1 // User canceled
endif

d1n=abs((xend-xstart)/xstep)+1 //number for X dimension
d2n=abs((yend-ystart)/ystep)+1 //number for Y dimension

make/D/N=((d2n*d1n), 200)/O test=0

for(k=0; k<=d1n-1; k+=1)
i=k*d2n
j=(k+1)*d2n
test[i,j][10]=xstart+k*xstep //make column 10 for X
for(l=0; l<=d2n-1; l+=1)
test[i+l][11]=ystart+l*ystep //make column 11 for Y
endfor
endfor
endfor
......................................................................
***********************************************************************8

three column function as below:
************************************************************************
variable i=0, j=0, k=0, l=0, m=0, n=0,o=0,p=0,q=0
variable d1n, d2n, d3n

Prompt xstart, "Start value X position:"
Prompt ystart, "Start value Y position:"
Prompt xend, "End value X position:"
Prompt yend, "End value Y position:"
Prompt xstep, "Step size of X direction:"
Prompt ystep, "Step size of Y dirction:"
Prompt zstart, "Start value Z position:"
Prompt zstep, "Step size of Z direction:"
Prompt zend, "End value Z position:"

make/D/N=((d2n*d1n*d3n), 200)/O test=0

d1n=abs((xend-xstart)/xstep)+1 //number for X dimension
d2n=abs((yend-ystart)/ystep)+1 //number for Y dimension
d3n=abs((zend-zstart)/zstep)+1 //number for Z dimension

for(m=0; m<=d3n-1; m+=1)
n=m*d1n*d2n
o=(m+1)*d1n*d2n
test[n,o][12]=zstart+m*zstep //make column 12 for Z

for(k=0; k<=d1n-1; k+=1)
i=k*d2n*m
j=(k+1)*d2n*(m+1)
test[i,j][10]=xstart+k*xstep //make column 10 for X
for(l=0; l<=d2n-1; l+=1)
test[(m+1)*i+l][11]=ystart+l*ystep //make column 11 for Y
endfor
endfor
endfor
................................................................................................
*******************************************************************************

I'm not quite sure what you are trying to do here, and I'm also not sure what your problem is, so it's difficult to answer your question. But given the code you pasted above, the second function probably wasn't working because you are missing a DoPrompt statement, so the [x,y,z][start|end|step] variables are never initialized properly. In the code you gave, you're also creating the wave before you are defining the values of d1n, d2n, and d3n, so therefore you get a zero point wave.

The code below compiles and creates a wave with points and data values. I'm not sure if this is ultimately what you are looking for, but maybe it's a start.

Function twopcolumn()
    variable i=0, j=0, k=0, l=0, m=0, n=0,o=0,p=0,q=0
    variable d1n, d2n, d3n
    Variable xstart, xend, ystart, yend, xstep, ystep
    Prompt xstart, "Start value X position:"
    Prompt ystart, "Start value Y position:"
    Prompt xend, "End value X position:"
    Prompt yend, "End value Y position:"
    Prompt xstep, "Step size of X direction:"
    Prompt ystep, "Step size of  Y dirction:"
   
    DoPrompt "Enter position parameters (in m)", xstart, ystart, xend, yend, xstep, ystep
    if (V_Flag)
        return -1                               // User canceled
    endif
   
    d1n=abs((xend-xstart)/xstep)+1     //number for X dimension
    d2n=abs((yend-ystart)/ystep)+1    //number for Y dimension
   
    make/D/N=((d2n*d1n), 200)/O test=0
       
    for(k=0; k<=d1n-1; k+=1)
        i=k*d2n
        j=(k+1)*d2n
        test[i,j][10]=xstart+k*xstep            //make column 10 for X 
        for(l=0; l<=d2n-1; l+=1)
            test[i+l][11]=ystart+l*ystep            //make column 11 for Y
        endfor
    endfor
End


Function ThreeOpColumn()
    variable i=0, j=0, k=0, l=0, m=0, n=0,o=0,p=0,q=0
    variable d1n, d2n, d3n
    Variable xstart, xend, ystart, yend, zstart, zend, xstep, ystep, zstep
    Prompt xstart, "Start value X position:"
    Prompt ystart, "Start value Y position:"
    Prompt xend, "End value X position:"
    Prompt yend, "End value Y position:"
    Prompt xstep, "Step size of X direction:"
    Prompt ystep, "Step size of  Y dirction:"
    Prompt zstart, "Start value Z position:"
    Prompt zstep, "Step size of Z direction:"
    Prompt zend, "End value Z position:"

    DoPrompt "Enter position parameters (in m)", xstart, ystart, zstart, xend, yend, zend, xstep, ystep, zstep
    if (V_Flag)
        return -1                               // User canceled
    endif
       

   
    d1n=abs((xend-xstart)/xstep)+1     //number for X dimension
    d2n=abs((yend-ystart)/ystep)+1    //number for Y dimension
    d3n=abs((zend-zstart)/zstep)+1    //number for Z dimension

    make/D/N=((d2n*d1n*d3n), 200)/O test=0
       
    for(m=0; m<=d3n-1; m+=1)
        n=m*d1n*d2n
        o=(m+1)*d1n*d2n
        test[n,o][12]=zstart+m*zstep        //make column 12 for Z
       
        for(k=0; k<=d1n-1; k+=1)
            i=k*d2n*m
            j=(k+1)*d2n*(m+1)
            test[i,j][10]=xstart+k*xstep            //make column 10 for X 
            for(l=0; l<=d2n-1; l+=1)
                test[(m+1)*i+l][11]=ystart+l*ystep          //make column 11 for Y
            endfor
        endfor
    endfor
End
Dear aclight:


Thanks for your comment.But the problem is not the missing a DoPrompt statement part.

The problem is around for and endfor part. the relation between the addtional m part(d3n) doesnot work well with k and l parts
Do you have some comments about that?
Thanks
xueshao wrote:
Dear aclight:


Thanks for your comment.But the problem is not the missing a DoPrompt statement part.

The problem is around for and endfor part. the relation between the addtional m part(d3n) doesnot work well with k and l parts
Do you have some comments about that?
Thanks


I'm sorry, but I really don't understand what you are trying to do here.

If you could provide an explanation of what exactly you expect these functions to do, and then what they are doing, that would be helpful. As is, I don't know that the problem is in the first place.
xueshao wrote:

it works in two columns,

the twopcolumn function as below:
*************************************************
variable i=0, j=0, k=0, l=0, m=0, n=0,o=0,p=0,q=0
variable d1n, d2n, d3n
Prompt xstart, "Start value X position:"
Prompt ystart, "Start value Y position:"
Prompt xend, "End value X position:"
Prompt yend, "End value Y position:"
Prompt xstep, "Step size of X direction:"
Prompt ystep, "Step size of Y dirction:"

DoPrompt "Enter position parameters (in m)", xstart, ystart, xend, yend, xstep, ystep
if (V_Flag)
return -1 // User canceled
endif

d1n=abs((xend-xstart)/xstep)+1 //number for X dimension
d2n=abs((yend-ystart)/ystep)+1 //number for Y dimension

make/D/N=((d2n*d1n), 200)/O test=0

for(k=0; k<=d1n-1; k+=1)
i=k*d2n
j=(k+1)*d2n
test[i,j][10]=xstart+k*xstep //make column 10 for X
for(l=0; l<=d2n-1; l+=1)
test[i+l][11]=ystart+l*ystep //make column 11 for Y
endfor
endfor
endfor



I don't know whether your problem has been resolved, but I wonder a) why the 2 dimensional example should run - there are two fors and three endfors. At least there should be one more loop for the 3 dimensional problem than for the 2 dimensional one. I b) also wonder what you try to achieve. Am I right that you want to assign function values to pairs (xy) or triples (xyz) of coordinates? Wouldn't that be easier using 2 and 3 dimensional waves, ie rows & columns (& layers)?. I realized that you make 2 dimensional waves for both cases where the number of rows depends on the number of coordinates and the number of columns is fixed to 200. Is there a reason for doing so?

Dear all:

I fix this problem now. Basic mathematic knowledge. Thanks for comments