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 f2rust_std::*;
const CHR: i32 = 1;
const DP: i32 = 2;
const INT: i32 = 3;
const TIME: i32 = 4;
const LNSIZE: i32 = 80;
const MSGLEN: i32 = 160;
const NCOMP: i32 = 10;
const MAXMOD: i32 = 10;
const SHORT: i32 = 32;
//$Procedure ZZEKTCNV ( Private: EK, time conversion )
pub fn ZZEKTCNV(
TIMSTR: &[u8],
ET: &mut f64,
ERROR: &mut bool,
ERRMSG: &mut [u8],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut LOCSTR = [b' '; LNSIZE as usize];
let mut MODIFY = ActualCharArray::new(SHORT, 1..=MAXMOD);
let mut PICTUR = [b' '; LNSIZE as usize];
let mut SCLMSG = [b' '; MSGLEN as usize];
let mut TYPE = [b' '; SHORT as usize];
let mut SCLKDP: f64 = 0.0;
let mut TVEC = StackArray::<f64, 10>::new(1..=NCOMP);
let mut CLKID: i32 = 0;
let mut LOC: i32 = 0;
let mut NTVEC: i32 = 0;
let mut FND: bool = false;
let mut MODS: bool = false;
let mut SUCCES: bool = false;
let mut YABBRV: bool = false;
//
// SPICELIB functions
//
//
// Local parameters
//
//
// Local variables
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"ZZEKTCNV", ctx)?;
//
// No error to start with.
//
*ERROR = false;
fstr::assign(ERRMSG, b" ");
//
// Get a left-justified, compressed, upper-case copy of
// the string, so we can easily search it for substrings
// that would identify it as SCLK. If we do find a
// match, remove the identifying substring (of the form
// 'MO SCLK', 'VGR1 SCLK', etc.).
//
CMPRSS(b" ", 1, TIMSTR, &mut LOCSTR);
LJUST(&LOCSTR.clone(), &mut LOCSTR);
UCASE(&LOCSTR.clone(), &mut LOCSTR, ctx);
LOC = POSR(&LOCSTR, b"SCLK", RTRIM(&LOCSTR));
if (LOC > 0) {
//
// It's a SCLK string. Find the ID code, if we can.
//
SCN2ID(
fstr::substr(&LOCSTR, 1..=(LOC + 3)),
&mut CLKID,
&mut FND,
ctx,
)?;
if !FND {
//
// We don't recognize this SCLK type.
//
*ERROR = true;
if (LOC > 1) {
fstr::assign(
ERRMSG,
b"Time conversion failed; SCLK type <#> was not recognized.",
);
REPMC(
&ERRMSG.to_vec(),
b"#",
fstr::substr(TIMSTR, 1..=(LOC - 1)),
ERRMSG,
);
} else {
fstr::assign(
ERRMSG,
b"Time conversion failed; SCLK name was not supplied.",
);
}
CHKOUT(b"ZZEKTCNV", ctx)?;
return Ok(());
}
//
// If we got this far, we recognized the SCLK type.
// Convert the time to ET.
//
SCPARS(
CLKID,
fstr::substr(&LOCSTR, (LOC + 4)..),
ERROR,
&mut SCLMSG,
&mut SCLKDP,
ctx,
)?;
if FAILED(ctx) {
//
// We'll arrive here if the required SCLK kernel hasn't
// been loaded.
//
*ERROR = true;
fstr::assign(
ERRMSG,
b"Unexpected SPICELIB error encountered while attempting to parse the string <",
);
SUFFIX(TIMSTR, 0, ERRMSG);
SUFFIX(b">", 0, ERRMSG);
CHKOUT(b"ZZEKTCNV", ctx)?;
return Ok(());
} else if *ERROR {
fstr::assign(
ERRMSG,
b"The string <#> didn\'t parse as a spacecraft clock string.",
);
REPMC(&ERRMSG.to_vec(), b"#", TIMSTR, ERRMSG);
SUFFIX(&SCLMSG, 3, ERRMSG);
CHKOUT(b"ZZEKTCNV", ctx)?;
return Ok(());
} else {
SCT2E(CLKID, SCLKDP, ET, ctx)?;
if FAILED(ctx) {
*ERROR = true;
fstr::assign(
ERRMSG,
b"Unexpected SPICELIB error encountered while attempting to parse the string <",
);
SUFFIX(TIMSTR, 0, ERRMSG);
SUFFIX(b">", 0, ERRMSG);
CHKOUT(b"ZZEKTCNV", ctx)?;
return Ok(());
}
}
} else {
//
// We could have a standard time string. Make sure that the
// time string is acceptable before actually calling STR2ET.
//
TPARTV(
&LOCSTR,
TVEC.as_slice_mut(),
&mut NTVEC,
&mut TYPE,
MODIFY.as_arg_mut(),
&mut MODS,
&mut YABBRV,
&mut SUCCES,
&mut PICTUR,
ERRMSG,
ctx,
);
if SUCCES {
//
// It's safe to pass the string to STR2ET.
//
STR2ET(&LOCSTR, ET, ctx)?;
if FAILED(ctx) {
*ERROR = true;
fstr::assign(
ERRMSG,
b"Unexpected SPICELIB error encountered while attempting to parse the string <",
);
SUFFIX(TIMSTR, 0, ERRMSG);
SUFFIX(b">", 0, ERRMSG);
CHKOUT(b"ZZEKTCNV", ctx)?;
return Ok(());
}
} else {
//
// The string cannot be parsed by STR2ET. The error message
// was set by TPARTV.
//
*ERROR = true;
CHKOUT(b"ZZEKTCNV", ctx)?;
return Ok(());
}
//
// We're done with the standard time string case.
//
}
//
// We've parsed a time string, if it was an SCLK or standard string.
//
CHKOUT(b"ZZEKTCNV", ctx)?;
Ok(())
}