blob: 85b21cc5144921cc9bf5df4dd8b9047eefcae202 (
plain) (
blame)
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
49
50
51
52
53
54
55
|
include "apertures.h"
# Sort flags:
define INC 1 # Sort by aperture position in increasing order
define DEC 2 # Sort by position in decreasing order
# AP_SORT -- Sort the apertures.
procedure ap_sort (current, aps, naps, flag)
int current # Current aperture
pointer aps[ARB] # Aperture data
int naps # Number of apertures
int flag # Sort flag
int i, j, apaxis
pointer ap
begin
if (naps < 1)
return
switch (flag) {
case INC:
apaxis = AP_AXIS (aps[1])
for (i = 1; i <= naps - 1; i = i + 1) {
for (j = i + 1; j <= naps; j = j + 1) {
if (AP_CEN(aps[i], apaxis) > AP_CEN(aps[j], apaxis)) {
ap = aps[i]
aps[i] = aps[j]
aps[j] = ap
if (current == i)
current = j
else if (current == j)
current = i
}
}
}
case DEC:
apaxis = AP_AXIS (aps[1])
for (i = 1; i <= naps - 1; i = i + 1) {
for (j = i + 1; j <= naps; j = j + 1) {
if (AP_CEN(aps[i], apaxis) < AP_CEN(aps[j], apaxis)) {
ap = aps[i]
aps[i] = aps[j]
aps[j] = ap
if (current == i)
current = j
else if (current == j)
current = i
}
}
}
}
end
|