1 /* zzekeri1.f -- translated by f2c (version 19980913).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include "f2c.h"
7
8 /* Table of constant values */
9
10 static integer c__3 = 3;
11 static integer c__1 = 1;
12 static doublereal c_b12 = 0.;
13 static integer c__5 = 5;
14
15 /* $Procedure ZZEKERI1 ( EK, LLE using record pointers, integer, type 1 ) */
zzekeri1_(integer * handle,integer * segdsc,integer * coldsc,integer * ikey,integer * recptr,logical * null,integer * prvidx,integer * prvptr)16 /* Subroutine */ int zzekeri1_(integer *handle, integer *segdsc, integer *
17 coldsc, integer *ikey, integer *recptr, logical *null, integer *
18 prvidx, integer *prvptr)
19 {
20 integer nrec, tree;
21 extern logical zzekscmp_(integer *, integer *, integer *, integer *,
22 integer *, integer *, integer *, char *, doublereal *, integer *,
23 logical *, ftnlen);
24 extern /* Subroutine */ int zzektrdp_(integer *, integer *, integer *,
25 integer *);
26 integer begin;
27 extern integer zzektrsz_(integer *, integer *);
28 extern /* Subroutine */ int chkin_(char *, ftnlen);
29 integer tsize;
30 extern logical failed_(void);
31 integer middle, begptr, endptr, midptr;
32 extern /* Subroutine */ int setmsg_(char *, ftnlen), errint_(char *,
33 integer *, ftnlen), sigerr_(char *, ftnlen), chkout_(char *,
34 ftnlen);
35 integer end;
36 logical leq;
37
38 /* $ Abstract */
39
40 /* Find the last column value less than or equal to a specified key, */
41 /* for a specifed integer EK column having a type 1 index, using */
42 /* dictionary ordering on integer data values and record pointers. */
43
44 /* $ Disclaimer */
45
46 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
47 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
48 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
49 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
50 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
51 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
52 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
53 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
54 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
55 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
56
57 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
58 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
59 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
60 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
61 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
62 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
63
64 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
65 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
66 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
67 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
68
69 /* $ Required_Reading */
70
71 /* EK */
72
73 /* $ Keywords */
74
75 /* EK */
76 /* PRIVATE */
77
78 /* $ Declarations */
79 /* $ Disclaimer */
80
81 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
82 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
83 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
84 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
85 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
86 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
87 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
88 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
89 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
90 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
91
92 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
93 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
94 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
95 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
96 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
97 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
98
99 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
100 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
101 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
102 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
103
104
105 /* Include Section: EK Column Descriptor Parameters */
106
107 /* ekcoldsc.inc Version 6 23-AUG-1995 (NJB) */
108
109
110 /* Note: The column descriptor size parameter CDSCSZ is */
111 /* declared separately in the include section CDSIZE$INC.FOR. */
112
113 /* Offset of column descriptors, relative to start of segment */
114 /* integer address range. This number, when added to the last */
115 /* integer address preceding the segment, yields the DAS integer */
116 /* base address of the first column descriptor. Currently, this */
117 /* offset is exactly the size of a segment descriptor. The */
118 /* parameter SDSCSZ, which defines the size of a segment descriptor, */
119 /* is declared in the include file eksegdsc.inc. */
120
121
122 /* Size of column descriptor */
123
124
125 /* Indices of various pieces of column descriptors: */
126
127
128 /* CLSIDX is the index of the column's class code. (We use the */
129 /* word `class' to distinguish this item from the column's data */
130 /* type.) */
131
132
133 /* TYPIDX is the index of the column's data type code (CHR, INT, DP, */
134 /* or TIME). The type is actually implied by the class, but it */
135 /* will frequently be convenient to look up the type directly. */
136
137
138
139 /* LENIDX is the index of the column's string length value, if the */
140 /* column has character type. A value of IFALSE in this element of */
141 /* the descriptor indicates that the strings have variable length. */
142
143
144 /* SIZIDX is the index of the column's element size value. This */
145 /* descriptor element is meaningful for columns with fixed-size */
146 /* entries. For variable-sized columns, this value is IFALSE. */
147
148
149 /* NAMIDX is the index of the base address of the column's name. */
150
151
152 /* IXTIDX is the data type of the column's index. IXTIDX */
153 /* contains a type value only if the column is indexed. For columns */
154 /* that are not indexed, the location IXTIDX contains the boolean */
155 /* value IFALSE. */
156
157
158 /* IXPIDX is a pointer to the column's index. IXTPDX contains a */
159 /* meaningful value only if the column is indexed. The */
160 /* interpretation of the pointer depends on the data type of the */
161 /* index. */
162
163
164 /* NFLIDX is the index of a flag indicating whether nulls are */
165 /* permitted in the column. The value at location NFLIDX is */
166 /* ITRUE if nulls are permitted and IFALSE otherwise. */
167
168
169 /* ORDIDX is the index of the column's ordinal position in the */
170 /* list of columns belonging to the column's parent segment. */
171
172
173 /* METIDX is the index of the column's integer metadata pointer. */
174 /* This pointer is a DAS integer address. */
175
176
177 /* The last position in the column descriptor is reserved. No */
178 /* parameter is defined to point to this location. */
179
180
181 /* End Include Section: EK Column Descriptor Parameters */
182
183 /* $ Disclaimer */
184
185 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
186 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
187 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
188 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
189 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
190 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
191 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
192 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
193 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
194 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
195
196 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
197 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
198 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
199 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
200 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
201 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
202
203 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
204 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
205 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
206 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
207
208
209 /* Include Section: EK Operator Codes */
210
211 /* ekopcd.inc Version 1 30-DEC-1994 (NJB) */
212
213
214 /* Within the EK system, operators used in EK queries are */
215 /* represented by integer codes. The codes and their meanings are */
216 /* listed below. */
217
218 /* Relational expressions in EK queries have the form */
219
220 /* <column name> <operator> <value> */
221
222 /* For columns containing numeric values, the operators */
223
224 /* EQ, GE, GT, LE, LT, NE */
225
226 /* may be used; these operators have the same meanings as their */
227 /* Fortran counterparts. For columns containing character values, */
228 /* the list of allowed operators includes those in the above list, */
229 /* and in addition includes the operators */
230
231 /* LIKE, UNLIKE */
232
233 /* which are used to compare strings to a template. In the character */
234 /* case, the meanings of the parameters */
235
236 /* GE, GT, LE, LT */
237
238 /* match those of the Fortran lexical functions */
239
240 /* LGE, LGT, LLE, LLT */
241
242
243 /* The additional unary operators */
244
245 /* ISNULL, NOTNUL */
246
247 /* are used to test whether a value of any type is null. */
248
249
250
251 /* End Include Section: EK Operator Codes */
252
253 /* $ Disclaimer */
254
255 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
256 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
257 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
258 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
259 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
260 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
261 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
262 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
263 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
264 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
265
266 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
267 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
268 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
269 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
270 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
271 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
272
273 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
274 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
275 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
276 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
277
278
279 /* Include Section: EK Segment Descriptor Parameters */
280
281 /* eksegdsc.inc Version 8 06-NOV-1995 (NJB) */
282
283
284 /* All `base addresses' referred to below are the addresses */
285 /* *preceding* the item the base applies to. This convention */
286 /* enables simplied address calculations in many cases. */
287
288 /* Size of segment descriptor. Note: the include file ekcoldsc.inc */
289 /* must be updated if this parameter is changed. The parameter */
290 /* CDOFF in that file should be kept equal to SDSCSZ. */
291
292
293 /* Index of the segment type code: */
294
295
296 /* Index of the segment's number. This number is the segment's */
297 /* index in the list of segments contained in the EK to which */
298 /* the segment belongs. */
299
300
301 /* Index of the DAS integer base address of the segment's integer */
302 /* meta-data: */
303
304
305 /* Index of the DAS character base address of the table name: */
306
307
308 /* Index of the segment's column count: */
309
310
311 /* Index of the segment's record count: */
312
313
314 /* Index of the root page number of the record tree: */
315
316
317 /* Index of the root page number of the character data page tree: */
318
319
320 /* Index of the root page number of the double precision data page */
321 /* tree: */
322
323
324 /* Index of the root page number of the integer data page tree: */
325
326
327 /* Index of the `modified' flag: */
328
329
330 /* Index of the `initialized' flag: */
331
332
333 /* Index of the shadowing flag: */
334
335
336 /* Index of the companion file handle: */
337
338
339 /* Index of the companion segment number: */
340
341
342 /* The next three items are, respectively, the page numbers of the */
343 /* last character, d.p., and integer data pages allocated by the */
344 /* segment: */
345
346
347 /* The next three items are, respectively, the page-relative */
348 /* indices of the last DAS word in use in the segment's */
349 /* last character, d.p., and integer data pages: */
350
351
352 /* Index of the DAS character base address of the column name list: */
353
354
355 /* The last descriptor element is reserved for future use. No */
356 /* parameter is defined to point to this location. */
357
358
359 /* End Include Section: EK Segment Descriptor Parameters */
360
361 /* $ Disclaimer */
362
363 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
364 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
365 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
366 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
367 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
368 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
369 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
370 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
371 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
372 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
373
374 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
375 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
376 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
377 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
378 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
379 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
380
381 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
382 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
383 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
384 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
385
386
387 /* Include Section: EK Data Types */
388
389 /* ektype.inc Version 1 27-DEC-1994 (NJB) */
390
391
392 /* Within the EK system, data types of EK column contents are */
393 /* represented by integer codes. The codes and their meanings */
394 /* are listed below. */
395
396 /* Integer codes are also used within the DAS system to indicate */
397 /* data types; the EK system makes no assumptions about compatibility */
398 /* between the codes used here and those used in the DAS system. */
399
400
401 /* Character type: */
402
403
404 /* Double precision type: */
405
406
407 /* Integer type: */
408
409
410 /* `Time' type: */
411
412 /* Within the EK system, time values are represented as ephemeris */
413 /* seconds past J2000 (TDB), and double precision numbers are used */
414 /* to store these values. However, since time values require special */
415 /* treatment both on input and output, and since the `TIME' column */
416 /* has a special role in the EK specification and code, time values */
417 /* are identified as a type distinct from double precision numbers. */
418
419
420 /* End Include Section: EK Data Types */
421
422 /* $ Brief_I/O */
423
424 /* Variable I/O Description */
425 /* -------- --- -------------------------------------------------- */
426 /* HANDLE I File handle. */
427 /* SEGDSC I Segment descriptor. */
428 /* COLDSC I Column descriptor. */
429 /* IKEY I Integer key. */
430 /* RECPTR I Record pointer. */
431 /* NULL I Null flag. */
432 /* PRVIDX O Ordinal position of predecessor of IKEY. */
433 /* PRVPTR O Pointer to record containing predecessor of IKEY. */
434
435 /* $ Detailed_Input */
436
437 /* HANDLE is an EK file handle. The file may be open for */
438 /* reading or writing. */
439
440 /* SEGDSC is the segment descriptor of the segment */
441 /* containing the column specified by COLDSC. */
442
443 /* COLDSC is the column descriptor of the column to be */
444 /* searched. */
445
446 /* IKEY, */
447 /* RECPTR are, respectively, an integer key and a pointer to */
448 /* an EK record containing that key. The last column */
449 /* entry less than or equal to this key is sought. */
450 /* The order relation used is dictionary ordering on */
451 /* the pair (IKEY, RECPTR). */
452
453 /* NULL is a logical flag indicating whether the input */
454 /* key is null. When NULL is .TRUE., IKEY is */
455 /* ignored by this routine. */
456
457 /* $ Detailed_Output */
458
459 /* PRVIDX is the ordinal position, according to the order */
460 /* relation implied by the column's index, of the */
461 /* record containing the last element less than or */
462 /* equal to IKEY, where the order relation is */
463 /* as indicated above. If the column contains */
464 /* elements equal to IKEY, PRVIDX is the index of the */
465 /* record designated by the input RECPTR. */
466
467 /* If all elements of the column are greater than */
468 /* IKEY, PRVIDX is set to zero. */
469
470 /* PRVPTR is a pointer to the record containing the element */
471 /* whose ordinal position is PRVIDX. */
472
473 /* If all elements of the column are greater than */
474 /* IKEY, PRVPTR is set to zero. */
475
476 /* $ Parameters */
477
478 /* None. */
479
480 /* $ Exceptions */
481
482 /* 1) If HANDLE is invalid, the error will be diagnosed by routines */
483 /* called by this routine. */
484
485 /* 2) If an I/O error occurs while reading or writing the indicated */
486 /* file, the error will be diagnosed by routines called by this */
487 /* routine. */
488
489 /* 3) If the tree is empty, PRVIDX and PRVPTR are set to zero. */
490 /* This case is not considered an error. */
491
492 /* $ Files */
493
494 /* See the EK Required Reading for a discussion of the EK file */
495 /* format. */
496
497 /* $ Particulars */
498
499 /* This routine finds the last column element less than or equal */
500 /* to a specified integer key, within a specified segment and */
501 /* column. The column must be indexed by a type 1 index. The order */
502 /* relation used is dictionary ordering on ordered pairs consisting */
503 /* of data values and record pointers: if the data values in two */
504 /* column entries are equal, the associated record pointers determine */
505 /* the order relation of the column entries. */
506
507 /* Type 1 indexes are implemented as DAS B*-trees. The data */
508 /* pointers of an index tree contain record pointers. Therefore, the */
509 /* tree implements an abstract order vector. */
510
511 /* In order to support the capability of creating an index for a */
512 /* column that has already been populated with data, this routine */
513 /* does not require that number of elements referenced by the */
514 /* input column's index match the number of elements in the column; */
515 /* the index is allowed to reference fewer elements. However, */
516 /* every record referenced by the index must be populated with data. */
517
518 /* $ Examples */
519
520 /* See ZZEKLERI. */
521
522 /* $ Restrictions */
523
524 /* None. */
525
526 /* $ Literature_References */
527
528 /* None. */
529
530 /* $ Author_and_Institution */
531
532 /* N.J. Bachman (JPL) */
533
534 /* $ Version */
535
536 /* - Beta Version 1.1.0, 07-FEB-1997 (NJB) */
537
538 /* Errors in comparisons of items of equal value were fixed. */
539 /* In such cases, items are compared according to order of */
540 /* their record pointers. */
541
542 /* - Beta Version 1.0.0, 11-OCT-1995 (NJB) */
543
544 /* -& */
545
546 /* SPICELIB functions */
547
548
549 /* Non-SPICELIB functions */
550
551
552 /* Local variables */
553
554
555 /* Use discovery check-in. */
556
557 if (failed_()) {
558 return 0;
559 }
560
561 /* Make sure the number of records in the segment is at least as */
562 /* large as the number of entries in the index: we must not look */
563 /* up any entries that don't exist! */
564
565 tree = coldsc[6];
566 tsize = zzektrsz_(handle, &tree);
567 nrec = segdsc[5];
568 if (tsize > nrec) {
569 chkin_("ZZEKERI1", (ftnlen)8);
570 setmsg_("Index size = # but column contains # records.", (ftnlen)45);
571 errint_("#", &tsize, (ftnlen)1);
572 errint_("#", &nrec, (ftnlen)1);
573 sigerr_("SPICE(SIZEMISMATCH)", (ftnlen)19);
574 chkout_("ZZEKERI1", (ftnlen)8);
575 return 0;
576 }
577
578 /* Handle the case of an empty tree gracefully. */
579
580 if (tsize == 0) {
581 *prvidx = 0;
582 *prvptr = 0;
583 return 0;
584 }
585
586 /* The algorithm used here is very like unto that used in LSTLED. */
587
588 begin = 1;
589 end = tsize;
590
591 /* Get the record pointers BEGPTR and ENDPTR of the least and */
592 /* greatest elements in the column. */
593
594 zzektrdp_(handle, &tree, &begin, &begptr);
595 zzektrdp_(handle, &tree, &end, &endptr);
596
597 /* Compare the input value to the smallest value in the column. */
598
599 if (zzekscmp_(&c__3, handle, segdsc, coldsc, &begptr, &c__1, &c__3, " ", &
600 c_b12, ikey, null, (ftnlen)1)) {
601
602 /* The smallest entry of the column is greater than the input */
603 /* value, so none of the entries are less than or equal to the */
604 /* input value. */
605
606 *prvidx = 0;
607 *prvptr = 0;
608 return 0;
609 } else if (zzekscmp_(&c__1, handle, segdsc, coldsc, &begptr, &c__1, &c__3,
610 " ", &c_b12, ikey, null, (ftnlen)1) && *recptr < begptr) {
611
612 /* The smallest entry of the column is greater than the input */
613 /* value, based on a comparison of record pointers, so none of the */
614 /* entries are less than or equal to the input value. */
615
616 *prvidx = 0;
617 *prvptr = 0;
618 return 0;
619 }
620
621 /* At this point, we know the input value is greater than or equal */
622 /* to the smallest element of the column. */
623
624 /* Compare the input value to the greatest value in the column. */
625
626 if (zzekscmp_(&c__5, handle, segdsc, coldsc, &endptr, &c__1, &c__3, " ", &
627 c_b12, ikey, null, (ftnlen)1)) {
628
629 /* The last element of the column is less than the */
630 /* input value. */
631
632 *prvidx = tsize;
633 zzektrdp_(handle, &tree, prvidx, prvptr);
634 return 0;
635 } else if (zzekscmp_(&c__1, handle, segdsc, coldsc, &endptr, &c__1, &c__3,
636 " ", &c_b12, ikey, null, (ftnlen)1) && endptr <= *recptr) {
637
638 /* The last element of the column is less than or equal to the */
639 /* input value, based on a comparison of record pointers. */
640
641 *prvidx = tsize;
642 *prvptr = endptr;
643 return 0;
644 }
645
646 /* The input value lies between some pair of column entries. */
647 /* The value is greater than or equal to the smallest column entry */
648 /* and less than the greatest entry, according to the dictionary */
649 /* ordering we're using. */
650
651 /* Below, we'll use the variable LEQ to indicate whether the "middle" */
652 /* element in our search is less than or equal to the input value. */
653
654 while(end > begin + 1) {
655
656 /* Find the record pointer of the element whose ordinal position */
657 /* is halfway between BEGIN and END. */
658
659 middle = (begin + end) / 2;
660 zzektrdp_(handle, &tree, &middle, &midptr);
661
662 /* Determine the order relation between IKEY and the column */
663 /* entry at record MIDPTR. */
664
665 if (zzekscmp_(&c__5, handle, segdsc, coldsc, &midptr, &c__1, &c__3,
666 " ", &c_b12, ikey, null, (ftnlen)1)) {
667
668 /* The column element at record MIDPTR is strictly less than */
669 /* IKEY, based on data values. */
670
671 leq = TRUE_;
672 } else if (zzekscmp_(&c__1, handle, segdsc, coldsc, &midptr, &c__1, &
673 c__3, " ", &c_b12, ikey, null, (ftnlen)1)) {
674
675 /* The column entry's value matches IKEY. We must */
676 /* compare record pointers at this point. */
677
678 leq = midptr <= *recptr;
679 } else {
680
681 /* The inequality of data values is strict. */
682
683 leq = FALSE_;
684 }
685 if (leq) {
686
687 /* The middle value is less than or equal to the input */
688 /* value. */
689
690 begin = middle;
691 } else {
692 end = middle;
693 }
694
695 /* The input value is greater than or equal to the element */
696 /* having ordinal position BEGIN and strictly less than the */
697 /* element having ordinal position END. */
698
699 }
700 *prvidx = begin;
701 zzektrdp_(handle, &tree, prvidx, prvptr);
702 return 0;
703 } /* zzekeri1_ */
704
705