-
Notifications
You must be signed in to change notification settings - Fork 5
/
ARRAY_GAV.EXP
executable file
·48 lines (40 loc) · 1.01 KB
/
ARRAY_GAV.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_GAV : REAL
VAR_INPUT
pt : POINTER TO ARRAY[0..32000] OF REAL;
size : UINT;
END_VAR
VAR
i: UINT;
stop: UINT;
END_VAR
(*
version 1.1 10. mar. 2009
programmer hugo
tested by tobias
this function will calculate the geometric 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_GAV := 1.0;
FOR i := 0 TO stop DO
IF pt^[i] > 0.0 THEN
ARRAY_GAV := ARRAY_GAV * pt^[i];
ELSE
ARRAY_GAV := 0.0;
RETURN;
END_IF;
END_FOR;
ARRAY_GAV := SQRTN(ARRAY_GAV,UINT_TO_INT(stop)+1);
(* revision history
hm 2. apr 2008 rev 1.0
original version
hm 10. mar. 2009 rev 1.1
real constants updated to new systax using dot
*)
END_FUNCTION