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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// STAR catalog type 1, get star data
///
/// Get data for a single star from a SPICE type 1 star catalog.
///
/// # Required Reading
///
/// * [EK](crate::required_reading::ek)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// INDEX I Star index.
/// RA O Right ascension in radians.
/// DEC O Declination in radians.
/// RASIG O Right ascension uncertainty in radians.
/// DECSIG O Declination uncertainty in radians.
/// CATNUM O Catalog number.
/// SPTYPE O Spectral type.
/// VMAG O Visual magnitude.
/// ```
///
/// # Detailed Input
///
/// ```text
/// INDEX is the index of the star in the list of stars
/// that satisfy the selection criteria specified in
/// the last call to STCF01.
/// ```
///
/// # Detailed Output
///
/// ```text
/// RA is right ascension of the star at the catalog epoch
/// in radians relative to the J2000 inertial frame.
///
/// DEC is declination of the star at the catalog epoch in
/// radians relative to the J2000 inertial frame.
///
/// RASIG is the uncertainty in right ascension of the star at
/// the catalog epoch in radians.
///
/// DECSIG is the uncertainty in declination of the star at
/// the catalog epoch in radians.
///
/// CATNUM is the star number in the catalog.
///
/// SPTYPE is the star's spectral type. See catalog description
/// for more information regarding encoding of spectral
/// type values.
///
/// VMAG is the visual magnitude of the star.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If fetching of any of output values fails, the error
/// SPICE(BADSTARINDEX) is signaled.
///
/// 2) If no star catalog has been loaded, an error is signaled by a
/// routine in the call tree of this routine.
///
/// 3) If a star catalog type 1 was not queried by calling STCF01
/// before calling this routine, an error is signaled by a routine
/// in the call tree of this routine.
/// ```
///
/// # Files
///
/// ```text
/// This routine reads the data from SPICE type 1 star catalog file
/// loaded into the program by a call to STCL01.
///
/// SPICE type 1 star catalog files MUST contain a single data table.
/// It can occupy a single segment or it can spread across multiple
/// segments. This table MUST include the following columns:
///
/// column name data type units
/// ----------------------------------------------------
/// RA DOUBLE PRECISION DEGREES
/// DEC DOUBLE PRECISION DEGREES
/// RA_SIGMA DOUBLE PRECISION DEGREES
/// DEC_SIGMA DOUBLE PRECISION DEGREES
/// CATALOG_NUMBER INTEGER
/// SPECTRAL_TYPE CHARACTER*(4)
/// VISUAL_MAGNITUDE DOUBLE PRECISION
///
/// Nulls are not allowed in any of the columns.
/// Other columns can also be present in the table but their data
/// will NOT be accessible through STCF01 and STCG01 --
/// the interface used to access data in the catalog. Note
/// that the names and attributes of these additional columns
/// must be identical for all segments containing this table.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine is intended to be a part of the user interface to
/// the SPICE type 1 star catalog. It allows the caller to retrieve
/// data for a single star found by STCF01 using the star's
/// index within the search result array. This subroutine MUST
/// NOT be called before a search by STCF01 was done.
///
/// Other routines in the SPICE type 1 star catalog access
/// family are:
///
/// STCL01 load the catalog file and make its data
/// available for search and retrieval.
///
/// STCF01 search through the catalog for all stars within
/// a specified RA-DEC rectangle.
/// ```
///
/// # Examples
///
/// ```text
/// In the following code fragment, STCG01 is used to retrieve
/// position and characteristics for every star within an RA - DEC
/// rectangle from a particular SPICE type 1 star catalog.
///
/// C
/// C Load catalog file.
/// C
/// CALL STCL01 ( CATFN, TABNAM, HANDLE )
/// C
/// C Search through the loaded catalog.
/// C
/// CALL STCF01 ( TABNAM, RAMIN, RAMAX,
/// . DECMIN, DECMAX, NSTARS )
/// C
/// C Retrieve data for every star found.
/// C
/// DO I = 1, NSTARS
///
/// CALL STCG01 ( I, RA, DEC, RASIG, DECSIG,
/// . CATNUM, SPTYPE, VMAG )
///
/// END DO
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) The catalog file STCG01 reads data from MUST be loaded
/// by STCL01 and a search through the catalog MUST be done by
/// STCF01 before STCG01 is called.
///
/// 2) No other EK queries can be made between the call to STCF01
/// and the call to STCG01.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// B.V. Semenov (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 16-JUN-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Updated header to comply with NAIF standard. Corrected argument
/// names "RASIG" and "DECSIG" in $Brief_I/O.
///
/// Updated entry #3 in $Exceptions section.
///
/// - SPICELIB Version 1.0.0, 15-MAY-1996 (BVS)
/// ```
pub fn stcg01(
ctx: &mut SpiceContext,
index: i32,
ra: &mut f64,
dec: &mut f64,
rasig: &mut f64,
decsig: &mut f64,
catnum: &mut i32,
sptype: &mut str,
vmag: &mut f64,
) -> crate::Result<()> {
STCG01(
index,
ra,
dec,
rasig,
decsig,
catnum,
fstr::StrBytes::new(sptype).as_mut(),
vmag,
ctx.raw_context(),
)?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure STCG01 ( STAR catalog type 1, get star data )
pub fn STCG01(
INDEX: i32,
RA: &mut f64,
DEC: &mut f64,
RASIG: &mut f64,
DECSIG: &mut f64,
CATNUM: &mut i32,
SPTYPE: &mut [u8],
VMAG: &mut f64,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut FOUND: bool = false;
let mut NULL: bool = false;
//
//
// SPICELIB functions
//
//
// Local variables.
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"STCG01", ctx)?;
}
//
// Fetch data from the catalog in the following order
// as defined QUERY string template in STCF01 routine
//
// RA, DEC, RASIG, DECSIG, CATNUM, SPTYPE, VMAG
//
// Check FOUNDs and report error if any of the parameters
// is not found.
//
// Since NULLs are not allowed in any of the star catalog
// columns, no check for NULLs is performed.
//
EKGD(1, INDEX, 1, RA, &mut NULL, &mut FOUND, ctx)?;
if !FOUND {
SETMSG(b"RA value for star # not found. ", ctx);
ERRINT(b"#", INDEX, ctx);
SIGERR(b"SPICE(BADSTARINDEX)", ctx)?;
CHKOUT(b"STCG01", ctx)?;
return Ok(());
}
EKGD(2, INDEX, 1, DEC, &mut NULL, &mut FOUND, ctx)?;
if !FOUND {
SETMSG(b"DEC value for star # not found. ", ctx);
ERRINT(b"#", INDEX, ctx);
SIGERR(b"SPICE(BADSTARINDEX)", ctx)?;
CHKOUT(b"STCG01", ctx)?;
return Ok(());
}
EKGD(3, INDEX, 1, RASIG, &mut NULL, &mut FOUND, ctx)?;
if !FOUND {
SETMSG(b"RASIG value for star # not found. ", ctx);
ERRINT(b"#", INDEX, ctx);
SIGERR(b"SPICE(BADSTARINDEX)", ctx)?;
CHKOUT(b"STCG01", ctx)?;
return Ok(());
}
EKGD(4, INDEX, 1, DECSIG, &mut NULL, &mut FOUND, ctx)?;
if !FOUND {
SETMSG(b"DECSIG value for star # not found.", ctx);
ERRINT(b"#", INDEX, ctx);
SIGERR(b"SPICE(BADSTARINDEX)", ctx)?;
CHKOUT(b"STCG01", ctx)?;
return Ok(());
}
EKGI(5, INDEX, 1, CATNUM, &mut NULL, &mut FOUND, ctx)?;
if !FOUND {
SETMSG(b"CATNUM value for star # not found.", ctx);
ERRINT(b"#", INDEX, ctx);
SIGERR(b"SPICE(BADSTARINDEX)", ctx)?;
CHKOUT(b"STCG01", ctx)?;
return Ok(());
}
EKGC(6, INDEX, 1, SPTYPE, &mut NULL, &mut FOUND, ctx)?;
if !FOUND {
SETMSG(b"SPTYPE value for star # not found.", ctx);
ERRINT(b"#", INDEX, ctx);
SIGERR(b"SPICE(BADSTARINDEX)", ctx)?;
CHKOUT(b"STCG01", ctx)?;
return Ok(());
}
EKGD(7, INDEX, 1, VMAG, &mut NULL, &mut FOUND, ctx)?;
if !FOUND {
SETMSG(b"VMAG value for star # not found. ", ctx);
ERRINT(b"#", INDEX, ctx);
SIGERR(b"SPICE(BADSTARINDEX)", ctx)?;
CHKOUT(b"STCG01", ctx)?;
return Ok(());
}
//
// Convert angles to radians before return.
//
*RA = (*RA * RPD(ctx));
*DEC = (*DEC * RPD(ctx));
*RASIG = (*RASIG * RPD(ctx));
*DECSIG = (*DECSIG * RPD(ctx));
CHKOUT(b"STCG01", ctx)?;
Ok(())
}