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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
pub const LBCELL: i32 = -5;
/// Copy a character cell
///
/// Copy the contents of a character cell to another cell.
///
/// # Required Reading
///
/// * [CELLS](crate::required_reading::cells)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// CELL I Cell to be copied.
/// COPY O New cell.
/// ```
///
/// # Detailed Input
///
/// ```text
/// CELL is a cell.
/// ```
///
/// # Detailed Output
///
/// ```text
/// COPY is a cell which contains the same elements as the
/// input cell, in the same order. If the size (maximum
/// cardinality) of the output cell is smaller than
/// the cardinality of the input cell, then only as many
/// items as will fit in the output cell are copied,
/// and an error is signaled.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the output cell in not large enough to hold the elements
/// of the input cell, the error SPICE(CELLTOOSMALL) is signaled.
///
/// 2) If length of the elements of the output cell is less than the
/// length of the elements of the input cell, the error
/// SPICE(ELEMENTSTOOSHORT) is signaled.
/// ```
///
/// # Particulars
///
/// ```text
/// The copy routines (COPYC, COPYD, and COPYI) are used primarily
/// to manipulate working cells, since many routines that use cells
/// (binary set routines, for instance) do not allow cells to be
/// combined or manipulated in place.
/// ```
///
/// # Examples
///
/// ```text
/// In the following example, COPYC is used to copy the result
/// of the union of two sets (ordered cells) from a temporary
/// working set back into the one of the original set.
///
/// CALL UNIONC ( BODIES, PLANETS, TEMP )
/// CALL COPYC ( TEMP, BODIES )
///
/// If the size of the temporary cell is greater than the size
/// of the original set, the function FAILED should be checked to be
/// sure that no overflow occurred. If BODIES is at least as
/// large as TEMP, no such check is necessary.
/// ```
///
/// # Author and Institution
///
/// ```text
/// C.A. Curzon (JPL)
/// J. Diaz del Rio (ODC Space)
/// W.L. Taber (JPL)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 20-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 (CAC) (WLT) (IMU)
/// ```
///
/// # Revisions
///
/// ```text
/// - Beta Version 2.0.0, 09-JAN-1989 (NJB)
///
/// Error signaled if output set elements are not long enough.
/// Length must be at least max of lengths of input elements.
/// Also, calling protocol for EXCESS has been changed. And,
/// elements LBCELL through -2 of control area are now copied to
/// the output cell.
/// ```
pub fn copyc(ctx: &mut SpiceContext, cell: CharArray, copy: CharArrayMut) -> crate::Result<()> {
COPYC(cell, copy, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure COPYC ( Copy a character cell )
pub fn COPYC(CELL: CharArray, COPY: CharArrayMut, ctx: &mut Context) -> f2rust_std::Result<()> {
let CELL = DummyCharArray::new(CELL, None, LBCELL..);
let mut COPY = DummyCharArrayMut::new(COPY, None, LBCELL..);
let mut SIZE: i32 = 0;
let mut CARD: i32 = 0;
let mut MOVED: i32 = 0;
let mut TRUNC: bool = false;
let mut REQLEN: i32 = 0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Set up the error processing.
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"COPYC", ctx)?;
//
// We need the cardinality of the input cell, and the size of
// the output cell.
//
CARD = CARDC(CELL.as_arg(), ctx)?;
SIZE = SIZEC(COPY.as_arg(), ctx)?;
//
// Start moving the elements, one by one. Stop if the output
// cell fills up. Copy the control area too, except for the
// the size and cardinality values. Truncation indicator
// starts at .FALSE.
//
TRUNC = false;
REQLEN = 0;
MOVED = intrinsics::MIN0(&[CARD, SIZE]);
for I in 1..=MOVED {
fstr::assign(COPY.get_mut(I), CELL.get(I));
//
// Test for truncation:
//
if fstr::ne(COPY.get(I), CELL.get(I)) {
TRUNC = true;
REQLEN = intrinsics::MAX0(&[REQLEN, LASTPC(&CELL[I])]);
}
}
for I in LBCELL..=-2 {
fstr::assign(COPY.get_mut(I), CELL.get(I));
//
// Test for truncation:
//
if fstr::ne(COPY.get(I), CELL.get(I)) {
TRUNC = true;
REQLEN = intrinsics::MAX0(&[REQLEN, LASTPC(&CELL[I])]);
}
}
//
// Set the cardinality of the output cell.
//
SCARDC(MOVED, COPY.as_arg_mut(), ctx)?;
//
// We've got an error if the output cell was too small.
//
if (SIZE < CARD) {
EXCESS((CARD - SIZE), b"cell", ctx)?;
SIGERR(b"SPICE(CELLTOOSMALL)", ctx)?;
CHKOUT(b"COPYC", ctx)?;
return Ok(());
}
//
// We also have an error if the output set elements are not long
// enough.
//
if TRUNC {
SETMSG(
b"Length of output cell is #. Length required to contain result is #.",
ctx,
);
ERRINT(b"#", intrinsics::LEN(©[LBCELL]), ctx);
ERRINT(b"#", REQLEN, ctx);
SIGERR(b"SPICE(ELEMENTSTOOSHORT)", ctx)?;
CHKOUT(b"COPYC", ctx)?;
return Ok(());
}
CHKOUT(b"COPYC", ctx)?;
Ok(())
}