Vector size and declaration
Posted: Mon Oct 22, 2007 5:20 am
Hi everyone,
i've a reproduced in a simple script a problem that occured in a complex one.
Basicaly, i declare 2 vectors of the size Number_Of_Loops.
Then there is a for_loop, I fill in the vectors at every turn of the loop.
This is working generally well but, for some parameters it freaks out!
The vectors have not a size = Number_Of_Loops anymore but
size = Number_Of_Loops - 1
Furthermore, Number_Of_Loops is not modified after being initialized.
This is annoying because the script goes out of range when trying to fill the last element of the vector...
Thank you for any advice.
Here is the simple code reproducing the problem, feel free to try other parameters:
i've a reproduced in a simple script a problem that occured in a complex one.
Basicaly, i declare 2 vectors of the size Number_Of_Loops.
Then there is a for_loop, I fill in the vectors at every turn of the loop.
This is working generally well but, for some parameters it freaks out!
The vectors have not a size = Number_Of_Loops anymore but
size = Number_Of_Loops - 1
Furthermore, Number_Of_Loops is not modified after being initialized.
This is annoying because the script goes out of range when trying to fill the last element of the vector...
Thank you for any advice.
Here is the simple code reproducing the problem, feel free to try other parameters:
Code: Select all
////////////////////////////////////////////////////////////////
indexmax = 0.11 //problems also with indexmax = 0.21 and indexmin = 0.2
indexmin = 0.1
Increment = 0.01
objref h, a, gh
gh = new Graph()
k = 0
Number_Of_Loops = (1 + (indexmax - indexmin) / Increment)
print "Number_Of_Loops= ", Number_Of_Loops
h = new Vector(Number_Of_Loops) //Ordinate vector for the plot
a = new Vector(Number_Of_Loops) //Abciss vector for the plot
print "Number_Of_Loops= ", Number_Of_Loops
print "size of h= ", h.size()
print "size of a= ", a.size()
for(index = indexmin; index <= indexmax; index = index + Increment){
print "Loop Number:", k + 1, " / ", Number_Of_Loops, ", Ordinate = ", index
h.x[index] = index
a.x[index] = k
k = k + 1
}//end of Amp
gh.size(0, k + 1, 0, indexmax) // appropriate X-Y-scaling
h.plot(gh, a, 3,1)