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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
//
// T_SWAPAC is a utility routine used for testing SWAPAC. T_SWAPAC
// uses an alternate implementation of the swapping algorithm that
// uses work space to build the output array: the swapping
// algorithm is quite simple when the constraint of in-place
// operation is removed.
//
// This routine does no error checking.
//
pub fn T_SWAPAC(
SIZE: i32,
N: i32,
LOCN: i32,
M: i32,
LOCM: i32,
ARRAY: CharArrayMut,
WORK: CharArrayMut,
) {
let mut ARRAY = DummyCharArrayMut::new(ARRAY, None, 1..);
let mut WORK = DummyCharArrayMut::new(WORK, None, 1..);
let mut LOC: i32 = 0;
let mut LOWER: i32 = 0;
let mut NLOW: i32 = 0;
let mut NMOVE: i32 = 0;
let mut NUP: i32 = 0;
let mut TO: i32 = 0;
let mut UPPER: i32 = 0;
//
// Local variables
//
//
// We'll build the output array in WORK; then we'll copy the
// result back to ARRAY.
//
// Identify the start indices of the "top" and "bottom" array slices
// to be swapped. We consider the lower addresses to be at the
// "top" of the array.
//
UPPER = intrinsics::MIN0(&[LOCN, LOCM]);
LOWER = intrinsics::MAX0(&[LOCN, LOCM]);
if (UPPER == LOCN) {
NUP = N;
NLOW = M;
} else {
NUP = M;
NLOW = N;
}
//
// Move the elements preceding UPPER into WORK.
//
TO = 1;
NMOVE = (UPPER - 1);
spicelib::MOVEC(ARRAY.subarray(1), NMOVE, WORK.subarray_mut(TO));
//
// Move the elements in the lower slice into WORK.
//
TO = (TO + NMOVE);
NMOVE = NLOW;
spicelib::MOVEC(ARRAY.subarray(LOWER), NMOVE, WORK.subarray_mut(TO));
//
// Move the elements between the slices into WORK.
//
TO = (TO + NMOVE);
NMOVE = ((LOWER - 1) - ((UPPER + NUP) - 1));
spicelib::MOVEC(ARRAY.subarray((UPPER + NUP)), NMOVE, WORK.subarray_mut(TO));
//
// Move the elements in the upper slice into WORK.
//
TO = (TO + NMOVE);
NMOVE = NUP;
spicelib::MOVEC(ARRAY.subarray(UPPER), NMOVE, WORK.subarray_mut(TO));
//
// Move the elements below the lower slice into WORK.
//
TO = (TO + NMOVE);
LOC = (LOWER + NLOW);
NMOVE = (SIZE - (LOC - 1));
spicelib::MOVEC(ARRAY.subarray(LOC), NMOVE, WORK.subarray_mut(TO));
//
// Copy WORK into ARRAY.
//
spicelib::MOVEC(WORK.as_arg(), SIZE, ARRAY.as_arg_mut());
}