-
Notifications
You must be signed in to change notification settings - Fork 5
/
ARRAY_AVG.EXP
executable file
·48 lines (39 loc) · 1.04 KB
/
ARRAY_AVG.EXP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Mathematical\/Array' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
FUNCTION ARRAY_AVG : REAL
VAR_INPUT
pt : POINTER TO ARRAY[0..32000] OF REAL;
size : UINT;
END_VAR
VAR
i: UINT;
stop: UINT;
END_VAR
(*
version 1.3 10. mar. 2009
programmer hugo
tested by tobias
this function will calculate the average of a given array.
the function needs to be called: array_avg(adr("array"),sizeof("array"));
because this function works with pointers its very time efficient and it needs no extra memory.
*)
(* @END_DECLARATION := '0' *)
stop := SHR(size,2)-1;
ARRAY_AVG := pt^[0];
FOR i := 1 TO stop DO
ARRAY_AVG := ARRAY_AVG + pt^[i];
END_FOR;
ARRAY_AVG := ARRAY_AVG / UINT_TO_REAL(stop + 1);
(* revision history
hm 2. oct 2007 rev 1.0
original version
hm 12. dec 2007 rev 1.1
chaged code for better performance
hm 16. mar. 2008 rev 1.2
changed input size to uint
hm 10. mar. 2009 rev 1.3
added type conversion for compatibility reasons
*)
END_FUNCTION