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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Insert at location in double precision array
///
/// Insert one or more elements into a double precision array at
/// the indicated location.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// ELTS I Elements to be inserted.
/// NE I Number of elements to be inserted.
/// LOC I Location of the first inserted element.
/// ARRAY I-O Input/output array.
/// NA I-O Number of elements in the input/output array.
/// ```
///
/// # Detailed Input
///
/// ```text
/// ELTS contains one or more elements which are to be
/// inserted into the input array.
///
/// NE is the number of elements to be inserted.
///
/// LOC is the location in the array at which the first
/// element of ELTS is to be inserted. LOC must be
/// within the interval [1, NA+1]. To append to
/// ARRAY, set LOC equal to NA+1.
///
/// 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 the elements
/// of ELT inserted into positions LOC through LOC+NE-1.
/// The original elements in these positions are moved
/// back to make room for the inserted elements.
///
/// NA on output, is the number of elements in ARRAY.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) The dimension of the array is set equal to zero if its
/// input value is less than one.
///
/// 2) If LOC is not in the interval [1, NA+1], the error
/// SPICE(INVALIDINDEX) is signaled.
///
/// 3) If the number of elements to be inserted is less than one,
/// the array is not modified.
/// ```
///
/// # Particulars
///
/// ```text
/// The elements in positions LOC through LOC+NE-1 are moved back
/// by NE spaces to make room for the new elements, which are then
/// inserted into the vacated spaces.
/// ```
///
/// # Examples
///
/// ```text
/// Let
///
/// ELTS(1) = 5.0D0 NA = 4 ARRAY(1) = 1.0D0
/// ELTS(2) = 6.0D0 ARRAY(2) = 2.0D0
/// ELTS(3) = 7.0D0 ARRAY(3) = 3.0D0
/// ARRAY(4) = 4.0D0
///
/// Then the call
///
/// CALL INSLAD ( ELTS, 3, 3, ARRAY, NA )
///
/// yields the following result:
///
/// NA = 7 ARRAY(1) = 1.0D0
/// ARRAY(2) = 2.0D0
/// ARRAY(3) = 5.0D0
/// ARRAY(4) = 6.0D0
/// ARRAY(5) = 7.0D0
/// ARRAY(6) = 3.0D0
/// ARRAY(7) = 4.0D0
///
///
/// The following calls to INSLAD signal errors.
///
/// CALL INSLAD ( ELTS, 3, -1, ARRAY, NA )
/// CALL INSLAD ( ELTS, 3, 6, ARRAY, NA )
/// CALL INSLAD ( ELTS, 3, 2, ARRAY, -1 )
/// CALL INSLAD ( ELTS, 3, -1, ARRAY, -1 )
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) The array must be large enough to contain both the original
/// and the inserted elements.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// H.A. Neilan (JPL)
/// W.L. Taber (JPL)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 13-AUG-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) (HAN)
/// ```
///
/// # Revisions
///
/// ```text
/// - Beta Version 2.0.0, 30-DEC-1988 (HAN)
///
/// If the location at which the elements are to be inserted is
/// not in the interval [1, NA+1], an error is signaled.
/// Locations not within that interval refer to non-existent
/// array elements. (To append to the array, the location
/// should be equal to NA+1.)
///
/// A negative dimension bug was fixed. The results of the
/// old version were unpredictable if the input array dimension
/// was negative. To avoid this problem the maximum of zero and
/// the input dimension becomes the dimension used by the
/// the routine. In this case, the only valid location at which
/// to insert is 1. If it is not 1, an error is signaled
/// when the location is checked.
/// ```
pub fn inslad(
ctx: &mut SpiceContext,
elts: &[f64],
ne: i32,
loc: i32,
array: &mut [f64],
na: &mut i32,
) -> crate::Result<()> {
INSLAD(elts, ne, loc, array, na, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure INSLAD (Insert at location in double precision array)
pub fn INSLAD(
ELTS: &[f64],
NE: i32,
LOC: i32,
ARRAY: &mut [f64],
NA: &mut i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let ELTS = DummyArray::new(ELTS, 1..);
let mut ARRAY = DummyArrayMut::new(ARRAY, 1..);
let mut SIZE: i32 = 0;
//
// SPICELIB functions
//
//
// Other functions
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"INSLAD", ctx)?;
}
//
// Check the dimension of the array.
//
SIZE = intrinsics::MAX0(&[0, *NA]);
//
// Make sure the location at which the elements are to be inserted
// is not out of range. If it is, signal an error and bail out.
//
if ((LOC < 1) || (LOC > (SIZE + 1))) {
SETMSG(b"Location was *.", ctx);
ERRINT(b"*", LOC, ctx);
SIGERR(b"SPICE(INVALIDINDEX)", ctx)?;
CHKOUT(b"INSLAD", ctx)?;
return Ok(());
}
//
// If the number of elements to be inserted is greater than zero,
// insert them. If not, do not modify the array.
//
if (NE > 0) {
//
// Move the trailing elements back to make room for the new ones.
//
for I in intrinsics::range(SIZE, LOC, -1) {
ARRAY[(I + NE)] = ARRAY[I];
}
//
// Now put the new elements in the vacated spaces.
//
for I in 1..=NE {
ARRAY[((LOC + I) - 1)] = ELTS[I];
}
//
// Update the number of elements in the array.
//
*NA = (SIZE + NE);
}
CHKOUT(b"INSLAD", ctx)?;
Ok(())
}