Hi, im creating compressor station project with S7-1200.
Project requires that 4 compressors should work in cascade - that's already done, and they should start always the one with smallest hour counter.
So i've done bubble sort in scl. Function takes time in hours from counter
and should output the number of compressor in descending hours order.
Problem is that when if 2 or more Inputs got the same value for example i've got the same numbers on outputs.
For example 4 2 2 1
I've really stuck as it my first scl function - could You post some hints how to avoid duplicated output ?
Regards.
Project requires that 4 compressors should work in cascade - that's already done, and they should start always the one with smallest hour counter.
So i've done bubble sort in scl. Function takes time in hours from counter
and should output the number of compressor in descending hours order.
Code:
//------------------------------------------------------------------------------
// Bubble sort
//------------------------------------------------------------------------------
// --- Make an array from inputs
#Array1[1]:=#Input1;
#Array1[2]:=#Input2;
#Array1[3]:=#Input3;
#Array1[4]:=#Input4;
// --- Run bubble sort on array
REPEAT #swap:=false;
FOR #i:=4 TO 2 BY -1 DO
IF #Array1[#i-1] > #Array1[#i] THEN
#aux:=#Array1[#i];
#Array1[#i] :=#Array1[#i-1];
#Array1[#i-1] :=#aux;
#swap:=true;
END_IF;
END_FOR;
UNTIL NOT #swap END_REPEAT;
// --- Assign positions to values
FOR #i:=1 TO 4 BY 1 DO
IF #Array1[#i] = #Input1 THEN #Array1[#i] := 1; END_IF;
IF #Array1[#i] = #Input2 THEN #Array1[#i] := 2; END_IF;
IF #Array1[#i] = #Input3 THEN #Array1[#i] := 3; END_IF;
IF #Array1[#i] = #Input4 THEN #Array1[#i] := 4; END_IF;
END_FOR;
#Out1 := #Array1[1];
#Out2 := #Array1[2];
#Out3 := #Array1[3];
#Out4 := #Array1[4];
Problem is that when if 2 or more Inputs got the same value for example i've got the same numbers on outputs.
For example 4 2 2 1
I've really stuck as it my first scl function - could You post some hints how to avoid duplicated output ?
Regards.