Hi Rob,
I imported your ITF file, tried it, and the same problem is still there. The bubble sort is still having the effect of corrupting the array fill.
The duplicate removal feature still works if you remove the bubble sort component, and it will remove duplicate values out of $da[k], even if it’s not bubble sorted.
I’ve attached 2 pics so you can see what I’m seeing of your code. With your original unmodified code, and, with the bubble sort deleted (the duplication removal is still present).
The bubble sort code is interfering with storage of the correct values in $da[k]. That’s what is happening, or that is at least what looks to be happening.
What must be happening is that the bubble sort is scrambling the values – sorting them – and when $da[k] is looping in its summation process, it is writing it’s values into the wrong index, so then summing up incorrectly. The bubble sort sorts it every bar, and then the array summation of $da[k] puts it in the wrong index again. This might then explain why the results with the bubble sort are semi-homogenous and slightly trending up too.
It’s sort of like you need to copy $da[k] (and $la[k]) into a new disposable array(s) – each bar – the bubble sort sorts those temp arrays – and that is your answer. And when I mean temporary disposable array(s), I mean before the bubble sort process, to be clear, because the bubble sort process itself uses temporary arrays, not to be mistaken with them.
The first part of the code can keep on producing $da[k], and the bubble sort never “sees” it, it only works on copied disposable arrays that would need to be created each bar.
I don’t think it’s a problem necessarily with the bubble sort code itself, but how the bubble sort is interacting with the filling of $da[k] when an array summation as per below is used in its creation.
once $da[k]=0
$da[k] = newcount+$da[k]
Many thanks Rob for your perseverance and patience,
Finning