1 /* ekbseg.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__512 = 512;
11 static integer c__32 = 32;
12 static integer c__1 = 1;
13 static integer c__100 = 100;
14 
15 /* $Procedure      EKBSEG ( EK, start new segment ) */
ekbseg_(integer * handle,char * tabnam,integer * ncols,char * cnames,char * decls,integer * segno,ftnlen tabnam_len,ftnlen cnames_len,ftnlen decls_len)16 /* Subroutine */ int ekbseg_(integer *handle, char *tabnam, integer *ncols,
17 	char *cnames, char *decls, integer *segno, ftnlen tabnam_len, ftnlen
18 	cnames_len, ftnlen decls_len)
19 {
20     /* Initialized data */
21 
22     static logical first = TRUE_;
23 
24     /* System generated locals */
25     integer i__1, i__2;
26 
27     /* Builtin functions */
28     integer s_rnge(char *, integer, char *, integer);
29 
30     /* Local variables */
31     extern /* Subroutine */ int zzekpdec_(char *, integer *, ftnlen),
32 	    zzekpgch_(integer *, char *, ftnlen);
33     integer i__;
34     extern integer zzekstyp_(integer *, integer *);
35     integer idend;
36     extern /* Subroutine */ int chkin_(char *, ftnlen), errch_(char *, char *,
37 	     ftnlen, ftnlen);
38     integer stype;
39     extern logical failed_(void);
40     extern /* Subroutine */ int chckid_(char *, integer *, char *, ftnlen,
41 	    ftnlen);
42     extern integer lastnb_(char *, ftnlen);
43     extern logical return_(void);
44     integer cdscrs[1100]	/* was [11][100] */;
45     static integer idspec[518];
46     integer nchars;
47     extern /* Subroutine */ int chkout_(char *, ftnlen), ssizei_(integer *,
48 	    integer *), lxdfid_(integer *), lxidnt_(integer *, char *,
49 	    integer *, integer *, integer *, ftnlen), setmsg_(char *, ftnlen),
50 	     sigerr_(char *, ftnlen), errint_(char *, integer *, ftnlen),
51 	    zzekbs01_(integer *, char *, integer *, char *, integer *,
52 	    integer *, ftnlen, ftnlen), zzekbs02_(integer *, char *, integer *
53 	    , char *, integer *, integer *, ftnlen, ftnlen);
54 
55 /* $ Abstract */
56 
57 /*     Start a new segment in an E-kernel. */
58 
59 /* $ Disclaimer */
60 
61 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
62 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
63 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
64 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
65 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
66 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
67 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
68 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
69 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
70 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
71 
72 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
73 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
74 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
75 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
76 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
77 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
78 
79 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
80 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
81 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
82 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
83 
84 /* $ Required_Reading */
85 
86 /*     EK */
87 
88 /* $ Keywords */
89 
90 /*     EK */
91 
92 /* $ Declarations */
93 /* $ Disclaimer */
94 
95 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
96 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
97 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
98 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
99 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
100 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
101 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
102 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
103 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
104 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
105 
106 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
107 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
108 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
109 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
110 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
111 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
112 
113 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
114 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
115 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
116 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
117 
118 
119 /*     Include Section:  EK Boolean Enumerated Type */
120 
121 
122 /*        ekbool.inc Version 1   21-DEC-1994 (NJB) */
123 
124 
125 /*     Within the EK system, boolean values sometimes must be */
126 /*     represented by integer or character codes.  The codes and their */
127 /*     meanings are listed below. */
128 
129 /*     Integer code indicating `true': */
130 
131 
132 /*     Integer code indicating `false': */
133 
134 
135 /*     Character code indicating `true': */
136 
137 
138 /*     Character code indicating `false': */
139 
140 
141 /*     End Include Section:  EK Boolean Enumerated Type */
142 
143 /* $ Disclaimer */
144 
145 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
146 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
147 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
148 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
149 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
150 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
151 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
152 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
153 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
154 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
155 
156 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
157 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
158 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
159 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
160 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
161 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
162 
163 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
164 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
165 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
166 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
167 
168 
169 /*     Include Section:  EK Column Descriptor Parameters */
170 
171 /*        ekcoldsc.inc Version 6    23-AUG-1995 (NJB) */
172 
173 
174 /*     Note:  The column descriptor size parameter CDSCSZ  is */
175 /*     declared separately in the include section CDSIZE$INC.FOR. */
176 
177 /*     Offset of column descriptors, relative to start of segment */
178 /*     integer address range.  This number, when added to the last */
179 /*     integer address preceding the segment, yields the DAS integer */
180 /*     base address of the first column descriptor.  Currently, this */
181 /*     offset is exactly the size of a segment descriptor.  The */
182 /*     parameter SDSCSZ, which defines the size of a segment descriptor, */
183 /*     is declared in the include file eksegdsc.inc. */
184 
185 
186 /*     Size of column descriptor */
187 
188 
189 /*     Indices of various pieces of column descriptors: */
190 
191 
192 /*     CLSIDX is the index of the column's class code.  (We use the */
193 /*     word `class' to distinguish this item from the column's data */
194 /*     type.) */
195 
196 
197 /*     TYPIDX is the index of the column's data type code (CHR, INT, DP, */
198 /*     or TIME).  The type is actually implied by the class, but it */
199 /*     will frequently be convenient to look up the type directly. */
200 
201 
202 
203 /*     LENIDX is the index of the column's string length value, if the */
204 /*     column has character type.  A value of IFALSE in this element of */
205 /*     the descriptor indicates that the strings have variable length. */
206 
207 
208 /*     SIZIDX is the index of the column's element size value.  This */
209 /*     descriptor element is meaningful for columns with fixed-size */
210 /*     entries.  For variable-sized columns, this value is IFALSE. */
211 
212 
213 /*     NAMIDX is the index of the base address of the column's name. */
214 
215 
216 /*     IXTIDX is the data type of the column's index.  IXTIDX */
217 /*     contains a type value only if the column is indexed. For columns */
218 /*     that are not indexed, the location IXTIDX contains the boolean */
219 /*     value IFALSE. */
220 
221 
222 /*     IXPIDX is a pointer to the column's index.  IXTPDX contains a */
223 /*     meaningful value only if the column is indexed.  The */
224 /*     interpretation of the pointer depends on the data type of the */
225 /*     index. */
226 
227 
228 /*     NFLIDX is the index of a flag indicating whether nulls are */
229 /*     permitted in the column.  The value at location NFLIDX is */
230 /*     ITRUE if nulls are permitted and IFALSE otherwise. */
231 
232 
233 /*     ORDIDX is the index of the column's ordinal position in the */
234 /*     list of columns belonging to the column's parent segment. */
235 
236 
237 /*     METIDX is the index of the column's integer metadata pointer. */
238 /*     This pointer is a DAS integer address. */
239 
240 
241 /*     The last position in the column descriptor is reserved.  No */
242 /*     parameter is defined to point to this location. */
243 
244 
245 /*     End Include Section:  EK Column Descriptor Parameters */
246 
247 /* $ Disclaimer */
248 
249 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
250 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
251 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
252 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
253 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
254 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
255 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
256 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
257 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
258 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
259 
260 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
261 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
262 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
263 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
264 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
265 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
266 
267 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
268 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
269 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
270 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
271 
272 
273 /*     Include Section:  EK Column Name Size */
274 
275 /*        ekcnamsz.inc Version 1    17-JAN-1995 (NJB) */
276 
277 
278 /*     Size of column name, in characters. */
279 
280 
281 /*     End Include Section:  EK Column Name Size */
282 
283 /* $ Disclaimer */
284 
285 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
286 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
287 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
288 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
289 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
290 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
291 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
292 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
293 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
294 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
295 
296 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
297 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
298 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
299 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
300 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
301 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
302 
303 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
304 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
305 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
306 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
307 
308 
309 /*     Include Section:  EK Data Page Parameters */
310 
311 /*        ekfilpar.inc  Version 1  03-APR-1995 (NJB) */
312 
313 /*     These parameters apply to EK files using architecture 4. */
314 /*     These files use a paged DAS file as their underlying file */
315 /*     structure. */
316 
317 /*     In paged DAS EK files, data pages are structured:  they contain */
318 /*     metadata as well as data.  The metadata is located in the last */
319 /*     few addresses of each page, so as to interfere as little as */
320 /*     possible with calculation of data addresses. */
321 
322 /*     Each data page belongs to exactly one segment.  Some bookkeeping */
323 /*     information, such as record pointers, is also stored in data */
324 /*     pages. */
325 
326 /*     Each page contains a forward pointer that allows rapid lookup */
327 /*     of data items that span multiple pages.  Each page also keeps */
328 /*     track of the current number of links from its parent segment */
329 /*     to the page.  Link counts enable pages to `know' when they */
330 /*     are no longer in use by a segment; unused pages are deallocated */
331 /*     and returned to the free list. */
332 
333 /*     The parameters in this include file depend on the parameters */
334 /*     declared in the include file ekpage.inc.  If those parameters */
335 /*     change, this file must be updated.  The specified parameter */
336 /*     declarations we need from that file are: */
337 
338 /*        INTEGER               PGSIZC */
339 /*        PARAMETER           ( PGSIZC = 1024 ) */
340 
341 /*        INTEGER               PGSIZD */
342 /*        PARAMETER           ( PGSIZD = 128 ) */
343 
344 /*        INTEGER               PGSIZI */
345 /*        PARAMETER           ( PGSIZI = 256 ) */
346 
347 
348 
349 /*     Character pages use an encoding mechanism to represent integer */
350 /*     metadata.  Each integer is encoded in five consecutive */
351 /*     characters. */
352 
353 
354 /*     Character data page parameters: */
355 
356 
357 /*     Size of encoded integer: */
358 
359 
360 /*     Usable page size: */
361 
362 
363 /*     Location of character forward pointer: */
364 
365 
366 /*     Location of character link count: */
367 
368 
369 /*     Double precision data page parameters: */
370 
371 /*     Usable page size: */
372 
373 
374 /*     Location of d.p. forward pointer: */
375 
376 
377 /*     Location of d.p. link count: */
378 
379 
380 /*     Integer data page parameters: */
381 
382 /*     Usable page size: */
383 
384 
385 /*     Location of integer forward pointer: */
386 
387 
388 /*     Location of integer link count: */
389 
390 
391 /*     End Include Section:  EK Data Page Parameters */
392 
393 /* $ Disclaimer */
394 
395 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
396 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
397 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
398 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
399 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
400 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
401 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
402 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
403 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
404 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
405 
406 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
407 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
408 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
409 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
410 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
411 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
412 
413 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
414 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
415 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
416 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
417 
418 
419 /*     Include Section:  EK File Metadata Parameters */
420 
421 /*        ekfilpar.inc  Version 1  28-MAR-1995 (NJB) */
422 
423 /*     These parameters apply to EK files using architecture 4. */
424 /*     These files use a paged DAS file as their underlying file */
425 /*     structure. */
426 
427 /*     The metadata for an architecture 4 EK file is very simple:  it */
428 /*     consists of a single integer, which is a pointer to a tree */
429 /*     that in turn points to the segments in the EK.  However, in the */
430 /*     interest of upward compatibility, one integer page is reserved */
431 /*     for the file's metadata. */
432 
433 
434 /*     Size of file parameter block: */
435 
436 
437 /*     All offsets shown below are relative to the beginning of the */
438 /*     first integer page in the EK. */
439 
440 
441 /*     Index of the segment pointer tree---this location contains the */
442 /*     root page number of the tree: */
443 
444 
445 /*     End Include Section:  EK File Metadata Parameters */
446 
447 /* $ Disclaimer */
448 
449 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
450 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
451 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
452 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
453 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
454 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
455 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
456 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
457 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
458 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
459 
460 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
461 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
462 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
463 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
464 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
465 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
466 
467 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
468 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
469 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
470 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
471 
472 
473 /*     Include Section:  EK General Limit Parameters */
474 
475 /*        ekglimit.inc  Version 1    21-MAY-1995 (NJB) */
476 
477 
478 /*     This file contains general limits for the EK system. */
479 
480 /*     MXCLSG is the maximum number of columns allowed in a segment. */
481 /*     This limit applies to logical tables as well, since all segments */
482 /*     in a logical table must have the same column definitions. */
483 
484 
485 /*     End Include Section:  EK General Limit Parameters */
486 
487 /* $ Disclaimer */
488 
489 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
490 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
491 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
492 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
493 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
494 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
495 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
496 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
497 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
498 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
499 
500 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
501 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
502 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
503 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
504 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
505 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
506 
507 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
508 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
509 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
510 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
511 
512 
513 /*     Include Section:  EK Das Paging Parameters */
514 
515 /*        ekpage.inc  Version 4    25-AUG-1995 (NJB) */
516 
517 
518 
519 /*     The EK DAS paging system makes use of the integer portion */
520 /*     of an EK file's DAS address space to store the few numbers */
521 /*     required to describe the system's state.  The allocation */
522 /*     of DAS integer addresses is shown below. */
523 
524 
525 /*                       DAS integer array */
526 
527 /*        +--------------------------------------------+ */
528 /*        |            EK architecture code            |  Address = 1 */
529 /*        +--------------------------------------------+ */
530 /*        |      Character page size (in DAS words)    | */
531 /*        +--------------------------------------------+ */
532 /*        |        Character page base address         | */
533 /*        +--------------------------------------------+ */
534 /*        |      Number of character pages in file     | */
535 /*        +--------------------------------------------+ */
536 /*        |   Number of character pages on free list   | */
537 /*        +--------------------------------------------+ */
538 /*        |      Character free list head pointer      |  Address = 6 */
539 /*        +--------------------------------------------+ */
540 /*        |                                            |  Addresses = */
541 /*        |           Metadata for d.p. pages          |    7--11 */
542 /*        |                                            | */
543 /*        +--------------------------------------------+ */
544 /*        |                                            |  Addresses = */
545 /*        |         Metadata for integer pages         |    12--16 */
546 /*        |                                            | */
547 /*        +--------------------------------------------+ */
548 /*                              . */
549 /*                              . */
550 /*                              . */
551 /*        +--------------------------------------------+ */
552 /*        |                                            |  End Address = */
553 /*        |                Unused space                |  integer page */
554 /*        |                                            |  end */
555 /*        +--------------------------------------------+ */
556 /*        |                                            |  Start Address = */
557 /*        |             First integer page             |  integer page */
558 /*        |                                            |  base */
559 /*        +--------------------------------------------+ */
560 /*                              . */
561 /*                              . */
562 /*                              . */
563 /*        +--------------------------------------------+ */
564 /*        |                                            | */
565 /*        |              Last integer page             | */
566 /*        |                                            | */
567 /*        +--------------------------------------------+ */
568 
569 /*     The following parameters indicate positions of elements in the */
570 /*     paging system metadata array: */
571 
572 
573 
574 /*     Number of metadata items per data type: */
575 
576 
577 /*     Character metadata indices: */
578 
579 
580 /*     Double precision metadata indices: */
581 
582 
583 /*     Integer metadata indices: */
584 
585 
586 /*     Size of metadata area: */
587 
588 
589 /*     Page sizes, in units of DAS words of the appropriate type: */
590 
591 
592 /*     Default page base addresses: */
593 
594 
595 /*     End Include Section:  EK Das Paging Parameters */
596 
597 /* $ Disclaimer */
598 
599 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
600 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
601 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
602 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
603 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
604 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
605 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
606 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
607 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
608 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
609 
610 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
611 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
612 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
613 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
614 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
615 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
616 
617 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
618 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
619 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
620 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
621 
622 
623 /*     Include Section:  EK Record Pointer Parameters */
624 
625 /*        ekrecptr.inc Version 2  18-JUL-1995 (NJB) */
626 
627 
628 /*     This file declares parameters used in EK record pointers. */
629 /*     Each segment references data in a given record via two levels */
630 /*     of indirection:  a record number points to a record pointer, */
631 /*     which is a structured array of metadata and data pointers. */
632 
633 /*     Record pointers always occupy contiguous ranges of integer */
634 /*     addresses. */
635 
636 /*     The parameter declarations in this file depend on the assumption */
637 /*     that integer pages contain 256 DAS integer words and that the */
638 /*     maximum number of columns in a segment is 100.  Record pointers */
639 /*     are stored in integer data pages, so they must fit within the */
640 /*     usable data area afforded by these pages.  The size of the usable */
641 /*     data area is given by the parameter IPSIZE which is declared in */
642 /*     ekdatpag.inc.  The assumed value of IPSIZE is 254. */
643 
644 
645 /*     The first element of each record pointer is a status indicator. */
646 /*     The meanings of status indicators depend on whether the parent EK */
647 /*     is shadowed or not.  For shadowed EKs, allowed status values and */
648 /*     their meanings are: */
649 
650 /*        OLD       The record has not been modified since */
651 /*                  the EK containing the record was opened. */
652 
653 /*        UPDATE    The record is an update of a previously existing */
654 /*                  record.  The original record is now on the */
655 /*                  modified record list. */
656 
657 /*        NEW       The record has been added since the EK containing the */
658 /*                  record was opened.  The record is not an update */
659 /*                  of a previously existing record. */
660 
661 /*        DELOLD    This status applies only to a backup record. */
662 /*                  DELOLD status indicates that the record corresponds */
663 /*                  to a deleted OLD record in the source segment. */
664 
665 /*        DELNEW    This status applies only to a backup record. */
666 /*                  DELNEW status indicates that the record corresponds */
667 /*                  to a deleted NEW record in the source segment. */
668 
669 /*        DELUPD    This status applies only to a backup record. */
670 /*                  DELUPD status indicates that the record corresponds */
671 /*                  to a deleted UPDATEd record in the source segment. */
672 
673 /*     In EKs that are not shadowed, all records have status OLD. */
674 
675 
676 
677 /*     The following parameters refer to indices within the record */
678 /*     pointer structure: */
679 
680 /*     Index of status indicator: */
681 
682 
683 /*     Each record pointer contains a pointer to its companion:  for a */
684 /*     record belonging to a shadowed EK, this is the backup counterpart, */
685 /*     or if the parent EK is itself a backup EK, a pointer to the */
686 /*     record's source record.  The pointer is UNINIT (see below) if the */
687 /*     record is unmodified. */
688 
689 /*     Record companion pointers contain record numbers, not record */
690 /*     base addresses. */
691 
692 /*     Index of record's companion pointer: */
693 
694 
695 /*     Each data item is referenced by an integer.  The meaning of */
696 /*     this integer depends on the representation of data in the */
697 /*     column to which the data item belongs.  Actual lookup of a */
698 /*     data item must be done by subroutines appropriate to the class of */
699 /*     the column to which the item belongs.  Note that data items don't */
700 /*     necessarily occupy contiguous ranges of DAS addresses. */
701 
702 /*     Base address of data pointers: */
703 
704 
705 /*     Maximum record pointer size: */
706 
707 
708 /*     Data pointers are given the value UNINIT to start with; this */
709 /*     indicates that the data item is uninitialized.  UNINIT is */
710 /*     distinct from the value NULL.  NOBACK indicates an uninitialized */
711 /*     backup column entry. */
712 
713 
714 /*     End Include Section:  EK Record Pointer Parameters */
715 
716 /* $ Disclaimer */
717 
718 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
719 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
720 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
721 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
722 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
723 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
724 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
725 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
726 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
727 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
728 
729 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
730 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
731 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
732 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
733 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
734 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
735 
736 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
737 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
738 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
739 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
740 
741 
742 /*     Include Section:  EK Segment Descriptor Parameters */
743 
744 /*        eksegdsc.inc  Version 8  06-NOV-1995 (NJB) */
745 
746 
747 /*     All `base addresses' referred to below are the addresses */
748 /*     *preceding* the item the base applies to.  This convention */
749 /*     enables simplied address calculations in many cases. */
750 
751 /*     Size of segment descriptor.  Note:  the include file ekcoldsc.inc */
752 /*     must be updated if this parameter is changed.  The parameter */
753 /*     CDOFF in that file should be kept equal to SDSCSZ. */
754 
755 
756 /*     Index of the segment type code: */
757 
758 
759 /*     Index of the segment's number.  This number is the segment's */
760 /*     index in the list of segments contained in the EK to which */
761 /*     the segment belongs. */
762 
763 
764 /*     Index of the DAS integer base address of the segment's integer */
765 /*     meta-data: */
766 
767 
768 /*     Index of the DAS character base address of the table name: */
769 
770 
771 /*     Index of the segment's column count: */
772 
773 
774 /*     Index of the segment's record count: */
775 
776 
777 /*     Index of the root page number of the record tree: */
778 
779 
780 /*     Index of the root page number of the character data page tree: */
781 
782 
783 /*     Index of the root page number of the double precision data page */
784 /*     tree: */
785 
786 
787 /*     Index of the root page number of the integer data page tree: */
788 
789 
790 /*     Index of the `modified' flag: */
791 
792 
793 /*     Index of the `initialized' flag: */
794 
795 
796 /*     Index of the shadowing flag: */
797 
798 
799 /*     Index of the companion file handle: */
800 
801 
802 /*     Index of the companion segment number: */
803 
804 
805 /*     The next three items are, respectively, the page numbers of the */
806 /*     last character, d.p., and integer data pages allocated by the */
807 /*     segment: */
808 
809 
810 /*     The next three items are, respectively, the page-relative */
811 /*     indices of the last DAS word in use in the segment's */
812 /*     last character, d.p., and integer data pages: */
813 
814 
815 /*     Index of the DAS character base address of the column name list: */
816 
817 
818 /*     The last descriptor element is reserved for future use.  No */
819 /*     parameter is defined to point to this location. */
820 
821 
822 /*     End Include Section:  EK Segment Descriptor Parameters */
823 
824 /* $ Disclaimer */
825 
826 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
827 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
828 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
829 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
830 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
831 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
832 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
833 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
834 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
835 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
836 
837 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
838 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
839 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
840 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
841 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
842 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
843 
844 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
845 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
846 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
847 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
848 
849 
850 /*     Include Section:  EK Table Name Size */
851 
852 /*        ektnamsz.inc Version 1    17-JAN-1995 (NJB) */
853 
854 
855 /*     Size of table name, in characters. */
856 
857 
858 /*     End Include Section:  EK Table Name Size */
859 
860 /* $ Disclaimer */
861 
862 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
863 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
864 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
865 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
866 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
867 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
868 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
869 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
870 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
871 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
872 
873 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
874 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
875 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
876 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
877 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
878 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
879 
880 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
881 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
882 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
883 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
884 
885 
886 /*     Include Section:  EK Data Types */
887 
888 /*        ektype.inc Version 1  27-DEC-1994 (NJB) */
889 
890 
891 /*     Within the EK system, data types of EK column contents are */
892 /*     represented by integer codes.  The codes and their meanings */
893 /*     are listed below. */
894 
895 /*     Integer codes are also used within the DAS system to indicate */
896 /*     data types; the EK system makes no assumptions about compatibility */
897 /*     between the codes used here and those used in the DAS system. */
898 
899 
900 /*     Character type: */
901 
902 
903 /*     Double precision type: */
904 
905 
906 /*     Integer type: */
907 
908 
909 /*     `Time' type: */
910 
911 /*     Within the EK system, time values are represented as ephemeris */
912 /*     seconds past J2000 (TDB), and double precision numbers are used */
913 /*     to store these values.  However, since time values require special */
914 /*     treatment both on input and output, and since the `TIME' column */
915 /*     has a special role in the EK specification and code, time values */
916 /*     are identified as a type distinct from double precision numbers. */
917 
918 
919 /*     End Include Section:  EK Data Types */
920 
921 /* $ Brief_I/O */
922 
923 /*     Variable  I/O  Description */
924 /*     --------  ---  -------------------------------------------------- */
925 /*     HANDLE     I   File handle. */
926 /*     TABNAM     I   Table name. */
927 /*     NCOLS      I   Number of columns in the segment. */
928 /*     CNAMES     I   Names of columns. */
929 /*     DECLS      I   Declarations of columns. */
930 /*     SEGNO      O   Segment number. */
931 
932 /* $ Detailed_Input */
933 
934 /*     HANDLE         the handle of an EK file that is open for writing. */
935 
936 /*     TABNAM         is the name of the EK table to which the current */
937 /*                    segment belongs.  All segments in the EK file */
938 /*                    designated by HANDLE must have identical column */
939 /*                    attributes. TABNAM must not exceed 32 characters */
940 /*                    in length.  Case is not significant.  Table names */
941 /*                    must start with a letter and contain only */
942 /*                    characters from the set {A-Z,a-z,0-9,$,_}. */
943 
944 /*     NCOLS          is the number of columns in a new segment. */
945 
946 /*     CNAMES, */
947 /*     DECLS          are, respectively, and array of column names and */
948 /*                    their corresponding declarations:  the Ith element */
949 /*                    of CNAMES and the Ith element of DECLS apply to */
950 /*                    the Ith column in the segment. */
951 
952 /*                    Column names must not exceed CNAMSZ (32) characters */
953 /*                    in length.  Case is not significant.  Column names */
954 /*                    must start with a letter and contain only */
955 /*                    characters from the set {A-Z,a-z,0-9,$,_}. */
956 
957 /*                    The declarations are strings that contain */
958 /*                    `keyword=value' assignments that define the */
959 /*                    attributes of the columns to which they apply.  The */
960 /*                    column attributes that are defined by a column */
961 /*                    declaration are: */
962 
963 /*                       DATATYPE */
964 /*                       SIZE */
965 /*                       <is the column indexed?> */
966 /*                       <does the column allow null values?> */
967 
968 /*                    The form of a declaration is */
969 
970 /*                       'DATATYPE  = <type>, */
971 /*                        SIZE      = <size>, */
972 /*                        INDEXED   = <boolean>, */
973 /*                        NULLS_OK  = <boolean>' */
974 
975 /*                    For example, an indexed, scalar, integer column */
976 /*                    that allows null values would have the declaration */
977 
978 /*                       'DATATYPE  = INTEGER, */
979 /*                        SIZE      = 1, */
980 /*                        INDEXED   = TRUE, */
981 /*                        NULLS_OK  = TRUE' */
982 
983 /*                    Commas are required to separate the assignments */
984 /*                    within declarations; white space is optional; */
985 /*                    case is not significant. */
986 
987 /*                    The order in which the attribute keywords are */
988 /*                    listed in declaration is not significant. */
989 
990 /*                    Every column in a segment must be declared. */
991 
992 /*                    Each column entry is effectively an array, each */
993 /*                    element of which has the declared data type.  The */
994 /*                    SIZE keyword indicates how many elements are in */
995 /*                    each entry of the column in whose declaration the */
996 /*                    keyword appears.  Note that only scalar-valued */
997 /*                    columns (those for which SIZE = 1) may be */
998 /*                    referenced in query constraints.  A size */
999 /*                    assignment has the syntax */
1000 
1001 /*                       SIZE = <integer> */
1002 
1003 /*                    or */
1004 /*                       SIZE = VARIABLE */
1005 
1006 /*                    The size value defaults to 1 if omitted. */
1007 
1008 /*                    The DATATYPE keyword defines the data type of */
1009 /*                    column entries.  The DATATYPE assignment syntax */
1010 /*                    has any of the forms */
1011 
1012 /*                       DATATYPE = CHARACTER*(<length>) */
1013 /*                       DATATYPE = CHARACTER*(*) */
1014 /*                       DATATYPE = DOUBLE PRECISION */
1015 /*                       DATATYPE = INTEGER */
1016 /*                       DATATYPE = TIME */
1017 
1018 /*                    As the datatype declaration syntax suggests, */
1019 /*                    character strings may have fixed or variable */
1020 /*                    length.  Variable-length strings are allowed only */
1021 /*                    in columns of size 1. */
1022 
1023 /*                    Optionally, scalar-valued columns may be indexed. */
1024 /*                    To create an index for a column, use the assignment */
1025 
1026 /*                       INDEXED = TRUE */
1027 
1028 /*                    By default, columns are not indexed. */
1029 
1030 /*                    Optionally, any column can allow null values.  To */
1031 /*                    indicate that a column may allow null values, use */
1032 /*                    the assigment */
1033 
1034 /*                       NULLS_OK = TRUE */
1035 
1036 /*                    in the column declaration.  By default, null */
1037 /*                    values are not allowed in column entries. */
1038 
1039 /* $ Detailed_Output */
1040 
1041 /*     SEGNO          is the number of the segment created by this */
1042 /*                    routine.  Segment numbers are used as unique */
1043 /*                    identifiers by other EK access routines. */
1044 
1045 /* $ Parameters */
1046 
1047 /*     None. */
1048 
1049 /* $ Exceptions */
1050 
1051 /*     1)  If HANDLE is invalid, the error will be diagnosed by routines */
1052 /*         called by this routine. */
1053 
1054 /*     2)  If TABNAM is more than TNAMSZ characters long, the error */
1055 /*         is diagnosed by routines called by this routine. */
1056 
1057 /*     3)  If TABNAM contains any nonprintable characters, the error */
1058 /*         is diagnosed by routines called by this routine. */
1059 
1060 /*     4)  If NCOLS is non-positive or greater than the maximum allowed */
1061 /*         number MXCLSG, the error SPICE(INVALIDCOUNT) is signalled. */
1062 
1063 /*     5)  If any column name exceeds CNAMSZ characters in length, the */
1064 /*         error is diagnosed by routines called by this routine. */
1065 
1066 /*     6)  If any column name contains non-printable characters, the */
1067 /*         error is diagnosed by routines called by this routine. */
1068 
1069 /*     7)  If a declaration cannot be understood by this routine, the */
1070 /*         error is diagnosed by routines called by this routine. */
1071 
1072 /*     8)  If an non-positive string length or element size is specified, */
1073 /*         the error is diagnosed by routines called by this routine. */
1074 
1075 /*     9)  If an I/O error occurs while reading or writing the indicated */
1076 /*         file, the error will be diagnosed by routines called by this */
1077 /*         routine. */
1078 
1079 /* $ Files */
1080 
1081 /*     See the EK Required Reading for a discussion of the EK file */
1082 /*     format. */
1083 
1084 /* $ Particulars */
1085 
1086 /*     This routine operates by side effects:  it prepares an EK for */
1087 /*     the addition of a new segment.  It is not necessary to take */
1088 /*     any special action to `complete' a segment; segments are readable */
1089 /*     after the completion of any record insertion, deletion, write, */
1090 /*     or update operation. */
1091 
1092 /* $ Examples */
1093 
1094 /*     1)  Suppose we have an E-kernel named ORDER_DB.EK which contains */
1095 /*         records of orders for data products.  The E-kernel has a */
1096 /*         table called DATAORDERS that consists of the set of columns */
1097 /*         listed below: */
1098 
1099 /*            DATAORDERS */
1100 
1101 /*               Column Name     Data Type */
1102 /*               -----------     --------- */
1103 /*               ORDER_ID        INTEGER */
1104 /*               CUSTOMER_ID     INTEGER */
1105 /*               LAST_NAME       CHARACTER*(*) */
1106 /*               FIRST_NAME      CHARACTER*(*) */
1107 /*               ORDER_DATE      TIME */
1108 /*               COST            DOUBLE PRECISION */
1109 
1110 /*         The order database also has a table of items that have been */
1111 /*         ordered.  The columns of this table are shown below: */
1112 
1113 /*            DATAITEMS */
1114 
1115 /*               Column Name     Data Type */
1116 /*               -----------     --------- */
1117 /*               ITEM_ID         INTEGER */
1118 /*               ORDER_ID        INTEGER */
1119 /*               ITEM_NAME       CHARACTER*(*) */
1120 /*               DESCRIPTION     CHARACTER*(*) */
1121 /*               PRICE           DOUBLE PRECISION */
1122 
1123 
1124 /*         We'll suppose that the file ORDER_DB.EK contains two segments, */
1125 /*         the first containing the DATAORDERS table and the second */
1126 /*         containing the DATAITEMS table. */
1127 
1128 /*         Below, we show how we'd open a new EK file and start the */
1129 /*         first of the segments described above. */
1130 
1131 
1132 /*            C */
1133 /*            C     Open a new EK file.  For simplicity, we will not */
1134 /*            C     reserve any space for the comment area, so the */
1135 /*            C     number of reserved comment characters is zero. */
1136 /*            C     The variable IFNAME is the internal file name. */
1137 /*            C */
1138 /*                  NRESVC  =  0 */
1139 /*                  IFNAME  =  'Test EK/Created 20-SEP-1995' */
1140 
1141 /*                  CALL EKOPN ( 'ORDER_DB.EK', IFNAME, NRESVC, HANDLE ) */
1142 
1143 /*            C */
1144 /*            C     Set up the table and column names and declarations */
1145 /*            C     for the DATAORDERS segment.  We'll index all of */
1146 /*            C     the columns.  All columns are scalar, so we omit */
1147 /*            C     the size declaration.  Only the COST column may take */
1148 /*            C     null values. */
1149 /*            C */
1150 /*                  TABLE     =  'DATAORDERS' */
1151 /*                  NCOLS     =  6 */
1152 
1153 /*                  CNAMES(1) =  'ORDER_ID' */
1154 /*                  CDECLS(1) =  'DATATYPE = INTEGER, INDEXED = TRUE' */
1155 
1156 /*                  CNAMES(2) =  'CUSTOMER_ID' */
1157 /*                  CDECLS(2) =  'DATATYPE = INTEGER, INDEXED = TRUE' */
1158 
1159 /*                  CNAMES(3) =  'LAST_NAME' */
1160 /*                  CDECLS(3) =  'DATATYPE = CHARACTER*(*),' // */
1161 /*                 .             'INDEXED  = TRUE' */
1162 
1163 /*                  CNAMES(4) =  'FIRST_NAME' */
1164 /*                  CDECLS(4) =  'DATATYPE = CHARACTER*(*),' // */
1165 /*                 .             'INDEXED  = TRUE' */
1166 
1167 /*                  CNAMES(5) =  'ORDER_DATE' */
1168 /*                  CDECLS(5) =  'DATATYPE = TIME, INDEXED  = TRUE' */
1169 
1170 /*                  CNAMES(6) =  'COST' */
1171 /*                  CDECLS(6) =  'DATATYPE = DOUBLE PRECISION,' // */
1172 /*                 .             'INDEXED  = TRUE'           // */
1173 /*                 .             'NULLS_OK = TRUE' */
1174 
1175 /*            C */
1176 /*            C     Start the segment. */
1177 /*            C */
1178 /*                  CALL EKBSEG ( HANDLE,  TABNAM,  NCOLS, */
1179 /*                 .              CNAMES,  CDECLS,  SEGNO  ) */
1180 
1181 /*            C */
1182 /*            C     Add data to the segment.  No special action */
1183 /*            C     is required to finish the segment. */
1184 /*            C */
1185 /*                  [Data is added via calls to EKAPPR and the */
1186 /*                   EKACEC, EKACED, and EKACEI routines.  See any */
1187 /*                   of these routines for examples.] */
1188 
1189 /*            C */
1190 /*            C     At this point, the second segment could be */
1191 /*            C     created by an analogous process.  In fact, the */
1192 /*            C     second segment could be created at any time; it is */
1193 /*            C     not necessary to populate the first segment with */
1194 /*            C     data before starting the second segment. */
1195 /*            C */
1196 
1197 /*            C */
1198 /*            C     The file must be closed by a call to EKCLS. */
1199 /*            C */
1200 /*                  CALL EKCLS ( HANDLE ) */
1201 
1202 
1203 /* $ Restrictions */
1204 
1205 /*     None. */
1206 
1207 /* $ Literature_References */
1208 
1209 /*     None. */
1210 
1211 /* $ Author_and_Institution */
1212 
1213 /*     N.J. Bachman   (JPL) */
1214 
1215 /* $ Version */
1216 
1217 /* -    SPICELIB Version 1.1.0, 07-JUL-1996 (NJB) */
1218 
1219 /*        Erroneous error message for invalid column names was fixed. */
1220 /*        Previous version line was changed from "Beta" to "SPICELIB." */
1221 
1222 /* -    SPICELIB Version 1.0.0, 06-NOV-1995 (NJB) */
1223 
1224 /* -& */
1225 /* $ Index_Entries */
1226 
1227 /*     start new E-kernel segment */
1228 /*     start new EK segment */
1229 
1230 /* -& */
1231 /* $ Revisions */
1232 
1233 /* -    SPICELIB Version 1.1.0, 07-JUL-1996 (NJB) */
1234 
1235 /*        Erroneous error message for invalid column names was fixed. */
1236 /*        Previous version line was changed from "Beta" to "SPICELIB." */
1237 
1238 /* -& */
1239 
1240 /*     SPICELIB functions */
1241 
1242 
1243 /*     Non-SPICELIB functions */
1244 
1245 
1246 /*     Local parameters */
1247 
1248 
1249 /*     Local variables */
1250 
1251 
1252 /*     Saved variables */
1253 
1254 
1255 /*     Initial values */
1256 
1257 
1258 /*     Standard SPICE error handling. */
1259 
1260     if (return_()) {
1261 	return 0;
1262     } else {
1263 	chkin_("EKBSEG", (ftnlen)6);
1264     }
1265 
1266 /*     Before trying to actually write anything, do every error */
1267 /*     check we can. */
1268 
1269 /*     Is this file handle valid--is the file open for paged write */
1270 /*     access?  Signal an error if not. */
1271 
1272     zzekpgch_(handle, "WRITE", (ftnlen)5);
1273     if (failed_()) {
1274 	chkout_("EKBSEG", (ftnlen)6);
1275 	return 0;
1276     }
1277 
1278 /*     Get the default identifier specification the first time through. */
1279 
1280     if (first) {
1281 	ssizei_(&c__512, idspec);
1282 	lxdfid_(idspec);
1283 	first = FALSE_;
1284     }
1285 
1286 /*     The table name must not be too long, and all of its characters */
1287 /*     must be printable (it's ok for it to unprintable). */
1288 
1289     chckid_("EK table name", &c__32, tabnam, (ftnlen)13, tabnam_len);
1290     if (failed_()) {
1291 	chkout_("EKBSEG", (ftnlen)6);
1292 	return 0;
1293     }
1294 
1295 /*     Make sure the table name satisfies all of our restrictions on */
1296 /*     allowed characters. */
1297 
1298     lxidnt_(idspec, tabnam, &c__1, &idend, &nchars, tabnam_len);
1299     if (nchars == 0 || nchars < lastnb_(tabnam, tabnam_len)) {
1300 	setmsg_("Table name <#> violates syntax rules.", (ftnlen)37);
1301 	errch_("#", tabnam, (ftnlen)1, tabnam_len);
1302 	sigerr_("SPICE(INVALIDNAME)", (ftnlen)18);
1303 	chkout_("EKBSEG", (ftnlen)6);
1304 	return 0;
1305     }
1306 
1307 /*     Check out NCOLS. */
1308 
1309     if (*ncols < 1 || *ncols > 100) {
1310 	setmsg_("Number of columns must be in range 1:#, was #.", (ftnlen)46);
1311 	errint_("#", &c__100, (ftnlen)1);
1312 	errint_("#", ncols, (ftnlen)1);
1313 	sigerr_("SPICE(INVALIDCOUNT)", (ftnlen)19);
1314 	chkout_("EKBSEG", (ftnlen)6);
1315 	return 0;
1316     }
1317 
1318 /*     Check the column names for length and printability. */
1319 
1320     i__1 = *ncols;
1321     for (i__ = 1; i__ <= i__1; ++i__) {
1322 	chckid_("EK column name", &c__32, cnames + (i__ - 1) * cnames_len, (
1323 		ftnlen)14, cnames_len);
1324 	if (failed_()) {
1325 	    chkout_("EKBSEG", (ftnlen)6);
1326 	    return 0;
1327 	}
1328 
1329 /*        Make sure each column name satisfies all of our restrictions on */
1330 /*        allowed characters. */
1331 
1332 	lxidnt_(idspec, cnames + (i__ - 1) * cnames_len, &c__1, &idend, &
1333 		nchars, cnames_len);
1334 	if (nchars == 0 || nchars < lastnb_(cnames + (i__ - 1) * cnames_len,
1335 		cnames_len)) {
1336 	    setmsg_("Column name <#> violates syntax rules.", (ftnlen)38);
1337 	    errch_("#", cnames + (i__ - 1) * cnames_len, (ftnlen)1,
1338 		    cnames_len);
1339 	    sigerr_("SPICE(INVALIDNAME)", (ftnlen)18);
1340 	    chkout_("EKBSEG", (ftnlen)6);
1341 	    return 0;
1342 	}
1343     }
1344 
1345 /*     Parse the column declarations before proceeding. */
1346 
1347     i__1 = *ncols;
1348     for (i__ = 1; i__ <= i__1; ++i__) {
1349 
1350 /*        Parse the declaration of the Ith column.  The descriptor is */
1351 /*        returned with all elements other than pointers initialized. */
1352 
1353 	zzekpdec_(decls + (i__ - 1) * decls_len, &cdscrs[(i__2 = i__ * 11 -
1354 		11) < 1100 && 0 <= i__2 ? i__2 : s_rnge("cdscrs", i__2, "ekb"
1355 		"seg_", (ftnlen)549)], decls_len);
1356 	if (failed_()) {
1357 	    chkout_("EKBSEG", (ftnlen)6);
1358 	    return 0;
1359 	}
1360     }
1361 
1362 /*     Determine the segment type. */
1363 
1364     stype = zzekstyp_(ncols, cdscrs);
1365 
1366 /*     Create the segment metadata according to the segment's type. */
1367 
1368     if (stype == 1) {
1369 	zzekbs01_(handle, tabnam, ncols, cnames, cdscrs, segno, tabnam_len,
1370 		cnames_len);
1371     } else if (stype == 2) {
1372 	zzekbs02_(handle, tabnam, ncols, cnames, cdscrs, segno, tabnam_len,
1373 		cnames_len);
1374     } else {
1375 	setmsg_("Segment type # is not currently supported.", (ftnlen)42);
1376 	errint_("#", &stype, (ftnlen)1);
1377 	sigerr_("SPICE(BUG)", (ftnlen)10);
1378 	chkout_("EKBSEG", (ftnlen)6);
1379 	return 0;
1380     }
1381     chkout_("EKBSEG", (ftnlen)6);
1382     return 0;
1383 } /* ekbseg_ */
1384 
1385