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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const LINLEN: i32 = 1000;
const BUFSIZ: i32 = 22;
//$Procedure DAFECU( DAF extract comments to a logical unit )
pub fn DAFECU(
HANDLE: i32,
COMLUN: i32,
COMNTS: &mut bool,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut COMBUF = ActualCharArray::new(LINLEN, 1..=BUFSIZ);
let mut IOSTAT: i32 = 0;
let mut NUMCOM: i32 = 0;
let mut EOC: bool = false;
let mut GOTSOM: bool = false;
let mut OPENED: bool = false;
//
// SPICELIB functions
//
//
// Local parameters
//
// Set the value for the maximum length of a text line.
//
//
// Set the size of the comment buffer.
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if spicelib::RETURN(ctx) {
return Ok(());
} else {
spicelib::CHKIN(b"DAFECU", ctx)?;
}
//
// Verify that the DAF file attached to HANDLE is opened for reading.
//
spicelib::DAFSIH(HANDLE, b"READ", ctx)?;
if spicelib::FAILED(ctx) {
spicelib::CHKOUT(b"DAFECU", ctx)?;
return Ok(());
}
//
// Logical units must be positive. If it is not, signal an error.
//
if (COMLUN <= 0) {
spicelib::SETMSG(
b"# is not a valid logical unit. Logical units must be positive.",
ctx,
);
spicelib::ERRINT(b"#", COMLUN, ctx);
spicelib::SIGERR(b"SPICE(INVALIDARGUMENT)", ctx)?;
spicelib::CHKOUT(b"DAFECU", ctx)?;
return Ok(());
}
//
// Verify that there is an open ASCII text file attached to COMLUN.
//
{
use f2rust_std::io;
let specs = io::InquireSpecs {
unit: Some(COMLUN),
opened: Some(&mut OPENED),
..Default::default()
};
IOSTAT = io::capture_iostat(|| ctx.inquire(specs))?;
}
if (IOSTAT != 0) {
spicelib::SETMSG(
b"The INQUIRE on logical unit # failed. The value of IOSTAT was #.",
ctx,
);
spicelib::ERRINT(b"#", COMLUN, ctx);
spicelib::ERRINT(b"#", IOSTAT, ctx);
spicelib::SIGERR(b"SPICE(INQUIREFAILED)", ctx)?;
spicelib::CHKOUT(b"DAFECU", ctx)?;
return Ok(());
}
if !OPENED {
spicelib::SETMSG(
b"There is no open file attached to logical unit #, so no comments could be written.",
ctx,
);
spicelib::ERRINT(b"#", COMLUN, ctx);
spicelib::SIGERR(b"SPICE(INVALIDARGUMENT)", ctx)?;
spicelib::CHKOUT(b"DAFECU", ctx)?;
return Ok(());
}
//
// Initialize some things before the loop.
//
NUMCOM = 0;
EOC = false;
GOTSOM = false;
while !EOC {
//
// While we have not reached the end of the comments, get some
// more.
//
spicelib::DAFEC(
HANDLE,
BUFSIZ,
&mut NUMCOM,
COMBUF.as_arg_mut(),
&mut EOC,
ctx,
)?;
if spicelib::FAILED(ctx) {
spicelib::CHKOUT(b"DAFECU", ctx)?;
return Ok(());
}
if (NUMCOM > 0) {
//
// If NUMCOM .GT. 0 then we did get some comments, and we need
// to write them out, but first, set the flag indicating that
// we got some comments.
//
if !GOTSOM {
GOTSOM = true;
}
spicelib::WRITLA(NUMCOM, COMBUF.as_arg(), COMLUN, ctx)?;
if spicelib::FAILED(ctx) {
spicelib::CHKOUT(b"DAFECU", ctx)?;
return Ok(());
}
}
}
//
// Set the output flag indicating whether or not we got any comments.
//
*COMNTS = GOTSOM;
spicelib::CHKOUT(b"DAFECU", ctx)?;
Ok(())
}