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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Remove elements from a character array
///
/// Remove one or more elements from a character array at the
/// indicated location.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// NE I Number of elements to be removed.
/// LOC I Location of the first removed element.
/// ARRAY I-O Input/output array.
/// NA I-O Number of elements in the input/output array.
/// ```
///
/// # Detailed Input
///
/// ```text
/// NE is the number of elements to be removed.
///
/// LOC is the location in the array at which the first
/// element is to be removed.
///
/// ARRAY on input, is the original array.
///
/// NA on input, is the number of elements in ARRAY.
/// ```
///
/// # Detailed Output
///
/// ```text
/// ARRAY on output, is the original array with elements
/// LOC through LOC+NE-1 removed. Succeeding elements
/// are moved forward to fill the vacated spaces.
///
/// NA on output, is the number of elements in ARRAY.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If LOC is not in the interval [1, NA], the error
/// SPICE(INVALIDINDEX) is signaled.
///
/// 2) If the number of elements to be removed is greater than the
/// number of elements that can be removed, the error
/// SPICE(NONEXISTELEMENTS) is signaled.
///
/// 3) If NE is less than one, the array is not modified.
///
/// 4) If NA is less than one, any location is invalid, and, the
/// error SPICE(INVALIDINDEX) is signaled.
/// ```
///
/// # Particulars
///
/// ```text
/// The elements in positions LOC through LOC+NE-1 are overwritten
/// as the elements beginning at LOC+NE are moved back.
/// ```
///
/// # Examples
///
/// ```text
/// Let
///
/// NA = 7 ARRAY(1) = 'The'
/// ARRAY(2) = 'boy'
/// ARRAY(3) = 'in'
/// ARRAY(4) = 'the'
/// ARRAY(5) = 'park'
/// ARRAY(6) = 'fell'
/// ARRAY(7) = 'down'
///
/// Then the call
///
/// CALL REMLAC ( 3, 3, ARRAY, NA )
///
/// yields the following result:
///
/// NA = 4 ARRAY(1) = 'The'
/// ARRAY(2) = 'boy'
/// ARRAY(3) = 'fell'
/// ARRAY(4) = 'down'
///
///
/// The following calls would signal errors:
///
/// CALL REMLAC ( 3, 1, ARRAY, -1 )
/// CALL REMLAC ( 3, -1, ARRAY, 7 )
/// CALL REMLAC ( 3, 6, ARRAY, 7 )
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// W.L. Taber (JPL)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 05-JUN-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)
///
/// Comment section for permuted index source lines was added
/// following the header.
///
/// - SPICELIB Version 1.0.0, 31-JAN-1990 (IMU)
/// ```
///
/// # Revisions
///
/// ```text
/// - Beta Version 2.0.0, 1-JAN-1989 (HAN)
///
/// Code was added to handle the following exceptional
/// inputs.
///
/// If the dimension of the array is less than one, any
/// value of LOC is invalid. The old version did not check
/// the dimension of the array, and as a result, its output
/// was unpredictable.
///
/// If the location at which the elements are to be removed is
/// not in the interval [1, NA], an error is signaled.
/// Locations not within that interval refer to non-existent
/// array elements. The old routine did not signal an error.
/// It just returned the original array.
///
/// If the number of elements to be removed is greater than the
/// number of elements can be removed, an error is signaled.
/// In the old version, only those elements that could be
/// removed were removed, and no error was signaled.
/// ```
pub fn remlac(
ctx: &mut SpiceContext,
ne: i32,
loc: i32,
array: CharArrayMut,
na: &mut i32,
) -> crate::Result<()> {
REMLAC(ne, loc, array, na, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure REMLAC ( Remove elements from a character array )
pub fn REMLAC(
NE: i32,
LOC: i32,
ARRAY: CharArrayMut,
NA: &mut i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut ARRAY = DummyCharArrayMut::new(ARRAY, None, 1..);
//
// SPICELIB functions
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"REMLAC", ctx)?;
}
//
// If LOC does not point to an actual element, signal an error and
// check out. If the dimension of the array is less than one, any
// value of LOC is invalid, and an error is signaled.
//
if ((LOC < 1) || (LOC > *NA)) {
SETMSG(b"Location was *.", ctx);
ERRINT(b"*", LOC, ctx);
SIGERR(b"SPICE(INVALIDINDEX)", ctx)?;
CHKOUT(b"REMLAC", ctx)?;
return Ok(());
//
// Don't try to remove non-existent elements.
//
} else if (NE > ((*NA - LOC) + 1)) {
SETMSG(b"Trying to remove non-existent elements.", ctx);
SIGERR(b"SPICE(NONEXISTELEMENTS)", ctx)?;
CHKOUT(b"REMLAC", ctx)?;
return Ok(());
//
// If there are elements to be removed, remove them. Otherwise,
// do not modify the array.
//
} else if (NE > 0) {
//
// Move the elements forward.
//
for I in LOC..=(*NA - NE) {
let val = ARRAY.get((I + NE)).to_vec();
fstr::assign(ARRAY.get_mut(I), &val);
}
//
// Update the number of elements in the array.
//
*NA = (*NA - NE);
}
CHKOUT(b"REMLAC", ctx)?;
Ok(())
}