File: cmcomputeorder23.c

package info (click to toggle)
calceph 4.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,944 kB
  • sloc: ansic: 21,414; fortran: 4,054; python: 1,569; sh: 197; makefile: 5
file content (678 lines) | stat: -rwxr-xr-x 26,190 bytes parent folder | download | duplicates (2)
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
/*-----------------------------------------------------------------*/
/*!
 \file cmcomputeorder23.c
 \brief Check the output of the function calceph_compute_order for the order 2 and 3.
 
 \author  M. Gastineau
 Astronomie et Systemes Dynamiques, IMCCE, CNRS, Observatoire de Paris.
 
 Copyright, 2016, 2017, 2018, 2019, CNRS
 email of the author : Mickael.Gastineau@obspm.fr
 
 History:
 */
/*-----------------------------------------------------------------*/

/*-----------------------------------------------------------------*/
/* License  of this file :
 This file is "triple-licensed", you have to choose one  of the three licenses
 below to apply on this file.
 
 CeCILL-C
 The CeCILL-C license is close to the GNU LGPL.
 ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html )
 
 or CeCILL-B
 The CeCILL-B license is close to the BSD.
 (http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt)
 
 
 or CeCILL v2.1
 The CeCILL license is compatible with the GNU GPL.
 ( http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.html )
 
 
 This library is governed by the CeCILL-C, CeCILL-B or the CeCILL license under
 French law and abiding by the rules of distribution of free software.
 You can  use, modify and/ or redistribute the software under the terms
 of the CeCILL-C,CeCILL-B or CeCILL license as circulated by CEA, CNRS and INRIA
 at the following URL "http://www.cecill.info".
 
 As a counterpart to the access to the source code and  rights to copy,
 modify and redistribute granted by the license, users are provided only
 with a limited warranty  and the software's author,  the holder of the
 economic rights,  and the successive licensors  have only  limited
 liability.
 
 In this respect, the user's attention is drawn to the risks associated
 with loading,  using,  modifying and/or developing or reproducing the
 software by the user in light of its specific status of free software,
 that may mean  that it is complicated to manipulate,  and  that  also
 therefore means  that it is reserved for developers  and  experienced
 professionals having in-depth computer knowledge. Users are therefore
 encouraged to load and test the software's suitability as regards their
 requirements in conditions enabling the security of their systems and/or
 data to be ensured and,  more generally, to use and operate it in the
 same conditions as regards security.
 
 The fact that you are presently reading this means that you have had
 knowledge of the CeCILL-C,CeCILL-B or CeCILL license and that you accept its terms.
 */
/*-----------------------------------------------------------------*/

#include <stdio.h>
#include "calceph.h"
#include "openfiles.h"
#include "numericalderivative.h"

static double myabs(double x);

static int maincheck0(int nbfile, const char *const filear[], int prefetch, double mindate);

static int maincheck(int nbfile, const char *const filear[], const char *checkfile, int prefetch, double mindate,
                     double thresold);
int main(void);

static double myabs(double x)
{
    if (x != x)
        return 1E300;
    return (x > 0 ? x : -x);
}

static double myabsrel(double x, double y)
{
    if (x != x)
        return 1E300;
    if (y != y)
        return 1E300;
    if (myabs(x) > 1E-50)
    {
        if (myabs(y / x) - 1E0 > 1E-2)
            return 1E200;
    }
    return (myabs(x) < 1E-5 ? myabs(x - y) : myabs((x - y) / x));
}

/*-----------------------------------------------------------------*/
/* return mod(x, 2*pi) between 0 and 2*pi. */
/*-----------------------------------------------------------------*/
static double myfmod2pi(double x)
{
    double pi2 = 6.283185307179586E0;

    while (x >= pi2)
        x = x - pi2;
    while (x <= 0)
        x = x + pi2;
    return x;
}

/*-----------------------------------------------------------------*/
/* main check function */
/*-----------------------------------------------------------------*/
static int maincheck0(int nbfile, const char *const filear[], int prefetch, double mindate)
{
    int res, n, j, nder;

    int target, center;

    double jd0;

    double dt;

    double PV[6];
    double PVder[6];

    double PVcheck[12];

    double seuil, seuilder;

    double AU;

    FILE *fcheck;

    FILE *foutputpython;        /* produce a file for the python test which contains the derivatives values */

    t_calcephbin *peph;

    int unit;

    int order;

    foutputpython = fopen("example1_tests_23_derivative.dat", "wt");
    if (foutputpython == NULL)
    {
        printf("example1_tests_23_derivative.dat can't be opened\n");
        return 1;
    }

    for (order = 2; order <= 3; order++)
    {

        fcheck = tests_fopen("example1_tests.dat", "rt");
        if (fcheck == NULL)
        {
            printf("example1_tests.dat is missing\n");
            return 1;
        }
        /* open the ephemeris file */
        peph = tests_calceph_open_array(nbfile, filear);
        res = (peph != NULL);

        if (res)
        {
            res = calceph_getconstant(peph, "AU", &AU);
            if (prefetch == 1)
            {
                res = calceph_prefetch(peph);
                if (res == 0)
                    calceph_close(peph);
            }
        }

        if (res)
        {
            while (!feof(fcheck))
            {
                /* read the references coordinates */
                int iret = fscanf(fcheck, "%le %d %d ", &jd0, &target, &center);

                if (feof(fcheck))
                {
                    res = 0;
                    break;
                }
                if (iret != 3)
                {
                    printf("fscanf failure\n");
                    res = 1;
                    break;
                }
                for (j = 0; j < 6; j++)
                {
                    if (fscanf(fcheck, "%le", PV + j) != 1)
                    {
                        printf("fscanf failure\n");
                        res = 1;
                        break;
                    }
                }

                dt = jd0 - (int) jd0;
                jd0 = ((int) jd0) + 2.4515450000000000000E+06;

                if (jd0 < mindate)
                    continue;
                n = 6;
                nder = 3 * (order - 1);
                seuilder = 1E-4;
                if (target != 15 && target != 16)
                {
                    seuil = 5E-6;
                    /* check UA/DAY */
                    unit = CALCEPH_UNIT_AU + CALCEPH_UNIT_DAY;
                    for (j = 0; j < n + nder; j++)
                        PVcheck[j] = 0.E0;
                    if (calceph_compute_order(peph, jd0, dt, target, center, unit, order, PVcheck) == 0)
                    {
                        res = 1;
                        break;
                    }
                    for (j = 0; j < n; j++)
                    {
                        if (myabsrel(PVcheck[j], PV[j]) >= seuil)
                        {
                            printf("failure AU/DAY for %d %d at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                                   target, center, jd0, dt, PVcheck[j] - PV[j], PVcheck[j], PV[j]);
                            printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                            res = 1;
                            return res;
                        }
                    }
                    if (tests_calceph_evaluate_derivate_compute(peph, jd0, dt, target, center, unit, PVder) == 0)
                    {
                        res = 1;
                        break;
                    }
                    for (j = 0; j < nder; j++)
                    {
                        if (myabsrel(PVcheck[j + n], PVder[j]) >= seuilder)
                        {
                            printf
                                ("failure AU/DAY for derivative %d %d  (j=%d) at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                                 target, center, j + n, jd0, dt, PVcheck[j + n] - PVder[j], PVcheck[j + n], PVder[j]);
                            printf("relative diff=%e\n",
                                   PVder[j] != 0 ? (PVcheck[j + n] - PVder[j]) / PVder[j] : PVcheck[j + n] - PVder[j]);
                            printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                            res = 1;
                            return res;
                        }
                    }

                    /* produce the output for python tests */
                    fprintf(foutputpython, "%23.16E %23.16E %d %d %d %d ", jd0, dt, target, center, unit, order);
                    for (j = 0; j < 3 * (order + 1); j++)
                    {
                        fprintf(foutputpython, "%23.16E ", PVcheck[j]);
                    }
                    fprintf(foutputpython, "\n");

                    /* check UA/SEC */
                    unit = CALCEPH_UNIT_AU + CALCEPH_UNIT_SEC;
                    for (j = 0; j < n + nder; j++)
                        PVcheck[j] = 0.E0;
                    if (calceph_compute_order(peph, jd0, dt, target, center, unit, order, PVcheck) == 0)
                    {
                        res = 1;
                        break;
                    }
                    for (j = 3; j < n; j++)
                        PVcheck[j] *= 86400E0;
                    for (j = 0; j < n; j++)
                    {
                        if (myabsrel(PVcheck[j], PV[j]) >= seuil)
                        {
                            printf("failure AU/SEC for %d %d at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                                   target, center, jd0, dt, PVcheck[j] - PV[j], PVcheck[j], PV[j]);
                            printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                            res = 1;
                            return res;
                        }
                    }
                    if (tests_calceph_evaluate_derivate_compute(peph, jd0, dt, target, center, unit, PVder) == 0)
                    {
                        res = 1;
                        break;
                    }
                    for (j = 0; j < nder; j++)
                    {
                        if (myabsrel(PVcheck[j + n], PVder[j]) >= seuilder)
                        {
                            printf
                                ("failure AU/SEC for derivative %d %d  (j=%d) at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                                 target, center, j + n, jd0, dt, PVcheck[j + n] - PVder[j], PVcheck[j + n], PVder[j]);
                            printf("relative diff=%e\n",
                                   PVder[j] != 0 ? (PVcheck[j + n] - PVder[j]) / PVder[j] : PVcheck[j + n] - PVder[j]);
                            printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                            res = 1;
                            return res;
                        }
                    }

                    /* check KM/DAY */
                    unit = CALCEPH_UNIT_KM + CALCEPH_UNIT_DAY;
                    for (j = 0; j < n + nder; j++)
                        PVcheck[j] = 0.E0;
                    if (calceph_compute_order(peph, jd0, dt, target, center, unit, order, PVcheck) == 0)
                    {
                        res = 1;
                        break;
                    }
                    for (j = 0; j < n; j++)
                        PVcheck[j] /= AU;
                    for (j = 0; j < n; j++)
                    {
                        if (myabsrel(PVcheck[j], PV[j]) >= seuil)
                        {
                            printf("failure KM/DAY for %d %d at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                                   target, center, jd0, dt, PVcheck[j] - PV[j], PVcheck[j], PV[j]);
                            printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                            res = 1;
                            return res;
                        }
                    }
                    if (tests_calceph_evaluate_derivate_compute(peph, jd0, dt, target, center, unit, PVder) == 0)
                    {
                        res = 1;
                        break;
                    }
                    for (j = 0; j < nder; j++)
                    {
                        if (myabsrel(PVcheck[j + n], PVder[j]) >= seuilder)
                        {
                            printf
                                ("failure KM/DAY for derivative %d %d  (j=%d) at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                                 target, center, j + n, jd0, dt, PVcheck[j + n] - PVder[j], PVcheck[j + n], PVder[j]);
                            printf("relative diff=%e\n",
                                   PVder[j] != 0 ? (PVcheck[j + n] - PVder[j]) / PVder[j] : PVcheck[j + n] - PVder[j]);
                            printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                            res = 1;
                            return res;
                        }
                    }

                    /* check KM/SEC */
                    unit = CALCEPH_UNIT_KM + CALCEPH_UNIT_SEC;
                    for (j = 0; j < n + nder; j++)
                        PVcheck[j] = 0.E0;
                    if (calceph_compute_order(peph, jd0, dt, target, center, unit, order, PVcheck) == 0)
                    {
                        res = 1;
                        break;
                    }
                    for (j = 0; j < n; j++)
                        PVcheck[j] /= AU;
                    for (j = 3; j < n; j++)
                        PVcheck[j] *= 86400E0;
                    for (j = 0; j < n; j++)
                    {
                        if (myabsrel(PVcheck[j], PV[j]) >= seuil)
                        {
                            printf("failure KM/SEC for %d %d at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                                   target, center, jd0, dt, PVcheck[j] - PV[j], PVcheck[j], PV[j]);
                            printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                            res = 1;
                            return res;
                        }
                    }
                    if (tests_calceph_evaluate_derivate_compute(peph, jd0, dt, target, center, unit, PVder) == 0)
                    {
                        res = 1;
                        break;
                    }
                    for (j = 0; j < nder; j++)
                    {
                        if (myabsrel(PVcheck[j + n], PVder[j]) >= seuilder)
                        {
                            printf
                                ("failure KM/SEC for derivative %d %d  (j=%d) at time %23.16E %23.16E : diff=%e  (%23.16E - %23.16E)\n",
                                 target, center, j + n, jd0, dt, PVcheck[j + n] - PVder[j], PVcheck[j + n], PVder[j]);
                            printf("relative diff=%e\n",
                                   PVder[j] != 0 ? (PVcheck[j + n] - PVder[j]) / PVder[j] : PVcheck[j + n] - PVder[j]);
                            printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                            res = 1;
                            return res;
                        }
                    }

                }

                if (target == 15)
                {
                    seuil = 1E-7;
                    /* check RAD/DAY */
                    unit = CALCEPH_UNIT_RAD + CALCEPH_UNIT_DAY;
                    for (j = 0; j < n; j++)
                        PVcheck[j] = 0.E0;
                    if (calceph_orient_order(peph, jd0, dt, target, unit, order, PVcheck) == 0)
                    {
                        res = 1;
                        break;
                    }
                    for (j = 0; j < n; j++)
                    {
                        double pvj = PV[j];

                        double pvc = PVcheck[j];

                        if (j == 2)
                        {
                            pvj = myfmod2pi(pvj);
                            pvc = myfmod2pi(pvc);
                        }
                        if (myabs(pvc - pvj) >= seuil)
                        {
                            printf
                                ("failure RAD/DAY for %d %d (j=%d) at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                                 target, center, j, jd0, dt, PVcheck[j] - PV[j], PVcheck[j], PV[j]);
                            printf
                                ("failure RAD/DAY for %d %d (j=%d) at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                                 target, center, j, jd0, dt, pvc - pvj, pvc, pvj);
                            printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                            res = 1;
                            return res;
                        }
                    }
                    if (tests_calceph_evaluate_derivate_compute(peph, jd0, dt, target, center, unit, PVder) == 0)
                    {
                        res = 1;
                        break;
                    }
                    for (j = 0; j < nder; j++)
                    {
                        if (myabsrel(PVcheck[j + n], PVder[j]) >= seuilder)
                        {
                            printf
                                ("failure RAD/DAY for derivative %d %d  (j=%d) at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                                 target, center, j + n, jd0, dt, PVcheck[j + n] - PVder[j], PVcheck[j + n], PVder[j]);
                            printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                            res = 1;
                            return res;
                        }
                    }

                    /* check AU/SEC */
                    unit = CALCEPH_UNIT_RAD + CALCEPH_UNIT_SEC;
                    for (j = 0; j < n; j++)
                        PVcheck[j] = 0.E0;
                    if (calceph_orient_order(peph, jd0, dt, target, unit, order, PVcheck) == 0)
                    {
                        res = 1;
                        break;
                    }
                    for (j = 3; j < n; j++)
                        PVcheck[j] *= 86400E0;
                    for (j = 0; j < n; j++)
                    {
                        double pvj = PV[j];

                        double pvc = PVcheck[j];

                        if (j == 2)
                        {
                            pvj = myfmod2pi(pvj);
                            pvc = myfmod2pi(pvc);
                        }
                        if (myabs(pvc - pvj) >= seuil)
                        {
                            printf
                                ("failure RAD/SEC for %d %d (j=%d) at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                                 target, center, j, jd0, dt, PVcheck[j] - PV[j], PVcheck[j], PV[j]);
                            printf
                                ("failure RAD/SEC for %d %d (j=%d) at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                                 target, center, j, jd0, dt, pvc - pvj, pvc, pvj);
                            printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                            res = 1;
                            return res;
                        }
                    }
                    if (tests_calceph_evaluate_derivate_compute(peph, jd0, dt, target, center, unit, PVder) == 0)
                    {
                        res = 1;
                        break;
                    }
                    for (j = 0; j < nder; j++)
                    {
                        /* printf("diff:%g\n", myabs(PVcheck[j+n] - PVder[j])); */
                        if (myabsrel(PVcheck[j + n], PVder[j]) >= seuilder)
                        {
                            printf
                                ("failure RAD/SEC for derivative %d %d  (j=%d) at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                                 target, center, j + n, jd0, dt, PVcheck[j + n] - PVder[j], PVcheck[j + n], PVder[j]);
                            printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                            res = 1;
                            return res;
                        }
                    }

                }
            };

            /* close the ephemeris file */
            calceph_close(peph);
        }
        else
            res = 1;

        fclose(fcheck);

        if (res != 0)
            return res;
    }

    fclose(foutputpython);

    return res;
}

/*-----------------------------------------------------------------*/
/* main check function */
/*-----------------------------------------------------------------*/
static int maincheck(int nbfile, const char *const filear[], const char *checkfile, int prefetch, double mindate,
                     double thresold)
{
    int res, n, j, nder;

    int target, center;

    double jd0;

    double dt;

    double PV[6];

    double PVder[6];

    double PVcheck[12];

    double seuil, seuilder;

    FILE *fcheck;

    t_calcephbin *peph;

    int unit;

    int order;

    for (order = 2; order <= 3; order++)
    {

        fcheck = tests_fopen(checkfile, "rt");
        if (fcheck == NULL)
        {
            printf("%s is missing\n", checkfile);
            return 1;
        }

        /* open the ephemeris file */
        peph = tests_calceph_open_array(nbfile, filear);
        res = (peph != NULL);

        if (res)
        {
            while (!feof(fcheck))
            {
                /* read the references coordinates */
                int iret = fscanf(fcheck, "%le %d %d ", &jd0, &target, &center);

                if (feof(fcheck))
                {
                    res = 0;
                    break;
                }

                if (iret != 3)
                {
                    printf("fscanf failure\n");
                    res = 1;
                    break;
                }
                for (j = 0; j < 6; j++)
                {
                    if (fscanf(fcheck, "%le", PV + j) != 1)
                    {
                        printf("fscanf failure\n");
                        res = 1;
                        break;
                    }
                }

                dt = jd0 - (int) jd0;
                jd0 = ((int) jd0) + 2.4515450000000000000E+06;

                if (jd0 < mindate)
                    continue;
                /* compute  the coordinates */
                seuil = thresold;
                seuilder = 200 * thresold;
                unit = CALCEPH_UNIT_KM + CALCEPH_UNIT_SEC + CALCEPH_USE_NAIFID;
                n = 6;
                nder = 3 * (order - 1);
                for (j = 0; j < n + nder; j++)
                    PVcheck[j] = 0.E0;
                if (calceph_compute_order(peph, jd0, dt, target, center, unit, order, PVcheck) == 0)
                {
                    res = 1;
                    break;
                }
                for (j = 0; j < 6; j++)
                {
                    if (myabs((PVcheck[j] - PV[j]) / PV[j]) >= seuil)
                    {
                        printf("failure KM/SEC for %d %d at time %23.16E %23.16E : diff=%e %e (%23.16E - %23.16E)\n",
                               target, center, jd0, dt, PVcheck[j] - PV[j], (PVcheck[j] - PV[j]) / PV[j], PVcheck[j],
                               PV[j]);
                        printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                        res = 1;
                        return res;
                    }
                }
                if (tests_calceph_evaluate_derivate_compute(peph, jd0, dt, target, center, unit, PVder) == 0)
                {
                    res = 1;
                    break;
                }
                for (j = 0; j < nder; j++)
                {
                    if (myabsrel(PVcheck[j + n], PVder[j]) >= seuilder * 1E3)
                    {
                        printf
                            ("failure KM/SEC for derivative %d %d  (j=%d) at time %23.16E %23.16E : diff=%e (%23.16E - %23.16E)\n",
                             target, center, j + n, jd0, dt, PVcheck[j + n] - PVder[j], PVcheck[j + n], PVder[j]);
                        printf("prefetch=%d file='%s'\n", prefetch, filear[0]);
                        res = 1;
                        return res;
                    }
                }
            };

            /* close the ephemeris file */
            calceph_close(peph);
        }
        else
            res = 1;
        fclose(fcheck);
    }
    return res;
}

/*-----------------------------------------------------------------*/
/* main program */
/*-----------------------------------------------------------------*/
int main(void)
{
    int res = 0;
    const char *filearinpop[] = { "../examples/example1.dat" };
    const char *filenamespk[] = { "../examples/example1.bsp", "../examples/example1.tpc",
        "../examples/example1.tf", "../examples/example1.bpc", "../examples/example1spk_time.bsp"
    };
    const char *filearseg8[] = { "example1spk_seg8.bsp" };
    const char *filearseg9[] = { "example1spk_seg9.bsp" };
    const char *filearseg12[] = { "example1spk_seg12.bsp" };
    const char *filearseg13[] = { "example1spk_seg13.bsp" };

    res = maincheck0(1, filearinpop, 0, 2.4425618750000000E+06);
    if (res == 0)
        res = maincheck0(5, filenamespk, 0, 2.4425618750000000E+06);
    if (res == 0)
        res = maincheck(1, filearseg12, "example1spk_seg12.txt", 1, 2450590.0, 1E-10);
    if (res == 0)
        res = maincheck(1, filearseg13, "example1spk_seg13.txt", 1, 2450108.0, 1E-10);
    if (res == 0)
        res = maincheck(1, filearseg8, "example1spk_seg8.txt", 1, 2450590.0, 1E-9);
    if (res == 0)
        res = maincheck(1, filearseg9, "example1spk_seg9.txt", 1, 2450108.0, 1E-9);
    return res;
}