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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const ANWRDS: i32 = 22;
const AWRDS: i32 = 33;
const WDSIZE: i32 = 32;
struct SaveVars {
ANWORD: ActualCharArray,
AWORD: ActualCharArray,
MYWORD: Vec<u8>,
MYCASE: Vec<u8>,
BEGIN: Vec<u8>,
CAPS: i32,
START: ActualCharArray,
A: ActualCharArray,
AN: ActualCharArray,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut ANWORD = ActualCharArray::new(8, 1..=ANWRDS);
let mut AWORD = ActualCharArray::new(8, 1..=AWRDS);
let mut MYWORD = vec![b' '; WDSIZE as usize];
let mut MYCASE = vec![b' '; 1 as usize];
let mut BEGIN = vec![b' '; 1 as usize];
let mut CAPS: i32 = 0;
let mut START = ActualCharArray::new(WDSIZE, 1..=7);
let mut A = ActualCharArray::new(2, 1..=3);
let mut AN = ActualCharArray::new(2, 1..=3);
{
use f2rust_std::data::Val;
let mut clist = [Val::C(b"A"), Val::C(b"A"), Val::C(b"a")].into_iter();
A.iter_mut()
.for_each(|n| fstr::assign(n, clist.next().unwrap().into_str()));
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [Val::C(b"AN"), Val::C(b"An"), Val::C(b"an")].into_iter();
AN.iter_mut()
.for_each(|n| fstr::assign(n, clist.next().unwrap().into_str()));
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [
Val::C(b"HEIR"),
Val::C(b"HONEST"),
Val::C(b"HONOR"),
Val::C(b"H"),
Val::C(b"HOUR"),
Val::C(b"HORS "),
Val::C(b"HOMBRE"),
Val::C(b"F"),
Val::C(b"L"),
Val::C(b"M"),
Val::C(b"N"),
Val::C(b"R"),
Val::C(b"S"),
Val::C(b"X"),
Val::C(b"UNIN"),
Val::C(b"UNIM"),
Val::C(b"ONEI"),
Val::C(b"ONER"),
Val::C(b"SPK"),
Val::C(b"EK"),
Val::C(b"IK"),
Val::C(b"SCLK"),
]
.into_iter();
ANWORD
.iter_mut()
.for_each(|n| fstr::assign(n, clist.next().unwrap().into_str()));
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [
Val::C(b"HORSE"),
Val::C(b"ONE"),
Val::C(b"ONE-"),
Val::C(b"ONCE"),
Val::C(b"ONENESS"),
Val::C(b"UIG"),
Val::C(b"UIN"),
Val::C(b"UKA"),
Val::C(b"UKE"),
Val::C(b"UKO"),
Val::C(b"UKI"),
Val::C(b"UKU"),
Val::C(b"ULOT"),
Val::C(b"UNANI"),
Val::C(b"UNI"),
Val::C(b"UNINU"),
Val::C(b"UPA"),
Val::C(b"URA"),
Val::C(b"URE"),
Val::C(b"URO"),
Val::C(b"USA"),
Val::C(b"USE"),
Val::C(b"USU"),
Val::C(b"UTE"),
Val::C(b"UTI"),
Val::C(b"UTO"),
Val::C(b"UVA"),
Val::C(b"UVE"),
Val::C(b"UVU"),
Val::C(b"EU"),
Val::C(b"EWE"),
Val::C(b"UTRI"),
Val::C(b"U"),
]
.into_iter();
AWORD
.iter_mut()
.for_each(|n| fstr::assign(n, clist.next().unwrap().into_str()));
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
Self {
ANWORD,
AWORD,
MYWORD,
MYCASE,
BEGIN,
CAPS,
START,
A,
AN,
}
}
}
/// AN or A ?
///
/// Return the correct article "a" or "an" used to modify a word
/// and return it capitalized, lower case, or upper case.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// WORD I is a word that should be modified by "a" or "an".
/// CASE I 'U', 'L', or 'C' to specify capitalization of ANA.
///
/// The function returns the correct article, 'A' or 'AN', needed to
/// modify a word WORD, appropriately capitalized.
/// ```
///
/// # Detailed Input
///
/// ```text
/// WORD is any English word for which you want to write the
/// correct phrase "a(an) response(answer)". The case of the
/// letters of word do not matter.
///
/// Leading white space in word is ignored. The characters
/// " and ' are ignored. Thus ''' apple '' ' and
/// '"apple"' and ' apple' and 'apple' are all treated as
/// the same word.
///
/// CASE is a character that describes how the value returned in
/// ANA should be capitalized. The rules are:
///
/// 'U' --- ANA is returned in all caps ( A, AN )
/// 'C' --- ANA is returned capitalized ( A, An )
/// 'L' --- ANA is returned lower case ( a, an )
///
/// The case of CASE does not matter. Any value other than
/// those specified result in ANA being returned in all lower
/// case.
/// ```
///
/// # Detailed Output
///
/// ```text
/// The function returns the correct indefinite article needed to
/// modify the word contained in WORD.
///
/// ANA should be declared to be
///
/// CHARACTER*(2)
///
/// (or CHARACTER*(N) where N > 1) in the calling program.
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
///
/// 1) If the uppercase value of CASE is not 'U', 'C' or 'L', it
/// shall be treated as 'L'.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine allows you to construct grammatically correct phrases
/// when you need to modify a word by an indefinite article. Using
/// the pronunciations contained in the Webster's Ninth Collegiate
/// Dictionary, the phrase
///
/// ANA(WORD, CASE) // ' ' // WORD
///
/// will be grammatically correct.
/// ```
///
/// # Examples
///
/// ```text
/// Suppose you wished to construct one of the messages
///
/// 'a new file'
/// 'an existing file'
///
/// and that the NEW/EXISTING word was in the variable WORD. Then
/// you could write
///
/// MESSAGE = ANA( WORD, 'L' ) // ' ' // WORD // ' file '
/// CALL CMPRSS ( ' ', 1, MESSAGE, MESSAGE )
/// ```
///
/// # Literature References
///
/// ```text
/// [1] Merriam-Webster (Ed.), "Webster's Ninth New Collegiate
/// Dictionary," 10th edition, 1990.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// B.V. Semenov (JPL)
/// W.L. Taber (JPL)
/// E.D. Wright (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.3, 24-NOV-2021 (JDR)
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 1.1.2, 28-FEB-2008 (BVS)
///
/// Corrected the contents of the $Required_Reading section.
///
/// - SPICELIB Version 1.1.1, 22-SEP-2004 (EDW)
///
/// Added Copyright section.
///
/// - SPICELIB Version 1.1.0, 18-JAN-2001 (WLT)
///
/// Made SCLK an "an" word.
///
/// - SPICELIB Version 1.0.0, 29-NOV-1995 (WLT)
/// ```
pub fn ana(ctx: &mut SpiceContext, word: &str, case: &str, ana: &mut str) {
ANA(
word.as_bytes(),
case.as_bytes(),
fstr::StrBytes::new(ana).as_mut(),
ctx.raw_context(),
);
}
//$Procedure ANA ( AN or A ? )
pub fn ANA(WORD: &[u8], CASE: &[u8], ANA: &mut [u8], ctx: &mut Context) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
UCASE(WORD, &mut save.MYWORD, ctx);
REPLCH(&save.MYWORD.to_vec(), b"\'", b" ", &mut save.MYWORD);
REPLCH(&save.MYWORD.to_vec(), b"\"", b" ", &mut save.MYWORD);
LJUST(&save.MYWORD.to_vec(), &mut save.MYWORD);
UCASE(CASE, &mut save.MYCASE, ctx);
fstr::assign(ANA, b" ");
if fstr::eq(&save.MYCASE, b"U") {
save.CAPS = 1;
} else if fstr::eq(&save.MYCASE, b"C") {
save.CAPS = 2;
} else {
save.CAPS = 3;
}
//
// Handle the obvious things first.
//
fstr::assign(&mut save.BEGIN, fstr::substr(&save.MYWORD, 1..=1));
if (intrinsics::INDEX(b"AI", &save.BEGIN) > 0) {
fstr::assign(ANA, save.AN.get(save.CAPS));
return;
} else if (intrinsics::INDEX(b"BCDGJKPQTVWYZ", &save.BEGIN) > 0) {
fstr::assign(ANA, save.A.get(save.CAPS));
return;
}
//
// If we are still here, we need to be a bit more careful
// in our determination of ANA.
//
// Get the beginnings of the input word.
//
for I in 1..=7 {
fstr::assign(save.START.get_mut(I), fstr::substr(&save.MYWORD, 1..=I));
}
//
// Now see if the start of the input word belongs to
// one of the special collections.
//
for I in intrinsics::range(7, 2, -1) {
if (ISRCHC(&save.START[I], AWRDS, save.AWORD.as_arg()) != 0) {
fstr::assign(ANA, save.A.get(save.CAPS));
return;
}
if (ISRCHC(&save.START[I], ANWRDS, save.ANWORD.as_arg()) != 0) {
fstr::assign(ANA, save.AN.get(save.CAPS));
return;
}
}
//
// If we got this far we can determine the ANA by
// just looking at the beginning of the string.
//
if (intrinsics::INDEX(b"AEIOU", fstr::substr(&save.MYWORD, 1..=1)) > 0) {
fstr::assign(ANA, save.AN.get(save.CAPS));
} else {
fstr::assign(ANA, save.A.get(save.CAPS));
}
}