rsspice 0.1.0

Pure Rust port of the SPICE Toolkit for space geometry
Documentation
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
//
// GENERATED FILE
//

use super::*;
use f2rust_std::*;

const RECSYS: &[u8] = b"RECTANGULAR";
const LATSYS: &[u8] = b"LATITUDINAL";
const SPHSYS: &[u8] = b"SPHERICAL";
const RADSYS: &[u8] = b"RA/DEC";
const CYLSYS: &[u8] = b"CYLINDRICAL";
const GEOSYS: &[u8] = b"GEODETIC";
const PGRSYS: &[u8] = b"PLANETOGRAPHIC";
const XCRD: &[u8] = b"X";
const YCRD: &[u8] = b"Y";
const ZCRD: &[u8] = b"Z";
const RADCRD: &[u8] = b"RADIUS";
const LONCRD: &[u8] = b"LONGITUDE";
const LATCRD: &[u8] = b"LATITUDE";
const RACRD: &[u8] = b"RIGHT ASCENSION";
const DECCRD: &[u8] = b"DECLINATION";
const RNGCRD: &[u8] = b"RANGE";
const CLTCRD: &[u8] = b"COLATITUDE";
const ALTCRD: &[u8] = b"ALTITUDE";
const POSDEF: &[u8] = b"POSITION";
const SOBDEF: &[u8] = b"SUB-OBSERVER POINT";
const SINDEF: &[u8] = b"SURFACE INTERCEPT POINT";
const NWREL: i32 = 5;
const NWLONG: i32 = 7;
const EXWIDX: i32 = ((NWREL + NWLONG) + 1);
const MXBEGM: i32 = 55;
const MXENDM: i32 = 13;
const MXMSG: i32 = ((MXBEGM + MXENDM) + 10);
const REPFIL: &[u8] = b"zzgfrpwk.txt";
const VTIGHT: f64 = 0.000000000001;
const LNSIZE: i32 = 80;
const MAXWIN: i32 = 400;

struct SaveVars {
    BEGMSG: Vec<u8>,
    ENDMSG: Vec<u8>,
    LINE: Vec<u8>,
    PCTSTR: Vec<u8>,
    QNAME: Vec<u8>,
    XBEGMS: Vec<u8>,
    XENDMS: Vec<u8>,
    XLINE: Vec<u8>,
    FRAC: f64,
    INCR: f64,
    TOTAL: f64,
    WAIT: f64,
    XINCR: f64,
    XTOTAL: f64,
    XWAIT: f64,
    IOSTAT: i32,
    NRPORT: i32,
    TCHECK: i32,
    UNIT: i32,
    XCHECK: i32,
    XNL: i32,
    XUNIT: i32,
}

impl SaveInit for SaveVars {
    fn new() -> Self {
        let mut BEGMSG = vec![b' '; MXBEGM as usize];
        let mut ENDMSG = vec![b' '; MXENDM as usize];
        let mut LINE = vec![b' '; LNSIZE as usize];
        let mut PCTSTR = vec![b' '; LNSIZE as usize];
        let mut QNAME = vec![b' '; LNSIZE as usize];
        let mut XBEGMS = vec![b' '; MXBEGM as usize];
        let mut XENDMS = vec![b' '; MXENDM as usize];
        let mut XLINE = vec![b' '; LNSIZE as usize];
        let mut FRAC: f64 = 0.0;
        let mut INCR: f64 = 0.0;
        let mut TOTAL: f64 = 0.0;
        let mut WAIT: f64 = 0.0;
        let mut XINCR: f64 = 0.0;
        let mut XTOTAL: f64 = 0.0;
        let mut XWAIT: f64 = 0.0;
        let mut IOSTAT: i32 = 0;
        let mut NRPORT: i32 = 0;
        let mut TCHECK: i32 = 0;
        let mut UNIT: i32 = 0;
        let mut XCHECK: i32 = 0;
        let mut XNL: i32 = 0;
        let mut XUNIT: i32 = 0;

        Self {
            BEGMSG,
            ENDMSG,
            LINE,
            PCTSTR,
            QNAME,
            XBEGMS,
            XENDMS,
            XLINE,
            FRAC,
            INCR,
            TOTAL,
            WAIT,
            XINCR,
            XTOTAL,
            XWAIT,
            IOSTAT,
            NRPORT,
            TCHECK,
            UNIT,
            XCHECK,
            XNL,
            XUNIT,
        }
    }
}

//$Procedure      F_ZZGFRPWK ( Test ZZGFRPWK entry points )
pub fn F_ZZGFRPWK(OK: &mut bool, ctx: &mut Context) -> f2rust_std::Result<()> {
    let save = ctx.get_vars::<SaveVars>();
    let save = &mut *save.borrow_mut();

    //
    // SPICELIB functions
    //

    //
    // Local parameters
    //

    //
    // Local Variables
    //

    //
    // Saved everything
    //

    //
    // Initial values
    //

    //
    // Begin every test family with an open call.
    //
    testutil::TOPEN(b"F_ZZGFRPWK", ctx)?;

    //*********************************************************************
    //*
    //*    Normal cases
    //*
    //*********************************************************************

    //
    //---- Case -------------------------------------------------------------
    //
    testutil::TCASE(b"Test ZZGFTSWK parameter storage.", ctx)?;

    //
    // Open a text file to capture the progress report.
    //
    if spicelib::EXISTS(REPFIL, ctx)? {
        spicelib::DELFIL(REPFIL, ctx)?;
        testutil::CHCKXC(false, b" ", OK, ctx)?;
    }

    spicelib::TXTOPN(REPFIL, &mut save.XUNIT, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::ZZGFWKUN(save.XUNIT, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    save.XTOTAL = ((MAXWIN as f64) / 2.0);

    fstr::assign(
        &mut save.XBEGMS,
        b"@-------------------Message prefix--------------------@",
    );
    fstr::assign(&mut save.XENDMS, b"@***suffix**@");

    save.XWAIT = 2.0;
    save.XCHECK = 10;

    //
    // Call the progress report display initializer.
    //
    spicelib::ZZGFTSWK(
        save.XTOTAL,
        save.XWAIT,
        save.XCHECK,
        &save.XBEGMS,
        &save.XENDMS,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Fetch the current report parameters from the ZZGFRPWK monitor.
    //
    spicelib::ZZGFWKMO(
        &mut save.UNIT,
        &mut save.TOTAL,
        &mut save.WAIT,
        &mut save.TCHECK,
        &mut save.BEGMSG,
        &mut save.ENDMSG,
        &mut save.INCR,
        ctx,
    );
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Check the stored values from ZZGFWKMO against the expected
    // values.

    testutil::CHCKSI(b"UNIT", save.UNIT, b"=", save.XUNIT, 0, OK, ctx)?;
    testutil::CHCKSD(b"TOTAL", save.TOTAL, b"~", save.XTOTAL, VTIGHT, OK, ctx)?;
    testutil::CHCKSD(b"WAIT", save.WAIT, b"=", save.XWAIT, 0.0, OK, ctx)?;
    testutil::CHCKSI(b"TCHECK", save.TCHECK, b"=", save.XCHECK, 0, OK, ctx)?;
    testutil::CHCKSC(b"BEGMSG", &save.BEGMSG, b"=", &save.XBEGMS, OK, ctx)?;
    testutil::CHCKSC(b"ENDMSG", &save.ENDMSG, b"=", &save.XENDMS, OK, ctx)?;

    //
    //---- Case -------------------------------------------------------------
    //
    testutil::TCASE(b"Test the report file created by a call to ZZGFTSWK", ctx)?;

    //
    // Close and delete the existing log.
    //
    {
        use f2rust_std::io;

        let specs = io::CloseSpecs {
            unit: Some(save.XUNIT),
            ..Default::default()
        };
        ctx.close(specs)?;
    }
    spicelib::DELFIL(REPFIL, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Open a new log file.
    //
    spicelib::TXTOPN(REPFIL, &mut save.XUNIT, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::ZZGFWKUN(save.XUNIT, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Set up a search.
    //
    save.XTOTAL = ((MAXWIN as f64) / 2.0);

    fstr::assign(
        &mut save.XBEGMS,
        b"@-------------------Message prefix--------------------@",
    );
    fstr::assign(&mut save.XENDMS, b"@***suffix**@");

    save.XWAIT = 2.0;
    save.XCHECK = 10;

    //
    // Call the progress report display initializer.
    //
    spicelib::ZZGFTSWK(
        save.XTOTAL,
        save.XWAIT,
        save.XCHECK,
        &save.XBEGMS,
        &save.XENDMS,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Rewind the file to set the record pointer to the start
    // of the file.
    //
    {
        use f2rust_std::io;

        let specs = io::PosSpecs {
            unit: Some(save.XUNIT),
            ..Default::default()
        };
        save.IOSTAT = io::capture_iostat(|| ctx.rewind(specs))?;
    }
    testutil::CHCKSI(b"REWIND IOSTAT", save.IOSTAT, b"=", 0, 0, OK, ctx)?;

    if (save.IOSTAT == 0) {
        //
        // The first two lines of the file should be blank.
        //
        for I in 1..=2 {
            fstr::assign(&mut save.QNAME, b"Read IOSTAT no. *");
            spicelib::REPMI(&save.QNAME.to_vec(), b"*", I, &mut save.QNAME, ctx);
            testutil::CHCKXC(false, b" ", OK, ctx)?;

            {
                use f2rust_std::{
                    data::Val,
                    io::{self, Reader},
                };

                let mut reader = io::FormattedReader::new(ctx.io_unit(save.XUNIT)?, None, b"(A)")?;
                save.IOSTAT = io::capture_iostat(|| {
                    reader.start()?;
                    reader.read_str(&mut save.LINE)?;
                    reader.finish()?;
                    Ok(())
                })?;
            }
            testutil::CHCKSI(&save.QNAME, save.IOSTAT, b"=", 0, 0, OK, ctx)?;

            if (save.IOSTAT == 0) {
                fstr::assign(&mut save.QNAME, b"Log file line no. *");
                spicelib::REPMI(&save.QNAME.to_vec(), b"*", I, &mut save.QNAME, ctx);
                testutil::CHCKXC(false, b" ", OK, ctx)?;
                testutil::CHCKSC(&save.QNAME, &save.LINE, b"=", b" ", OK, ctx)?;
            }
        }
    }

    //
    // If we haven't hit an error, read the third line.
    //
    if (save.IOSTAT == 0) {
        {
            use f2rust_std::{
                data::Val,
                io::{self, Reader},
            };

            let mut reader = io::FormattedReader::new(ctx.io_unit(save.XUNIT)?, None, b"(A)")?;
            save.IOSTAT = io::capture_iostat(|| {
                reader.start()?;
                reader.read_str(&mut save.LINE)?;
                reader.finish()?;
                Ok(())
            })?;
        }
        testutil::CHCKSI(&save.QNAME, save.IOSTAT, b"=", 0, 0, OK, ctx)?;

        if (save.IOSTAT == 0) {
            //
            // Check the report line.
            //
            fstr::assign(&mut save.XLINE, &save.XBEGMS);
            spicelib::SUFFIX(b"  0.00%", 1, &mut save.XLINE);
            spicelib::SUFFIX(&save.XENDMS, 1, &mut save.XLINE);

            testutil::CHCKSC(b"LINE", &save.LINE, b"=", &save.XLINE, OK, ctx)?;
        }
    }

    //
    //---- Case -------------------------------------------------------------
    //
    testutil::TCASE(b"Test ZZGFKIN parameter storage.", ctx)?;

    for I in 1..=5 {
        save.XINCR = (I as f64);

        spicelib::ZZGFWKIN(save.XINCR, ctx)?;
        testutil::CHCKXC(false, b" ", OK, ctx)?;

        spicelib::ZZGFWKMO(
            &mut save.UNIT,
            &mut save.TOTAL,
            &mut save.WAIT,
            &mut save.TCHECK,
            &mut save.BEGMSG,
            &mut save.ENDMSG,
            &mut save.INCR,
            ctx,
        );
        testutil::CHCKXC(false, b" ", OK, ctx)?;
        //
        // We expect the last work increment to be I.
        //

        fstr::assign(&mut save.QNAME, b"INCR I=1");

        spicelib::REPMI(&save.QNAME.to_vec(), b"*", I, &mut save.QNAME, ctx);
        testutil::CHCKXC(false, b" ", OK, ctx)?;

        testutil::CHCKSD(&save.QNAME, save.INCR, b"~", save.XINCR, VTIGHT, OK, ctx)?;
    }

    //
    //---- Case -------------------------------------------------------------
    //
    testutil::TCASE(b"Test ZZGFWKAD parameter storage.", ctx)?;

    save.XWAIT = 17.0;
    save.XCHECK = 32;
    fstr::assign(
        &mut save.XBEGMS,
        b"$-------Message prefix--------------------------------$",
    );
    fstr::assign(&mut save.XENDMS, b"#***suffix**#");

    spicelib::ZZGFWKAD(save.XWAIT, save.XCHECK, &save.XBEGMS, &save.XENDMS, ctx);
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    // Fetch the current report parameters from the ZZGFRPWK monitor.
    //
    spicelib::ZZGFWKMO(
        &mut save.UNIT,
        &mut save.TOTAL,
        &mut save.WAIT,
        &mut save.TCHECK,
        &mut save.BEGMSG,
        &mut save.ENDMSG,
        &mut save.INCR,
        ctx,
    );
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Check the stored values from ZZGFWKMO against the expected
    // values.
    //
    // GFREPF is supposed to set the poll duration and call count to 0
    // seconds and 1 call, respectively. The work increment should be
    // set to 0.D0. These values are hard-coded in GFREPF.
    //
    testutil::CHCKSI(b"UNIT", save.UNIT, b"=", save.XUNIT, 0, OK, ctx)?;
    testutil::CHCKSD(b"TOTAL", save.TOTAL, b"~", save.XTOTAL, VTIGHT, OK, ctx)?;
    testutil::CHCKSD(b"WAIT", save.WAIT, b"=", save.XWAIT, 0.0, OK, ctx)?;
    testutil::CHCKSI(b"TCHECK", save.TCHECK, b"=", save.XCHECK, 0, OK, ctx)?;
    testutil::CHCKSC(b"BEGMSG", &save.BEGMSG, b"=", &save.XBEGMS, OK, ctx)?;
    testutil::CHCKSC(b"ENDMSG", &save.ENDMSG, b"=", &save.XENDMS, OK, ctx)?;

    //
    //---- Case -------------------------------------------------------------
    //
    testutil::TCASE(b"Test a report with multiple status lines.", ctx)?;

    //
    // Close and delete the existing log.
    //
    {
        use f2rust_std::io;

        let specs = io::CloseSpecs {
            unit: Some(save.XUNIT),
            ..Default::default()
        };
        ctx.close(specs)?;
    }
    spicelib::DELFIL(REPFIL, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Open a new log file.
    //
    spicelib::TXTOPN(REPFIL, &mut save.XUNIT, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::ZZGFWKUN(save.XUNIT, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Set up a search.
    //
    save.XTOTAL = 100.0;

    fstr::assign(
        &mut save.XBEGMS,
        b"@-----------------------------------Message prefix----@",
    );
    fstr::assign(&mut save.XENDMS, b"@*****suffix@");

    //
    // Check the system time every 10 increment calls.
    //
    save.XCHECK = 10;

    //
    // Set the wait time for display to zero.
    //
    save.XWAIT = 0.0;

    //
    // Call the progress report display initializer.
    //
    spicelib::ZZGFTSWK(
        save.XTOTAL,
        save.XWAIT,
        save.XCHECK,
        &save.XBEGMS,
        &save.XENDMS,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Report status 100 times. Each time, the increment is "1".
    //
    for I in 1..=100 {
        spicelib::ZZGFWKIN(1.0, ctx)?;
        testutil::CHCKXC(false, b" ", OK, ctx)?;
    }

    //
    // Rewind the file to set the record pointer to the start
    // of the file.
    //
    {
        use f2rust_std::io;

        let specs = io::PosSpecs {
            unit: Some(save.XUNIT),
            ..Default::default()
        };
        save.IOSTAT = io::capture_iostat(|| ctx.rewind(specs))?;
    }
    testutil::CHCKSI(b"REWIND IOSTAT", save.IOSTAT, b"=", 0, 0, OK, ctx)?;

    if (save.IOSTAT == 0) {
        //
        // The first two lines of the file should be blank.
        //
        for I in 1..=2 {
            fstr::assign(&mut save.QNAME, b"Read IOSTAT no. *");
            spicelib::REPMI(&save.QNAME.to_vec(), b"*", I, &mut save.QNAME, ctx);
            testutil::CHCKXC(false, b" ", OK, ctx)?;

            {
                use f2rust_std::{
                    data::Val,
                    io::{self, Reader},
                };

                let mut reader = io::FormattedReader::new(ctx.io_unit(save.XUNIT)?, None, b"(A)")?;
                save.IOSTAT = io::capture_iostat(|| {
                    reader.start()?;
                    reader.read_str(&mut save.LINE)?;
                    reader.finish()?;
                    Ok(())
                })?;
            }
            testutil::CHCKSI(&save.QNAME, save.IOSTAT, b"=", 0, 0, OK, ctx)?;

            if (save.IOSTAT == 0) {
                fstr::assign(&mut save.QNAME, b"Log file line no. *");
                spicelib::REPMI(&save.QNAME.to_vec(), b"*", I, &mut save.QNAME, ctx);
                testutil::CHCKXC(false, b" ", OK, ctx)?;
                testutil::CHCKSC(&save.QNAME, &save.LINE, b"=", b" ", OK, ctx)?;
            }
        }
    }

    //
    // If we haven't hit an error, read the rest of the file.
    //
    if (save.IOSTAT == 0) {
        for I in 1..=(intrinsics::IDNINT((save.XTOTAL / save.XCHECK as f64)) + 1) {
            fstr::assign(&mut save.QNAME, b"Log file line no. * IOSTAT");
            spicelib::REPMI(&save.QNAME.to_vec(), b"*", (I + 2), &mut save.QNAME, ctx);

            {
                use f2rust_std::{
                    data::Val,
                    io::{self, Reader},
                };

                let mut reader = io::FormattedReader::new(ctx.io_unit(save.XUNIT)?, None, b"(A)")?;
                save.IOSTAT = io::capture_iostat(|| {
                    reader.start()?;
                    reader.read_str(&mut save.LINE)?;
                    reader.finish()?;
                    Ok(())
                })?;
            }
            testutil::CHCKSI(&save.QNAME, save.IOSTAT, b"=", 0, 0, OK, ctx)?;

            if (save.IOSTAT == 0) {
                //
                // Check the report line.
                //
                spicelib::DPFMT(((10 * (I - 1)) as f64), b"XXX.XX", &mut save.PCTSTR, ctx)?;

                fstr::assign(&mut save.XLINE, &save.XBEGMS);
                spicelib::SUFFIX(&save.PCTSTR, 1, &mut save.XLINE);
                spicelib::SUFFIX(b"%", 0, &mut save.XLINE);
                spicelib::SUFFIX(&save.XENDMS, 1, &mut save.XLINE);

                testutil::CHCKSC(b"LINE", &save.LINE, b"=", &save.XLINE, OK, ctx)?;
            }
        }
    }

    //
    //---- Case -------------------------------------------------------------
    //
    testutil::TCASE(
        b"Test a report with multiple status lines, this time using a positive time delay.",
        ctx,
    )?;

    //
    // Close and delete the existing log.
    //
    {
        use f2rust_std::io;

        let specs = io::CloseSpecs {
            unit: Some(save.XUNIT),
            ..Default::default()
        };
        ctx.close(specs)?;
    }
    spicelib::DELFIL(REPFIL, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Open a new log file.
    //
    spicelib::TXTOPN(REPFIL, &mut save.XUNIT, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    spicelib::ZZGFWKUN(save.XUNIT, ctx)?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Set up a search. The search must take long enough
    // so that at least one XWAIT seconds pass per 20% of the
    // work.
    //
    save.XTOTAL = 250000000.0;

    fstr::assign(
        &mut save.XBEGMS,
        b"@-Message prefix--------------------------------------@",
    );
    fstr::assign(&mut save.XENDMS, b"@****Suffix*@");

    //
    // Check the system time once every XTOTAL/20 increment calls.
    //
    save.XCHECK = intrinsics::IDNINT((save.XTOTAL / 20 as f64));

    //
    // Set the wait time for display in seconds. The wait time is a
    // lower bound on the duration between progress report display
    // updates. Setting the wait to a small value won't cause more
    // updates to be displayed; in no event will there be more updates
    // than allowed by XCHECK. Setting the wait to a large value will
    // cause the test case to fail because some progress updates won't
    // get displayed.
    //
    save.XWAIT = 0.1;

    //
    // Call the progress report display initializer.
    //
    spicelib::ZZGFTSWK(
        save.XTOTAL,
        save.XWAIT,
        save.XCHECK,
        &save.XBEGMS,
        &save.XENDMS,
        ctx,
    )?;
    testutil::CHCKXC(false, b" ", OK, ctx)?;

    //
    // Set the progress increment to 5.
    //
    save.INCR = 5 as f64;

    //
    // Report status XTOTAL/INCR times. So every time the
    // system clock is checked, we expect that
    //
    //      FRAC = XCHECK * INCR / XTOTAL
    //
    //
    //           = 25%
    //
    // progress should have been made since the last check. We expect
    // 25% of the computation to take longer than XWAIT seconds, so we
    // should see a report line for every 25% progress.
    //
    save.FRAC = (((save.XCHECK as f64) * save.INCR) / save.XTOTAL);

    save.NRPORT = intrinsics::IDNINT((save.XTOTAL / save.INCR));

    for I in 1..=save.NRPORT {
        spicelib::ZZGFWKIN(save.INCR, ctx)?;
        testutil::CHCKXC(false, b" ", OK, ctx)?;
    }

    //
    // Rewind the file to set the record pointer to the start
    // of the file.
    //
    {
        use f2rust_std::io;

        let specs = io::PosSpecs {
            unit: Some(save.XUNIT),
            ..Default::default()
        };
        save.IOSTAT = io::capture_iostat(|| ctx.rewind(specs))?;
    }
    testutil::CHCKSI(b"REWIND IOSTAT", save.IOSTAT, b"=", 0, 0, OK, ctx)?;

    if (save.IOSTAT == 0) {
        //
        // The first two lines of the file should be blank.
        //
        for I in 1..=2 {
            fstr::assign(&mut save.QNAME, b"Read IOSTAT no. *");
            spicelib::REPMI(&save.QNAME.to_vec(), b"*", I, &mut save.QNAME, ctx);
            testutil::CHCKXC(false, b" ", OK, ctx)?;

            {
                use f2rust_std::{
                    data::Val,
                    io::{self, Reader},
                };

                let mut reader = io::FormattedReader::new(ctx.io_unit(save.XUNIT)?, None, b"(A)")?;
                save.IOSTAT = io::capture_iostat(|| {
                    reader.start()?;
                    reader.read_str(&mut save.LINE)?;
                    reader.finish()?;
                    Ok(())
                })?;
            }
            testutil::CHCKSI(&save.QNAME, save.IOSTAT, b"=", 0, 0, OK, ctx)?;

            if (save.IOSTAT == 0) {
                fstr::assign(&mut save.QNAME, b"Log file line no. *");
                spicelib::REPMI(&save.QNAME.to_vec(), b"*", I, &mut save.QNAME, ctx);
                testutil::CHCKXC(false, b" ", OK, ctx)?;
                testutil::CHCKSC(&save.QNAME, &save.LINE, b"=", b" ", OK, ctx)?;
            }
        }
    }

    //
    // If we haven't hit an error, read the rest of the file.
    //
    // The expected number of status lines in the report is the
    // number of update calls divided by the call check ratio,
    // plus one, since the first line shows 0% progress.
    //
    save.XNL = (1 + (save.NRPORT / save.XCHECK));

    if (save.IOSTAT == 0) {
        for I in 1..=save.XNL {
            fstr::assign(&mut save.QNAME, b"Log file line no. * IOSTAT");
            spicelib::REPMI(&save.QNAME.to_vec(), b"*", (I + 2), &mut save.QNAME, ctx);

            {
                use f2rust_std::{
                    data::Val,
                    io::{self, Reader},
                };

                let mut reader = io::FormattedReader::new(ctx.io_unit(save.XUNIT)?, None, b"(A)")?;
                save.IOSTAT = io::capture_iostat(|| {
                    reader.start()?;
                    reader.read_str(&mut save.LINE)?;
                    reader.finish()?;
                    Ok(())
                })?;
            }
            testutil::CHCKSI(&save.QNAME, save.IOSTAT, b"=", 0, 0, OK, ctx)?;

            if (save.IOSTAT == 0) {
                //
                // Check the report line.
                //
                spicelib::DPFMT(
                    ((((I - 1) * 100) as f64) * save.FRAC),
                    b"XXX.XX",
                    &mut save.PCTSTR,
                    ctx,
                )?;

                fstr::assign(&mut save.XLINE, &save.XBEGMS);
                spicelib::SUFFIX(&save.PCTSTR, 1, &mut save.XLINE);
                spicelib::SUFFIX(b"%", 0, &mut save.XLINE);
                spicelib::SUFFIX(&save.XENDMS, 1, &mut save.XLINE);

                testutil::CHCKSC(b"LINE", &save.LINE, b"=", &save.XLINE, OK, ctx)?;
            }
        }
    }

    //
    //---- Case -------------------------------------------------------------
    //
    testutil::TCASE(b"Clean up: delete log file.", ctx)?;

    if spicelib::EXISTS(REPFIL, ctx)? {
        {
            use f2rust_std::io;

            let specs = io::CloseSpecs {
                unit: Some(save.XUNIT),
                ..Default::default()
            };
            ctx.close(specs)?;
        }

        spicelib::DELFIL(REPFIL, ctx)?;
        testutil::CHCKXC(false, b" ", OK, ctx)?;
    }

    //*********************************************************************
    //*
    //*    Error cases
    //*
    //*********************************************************************

    //
    //---- Case -------------------------------------------------------------
    //
    testutil::TCASE(b"Call to umbrella routine", ctx)?;

    spicelib::ZZGFRPWK(1, 2.0, 3.0, 7, b" ", b" ", 0.5, ctx)?;

    testutil::CHCKXC(true, b"SPICE(BOGUSENTRY)", OK, ctx)?;

    testutil::T_SUCCESS(OK, ctx);
    Ok(())
}