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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const IMPLE: i32 = 0;
const IMPCLS: i32 = 1;
const EXPLT: i32 = 2;
const EXPLE: i32 = 3;
const EXPCLS: i32 = 4;
const MNIDXT: i32 = 0;
const MXIDXT: i32 = 4;
const CONBAS: i32 = 1;
const NCON: i32 = (CONBAS + 1);
const RDRBAS: i32 = (NCON + 1);
const NRDR: i32 = (RDRBAS + 1);
const RDRTYP: i32 = (NRDR + 1);
const REFBAS: i32 = (RDRTYP + 1);
const NREF: i32 = (REFBAS + 1);
const PDRBAS: i32 = (NREF + 1);
const NPDR: i32 = (PDRBAS + 1);
const PDRTYP: i32 = (NPDR + 1);
const PKTBAS: i32 = (PDRTYP + 1);
const NPKT: i32 = (PKTBAS + 1);
const RSVBAS: i32 = (NPKT + 1);
const NRSV: i32 = (RSVBAS + 1);
const PKTSZ: i32 = (NRSV + 1);
const PKTOFF: i32 = (PKTSZ + 1);
const NMETA: i32 = (PKTOFF + 1);
const MXMETA: i32 = NMETA;
const MNMETA: i32 = 15;
/// Generic Segments: Fetch constants
///
/// Fetch from the constants partition of a generic segment the
/// double precision numbers from FIRST to LAST. The segment is
/// identified by a DAF file handle and segment descriptor.
///
/// # Required Reading
///
/// * [DAF](crate::required_reading::daf)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// HANDLE I Handle of a DAF open for reading.
/// DESCR I Descriptor for a generic segment in the DAF.
/// FIRST I The index of the first constant value to fetch.
/// LAST I The index of the last constant value to fetch.
/// VALUES O The constant values that were requested.
/// ```
///
/// # Detailed Input
///
/// ```text
/// HANDLE is the handle of a DAF opened for reading that
/// contains the segment described by DESCR.
///
/// DESCR is the descriptor of the segment with the desired
/// constant values. This must be the descriptor for a
/// generic segment in the DAF associated with HANDLE.
///
/// FIRST is the index of the first value to fetch from the
/// constants section of the generic segment associated
/// with HANDLE and DESCR.
///
/// LAST is the index of the last value to fetch from the
/// constants section of the generic segment associated
/// with HANDLE and DESCR.
/// ```
///
/// # Detailed Output
///
/// ```text
/// VALUES is the array of constant values obtained from the
/// constants section of the generic segment associated
/// with HANDLE and DESCR.
/// ```
///
/// # Parameters
///
/// ```text
/// This subroutine makes use of parameters defined in the file
/// 'sgparam.inc'.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If FIRST is less than 1 or LAST is greater than the number of
/// constants, the error SPICE(REQUESTOUTOFBOUNDS) is signaled.
///
/// 2) If LAST is less than FIRST, the error SPICE(REQUESTOUTOFORDER)
/// is signaled.
/// ```
///
/// # Files
///
/// ```text
/// See the description of HANDLE above.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine allows easy access to values from the constants
/// partition of a generic segment in a DAF file. Please see the DAF
/// Required Reading or the include file 'sgparam.inc' for a more
/// detailed description of a generic segment.
/// ```
///
/// # Examples
///
/// ```text
/// Suppose that you have located a DAF generic segment. The
/// fragment of code below shows how to fetch all of the
/// constants from that segment.
///
/// Declarations:
///
/// DOUBLE PRECISION CONSTS(<enough room to hold constants>)
///
/// INTEGER MYNCON
///
/// Get the number of items in the constants section.
///
/// CALL SGMETA ( HANDLE, DESCR, NCON, MYNCON )
///
/// Fetch the constants from the segment.
///
/// CALL SGFCON ( HANDLE, DESCR, 1, MYNCON, CONSTS )
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) The segment described by DESCR must be a generic segment,
/// otherwise the results of this routine are not predictable.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// K.R. Gehringer (JPL)
/// W.L. Taber (JPL)
/// E.D. Wright (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.1, 26-OCT-2021 (JDR)
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 1.1.0, 07-SEP-2001 (EDW)
///
/// Replaced DAFRDA call with DAFGDA.
///
/// - SPICELIB Version 1.0.0, 11-APR-1995 (KRG) (WLT)
/// ```
pub fn sgfcon(
ctx: &mut SpiceContext,
handle: i32,
descr: &[f64],
first: i32,
last: i32,
values: &mut [f64],
) -> crate::Result<()> {
SGFCON(handle, descr, first, last, values, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure SGFCON ( Generic Segments: Fetch constants )
pub fn SGFCON(
HANDLE: i32,
DESCR: &[f64],
FIRST: i32,
LAST: i32,
VALUES: &mut [f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let DESCR = DummyArray::new(DESCR, 1..);
let mut VALUES = DummyArrayMut::new(VALUES, 1..);
let mut B: i32 = 0;
let mut BASE: i32 = 0;
let mut E: i32 = 0;
let mut MYNCON: i32 = 0;
//
// SPICELIB Functions
//
//
// Local Parameters
//
// Include the mnemonic values for the generic segment declarations.
//
//
// Local Variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"SGFCON", ctx)?;
//
// Get the value for the base of the constants and the number of
// constants in the generic segment.
//
SGMETA(HANDLE, DESCR.as_slice(), CONBAS, &mut BASE, ctx)?;
SGMETA(HANDLE, DESCR.as_slice(), NCON, &mut MYNCON, ctx)?;
if FAILED(ctx) {
CHKOUT(b"SGFCON", ctx)?;
return Ok(());
}
//
// Perform checks on the inputs for reasonableness.
//
if ((FIRST < 1) || (LAST > MYNCON)) {
SETMSG(b"The range of constants requested extends beyond the available constant data. Constants are available for indices 1 to #. You have requested data from # to #. ", ctx);
ERRINT(b"#", MYNCON, ctx);
ERRINT(b"#", FIRST, ctx);
ERRINT(b"#", LAST, ctx);
SIGERR(b"SPICE(REQUESTOUTOFBOUNDS)", ctx)?;
CHKOUT(b"SGFCON", ctx)?;
return Ok(());
}
if (LAST < FIRST) {
SETMSG(
b"The last constant item requested, #, is before the first constant item requested, #.",
ctx,
);
ERRINT(b"#", LAST, ctx);
ERRINT(b"#", FIRST, ctx);
SIGERR(b"SPICE(REQUESTOUTOFORDER)", ctx)?;
CHKOUT(b"SGFCON", ctx)?;
return Ok(());
}
//
// Compute the addresses of the data within the file and then fetch
// the data.
//
B = (BASE + FIRST);
E = (BASE + LAST);
DAFGDA(HANDLE, B, E, VALUES.as_slice_mut(), ctx)?;
CHKOUT(b"SGFCON", ctx)?;
Ok(())
}