Skip to content

OSCAT BASIC Arrays

Thomas Storek edited this page Apr 12, 2018 · 2 revisions

6. Arrays

6.1. _ARRAY_ABS

Type Function: BOOL
Input PT: Pointer (Pointer to the array)
SIZE: UINT (size of the array)
Output BOOL (TRUE)
The function _ARRAY_ABS calculates the elements of an arbitrary array Of
REAL in an absolute value. When called, a pointer to the array and its size
in bytes is transferred to the function. Under CoDeSys the call reads: _AR-
RAY_ABS(ADR(Array), SIZEOF(array)), where array is the name of the array
to be manipulated. ADR() is a standard function which identifes the poin-
ter to the array and SIZEOF() is a standard function, which determines the
size of the array. The function only returns TRUE. The array specifed by
the pointer is manipulated directly in memory.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Call: _ARRAY_ABS(ADR(bigarray), SIZEOF(bigarray))
Example: [0,-2,3,-1-5] is converted to [0,2,3,1,5]

6.2. _ARRAY_ADD

Type Function: BOOL
Input PT: Pointer (Pointer to the array)
SIZE: UINT (size of the array)
X: REAL (added value)
Output BOOL (TRUE)
The function _ARRAXY_ADD adds to each element of an arbitrary array of
REAL value X. When called a Pointer to the array and its size in bytes is
passed to the function. Under CoDeSys the call reads:
_ARRAY_ADD(ADR(Array), SIZEOF(Array), X), where array is the name of
the array to be manipulated. ADR() is a standard function which identifes
the pointer to the array and SIZEOF() is a standard function, which deter-
mines the size of the array. The function only returns TRUE. The array spe-
cifed by the pointer is manipulated directly in memory.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Call: _ARRAY_ADD(ADR(bigarray), SIZEOF(bigarray), X)
Example: [0,-2,3,-1-5] [0,-2,3,-1-5], X = 3 is converted into
[3,1,6,2,-2]

6.3. _ARRAY_INIT

Type Function: BOOL
Input PT: Pointer (Pointer to the array)
SIZE: UINT (size of the array)
INIT: REAL (initial value)
Output BOOL (TRUE)
The function _ARRAY_INIT initializes an arbitrary array of REAL with an in-
itial value. When called, a pointer to the array and its size in bytes is
transferred to the function. Under CoDeSys the call reads:
_ARRAY_INIT(ADR(Array), SIZEOF(Array), INIT), where array is the name of
the array to be manipulated. ADR() is a standard function which identifes
the pointer to the array and SIZEOF() is a standard function, which deter-
mines the size of the array. The function only returns TRUE. The array spe-
cifed by the pointer is manipulated directly in memory.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: _ARRAY_INIT(ADR(bigarray), SIZEOF(bigarray), 0)
initialized bigarray with 0.

6.4. _ARRAY_MEDIAN

Type Function: REAL
Input PT: Pointer (pointer to the array)
SIZE: UINT (size of the array)
Output REAL (median of the array)
The function _ARRAY_MEDIAN calculates the median value of an arbitrary
array of REAL. When called a pointer to the array and its size in bytes is
passed to the function. Under CoDeSys the call reads:
_ARRAY_MEDIAN(ADR(Array), SIZEOF(Array)), where array is the name of
the array to be manipulated. ADR() is a standard function, which identifes
the pointer to the array and SIZEOF() is a standard function, which deter-
mines the size of the array. In order to determine the median value the ar-
ray referenced by the pointer is sorted in the memory and remains after
function end sorted. The function _ARRAY_MEDIAN thus changes the con-
tents of the array.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
If an array is processed, which should not be changed, so it has to be co-
pied to a temporary array before handing over the Pointer and calling the
function.
Example: _ARRAY_MEDIAN(ADR(bigarray), SIZEOF(bigarray))
Median Value:
The median is the middle value to a sorted set of values.
Median of (12, 0, 4, 7, 1) is 4 After running the function the array remains
sorted in memory (0, 1, 4, 7, 12).
If the array contains an even number of elements the median is the avera-
ge of the two middle values of the array.

6.5. _ARRAY_MUL

Type Function: BOOL
Input PT: Pointer (Pointer to the array)
SIZE: UINT (size of the array)
X: REAL (multiplier)
Output BOOL (TRUE)
The function _ARRAY_MUL multiply each element of an arbitrary array of
REAL with the value X. When called a Pointer to the array and its size in
bytes is passed to the function. Under CoDeSys the call reads:
_ARRAY_MUL(ADR(Array), SIZEOF(Array), X), where array is the name of
the array to be manipulated. ADR() is a standard function which identifes
the pointer to the array and SIZEOF() is a standard function, which deter-
mines the size of the array. The function only returns TRUE. The array spe-
cifed by the pointer is manipulated directly in memory.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Call: _ARRAY_MUL(ADR(bigarray), SIZEOF(bigarray), X)
Example: [0,-2,3,-1-5], X = 3 is converted into [0, -6,9,-3,-15]

6.6. _ARRAY_SHUFFLE

Type Function: BOOL
Input PT: Pointer (pointer to the array)
SIZE: UINT (size of the array)
Output BOOL (result TRUE)
The function _array _ SHUFFLE exchanges the elements of an arbitrary ar-
ray Of REAL at random. When called, a Pointer to the array and its size in
bytes is transferred to the function. Under CoDeSys is the call:
_ARRAY_SHUFFLE(ADR(Array), SIZEOF(Array)), where array is the name of
the array to be manipulated. ADR() is a standard function, which identifes
the pointer to the array and SIZEOF() is a standard function, which deter-
mines the size of the array. The array referenced by the Pointer is manipu-
lated directly in memory and is available directly after exit the function.
The function _ARRAY_SHUFFLE thus changes the contents of the array.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
If an array is processed, which should not be changed, so it has to be co-
pied to a temporary array before handing over the Pointer and calling the
function.
Example: _ARRAY_SHUFFLE (ADRs(bigarray), SIZEOF(bigarray))
A call of the function _ARRAY_SHUFFLE could change an array as follows.
Since the function uses a pseudo random algorithm each time the result is
diferent, the results are not reproducible, even through a restart of the
program or the programmable logic control (plc).
Output array: (0,1,2,3,4,5,6,7,8,9)
Results: (5,0,3,9,7,2,1,8,4,6)
The result is not repeatable, the function returns after each call or even re-
start a new order.

6.7. _ARRAY_SORT

Type Function: BOOL
Input PT: Pointer (pointer to the array)
SIZE: UINT (size of the array)
Output BOOL (TRUE)
The function _array_SORT sorts an arbitrary array of REAL in ascending or-
der. When called, a pointer to the array and its size in bytes is transferred
to the function. Under CoDeSys the call is: _ARRAY_SORT(ADR(Array), SI-
ZEOF(Array)), where array is the name of the array to be manipulated.
ADR() is a standard function which identifes the pointer to the array and
SIZEOF() is a standard function, which determines the size of the array.
The function only returns TRUE. The array specifed by the pointer is mani-
pulated directly in memory.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: _ARRAY_SHUFFLE (ADRs(bigarray), SIZEOF(bigarray))

6.8. ARRAY_AVG

Type Function: REAL
Input PT: Pointer (pointer to the array)
SIZE: UINT (size of the array)
Output REAL (mean value of the array)
The function _ARRAY_AVG calculates the median value of an arbitrary ar-
ray ofREAL. When called, a pointer to the array and its size in bytes is pas-
sed to the function. Under CoDeSys the call reads:
ARRAY_AVG(ADR(Array), SIZEOF(Array)), where array is the name of the
array to be manipulated. ADR() is a standard function which identifes the
pointer to the array and SIZEOF() is a standard function, which determines
the size of the array. In order to determine the maximum, the array refe-
renced by the pointer is scanned directly in memory. The function
ARRAY_AVG does not change the content of the array.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: ARRAY_AVG(ADR(bigarray), SIZEOF (bigarray))

6.9. ARRAY_GAV

Type Function: REAL
Input PT: Pointer (pointer to the array)
SIZE: UINT (size of the array)
Output REAL (mean value of the array)
[fuzzy] The function _ARRAY_GAV calculates the median value of an arbi-
trary array of REAL. When called, a pointer to the array and its size in by-
tes is passed to the function. Under CoDeSys the call reads:
ARRAY_GAV(ADR(Array), SIZEOF(Array)), where array is the name of the
array to be manipulated. ADR() is a standard function which identifes the
pointer to the array and SIZEOF() is a standard function, which determines
the size of the array. In order to determine the maximum, the array refe-
renced by the pointer is scanned directly in memory. The function
ARRAY_GAV does not change the content of the array.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: ARRAY_GAV(ADR(bigarray), SIZEOF(bigarray))

6.10. ARRAY_HAV.

Type Function: REAL
Input PT: Pointer (pointer to the array)
SIZE: UINT (size of the array)
Output REAL (mean value of the array)
The function _ARRAY_HAV calculates the harmonic median value of an ar-
bitrary array of REAL. When called, a pointer to the array and its size in
bytes is passed to the function. Under CoDeSys the call reads:
ARRAY_HAV(ADR(Array), SIZEOF(Array)), where array is the name of the
array to be manipulated. ADR() is a standard function which identifes the
pointer to the array and SIZEOF() is a standard function, which determines
the size of the array. In order to determine the maximum, the array refe-
renced by the pointer is scanned directly in memory. The function
ARRAY_HAV does not change the content of the array.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: ARRAY_HAV(ADR(bigarray), SIZEOF (bigarray))

6.11. ARRAY_MAX

Type Function: REAL
Input PT: Pointer (Pointer to the array)
SIZE: UINT (size of the array)
Output REAL (maximum value of the array)
The function _ARRAY_REAL calculates the maximum value of an arbitrary
array ofREAL. When called, a pointer to the array and its size in bytes is
passed to the function. Under CoDeSys the call reads:
ARRAY_MAX(ADR(Array), SIZEOF(Array)), where array is the name of the
array to be manipulated. ADR() is a standard function which identifes the
pointer to the array and SIZEOF() is a standard function, which determines
the size of the array. In order to determine the maximum, the array refe-
renced by the pointer is scanned directly in memory. The function
ARRAY_MAX does not change the content of the array.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: ARRAY_MAX(ADR(bigarray), SIZEOF(bigarray))

6.12. ARRAY_MIN

Type Function: REAL
Input PT: Pointer (Pointer to the array)
SIZE: UINT (size of the array)
Output REAL (minimum value of the array)
The function ARRAY_MIN calculates the minimum value of any array of
REAL. When called the function passed a Pointer to the array and its size
in bytes. Under CoDeSys the call reads: ARRAY_MIN(ADR(Array),
SIZEOF(Array)), where array is the name of the array to be manipulated.
ADR() is a standard function, which identifes the pointer to the array and
SIZEOF() is a standard function, which determines the size of the array. In
order to determine the maximum, the array referenced by the pointer is
scanned directly in memory. The function ARRAY _ MIN does not change
the contents of the array.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: ARRAY_MIN(ADR(bigarray), SIZEOF(bigarray))

6.13. ARRAY_SDV

Type Function: REAL
Input PT: Pointer (Pointer to the array)
SIZE: UINT (size of the array)
Output REAL (standard deviation of the array)
The function _ARRAY_SDV calculates the standard deviation (Standard De-
viation) value of an arbitrary array of REAL. When called a pointer to the
array and its size in bytes is passed to the function. Under CoDeSys the
call reads: ARRAY_SDV(ADR(Array), SIZEOF(Array)), where array is the
name of the array to be manipulated. ADR() is a standard function, which
identifes the pointer to the array and SIZEOF() is a standard function,
which determines the size of the array. In order to determine the maxi-
mum, the array referenced by the pointer is scanned directly in memory.
The function ARRAY_SDV does not change the contents of the array.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: ARRAY_SDV(ADR(bigarray), SIZEOF(bigarray))

6.14. ARRAY_SPR

Type Function: REAL
Input PT: Pointer (Pointer to the array)
SIZE: UINT (size of the array)
Output REAL (dispersion of the array)
The function ARRAY_SPR determines the dispersion of an arbitrary array of
REAL. The dispersion is the maximum value in the array minus the mini-
mum value of the array. When called, a Pointer to the array and its size in
bytes is transferred to the function. Under CoDeSys the call reads:
ARRAY_SPR(ADR(Array), SIZEOF(Array)), where array is the name of the ar-
ray to be manipulated. ADR() is a standard function which identifes the
pointer to the array and SIZEOF() is a standard function, which determines
the size of the array. In order to determine the maximum, the array refe-
renced by the pointer is scanned directly in memory. The function
ARRAY_SPR does not change the content of the array.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: ARRAY_SPR(ADR(bigarray), SIZEOF(bigarray)) =
maximumvalue(bigarray) - minimalvalue(bigarray)

6.15. ARRAY_SUM

Type Function: REAL
Input PT: Pointer (Pointer to the array)
SIZE: UINT (size of the array)
Output REAL (sum of all values of the array)
The function _ARRAY_SUM calculates the sum of all values of an arbitrary
array of REAL. When called a pointer to the array and its size in bytes is
passed to the function. Under CoDeSys the call reads:
ARRAY_SUM(ADR(Array), SIZEOF(Array)), where array is the name of the
array to be manipulated. ADR() is a standard function, which identifes the
pointer to the array and SIZEOF() is a standard function, which determines
the size of the array. In order to determine the maximum, the array refe-
renced by the pointer is scanned directly in memory. The function
ARRAY_SUM does not change the content of the array.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: ARRAY_SUM(ADR(bigarray), SIZEOF(bigarray))

6.16. ARRAY_TREND

Type Function: REAL
Input PT: Pointer (Pointer to the array)
SIZE: UINT (size of the array)
Output REAL (development trend of the array)
The function _ARRAY_TREND calculates the trend development of all va-
lues of an arbitrary array of REAL. When called a pointer to the array and
its size in bytes is passed to the function. Under CoDeSys the call reads:
ARRAY_TREND(ADR(Array), SIZEOF(Array)), where array is the name of the
array to be manipulated. ADR() is a standard function, which identifes the
pointer to the array and SIZEOF() is a standard function, which determines
the size of the array. In order to determine the trend, the array referenced
by the pointer is scanned directly in memory. The function ARRAY_TREND
does not change the content of the array. This type of processing arrays is
very efcient because no additional memory is required and no surrender
values must be copied. The trend is determined by subtract the average
of the lower half of the values of the array from the average of the values
of the upper half of the array.
Example: [fuzzy] ARRAY_AVG(ADR(bigarray), SIZEOF (bigarray))

6.17. ARRAY_VAR

Type Function: REAL
Input PT: Pointer (Pointer to the array)
SIZE: UINT (size of the array)
Output REAL (variance of the array)
The function _ARRAY_VAR calculates the variance of an arbitrary array of
REAL. When called a pointer to the array and its size in bytes is passed to
the function. Under CoDeSys the call reads: ARRAY_VAR(ADR(Array), SI-
ZEOF(Array)), where array is the name of the array to be manipulated.
ADR() is a standard function, which identifes the pointer to the array and
SIZEOF() is a standard function, which determines the size of the array. In
order to determine the maximum, the array referenced by the pointer is
scanned directly in memory. The function ARRAY_VAR does not change the
content of the array.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: ARRAY_VAR(ADR(bigarray), SIZEOF(bigarray))

6.18. IS_SORTED

Type Function: BOOL
Input PT: Pointer (pointer to the array)
SIZE: UINT (size of the array)
Output BOOL (TRUE)
The function IS_SORTED checks whether any array of REAL is sorted in
ascending order. When called, a pointer to the array and its size in bytes is
transferred to the function. Under CoDeSys the call is:
_ARRAY_SORT(ADR(Array), SIZEOF(Array)), where array is the name of the
array to be manipulated. ADR() is a standard function which identifes the
pointer to the array and SIZEOF() is a standard function, which determines
the size of the array.
The function returns TRUE if the array is sorted in ascending order.
This type of processing arrays is very efcient because no additional me-
mory is required and no surrender values must be copied.
Example: IS_SORTED(ADR(bigarray), SIZEOF(bigarray))
Clone this wiki locally