F278_DSORT

Sort data in 32-bit data table (in smaller or larger number order)

The function sorts values (with +/- sign) in a data table in ascending or descending order.

Parameters

Input

s1_Start (DINT)

Starting area of data table to be sorted

s2_End (DINT)

Ending area of data table to be sorted

s3_Descending (INT)

Specifies sorting order:

  • 0 = ascending

  • 1 = descending

Remarks

  • Instead of using this F instruction, we recommend using the corresponding FP7 instruction: FP_DATA_SORT

  • The data are sorted via bubble sort in the order specified according to the value entered at input s3_Descending. Since the number of word comparisons increases in proportion to the square of the number of words, the sorting process can take some time when there are a large number of words. When the value at inputs s1_Start=s2_End, no sorting takes place.

  • Although this is a 32-bit instruction, the number of steps is the same as the 16-bit instruction.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the area specified using the index modifier exceeds the limit.

  • if the address of the variable at input s1_Start > s2_End

  • if s1_Start and s2_End belong to different data areas.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the area specified using the index modifier exceeds the limit.

  • if the address of the variable at input s1_Start > s2_End

  • if s1_Start and s2_End belong to different data areas.

Example

POU header

All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.

	VAR
		start: BOOL:=FALSE;
			(*activates the function*)
		data_array: ARRAY [0..4] OF DINT:=[4,7,-32,13,5];
			(*result after a 0->1 leading
edge from start: [-32,4,5,7,13]*)
		asc_order: INT:=0;
			(*which way to sort:
0 means ascending order
1 means descending order*)
	END_VAR

In this example, the input variable sort_order is declared. However, you can write a constant directly at the input contact of the function instead.

POU body

When the variable start is set to TRUE, the function is carried out.

Since the variable sort_order is set to 1, the specified data field in sorted in descending order.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 9 ;
        NETWORK_BODY
B(B_VARIN,,output,7,1,9,3,);
B(B_VARIN,,data field[0],7,2,9,4,);
B(B_VARIN,,data field[4],7,3,9,5,);
B(B_F,F278_DSORT,,9,0,18,6,,?DEN?D@'s1'?Ds2?Ds3?AENO);
B(B_VARIN,,sort_order,7,4,9,6,);
B(B_COMMENT,,sorting order:ø^s3 = 0:ascending~ 1:descending,10,6,25,8,);
L(1,0,1,9);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF start then
    F278_DSORT( s1_Start:= data_field[0],
         s2_End:= data_field[4],
         s3_Descending:= sort_order);
END_IF;

IL body

Modified on: 2022-08-23Feedback on this pagePanasonic hotline