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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const ZZGET: i32 = -1;
const ZZPUT: i32 = -2;
const ZZRESET: i32 = -3;
const ZZNOP: i32 = 3;
const GEN: i32 = 1;
const GF_REF: i32 = 2;
const GF_TOL: i32 = 3;
const GF_DT: i32 = 4;
const NID: i32 = 4;
/// GF, set a tolerance value for GF
///
/// Override the default GF convergence value used in the high
/// level GF routines.
///
/// # Required Reading
///
/// * [GF](crate::required_reading::gf)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// ZZPUT P ZZHOLDD stores a DP value.
/// GF_TOL P ZZHOLDD acts on the GF subsystem tolerance.
/// VALUE I Double precision value returned or to store.
/// ```
///
/// # Detailed Input
///
/// ```text
/// VALUE is the scalar double precision value to use as the GF
/// subsystem convergence tolerance. This value will override
/// the default tolerance, CNVTOL, defined in gf.inc. Units
/// are TDB seconds.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If VALUE is not strictly greater-than-zero, the error
/// SPICE(INVALIDTOLERANCE) is signaled.
/// ```
///
/// # Particulars
///
/// ```text
/// The high level GF routines (see gf.req for a listing) use a
/// default value for the convergence tolerance, CNVTOL, defined in
/// gf.inc. It may occur that a GF search run needs a different
/// convergence tolerance. GFSTOL programmatically changes the
/// tolerance used by those routines.
/// ```
///
/// # Examples
///
/// ```text
/// The numerical results shown for this example may differ across
/// platforms. The results depend on the SPICE kernels used as
/// input, the compiler and supporting libraries, and the machine
/// specific arithmetic implementation.
///
/// 1) Perform a search for occultation events of the sun by earth as
/// observed from the Moon center. Search during the interval from
/// 14 A.D. SEP 1 to 14 A.D. SEP 30 (Julian).
///
/// Use the meta-kernel shown below to load the required SPICE
/// kernels.
///
///
/// KPL/MK
///
/// File name: gfstol_ex1.tm
///
/// This meta-kernel is intended to support operation of SPICE
/// example programs. The kernels shown here should not be
/// assumed to contain adequate or correct versions of data
/// required by SPICE-based user applications.
///
/// In order for an application to use this meta-kernel, the
/// kernels referenced here must be present in the user's
/// current working directory.
///
/// The names and contents of the kernels referenced
/// by this meta-kernel are as follows:
///
/// File name Contents
/// --------- --------
/// pck00009.tpc Planet orientation and
/// radii
/// naif0009.tls Leapseconds
///
/// \begindata
///
/// KERNELS_TO_LOAD = ( 'pck00009.tpc',
/// 'naif0009.tls' )
///
/// \begintext
///
/// End of meta-kernel.
///
///
/// Use the SPK kernel below to load the required ephemeris,
/// covering year 14 AD.
///
/// de408.bsp
///
///
/// Example code begins here.
///
///
/// PROGRAM GFSTOL_EX1
/// IMPLICIT NONE
///
/// C
/// C SPICELIB functions
/// C
/// INTEGER WNCARD
///
/// C
/// C Local parameters
/// C
/// CHARACTER*(*) TIMFMT
/// PARAMETER ( TIMFMT =
/// . 'YYYY ERA MON DD HR:MN:SC.#### ::JCAL' )
///
/// INTEGER MAXWIN
/// PARAMETER ( MAXWIN = 2 * 100 )
///
/// INTEGER TIMLEN
/// PARAMETER ( TIMLEN = 40 )
///
/// INTEGER LBCELL
/// PARAMETER ( LBCELL = -5 )
///
/// C
/// C Local variables
/// C
/// CHARACTER*(TIMLEN) WIN0
/// CHARACTER*(TIMLEN) WIN1
/// CHARACTER*(TIMLEN) BEGSTR
/// CHARACTER*(TIMLEN) ENDSTR
///
/// DOUBLE PRECISION CNFINE ( LBCELL : 2 )
/// DOUBLE PRECISION RESULT ( LBCELL : MAXWIN )
/// DOUBLE PRECISION ET0
/// DOUBLE PRECISION ET1
/// DOUBLE PRECISION LEFT
/// DOUBLE PRECISION RIGHT
/// DOUBLE PRECISION STEP
///
/// INTEGER I
///
/// LOGICAL OK
///
/// C
/// C Saved variables
/// C
/// C The confinement and result windows CNFINE and RESULT are
/// C saved because this practice helps to prevent stack
/// C overflow.
/// C
/// SAVE CNFINE
/// SAVE RESULT
///
/// C
/// C Load kernels.
/// C
/// CALL FURNSH ( 'gfstol_ex1.tm' )
///
/// C
/// C Use an SPK covering year 14 AD.
/// C
/// CALL FURNSH ( 'de408.bsp' )
///
/// C
/// C Initialize the confinement and result windows.
/// C
/// CALL SSIZED ( 2, CNFINE )
/// CALL SSIZED ( MAXWIN, RESULT )
///
/// C
/// C Obtain the TDB time bounds of the confinement
/// C window, which is a single interval in this case.
/// C
/// WIN0 = '14 A.D. SEP 1 00:00:00'
/// WIN1 = '14 A.D. SEP 30 00:00:00'
///
/// CALL STR2ET ( WIN0, ET0 )
/// CALL STR2ET ( WIN1, ET1 )
///
/// C
/// C Insert the time bounds into the confinement
/// C window.
/// C
/// CALL WNINSD ( ET0, ET1, CNFINE )
///
/// C
/// C Select a 3-minute step. We'll ignore any occultations
/// C lasting less than 3 minutes.
/// C
/// STEP = 180.D0
///
/// C
/// C Perform the search. ET0 and ET1 have values ~-6*10^10,
/// C CNVTOL has value 10^-6, so double precision addition or
/// C subtraction of ET0 and ET1 with CNVTOL returns a result
/// C indistinguishable from ET0 and ET1.
/// C
/// C Reduce the GF convergence tolerance by an order of
/// C magnitude to resolve this condition.
/// C
/// CALL GFSTOL ( 1D-5 )
///
/// CALL GFOCLT ( 'ANY',
/// . 'EARTH', 'ellipsoid', 'IAU_EARTH',
/// . 'SUN', 'ellipsoid', 'IAU_SUN',
/// . 'LT', 'MOON', STEP,
/// . CNFINE, RESULT )
///
///
/// IF ( WNCARD(RESULT) .EQ. 0 ) THEN
///
/// WRITE (*,*) 'No occultation was found.'
///
/// ELSE
///
/// DO I = 1, WNCARD(RESULT)
///
/// C
/// C Fetch and display each occultation interval.
/// C
/// CALL WNFETD ( RESULT, I, LEFT, RIGHT )
///
/// CALL TIMOUT ( LEFT, TIMFMT, BEGSTR )
/// CALL TIMOUT ( RIGHT, TIMFMT, ENDSTR )
///
/// WRITE (*,*) 'Interval ', I
/// WRITE (*,*) ' Start time: '//BEGSTR
/// WRITE (*,*) ' Stop time: '//ENDSTR
///
/// END DO
///
/// END IF
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Interval 1
/// Start time: 14 A.D. SEP 27 05:02:02.8250
/// Stop time: 14 A.D. SEP 27 09:33:31.6995
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// E.D. Wright (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.0.1, 06-JUL-2021 (JDR)
///
/// Edited the header to comply with NAIF standard.
///
/// Added SAVE statements for CNFINE and RESULT variables in code
/// example.
///
/// - SPICELIB Version 1.0.0, 18-APR-2014 (EDW)
/// ```
pub fn gfstol(ctx: &mut SpiceContext, value: f64) -> crate::Result<()> {
GFSTOL(value, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure GFSTOL ( GF, set a tolerance value for GF )
pub fn GFSTOL(VALUE: f64, ctx: &mut Context) -> f2rust_std::Result<()> {
let mut OK: bool = false;
//
// SPICELIB functions
//
//
// Local variables.
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
}
//
// This routine wraps a call to ZZHOLDD with the appropriate ID and
// OP value.
//
//
// Check tolerance value.
//
if (VALUE <= 0.0) {
CHKIN(b"GFSTOL", ctx)?;
SETMSG(
b"Convergence tolerance must be greater-than zero. Input VALUE = #.",
ctx,
);
ERRDP(b"#", VALUE, ctx);
SIGERR(b"SPICE(INVALIDTOLERANCE)", ctx)?;
CHKOUT(b"GFSTOL", ctx)?;
return Ok(());
} else {
ZZHOLDD_ZZPUT(ZZPUT, GF_TOL, &mut OK, VALUE, ctx)?;
}
Ok(())
}