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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const BMARK: &[u8] = b"~NAIF/SPC BEGIN COMMENTS~";
const EMARK: &[u8] = b"~NAIF/SPC END COMMENTS~";
/// SPK and CK, ASCII to binary
///
/// Convert a text (ASCII) format SPK or CK file to an equivalent
/// binary file, including comments.
///
/// # Required Reading
///
/// * [SPC](crate::required_reading::spc)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// TEXT I Name of an existing text format SPK or CK file.
/// BINARY I Name of a binary SPK or CK file to be created.
/// ```
///
/// # Detailed Input
///
/// ```text
/// TEXT is the name of an existing text format SPK or CK
/// file that may contain comments in the appropriate
/// SPC format, as written by SPCB2A or SPCB2T. This
/// file is unchanged by calling SPCA2B.
///
/// BINARY is the name of a binary SPK or CK file to be created.
/// The binary file contains the same data and comments
/// as the text file, but in the binary format required
/// for use with the SPICELIB reader subroutines.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If there is an IOSTAT error while opening, reading, or writing
/// a file, the error is signaled by a routine in the call tree of
/// this routine.
///
/// 2) If the text file is not in the correct format, an error is
/// signaled by a routine in the call tree of this routine.
/// ```
///
/// # Files
///
/// ```text
/// See arguments TEXT and BINARY above.
/// ```
///
/// # Particulars
///
/// ```text
/// The SPICELIB SPK and CK reader subroutines read binary files.
/// However, because different computing environments have different
/// binary representations of numbers, you must convert SPK and CK
/// files to text format when porting from one system to another.
/// After converting the file to text, you can transfer it using
/// a transfer protocol program like Kermit or FTP. Then, convert
/// the text file back to binary format.
///
/// The following is a list of the SPICELIB routines that convert
/// SPK and CK files between binary and text format:
///
/// SPCA2B converts text to binary. It opens the text file,
/// creates a new binary file, and closes both files.
///
/// SPCB2A converts binary to text. It opens the binary file,
/// creates a new text file, and closes both files.
///
/// SPCT2B converts text to binary. It creates a new binary
/// file and closes it. The text file is open on
/// entrance and exit.
///
/// SPCB2T converts binary to text. It opens the binary
/// file and closes it. The text file is open on
/// entrance and exit
///
/// See the SPC required reading for more information
/// about SPC routines and the SPK and CK file formats.
/// ```
///
/// # Examples
///
/// ```text
/// This is an example of how to use SPCB2A and SPCA2B for
/// transferring files. Suppose A.BSP is a binary SPK file in
/// environment 1; to transfer it to environment 2, follow
/// these three steps:
///
/// 1) Call SPCB2A within a program in environment 1 to convert
/// the file to text:
///
/// CALL SPCB2A ( 'A.BSP', 'A.TSP' )
///
/// 2) Transfer the text file from environment 1 to environment 2
/// using FTP, Kermit, or some other file transfer utility,
/// for example,
///
/// ftp> put A.TSP
///
/// 3) Call SPCA2B within a program in environment 2 to convert
/// the file to binary on the new machine,
///
/// CALL SPCA2B ( 'A.TSP', 'A.BSP' )
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) This routine assumes that the data and comments in the
/// text format SPK or CK file come from a binary file
/// and were written by one of the routines SPCB2A or SPCB2T.
/// Data and/or comments written any other way may not be
/// in the correct format and, therefore, may not be handled
/// properly.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// J.E. McLean (JPL)
/// H.A. Neilan (JPL)
/// W.L. Taber (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.2.0, 03-JUN-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 1.1.1, 10-MAR-1992 (WLT)
///
/// Comment section for permuted index source lines was added
/// following the header.
///
/// - SPICELIB Version 1.1.0, 05-SEP-1991 (HAN)
///
/// Removed declarations of unused variables.
///
/// - SPICELIB Version 1.0.0, 05-APR-1991 (JEM)
/// ```
pub fn spca2b(ctx: &mut SpiceContext, text: &str, binary: &str) -> crate::Result<()> {
SPCA2B(text.as_bytes(), binary.as_bytes(), ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure SPCA2B ( SPK and CK, ASCII to binary )
pub fn SPCA2B(TEXT: &[u8], BINARY: &[u8], ctx: &mut Context) -> f2rust_std::Result<()> {
let mut UNIT: i32 = 0;
//
// SPICELIB functions
//
//
// Local parameters
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"SPCA2B", ctx)?;
}
//
// Open the text file with read access. SPCT2B will
// create the binary file and write the data and comments
// to it. Then we close the text file, and we're done.
//
TXTOPR(TEXT, &mut UNIT, ctx)?;
SPCT2B(UNIT, BINARY, ctx)?;
{
use f2rust_std::io;
let specs = io::CloseSpecs {
unit: Some(UNIT),
..Default::default()
};
ctx.close(specs)?;
}
CHKOUT(b"SPCA2B", ctx)?;
Ok(())
}