1 /* dasacu.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__22 = 22;
11 static integer c__1 = 1;
12
13 /* $Procedure DASACU ( DAS add comments from a logical unit ) */
dasacu_(integer * comlun,char * begmrk,char * endmrk,logical * insbln,integer * handle,ftnlen begmrk_len,ftnlen endmrk_len)14 /* Subroutine */ int dasacu_(integer *comlun, char *begmrk, char *endmrk,
15 logical *insbln, integer *handle, ftnlen begmrk_len, ftnlen
16 endmrk_len)
17 {
18 /* System generated locals */
19 integer i__1, i__2, i__3;
20 olist o__1;
21 cllist cl__1;
22 alist al__1;
23
24 /* Builtin functions */
25 integer f_open(olist *);
26 /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen);
27 integer s_cmp(char *, char *, ftnlen, ftnlen), f_clos(cllist *), s_rnge(
28 char *, integer, char *, integer), f_rew(alist *);
29
30 /* Local variables */
31 char line[255];
32 logical more;
33 integer i__, j;
34 extern /* Subroutine */ int dasac_(integer *, integer *, char *, ftnlen),
35 chkin_(char *, ftnlen);
36 integer ncomc;
37 extern /* Subroutine */ int errch_(char *, char *, ftnlen, ftnlen);
38 integer ncomr;
39 extern /* Subroutine */ int ljust_(char *, char *, ftnlen, ftnlen);
40 extern logical failed_(void);
41 extern /* Subroutine */ int readla_(integer *, integer *, integer *, char
42 *, logical *, ftnlen);
43 char ifname[60];
44 extern /* Subroutine */ int readln_(integer *, char *, logical *, ftnlen);
45 char combuf[255*22];
46 extern /* Subroutine */ int dassih_(integer *, char *, ftnlen);
47 extern integer lastnb_(char *, ftnlen);
48 integer length, intchr;
49 char idword[8];
50 extern /* Subroutine */ int dasrfr_(integer *, char *, char *, integer *,
51 integer *, integer *, integer *, ftnlen, ftnlen), errfnm_(char *,
52 integer *, ftnlen), sigerr_(char *, ftnlen);
53 integer numcom;
54 extern /* Subroutine */ int chkout_(char *, ftnlen);
55 integer nresvc;
56 extern /* Subroutine */ int getlun_(integer *);
57 integer iostat;
58 extern /* Subroutine */ int setmsg_(char *, ftnlen), errint_(char *,
59 integer *, ftnlen);
60 integer scrlun;
61 extern /* Subroutine */ int writla_(integer *, char *, integer *, ftnlen);
62 extern logical return_(void);
63 integer nresvr;
64 logical eof;
65
66 /* $ Abstract */
67
68 /* Add comments to a previously opened binary DAS file from a */
69 /* previously opened text file attached to a Fortran logical unit. */
70
71 /* $ Disclaimer */
72
73 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
74 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
75 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
76 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
77 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
78 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
79 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
80 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
81 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
82 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
83
84 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
85 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
86 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
87 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
88 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
89 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
90
91 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
92 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
93 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
94 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
95
96 /* $ Required_Reading */
97
98 /* None. */
99
100 /* $ Keywords */
101
102 /* None. */
103
104 /* $ Declarations */
105 /* $ Brief_I/O */
106
107 /* Variable I/O Description */
108 /* -------- --- -------------------------------------------------- */
109 /* COMLUN I Logical unit of the open comment text file. */
110 /* BEGMRK I The begin comments marker in the comment text file. */
111 /* ENDMRK I The end comments marker in the comment text file. */
112 /* INSBLN I A flag indicating whether to insert a blank line. */
113 /* HANDLE I Handle of a DAS file opened with write access. */
114 /* LNSIZE P Maximum length of comment line. */
115
116 /* $ Detailed_Input */
117
118 /* COMLUN The Fortran logical unit of a previously opened text */
119 /* file which contains comments that are to be added to */
120 /* the comment area of a binary E-Kernel file. */
121
122 /* BEGMRK A marker which identifies the beginning of the comments */
123 /* in the comment text file. This marker must appear on a */
124 /* line by itself, and leading and trailing blanks are not */
125 /* significant. */
126
127 /* The line immediately following this marker is the first */
128 /* comment line to be placed into the comment area of the */
129 /* binary DAS file. */
130
131 /* If the begin marker is blank, BEGMRK .EQ. ' ', then the */
132 /* comments are assumed to start at the current location */
133 /* in the comment text file. */
134
135 /* ENDMRK A marker which identifies the end of the comments in the */
136 /* comment text file. This marker must appear on a line by */
137 /* itself, and leading and trailing blanks are not */
138 /* significant. */
139
140 /* The line immediately preceding this marker is the last */
141 /* comment line to be placed into the comment area of the */
142 /* binary DAS file. */
143
144 /* If the end marker is blank, ENDMRK .EQ. ' ', then the */
145 /* comments are assumed to stop at the end of the comment */
146 /* text file. */
147
148 /* INSBLN A logical flag which indicates whether a blank line is */
149 /* to be inserted into the comment area of the binary DAS */
150 /* file attached to HANDLE before any comments are added */
151 /* to the comment area of the DAS file. This is to provide */
152 /* a simple mechanism for separating any comments already */
153 /* contained in the comment area of a DAS file from those */
154 /* comments that are being added. */
155
156 /* If the comment area of a binary DAS file is empty, the */
157 /* value of this flag is not significant, the comments will */
158 /* simply be placed into the comment area. */
159
160 /* HANDLE The file handle for a binary DAS file that has been */
161 /* opened with write access. */
162
163 /* $ Detailed_Output */
164
165 /* None. */
166
167 /* $ Parameters */
168
169 /* LNSIZE is both the maximum length of a comment line that can */
170 /* be read from the input file, and the maximum length */
171 /* of a comment line that this routine can write to the */
172 /* output DAS file. */
173
174 /* LNSIZE is set to 255 characters. */
175
176 /* The DAS file format itself does not impose a limit */
177 /* on the length of lines in comment area, other than */
178 /* that the character count must be expressible in a */
179 /* 32-bit signed integer. */
180
181 /* $ Exceptions */
182
183 /* 1) If the scratch file for temporarily holding the comments */
184 /* culled from the text file cannot be opened, then the */
185 /* error SPICE(FILEOPENFAILED) will be signaled. */
186
187 /* 2) If a non printing ASCII character is encountered in the */
188 /* comments, the error SPICE(ILLEGALCHARACTER) will be */
189 /* signaled. */
190
191 /* 3) If the begin marker cannot be found in the text file, the */
192 /* error SPICE(MARKERNOTFOUND) will be signaled. */
193
194 /* 4) If the end marker cannot be found in the text file, the */
195 /* error SPICE(MARKERNOTFOUND) will be signaled. */
196
197 /* $ Files */
198
199 /* 1) See parameters COMLUN and HANDLE in the $ Detailed_Inputs */
200 /* section. */
201
202 /* 2) A scratch file is used to temporarily hold the comments */
203 /* culled from the comment text file. This is so we do not */
204 /* have to find the place where we started searching for */
205 /* comments in the original file. */
206
207 /* $ Particulars */
208
209 /* This routine will place all lines between two specified markers, */
210 /* a `begin comments marker' and an `end comments marker,' in a */
211 /* text file into the comment area of a binary DAS file attached to */
212 /* HANDLE. If the `begin comments marker' is blank, then the */
213 /* comments are assumed to start at the current location of the */
214 /* comment text file attached to COMLUN. If the `end comments */
215 /* marker' is blank, then the comments are assumed to stop at the */
216 /* end of the comment text file attached to COMLUN. */
217
218 /* $ Examples */
219
220 /* We will be using the files `jabber.txt', 'batty.txt', and */
221 /* `wndrland.das' in the example which follows. */
222
223 /* `wndrland.das' is a binary DAS file with an empty comment area */
224 /* into which we are going to place the entire file */
225 /* `jabber.txt' and a selected portion of the file */
226 /* `batty.txt'. */
227
228 /* `jabber.txt' is a text file that is to be placed into the */
229 /* comment area of the binary DAS file `wndrland.das'. */
230
231 /* `batty.txt' is a text file from which will have a selected */
232 /* portion of its text placed into the comment area */
233 /* of the binary DAS file `wndrland.das'. */
234
235 /* Let -BOF- and -EOF- denote the beginning and end of a file, */
236 /* respectively. */
237
238 /* The file `jabber.txt' contains: */
239
240 /* -BOF- */
241 /* The Jabberwock */
242
243 /* 'Twas brillig, and the slithy toves */
244 /* Did gyre and gimble in the wabe; */
245 /* All mimsy were the borogoves, */
246 /* And the mome raths outgrabe. */
247
248 /* ``Beware the Jabberwock, my son! */
249 /* The jaws that bite, the claws that catch!'' */
250
251 /* And as in uffish thought he stood, */
252 /* The Jabberwock, with eyes of flame, */
253 /* Came whiffling through the tulgey wood, */
254 /* And burbled as it came! */
255
256 /* One, two! One, two! And through and through */
257 /* The vorpal blade went snicker-snack! */
258 /* He left it dead, and with its head */
259 /* He went galumphing back. */
260
261 /* ``And hast thou slain the Jabberwock? */
262 /* Come to my arms, my beamish boy! */
263 /* O frabjous day! Callooh! Callay!'' */
264 /* He chortled in his joy. */
265
266 /* Through the Looking-Glass */
267 /* Lewis Carroll */
268 /* -EOF- */
269
270 /* The file `batty.txt' contains: */
271
272 /* -BOF- */
273 /* This file contains a brief poem about bats. */
274
275 /* BEGIN bat poem */
276 /* Twinkle, twinkle, little bat! */
277 /* How I wonder what you're at! */
278 /* Up above the world you fly! */
279 /* Like a teatray in the sky. */
280
281 /* Alice's Adventures in Wonderland */
282 /* Lewis Carroll */
283 /* END bat poem */
284
285 /* And that's that for bats. */
286 /* -EOF- */
287
288 /* Let */
289
290 /* JABLUN be the logical unit for the file `jabber.txt' */
291 /* BATLUN be the logical unit for the file `batty.txt' */
292 /* and */
293 /* HANDLE be the DAS handle for the file `wndrland.das' */
294
295 /* The code fragment */
296
297 /* C */
298 /* C Open the files. */
299 /* C */
300 /* CALL DASOPW ( `wndrland.das', HANDLE ) */
301 /* CALL TXTOPN ( `jabber.txt' , JABLUN ) */
302 /* CALL TXTOPN ( `batty.txt' , BATLUN ) */
303 /* C */
304 /* C Initialize the markers for the file `jabber.txt'. We want */
305 /* C to include the entire file, so both markers are blank. */
306 /* C */
307 /* BEGMRK = ' ' */
308 /* ENDMRK = ' ' */
309 /* INSBLN = .TRUE. */
310 /* C */
311 /* C Add the comments from the file 'jabber.txt' */
312 /* C */
313 /* CALL DASACU ( JABLUN, BEGMRK, ENDMRK, INSBLN, HANDLE ) */
314 /* C */
315 /* C Initialize the markers for the file `batty.txt'. We want */
316 /* C to include the bat poem only, so we define the begin and */
317 /* C end marker accordingly. */
318 /* C */
319 /* BEGMRK = 'BEGIN bat poem' */
320 /* ENDMRK = 'END bat poem' */
321 /* INSBLN = .TRUE. */
322 /* C */
323 /* C Add the comments from the file 'batty.txt' */
324 /* C */
325 /* CALL DASACU ( BATLUN, BEGMRK, ENDMRK, INSBLN, HANDLE ) */
326 /* C */
327 /* C Close the files. */
328
329 /* CLOSE ( JABLUN ) */
330 /* CLOSE ( BATLUN ) */
331 /* CALL DASCLS ( HANDLE ) */
332
333 /* will create a comment area in `wndrland.das' which contains: */
334
335 /* -BOC- */
336 /* The Jabberwock */
337
338 /* 'Twas brillig, and the slithy toves */
339 /* Did gyre and gimble in the wabe; */
340 /* All mimsy were the borogoves, */
341 /* And the mome raths outgrabe. */
342
343 /* ``Beware the Jabberwock, my son! */
344 /* The jaws that bite, the claws that catch!'' */
345
346 /* And as in uffish thought he stood, */
347 /* The Jabberwock, with eyes of flame, */
348 /* Came whiffling through the tulgey wood, */
349 /* And burbled as it came! */
350
351 /* One, two! One, two! And through and through */
352 /* The vorpal blade went snicker-snack! */
353 /* He left it dead, and with its head */
354 /* He went galumphing back. */
355
356 /* ``And hast thou slain the Jabberwock? */
357 /* Come to my arms, my beamish boy! */
358 /* O frabjous day! Callooh! Callay!'' */
359 /* He chortled in his joy. */
360
361 /* Through the Looking-Glass */
362 /* Lewis Carroll */
363
364 /* Twinkle, twinkle, little bat! */
365 /* How I wonder what you're at! */
366 /* Up above the world you fly! */
367 /* Like a teatray in the sky. */
368
369 /* Alice's Adventures in Wonderland */
370 /* Lewis Carroll */
371 /* -EOC- */
372
373 /* where -BOC- and -EOC- represent the beginning and end of the */
374 /* comments, respectively. */
375
376 /* $ Restrictions */
377
378 /* 1) The begin comments marker, BEGMRK, and the end comments */
379 /* marker, ENDMRK, must each appear alone on a line in the */
380 /* comment text file if they are not blank. */
381
382 /* 2) The maximum length of a text line in the input comment file */
383 /* is specified by the LINLEN parameter defined below. Currently */
384 /* this value is 255 characters. */
385
386 /* 3) The maximum length of a single comment line that can be */
387 /* written by this routine to the output DAS file's comment area */
388 /* is specified by the parameter LINLEN defined below. Currently */
389 /* this value is 255 characters. */
390
391 /* 4) This routine uses constants that are specific to the ASCII */
392 /* character sequence. The results of using this routine with a */
393 /* different character sequence are unpredictable. */
394
395 /* $ Literature_References */
396
397 /* None. */
398
399 /* $ Author_and_Institution */
400
401 /* K.R. Gehringer (JPL) */
402
403 /* $ Version */
404
405 /* - SPICELIB 1.2.1, 15-MAR-2017 (NJB) */
406
407 /* Added description of parameter LNSIZE. Fixed typos */
408 /* throughout the comments. */
409
410 /* - SPICELIB 1.2.0, 07-JUL-1996 (NJB) */
411
412 /* Removed declaration, DATA and SAVE statements for unused */
413 /* variable FIRST. */
414
415 /* - Beta Version 1.1.0, 20-SEP-1995 (KRG) */
416
417 /* Added a check of FAILED after the call to GETLUN to trap */
418 /* an error, if one is signaled by GETLUN, before attempting to */
419 /* open the SCRATCH file. */
420
421 /* - Beta Version 1.0.0, 4-JAN-1993 (KRG) */
422
423 /* -& */
424 /* $ Index_Entries */
425
426 /* add comments from a logical unit to a das file */
427
428 /* -& */
429 /* $ Revisions */
430
431
432 /* - SPICELIB 1.2.0, 07-JUL-1996 (NJB) */
433
434 /* Removed declaration, DATA and SAVE statements for unused */
435 /* variable FIRST. */
436
437 /* - Beta Version 1.1.0, 20-SEP-1995 (KRG) */
438
439 /* Added a check of FAILED after the call to GETLUN to trap */
440 /* an error, if one is signaled by GETLUN, before attempting to */
441 /* open the SCRATCH file. */
442
443 /* -& */
444
445 /* SPICELIB functions */
446
447
448 /* Local parameters */
449
450 /* Set the value for the maximum length of a text line. */
451
452
453 /* Set the length of a DAS file ID word. */
454
455
456 /* Set the length of a DAS file internal filename. */
457
458
459 /* Set the size of the comment buffer. */
460
461
462 /* Maximum and minimum decimal values for the printable ASCII */
463 /* characters. */
464
465
466 /* Local variables */
467
468
469 /* Standard SPICE error handling. */
470
471 if (return_()) {
472 return 0;
473 } else {
474 chkin_("DASACU", (ftnlen)6);
475 }
476
477 /* Verify that the DAS file attached to HANDLE is opened with write */
478 /* access. */
479
480 dassih_(handle, "WRITE", (ftnlen)5);
481 if (failed_()) {
482 chkout_("DASACU", (ftnlen)6);
483 return 0;
484 }
485
486 /* Get the number of comment characters, and some other stuff that */
487 /* we will not be using. */
488
489 dasrfr_(handle, idword, ifname, &nresvr, &nresvc, &ncomr, &ncomc, (ftnlen)
490 8, (ftnlen)60);
491 if (failed_()) {
492 chkout_("DASACU", (ftnlen)6);
493 return 0;
494 }
495
496 /* Get an available logical unit for the comment scratch file. */
497
498 getlun_(&scrlun);
499 if (failed_()) {
500 chkout_("DASACU", (ftnlen)6);
501 return 0;
502 }
503
504 /* Attempt to open the comment scratch file. */
505
506 o__1.oerr = 1;
507 o__1.ounit = scrlun;
508 o__1.ofnm = 0;
509 o__1.orl = 0;
510 o__1.osta = "SCRATCH";
511 o__1.oacc = 0;
512 o__1.ofm = 0;
513 o__1.oblnk = 0;
514 iostat = f_open(&o__1);
515 if (iostat != 0) {
516 setmsg_("Attempt to open a temporary file failed. IOSTAT = #.", (
517 ftnlen)52);
518 errint_("#", &iostat, (ftnlen)1);
519 sigerr_("SPICE(FILEOPENFAILED)", (ftnlen)21);
520 chkout_("DASACU", (ftnlen)6);
521 return 0;
522 }
523
524 /* Start looking for the begin comment marker. If the begin marker */
525 /* is a blank line, then the comments begin on the first line of the */
526 /* comment file. Otherwise, the comments begin on the line */
527 /* immediately following the line which contains the begin comments */
528 /* marker. */
529
530 s_copy(line, " ", (ftnlen)255, (ftnlen)1);
531 eof = FALSE_;
532 while(s_cmp(line, begmrk, (ftnlen)255, begmrk_len) != 0) {
533 readln_(comlun, line, &eof, (ftnlen)255);
534 ljust_(line, line, (ftnlen)255, (ftnlen)255);
535 if (failed_()) {
536 cl__1.cerr = 0;
537 cl__1.cunit = scrlun;
538 cl__1.csta = 0;
539 f_clos(&cl__1);
540 chkout_("DASACU", (ftnlen)6);
541 return 0;
542 }
543
544 /* If we have encountered the end of file here, we have a */
545 /* problem: We did not find the begin comments marker in the */
546 /* text file. So, set an appropriate error message and signal */
547 /* the error. don't forget to close the scratch file. */
548
549 if (eof) {
550 cl__1.cerr = 0;
551 cl__1.cunit = scrlun;
552 cl__1.csta = 0;
553 f_clos(&cl__1);
554 setmsg_("The begin comments marker '#' was not found in the comm"
555 "ent file '#'.", (ftnlen)68);
556 errch_("#", begmrk, (ftnlen)1, begmrk_len);
557 errfnm_("#", comlun, (ftnlen)1);
558 sigerr_("SPICE(MARKERNOTFOUND)", (ftnlen)21);
559 chkout_("DASACU", (ftnlen)6);
560 return 0;
561 }
562 }
563
564 /* Begin reading in the comment lines from the comment file, */
565 /* placing them a buffer at a time into the temporary file. */
566 /* We also scan each line for non printing characters. */
567
568 s_copy(line, " ", (ftnlen)255, (ftnlen)1);
569 if (s_cmp(endmrk, " ", endmrk_len, (ftnlen)1) == 0) {
570
571 /* If the end mark is blank, then we want to go until we hit the */
572 /* end of the comment file. */
573
574 while(! eof) {
575 numcom = 0;
576 readla_(comlun, &c__22, &numcom, combuf, &eof, (ftnlen)255);
577 if (failed_()) {
578 cl__1.cerr = 0;
579 cl__1.cunit = scrlun;
580 cl__1.csta = 0;
581 f_clos(&cl__1);
582 chkout_("DASACU", (ftnlen)6);
583 return 0;
584 }
585
586 /* If we got some comments, we need to scan them for non */
587 /* printing characters. */
588
589 if (numcom > 0) {
590 i__1 = numcom;
591 for (i__ = 1; i__ <= i__1; ++i__) {
592 length = lastnb_(combuf + ((i__2 = i__ - 1) < 22 && 0 <=
593 i__2 ? i__2 : s_rnge("combuf", i__2, "dasacu_", (
594 ftnlen)587)) * 255, (ftnlen)255);
595
596 /* Scan the comment line for non printing characters. */
597
598 i__2 = length;
599 for (j = 1; j <= i__2; ++j) {
600
601 /* Check to see that the characters in the buffer */
602 /* are all printing ASCII characters. The bounds */
603 /* for printing ASCII characters are given by */
604 /* MAXPCH and MINPCH, which are defined in the */
605 /* $ Local Parameters section of the header. */
606
607 intchr = *(unsigned char *)&combuf[((i__3 = i__ - 1) <
608 22 && 0 <= i__3 ? i__3 : s_rnge("combuf",
609 i__3, "dasacu_", (ftnlen)599)) * 255 + (j - 1)
610 ];
611 if (intchr > 126 || intchr < 32) {
612 cl__1.cerr = 0;
613 cl__1.cunit = scrlun;
614 cl__1.csta = 0;
615 f_clos(&cl__1);
616 setmsg_("A nonprinting character was encountered"
617 " in the comments. Value: #", (ftnlen)65);
618 errint_("#", &intchr, (ftnlen)1);
619 sigerr_("SPICE(ILLEGALCHARACTER)", (ftnlen)23);
620 chkout_("DASACU", (ftnlen)6);
621 return 0;
622 }
623 }
624 }
625
626 /* Write the comments to the temporary file. */
627
628 writla_(&numcom, combuf, &scrlun, (ftnlen)255);
629 }
630 if (failed_()) {
631 cl__1.cerr = 0;
632 cl__1.cunit = scrlun;
633 cl__1.csta = 0;
634 f_clos(&cl__1);
635 chkout_("DASACU", (ftnlen)6);
636 return 0;
637 }
638 }
639 } else {
640
641 /* The endmark is non blank, then we want to go until we find a */
642 /* line in the comment file that matches the end mark that was */
643 /* entered. */
644
645 more = TRUE_;
646 while(more) {
647 numcom = 0;
648 readla_(comlun, &c__22, &numcom, combuf, &eof, (ftnlen)255);
649 if (failed_()) {
650 cl__1.cerr = 0;
651 cl__1.cunit = scrlun;
652 cl__1.csta = 0;
653 f_clos(&cl__1);
654 chkout_("DASACU", (ftnlen)6);
655 return 0;
656 }
657
658 /* Look for ENDMRK in the current buffer if we got some */
659 /* comments. */
660
661 if (numcom > 0) {
662 i__ = 1;
663 while(more && i__ <= numcom) {
664 s_copy(line, combuf + ((i__1 = i__ - 1) < 22 && 0 <= i__1
665 ? i__1 : s_rnge("combuf", i__1, "dasacu_", (
666 ftnlen)662)) * 255, (ftnlen)255, (ftnlen)255);
667 ljust_(line, line, (ftnlen)255, (ftnlen)255);
668 if (s_cmp(line, endmrk, (ftnlen)255, endmrk_len) == 0) {
669 more = FALSE_;
670 numcom = i__ - 1;
671 } else {
672 ++i__;
673 }
674 }
675 }
676
677 /* If we still have some comments, we need to scan them for */
678 /* non printing characters. */
679
680 if (numcom > 0) {
681 i__1 = numcom;
682 for (i__ = 1; i__ <= i__1; ++i__) {
683 length = lastnb_(combuf + ((i__2 = i__ - 1) < 22 && 0 <=
684 i__2 ? i__2 : s_rnge("combuf", i__2, "dasacu_", (
685 ftnlen)687)) * 255, (ftnlen)255);
686
687 /* Scan the comment line for non printinig characters. */
688
689 i__2 = length;
690 for (j = 1; j <= i__2; ++j) {
691
692 /* Check to see that the characters in the buffer */
693 /* are all printing ASCII characters. The bounds */
694 /* for printing ASCII characters are given by */
695 /* MAXPCH and MINPCH, which are defined in the */
696 /* $ Local Parameters section of the header. */
697
698 intchr = *(unsigned char *)&combuf[((i__3 = i__ - 1) <
699 22 && 0 <= i__3 ? i__3 : s_rnge("combuf",
700 i__3, "dasacu_", (ftnlen)699)) * 255 + (j - 1)
701 ];
702 if (intchr > 126 || intchr < 32) {
703 cl__1.cerr = 0;
704 cl__1.cunit = scrlun;
705 cl__1.csta = 0;
706 f_clos(&cl__1);
707 setmsg_("A nonprinting character was encountered"
708 " in the comment buffer. Value: #", (
709 ftnlen)71);
710 errint_("#", &intchr, (ftnlen)1);
711 sigerr_("SPICE(ILLEGALCHARACTER)", (ftnlen)23);
712 chkout_("DASACU", (ftnlen)6);
713 return 0;
714 }
715 }
716 }
717
718 /* Write the comments to the temporary file. */
719
720 writla_(&numcom, combuf, &scrlun, (ftnlen)255);
721 }
722 if (failed_()) {
723 cl__1.cerr = 0;
724 cl__1.cunit = scrlun;
725 cl__1.csta = 0;
726 f_clos(&cl__1);
727 chkout_("DASACU", (ftnlen)6);
728 return 0;
729 }
730
731 /* If we have encountered the end of file here, we have a */
732 /* problem: We did not find the end comments marker in the */
733 /* text file. So, set an appropriate error message and */
734 /* signal the error. */
735
736 if (more && eof) {
737 cl__1.cerr = 0;
738 cl__1.cunit = scrlun;
739 cl__1.csta = 0;
740 f_clos(&cl__1);
741 setmsg_("The end comments marker '#' was not found in the co"
742 "mment file '#'.", (ftnlen)66);
743 errch_("#", endmrk, (ftnlen)1, endmrk_len);
744 errfnm_("#", comlun, (ftnlen)1);
745 sigerr_("SPICE(MARKERNOTFOUND)", (ftnlen)21);
746 chkout_("DASACU", (ftnlen)6);
747 return 0;
748 }
749 }
750 }
751
752 /* If we made it to here, we have culled all of the comments out of */
753 /* the text file and they were all OK. So we need to add all of the */
754 /* comments to the DAS comment area now. */
755
756 /* If we are supposed to insert a blank line to separate the current */
757 /* addition from any previously stored comments, and there are */
758 /* comments already in the comment area, indicated by NCOMC > 0, then */
759 /* we insert the blank line. Otherwise, just add the comments. */
760
761 if (*insbln && ncomc > 0) {
762 dasac_(handle, &c__1, " ", (ftnlen)1);
763 if (failed_()) {
764 cl__1.cerr = 0;
765 cl__1.cunit = scrlun;
766 cl__1.csta = 0;
767 f_clos(&cl__1);
768 chkout_("DASACU", (ftnlen)6);
769 return 0;
770 }
771 }
772
773 /* Rewind the scratch file to get ready to put the comments into the */
774 /* comment area. */
775
776 al__1.aerr = 0;
777 al__1.aunit = scrlun;
778 f_rew(&al__1);
779
780 /* Begin reading through the scratch file, placing the comment lines */
781 /* into the comment area of the DAS file a buffer at a time */
782
783 eof = FALSE_;
784 while(! eof) {
785 numcom = 0;
786
787 /* Read in a buffer of comment lines. */
788
789 readla_(&scrlun, &c__22, &numcom, combuf, &eof, (ftnlen)255);
790
791 /* If we got some, add them to the comment area of the DAS file. */
792
793 if (numcom > 0) {
794 dasac_(handle, &numcom, combuf, (ftnlen)255);
795 }
796 if (failed_()) {
797 cl__1.cerr = 0;
798 cl__1.cunit = scrlun;
799 cl__1.csta = 0;
800 f_clos(&cl__1);
801 chkout_("DASACU", (ftnlen)6);
802 return 0;
803 }
804 }
805
806 /* Close the scratch file before exiting; it's the only one we */
807 /* opened. */
808
809 cl__1.cerr = 0;
810 cl__1.cunit = scrlun;
811 cl__1.csta = 0;
812 f_clos(&cl__1);
813 chkout_("DASACU", (ftnlen)6);
814 return 0;
815 } /* dasacu_ */
816
817