-
Yes, but where things are located in that block of memory depends on how you calculate the location in the memory - particularly when dealing with 2D arrays. Since you are also COPY NY+1 elements more than your original code, I'd say that it is possible that it's going wrong for that reason.
--
Mats
-
Hi again,
No, even with that fixed (allocating the coherent number of elements), I still obtian the same allocation. The problem is surely in the part of routine where I assign the variable:
Code:
k=0;
for(j = 0; j < NY; ++j){
for(i = 0; i < NX; ++i){
vars[0][k] = zonal[j][i];
k++;
}
}
and I don't know how to modify it correctly
-
That's what I meant by "copy" - you are writing NY * NX elements, not (NY-1) * (NX-1) elements to the new array. So the stride (step between each line) in the 1D layout is going to be different.
--
Mats
-
Hi,
yes, I understand what you mean, but I correctly it accordingly. Is the loop conceptually correct or am I assigning the wrong part of memory then?
thank you again
-
The original loop from the original code produces:
Code:
1 2 3 4
1 2 3 4
1 2 3 4
Your new code produces:
Code:
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
Now, if you use the write method to extract this, you will get:
Code:
1 2 3 4
5 1 2 3
4 5 1 2
written to disk. This assumes that I have understood things correctly. Does this make some sense compared to what you are seeing?
--
Mats
-
Hi again Mat,
The error was exactly on that! Thank you so much! I did different tries to prove it against the original code, and yes, it was the NX-1, NY-1 where I was allocating a bigger memory!
I can't believe I still make certain mistakes after years of programming ;) This dynamic allocation is very powerful, but delicate at the same time if not taken well care of
Thank you again for helping patiently
Best regards
CFD
-
Well, it ISN'T the allocation itself that is wrong - it is the loop that copies the zonal data into the variables[0][k] that goes wrong because you are incrementing k one more than the write loop does for each row.
--
Mats
-
Correct, now it's all clear;
thank you again
Simon