1 /* ekappr.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 /* $Procedure      EKAPPR ( EK, append record onto segment ) */
ekappr_(integer * handle,integer * segno,integer * recno)9 /* Subroutine */ int ekappr_(integer *handle, integer *segno, integer *recno)
10 {
11     /* System generated locals */
12     integer i__1, i__2;
13 
14     /* Local variables */
15     integer nrec;
16     extern /* Subroutine */ int zzekpgch_(integer *, char *, ftnlen),
17 	    zzekmloc_(integer *, integer *, integer *, integer *);
18     integer mbase;
19     extern /* Subroutine */ int chkin_(char *, ftnlen);
20     extern logical failed_(void);
21     integer mp, segdsc[24];
22     extern logical return_(void);
23     extern /* Subroutine */ int chkout_(char *, ftnlen), dasrdi_(integer *,
24 	    integer *, integer *, integer *), ekinsr_(integer *, integer *,
25 	    integer *);
26 
27 /* $ Abstract */
28 
29 /*     Append a new, empty record at the end of a specified E-kernel */
30 /*     segment. */
31 
32 /* $ Disclaimer */
33 
34 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
35 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
36 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
37 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
38 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
39 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
40 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
41 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
42 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
43 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
44 
45 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
46 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
47 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
48 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
49 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
50 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
51 
52 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
53 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
54 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
55 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
56 
57 /* $ Required_Reading */
58 
59 /*     EK */
60 
61 /* $ Keywords */
62 
63 /*     PRIVATE */
64 /*     UTILITY */
65 
66 /* $ Declarations */
67 /* $ Disclaimer */
68 
69 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
70 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
71 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
72 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
73 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
74 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
75 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
76 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
77 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
78 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
79 
80 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
81 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
82 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
83 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
84 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
85 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
86 
87 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
88 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
89 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
90 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
91 
92 
93 /*     Include Section:  EK Data Page Parameters */
94 
95 /*        ekfilpar.inc  Version 1  03-APR-1995 (NJB) */
96 
97 /*     These parameters apply to EK files using architecture 4. */
98 /*     These files use a paged DAS file as their underlying file */
99 /*     structure. */
100 
101 /*     In paged DAS EK files, data pages are structured:  they contain */
102 /*     metadata as well as data.  The metadata is located in the last */
103 /*     few addresses of each page, so as to interfere as little as */
104 /*     possible with calculation of data addresses. */
105 
106 /*     Each data page belongs to exactly one segment.  Some bookkeeping */
107 /*     information, such as record pointers, is also stored in data */
108 /*     pages. */
109 
110 /*     Each page contains a forward pointer that allows rapid lookup */
111 /*     of data items that span multiple pages.  Each page also keeps */
112 /*     track of the current number of links from its parent segment */
113 /*     to the page.  Link counts enable pages to `know' when they */
114 /*     are no longer in use by a segment; unused pages are deallocated */
115 /*     and returned to the free list. */
116 
117 /*     The parameters in this include file depend on the parameters */
118 /*     declared in the include file ekpage.inc.  If those parameters */
119 /*     change, this file must be updated.  The specified parameter */
120 /*     declarations we need from that file are: */
121 
122 /*        INTEGER               PGSIZC */
123 /*        PARAMETER           ( PGSIZC = 1024 ) */
124 
125 /*        INTEGER               PGSIZD */
126 /*        PARAMETER           ( PGSIZD = 128 ) */
127 
128 /*        INTEGER               PGSIZI */
129 /*        PARAMETER           ( PGSIZI = 256 ) */
130 
131 
132 
133 /*     Character pages use an encoding mechanism to represent integer */
134 /*     metadata.  Each integer is encoded in five consecutive */
135 /*     characters. */
136 
137 
138 /*     Character data page parameters: */
139 
140 
141 /*     Size of encoded integer: */
142 
143 
144 /*     Usable page size: */
145 
146 
147 /*     Location of character forward pointer: */
148 
149 
150 /*     Location of character link count: */
151 
152 
153 /*     Double precision data page parameters: */
154 
155 /*     Usable page size: */
156 
157 
158 /*     Location of d.p. forward pointer: */
159 
160 
161 /*     Location of d.p. link count: */
162 
163 
164 /*     Integer data page parameters: */
165 
166 /*     Usable page size: */
167 
168 
169 /*     Location of integer forward pointer: */
170 
171 
172 /*     Location of integer link count: */
173 
174 
175 /*     End Include Section:  EK Data Page Parameters */
176 
177 /* $ Disclaimer */
178 
179 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
180 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
181 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
182 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
183 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
184 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
185 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
186 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
187 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
188 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
189 
190 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
191 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
192 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
193 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
194 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
195 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
196 
197 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
198 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
199 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
200 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
201 
202 
203 /*     Include Section:  EK Das Paging Parameters */
204 
205 /*        ekpage.inc  Version 4    25-AUG-1995 (NJB) */
206 
207 
208 
209 /*     The EK DAS paging system makes use of the integer portion */
210 /*     of an EK file's DAS address space to store the few numbers */
211 /*     required to describe the system's state.  The allocation */
212 /*     of DAS integer addresses is shown below. */
213 
214 
215 /*                       DAS integer array */
216 
217 /*        +--------------------------------------------+ */
218 /*        |            EK architecture code            |  Address = 1 */
219 /*        +--------------------------------------------+ */
220 /*        |      Character page size (in DAS words)    | */
221 /*        +--------------------------------------------+ */
222 /*        |        Character page base address         | */
223 /*        +--------------------------------------------+ */
224 /*        |      Number of character pages in file     | */
225 /*        +--------------------------------------------+ */
226 /*        |   Number of character pages on free list   | */
227 /*        +--------------------------------------------+ */
228 /*        |      Character free list head pointer      |  Address = 6 */
229 /*        +--------------------------------------------+ */
230 /*        |                                            |  Addresses = */
231 /*        |           Metadata for d.p. pages          |    7--11 */
232 /*        |                                            | */
233 /*        +--------------------------------------------+ */
234 /*        |                                            |  Addresses = */
235 /*        |         Metadata for integer pages         |    12--16 */
236 /*        |                                            | */
237 /*        +--------------------------------------------+ */
238 /*                              . */
239 /*                              . */
240 /*                              . */
241 /*        +--------------------------------------------+ */
242 /*        |                                            |  End Address = */
243 /*        |                Unused space                |  integer page */
244 /*        |                                            |  end */
245 /*        +--------------------------------------------+ */
246 /*        |                                            |  Start Address = */
247 /*        |             First integer page             |  integer page */
248 /*        |                                            |  base */
249 /*        +--------------------------------------------+ */
250 /*                              . */
251 /*                              . */
252 /*                              . */
253 /*        +--------------------------------------------+ */
254 /*        |                                            | */
255 /*        |              Last integer page             | */
256 /*        |                                            | */
257 /*        +--------------------------------------------+ */
258 
259 /*     The following parameters indicate positions of elements in the */
260 /*     paging system metadata array: */
261 
262 
263 
264 /*     Number of metadata items per data type: */
265 
266 
267 /*     Character metadata indices: */
268 
269 
270 /*     Double precision metadata indices: */
271 
272 
273 /*     Integer metadata indices: */
274 
275 
276 /*     Size of metadata area: */
277 
278 
279 /*     Page sizes, in units of DAS words of the appropriate type: */
280 
281 
282 /*     Default page base addresses: */
283 
284 
285 /*     End Include Section:  EK Das Paging Parameters */
286 
287 /* $ Disclaimer */
288 
289 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
290 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
291 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
292 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
293 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
294 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
295 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
296 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
297 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
298 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
299 
300 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
301 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
302 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
303 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
304 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
305 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
306 
307 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
308 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
309 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
310 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
311 
312 
313 /*     Include Section:  EK Record Pointer Parameters */
314 
315 /*        ekrecptr.inc Version 2  18-JUL-1995 (NJB) */
316 
317 
318 /*     This file declares parameters used in EK record pointers. */
319 /*     Each segment references data in a given record via two levels */
320 /*     of indirection:  a record number points to a record pointer, */
321 /*     which is a structured array of metadata and data pointers. */
322 
323 /*     Record pointers always occupy contiguous ranges of integer */
324 /*     addresses. */
325 
326 /*     The parameter declarations in this file depend on the assumption */
327 /*     that integer pages contain 256 DAS integer words and that the */
328 /*     maximum number of columns in a segment is 100.  Record pointers */
329 /*     are stored in integer data pages, so they must fit within the */
330 /*     usable data area afforded by these pages.  The size of the usable */
331 /*     data area is given by the parameter IPSIZE which is declared in */
332 /*     ekdatpag.inc.  The assumed value of IPSIZE is 254. */
333 
334 
335 /*     The first element of each record pointer is a status indicator. */
336 /*     The meanings of status indicators depend on whether the parent EK */
337 /*     is shadowed or not.  For shadowed EKs, allowed status values and */
338 /*     their meanings are: */
339 
340 /*        OLD       The record has not been modified since */
341 /*                  the EK containing the record was opened. */
342 
343 /*        UPDATE    The record is an update of a previously existing */
344 /*                  record.  The original record is now on the */
345 /*                  modified record list. */
346 
347 /*        NEW       The record has been added since the EK containing the */
348 /*                  record was opened.  The record is not an update */
349 /*                  of a previously existing record. */
350 
351 /*        DELOLD    This status applies only to a backup record. */
352 /*                  DELOLD status indicates that the record corresponds */
353 /*                  to a deleted OLD record in the source segment. */
354 
355 /*        DELNEW    This status applies only to a backup record. */
356 /*                  DELNEW status indicates that the record corresponds */
357 /*                  to a deleted NEW record in the source segment. */
358 
359 /*        DELUPD    This status applies only to a backup record. */
360 /*                  DELUPD status indicates that the record corresponds */
361 /*                  to a deleted UPDATEd record in the source segment. */
362 
363 /*     In EKs that are not shadowed, all records have status OLD. */
364 
365 
366 
367 /*     The following parameters refer to indices within the record */
368 /*     pointer structure: */
369 
370 /*     Index of status indicator: */
371 
372 
373 /*     Each record pointer contains a pointer to its companion:  for a */
374 /*     record belonging to a shadowed EK, this is the backup counterpart, */
375 /*     or if the parent EK is itself a backup EK, a pointer to the */
376 /*     record's source record.  The pointer is UNINIT (see below) if the */
377 /*     record is unmodified. */
378 
379 /*     Record companion pointers contain record numbers, not record */
380 /*     base addresses. */
381 
382 /*     Index of record's companion pointer: */
383 
384 
385 /*     Each data item is referenced by an integer.  The meaning of */
386 /*     this integer depends on the representation of data in the */
387 /*     column to which the data item belongs.  Actual lookup of a */
388 /*     data item must be done by subroutines appropriate to the class of */
389 /*     the column to which the item belongs.  Note that data items don't */
390 /*     necessarily occupy contiguous ranges of DAS addresses. */
391 
392 /*     Base address of data pointers: */
393 
394 
395 /*     Maximum record pointer size: */
396 
397 
398 /*     Data pointers are given the value UNINIT to start with; this */
399 /*     indicates that the data item is uninitialized.  UNINIT is */
400 /*     distinct from the value NULL.  NOBACK indicates an uninitialized */
401 /*     backup column entry. */
402 
403 
404 /*     End Include Section:  EK Record Pointer Parameters */
405 
406 /* $ Disclaimer */
407 
408 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
409 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
410 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
411 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
412 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
413 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
414 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
415 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
416 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
417 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
418 
419 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
420 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
421 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
422 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
423 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
424 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
425 
426 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
427 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
428 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
429 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
430 
431 
432 /*     Include Section:  EK Segment Descriptor Parameters */
433 
434 /*        eksegdsc.inc  Version 8  06-NOV-1995 (NJB) */
435 
436 
437 /*     All `base addresses' referred to below are the addresses */
438 /*     *preceding* the item the base applies to.  This convention */
439 /*     enables simplied address calculations in many cases. */
440 
441 /*     Size of segment descriptor.  Note:  the include file ekcoldsc.inc */
442 /*     must be updated if this parameter is changed.  The parameter */
443 /*     CDOFF in that file should be kept equal to SDSCSZ. */
444 
445 
446 /*     Index of the segment type code: */
447 
448 
449 /*     Index of the segment's number.  This number is the segment's */
450 /*     index in the list of segments contained in the EK to which */
451 /*     the segment belongs. */
452 
453 
454 /*     Index of the DAS integer base address of the segment's integer */
455 /*     meta-data: */
456 
457 
458 /*     Index of the DAS character base address of the table name: */
459 
460 
461 /*     Index of the segment's column count: */
462 
463 
464 /*     Index of the segment's record count: */
465 
466 
467 /*     Index of the root page number of the record tree: */
468 
469 
470 /*     Index of the root page number of the character data page tree: */
471 
472 
473 /*     Index of the root page number of the double precision data page */
474 /*     tree: */
475 
476 
477 /*     Index of the root page number of the integer data page tree: */
478 
479 
480 /*     Index of the `modified' flag: */
481 
482 
483 /*     Index of the `initialized' flag: */
484 
485 
486 /*     Index of the shadowing flag: */
487 
488 
489 /*     Index of the companion file handle: */
490 
491 
492 /*     Index of the companion segment number: */
493 
494 
495 /*     The next three items are, respectively, the page numbers of the */
496 /*     last character, d.p., and integer data pages allocated by the */
497 /*     segment: */
498 
499 
500 /*     The next three items are, respectively, the page-relative */
501 /*     indices of the last DAS word in use in the segment's */
502 /*     last character, d.p., and integer data pages: */
503 
504 
505 /*     Index of the DAS character base address of the column name list: */
506 
507 
508 /*     The last descriptor element is reserved for future use.  No */
509 /*     parameter is defined to point to this location. */
510 
511 
512 /*     End Include Section:  EK Segment Descriptor Parameters */
513 
514 /* $ Disclaimer */
515 
516 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
517 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
518 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
519 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
520 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
521 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
522 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
523 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
524 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
525 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
526 
527 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
528 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
529 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
530 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
531 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
532 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
533 
534 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
535 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
536 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
537 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
538 
539 
540 /*     Include Section:  EK Data Types */
541 
542 /*        ektype.inc Version 1  27-DEC-1994 (NJB) */
543 
544 
545 /*     Within the EK system, data types of EK column contents are */
546 /*     represented by integer codes.  The codes and their meanings */
547 /*     are listed below. */
548 
549 /*     Integer codes are also used within the DAS system to indicate */
550 /*     data types; the EK system makes no assumptions about compatibility */
551 /*     between the codes used here and those used in the DAS system. */
552 
553 
554 /*     Character type: */
555 
556 
557 /*     Double precision type: */
558 
559 
560 /*     Integer type: */
561 
562 
563 /*     `Time' type: */
564 
565 /*     Within the EK system, time values are represented as ephemeris */
566 /*     seconds past J2000 (TDB), and double precision numbers are used */
567 /*     to store these values.  However, since time values require special */
568 /*     treatment both on input and output, and since the `TIME' column */
569 /*     has a special role in the EK specification and code, time values */
570 /*     are identified as a type distinct from double precision numbers. */
571 
572 
573 /*     End Include Section:  EK Data Types */
574 
575 /* $ Brief_I/O */
576 
577 /*     Variable  I/O  Description */
578 /*     --------  ---  -------------------------------------------------- */
579 /*     HANDLE     I   File handle. */
580 /*     SEGNO      I   Segment number. */
581 /*     RECNO      O   Number of appended record. */
582 
583 /* $ Detailed_Input */
584 
585 /*     HANDLE         is a file handle of an EK open for write access. */
586 
587 /*     SEGNO          is the number of the segment to which the record */
588 /*                    is to be added. */
589 
590 /* $ Detailed_Output */
591 
592 /*     RECNO          is the number of the record appended by this */
593 /*                    routine.  RECNO is used to identify the record */
594 /*                    when writing column entries to it. */
595 
596 /* $ Parameters */
597 
598 /*     None. */
599 
600 /* $ Exceptions */
601 
602 /*     1)  If HANDLE is invalid, the error will be diagnosed by routines */
603 /*         called by this routine.  The file will not be modified. */
604 
605 /*     2)  If SEGNO is out of range, the error SPICE(INVALIDINDEX) */
606 /*         will be signalled.  The file will not be modified. */
607 
608 /*     3)  If an I/O error occurs while reading or writing the indicated */
609 /*         file, the error will be diagnosed by routines called by this */
610 /*         routine.  The file may be corrupted. */
611 
612 /* $ Files */
613 
614 /*     See the EK Required Reading for a discussion of the EK file */
615 /*     format. */
616 
617 /* $ Particulars */
618 
619 /*     This routine operates by side effects:  It appends a new, empty */
620 /*     record structure to an EK segment.  The ordinal position of the */
621 /*     new record is one greater than the previous number of records in */
622 /*     in the segment. */
623 
624 /*     After a new record has been appended to a segment by this routine, */
625 /*     the record must be populated with data using the EKACEx */
626 /*     routines.  EKs are valid only when all of their column entries */
627 /*     are initialized. */
628 
629 /*     To insert a record into a segment at a specified ordinal position, */
630 /*     use the routine EKAPPR. */
631 
632 /*     This routine cannot be used with the "fast write" suite of */
633 /*     routines.  See the EK Required Reading for a discussion of the */
634 /*     fast writers. */
635 
636 /*     When a record is inserted into an EK file that is not shadowed, */
637 /*     the status of the record starts out set to OLD.  The status */
638 /*     does not change when data is added to the record. */
639 
640 /*     If the target EK is shadowed, the new record will be given the */
641 /*     status NEW.  Updating column values in the record does not change */
642 /*     its status.  When changes are committed, the status is set to OLD. */
643 /*     If a rollback is performed before changes are committed, the */
644 /*     record is deleted.  Closing the target file without committing */
645 /*     changes implies a rollback. */
646 
647 /* $ Examples */
648 
649 /*     1)  Append a record to a specified segment. */
650 
651 /*         Suppose we have an E-kernel named ORDER_DB.EK which contains */
652 /*         records of orders for data products.  The E-kernel has a */
653 /*         table called DATAORDERS that consists of the set of columns */
654 /*         listed below: */
655 
656 /*            DATAORDERS */
657 
658 /*               Column Name     Data Type */
659 /*               -----------     --------- */
660 /*               ORDER_ID        INTEGER */
661 /*               CUSTOMER_ID     INTEGER */
662 /*               LAST_NAME       CHARACTER*(*) */
663 /*               FIRST_NAME      CHARACTER*(*) */
664 /*               ORDER_DATE      TIME */
665 /*               COST            DOUBLE PRECISION */
666 
667 /*         The order database also has a table of items that have been */
668 /*         ordered.  The columns of this table are shown below: */
669 
670 /*            DATAITEMS */
671 
672 /*               Column Name     Data Type */
673 /*               -----------     --------- */
674 /*               ITEM_ID         INTEGER */
675 /*               ORDER_ID        INTEGER */
676 /*               ITEM_NAME       CHARACTER*(*) */
677 /*               DESCRIPTION     CHARACTER*(*) */
678 /*               PRICE           DOUBLE PRECISION */
679 
680 
681 /*         We'll suppose that the file ORDER_DB.EK contains two segments, */
682 /*         the first containing the DATAORDERS table and the second */
683 /*         containing the DATAITEMS table. */
684 
685 /*         If we wanted to insert a new record into the DATAORDERS */
686 /*         table in position 1, we'd make the following calls: */
687 
688 /*            C */
689 /*            C     Open the database for write access.  This call is */
690 /*            C     made when the file already exists.  See EKOPN for */
691 /*            C     an example of creating a new file. */
692 /*            C */
693 /*                  CALL EKOPW ( 'ORDER_DB.EK', HANDLE ) */
694 
695 /*            C */
696 /*            C     Append a new, empty record to the DATAORDERS */
697 /*            C     table. Recall that the DATAORDERS table */
698 /*            C     is in segment number 1.  The call will return */
699 /*            C     the number of the new, empty record. */
700 /*            C */
701 /*                  CALL EKAPPR ( HANDLE, 1, RECNO ) */
702 
703 /*            C */
704 /*            C     At this point, the new record is empty.  A valid EK */
705 /*            C     cannot contain empty records.  We fill in the data */
706 /*            C     here.  Data items are filled in one column at a time. */
707 /*            C     The order in which the columns are filled in is not */
708 /*            C     important.  We use the EKACEx (add column entry) */
709 /*            C     routines to fill in column entries.  We'll assume */
710 /*            C     that no entries are null.  All entries are scalar, */
711 /*            C     so the entry size is 1. */
712 /*            C */
713 /*                  ISNULL   =  .FALSE. */
714 /*                  ESIZE    =  1 */
715 
716 /*            C */
717 /*            C     The following variables will contain the data for */
718 /*            C     the new record. */
719 /*            C */
720 /*                  ORDID    =   10011 */
721 /*                  CUSTID   =   531 */
722 /*                  LNAME    =   'Scientist' */
723 /*                  FNAME    =   'Joe' */
724 /*                  ODATE    =   '1995-SEP-20' */
725 /*                  COST     =   0.D0 */
726 
727 /*            C */
728 /*            C     Note that the names of the routines called */
729 /*            C     correspond to the data types of the columns:  the */
730 /*            C     last letter of the routine name is C, I, or D, */
731 /*            C     depending on the data type.  Time values are */
732 /*            C     converted to ET for storage. */
733 /*            C */
734 /*                  CALL EKACEI ( HANDLE, SEGNO,  RECNO, 'ORDER_ID', */
735 /*                 .              SIZE,   ORDID,  ISNULL               ) */
736 
737 /*                  CALL EKACEI ( HANDLE, SEGNO,  RECNO, 'CUSTOMER_ID', */
738 /*                 .              SIZE,   CUSTID, ISNULL               ) */
739 
740 /*                  CALL EKACEC ( HANDLE, SEGNO,  RECNO, 'LAST_NAME', */
741 /*                 .              SIZE,   LNAME,  ISNULL               ) */
742 
743 /*                  CALL EKACEC ( HANDLE, SEGNO,  RECNO, 'FIRST_NAME', */
744 /*                 .              SIZE,   FNAME,  ISNULL               ) */
745 
746 
747 /*                  CALL UTC2ET ( ODATE,  ET ) */
748 /*                  CALL EKACED ( HANDLE, SEGNO,  RECNO, 'ORDER_DATE', */
749 /*                 .              SIZE,   ET,     ISNULL               ) */
750 
751 /*                  CALL EKACED ( HANDLE, SEGNO,  RECNO, 'COST', */
752 /*                 .              SIZE,   COST,   ISNULL               ) */
753 
754 /*            C */
755 /*            C     Close the file to make the update permanent. */
756 /*            C */
757 /*                  CALL EKCLS ( HANDLE ) */
758 
759 
760 /* $ Restrictions */
761 
762 /*     None. */
763 
764 /* $ Literature_References */
765 
766 /*     None. */
767 
768 /* $ Author_and_Institution */
769 
770 /*     N.J. Bachman   (JPL) */
771 
772 /* $ Version */
773 
774 /* -    SPICELIB Version 1.0.1, 09-JAN-2002 (NJB) */
775 
776 /*        Documentation change:  instances of the phrase "fast load" */
777 /*        were replaced with "fast write." */
778 
779 /* -    Beta Version 1.0.0, 19-DEC-1995 (NJB) */
780 
781 /* -& */
782 /* $ Index_Entries */
783 
784 /*     append record to EK segment */
785 
786 /* -& */
787 
788 /*     SPICELIB functions */
789 
790 
791 /*     Local variables */
792 
793 
794 /*     Standard SPICE error handling. */
795 
796     if (return_()) {
797 	return 0;
798     } else {
799 	chkin_("EKAPPR", (ftnlen)6);
800     }
801 
802 /*     Before trying to actually write anything, do every error */
803 /*     check we can. */
804 
805 /*     Is this file handle valid--is the file open for paged write */
806 /*     access?  Signal an error if not. */
807 
808     zzekpgch_(handle, "WRITE", (ftnlen)5);
809     if (failed_()) {
810 	chkout_("EKAPPR", (ftnlen)6);
811 	return 0;
812     }
813 
814 /*     Look up the integer metadata page and page base for the segment. */
815 /*     Given the base address, we can read the pertinent metadata in */
816 /*     one shot. */
817 
818     zzekmloc_(handle, segno, &mp, &mbase);
819     if (failed_()) {
820 	chkout_("EKAPPR", (ftnlen)6);
821 	return 0;
822     }
823     i__1 = mbase + 1;
824     i__2 = mbase + 24;
825     dasrdi_(handle, &i__1, &i__2, segdsc);
826 
827 /*     Obtain the number of records already present. */
828 
829     nrec = segdsc[5];
830 
831 /*     Insert the new record at the end of the segment. */
832 
833     *recno = nrec + 1;
834     ekinsr_(handle, segno, recno);
835     chkout_("EKAPPR", (ftnlen)6);
836     return 0;
837 } /* ekappr_ */
838 
839