See the images below.
The first image counts how many time the wind comes from a given direction; I only used the cardinal compass points (North, East, South West), but of course it could be expanded to additional inter-cardinal points (NNE, NE, ...). The direction indices are 1, 2, 3, and 4 for directions North, East, South, and West, respectively.
The important thing to note is that the cts (Array DINT[1..4]) contains the counts for each direction (cts[1] has the North counts; cts[2], cts[3], and cts[4] for East, South, and West, respectively.
View attachment 62545
CCW was what I had to hand when I did this, I assume it is similar enough to RSLogix to be clear what I am doing. The [sample_trigger] is equivalent to the /DN bit of a one-repeating one-second RSLogix timer.
N.B. [Switch 1] is 1 when the wind is coming from North, [Switch 2] is 1 when the wind is coming from the East, etc.
The second image shows how to determine the direction (N/E/W/S),
as a directional index (1/2/3/4), that has the greatest number of counts. I hope it is straightforward enough to understand. To answer the original question from Post #1, we don't need to compare the North count against all 16 counts from NNE, NE, ENE, E, ..., to determine if North is the wind direction with the most counts, then compare the NNE count against N, NE, ENE, ..., etc. It is enough to compare N counts against NNE counts, and save the wind direction of the greater of the two, then compare NE counts against that previous result and update the result, then ENE, etc. Since at any point in that process, the count of the intermediate result (wind direction) cannot be less than any of the previously-tested counts, if the next count tested is greater than the intermediate result, then that next count must be greatest.
That is called the invariant condition of the algorithm: the count of the intermediate direction result is not less than any of the previous directions tested. To initialize the algorithm, we assign 1 (North) as the intermediate result, which meets the invariant condition because no other direction has been tested. Then on each pass of the algorithm, we test a new index, and adjust the intermediate result as needed to maintain the invariant condition.
My point is that the code from my other example does exactly this, but in a loop, so there needs to be only one rung branch that does the compare and move sixteen times with
a different value of the direction index TEST_INDEX each time (instead of 1, 2, 3, ..._, and the other branches increment the direction index to be tested and repeat (loop) until all direction indices have been tested: