1 /* wrencd.f -- translated by f2c (version 19980913).
2    You must link the resulting object file with the libraries:
3 	-lf2c -lm   (in that order)
4 */
5 
6 #include "f2c.h"
7 
8 /* Table of constant values */
9 
10 static integer c__3 = 3;
11 static integer c__1 = 1;
12 
13 /* $Procedure  WRENCD  ( Write encoded d.p. numbers to text file ) */
wrencd_(integer * unit,integer * n,doublereal * data)14 /* Subroutine */ int wrencd_(integer *unit, integer *n, doublereal *data)
15 {
16     /* System generated locals */
17     address a__1[3];
18     integer i__1, i__2, i__3, i__4[3];
19     char ch__1[66];
20     cilist ci__1;
21 
22     /* Builtin functions */
23     integer s_rnge(char *, integer, char *, integer), s_wsfe(cilist *);
24     /* Subroutine */ int s_cat(char *, char **, integer *, integer *, ftnlen);
25     integer do_fio(integer *, char *, ftnlen), e_wsfe(void);
26 
27     /* Local variables */
28     char work[64*64];
29     extern /* Subroutine */ int dp2hx_(doublereal *, char *, integer *,
30 	    ftnlen);
31     integer i__;
32     extern /* Subroutine */ int chkin_(char *, ftnlen);
33     integer nitms, itmbeg, length[64];
34     extern /* Subroutine */ int sigerr_(char *, ftnlen), chkout_(char *,
35 	    ftnlen), setmsg_(char *, ftnlen);
36     integer iostat;
37     extern /* Subroutine */ int errint_(char *, integer *, ftnlen);
38     extern logical return_(void);
39 
40 /* $ Abstract */
41 
42 /*     Encode and write d.p. numbers to a text file. */
43 
44 /* $ Disclaimer */
45 
46 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
47 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
48 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
49 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
50 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
51 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
52 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
53 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
54 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
55 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
56 
57 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
58 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
59 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
60 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
61 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
62 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
63 
64 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
65 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
66 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
67 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
68 
69 /* $ Required_Reading */
70 
71 /*     None. */
72 
73 /* $ Keywords */
74 
75 /*     CONVERSION */
76 /*     NUMBERS */
77 /*     UTILITY */
78 
79 /* $ Declarations */
80 /* $ Brief_I/O */
81 
82 /*     Variable  I/O  Description */
83 /*     --------  ---  -------------------------------------------------- */
84 /*      UNIT      I    Fortran unit number of output text file. */
85 /*      N         I    Number of d.p. numbers to encode and write. */
86 /*      DATA      I    List of d.p. numbers to encode and write. */
87 
88 /* $ Detailed_Input */
89 
90 /*     UNIT     The Fortran unit number for a previously opened text */
91 /*              file. All writing will begin at the CURRENT POSITION */
92 /*              in the text file. */
93 
94 /*     N        The number of double precision numbers to be encoded */
95 /*              and written to the text file attached to UNIT. */
96 
97 /*     DATA     List of double precision numbers to be encoded and */
98 /*              written to the text file attached to UNIT. */
99 
100 /* $ Detailed_Output */
101 
102 /*     See the Particulars section for a description of the effect of */
103 /*     this routine. */
104 
105 /* $ Parameters */
106 
107 /*      None. */
108 
109 /* $ Exceptions */
110 
111 /*     1)   If N, the number of data items, is not positive, the error */
112 /*          SPICE(INVALIDARGUMENT) will be signalled. */
113 
114 /*     2)   If an error occurs while writing to the text file attached */
115 /*          to UNIT, the error SPICE(FILEWRITEFAILED) will be signalled. */
116 
117 /*     3)   If the Fortran logical unit UNIT is not defined, the results */
118 /*          of this routine are unpredictable. */
119 
120 /* $ Files */
121 
122 /*     See the description of UNIT in the Detailed_Input section. */
123 
124 /* $ Particulars */
125 
126 /*     This routine will accept a list of one or more double precision */
127 /*     numbers which it will encode into equivalent text strings and */
128 /*     write to the current position in a text file. The current */
129 /*     position in a file is defined to be the text line immediately */
130 /*     following the last text line that was written or read. The */
131 /*     encoded d.p. numbers are written to the output text file as */
132 /*     quoted character strings so that a Fortran list directed read may */
133 /*     be used to read the encoded values, rather than a formatted read */
134 /*     with the format specifier FMT = '(A)'. */
135 
136 /*     This routine is one of a pair of routines which are used to */
137 /*     encode and decode d.p. numbers: */
138 
139 /*           WRENCD -- Encode and write d.p. numbers to a file. */
140 /*           RDENCD -- Read and decode d.p. numbers from a file. */
141 
142 /*     The encoding/decoding of d.p.numbers is performed to provide a */
143 /*     portable means for transferring data values. */
144 
145 /*     Currently the text string produced will be in a base 16 */
146 /*     ``scientific notation.'' This format retains the full precision */
147 /*     available for d.p. numbers on any given computer architecture. */
148 /*     See DP2HX.FOR and HX2DP.FOR for details. */
149 
150 /* $ Examples */
151 
152 /*     Please note that the output format in the examples is not */
153 /*     intended to be exactly identical with the output format of this */
154 /*     routine in actual use. The output format used in the examples is */
155 /*     intended to aid in the understanding of how this routine works. */
156 /*     It is NOT intended to be a specification of the output format for */
157 /*     this routine. */
158 
159 /*     Let */
160 
161 /*        UNIT     be the Fortran logical unit of a previously opened */
162 /*                 text file. */
163 
164 /*        N        = 100 */
165 
166 /*        DATA(I)  = DBLE(I), I = 1,N */
167 
168 /*     Then, the subroutine call */
169 
170 /*           CALL WRENCD( UNIT, N, DATA ) */
171 
172 /*     will write the first 100 integers as encoded d.p. numbers to the */
173 /*     output text file attached to UNIT, beginning at the current */
174 /*     position in the output file, which is marked by an arrow, '-->'. */
175 /*     The resulting output will look something like the following: */
176 
177 /*        -->'1^1' '2^1' '3^1' '4^1' '5^1' '6^1' '7^1' '8^1' '9^1' */
178 /*           'A^1' 'B^1' 'C^1' 'D^1' 'E^1' 'F^1' '1^2' '11^2' '12^2' */
179 /*           '13^2' '14^2' '15^2' '16^2' '17^2' '18^2' '19^2' '1A^2' */
180 /*           '1B^2' '1C^2' '1D^2' '1E^2' '1F^2' '2^2' '21^2' '22^2' */
181 /*           '23^2' '24^2' '25^2' '26^2' '27^2' '28^2' '29^2' '2A^2' */
182 /*           '2B^2' '2C^2' '2D^2' '2E^2' '2F^2' '3^2' '31^2' '32^2' */
183 /*           '33^2' '34^2' '35^2' '36^2' '37^2' '38^2' '39^2' '3A^2' */
184 /*           '3B^2' '3C^2' '3D^2' '3E^2' '3F^2' '4^2' */
185 /*           '41^2' '42^2' '43^2' '44^2' '45^2' '46^2' '47^2' '48^2' */
186 /*           '49^2' '4A^2' '4B^2' '4C^2' '4D^2' '4E^2' '4F^2' '5^2' */
187 /*           '51^2' '52^2' '53^2' '54^2' '55^2' '56^2' '57^2' '58^2' */
188 /*           '59^2' '5A^2' '5B^2' '5C^2' '5D^2' '5E^2' '5F^2' '6^2' */
189 /*           '61^2' '62^2' '63^2' '64^2' */
190 /*        --> */
191 
192 /*     At this point, the arrow marks the position of the file pointer */
193 /*     immediately after the call to WRENCD. */
194 
195 /* $ Restrictions */
196 
197 /*     None. */
198 
199 /* $ Literature_References */
200 
201 /*     None. */
202 
203 /* $ Author_and_Institution */
204 
205 /*     K.R. Gehringer (JPL) */
206 
207 /* $ Version */
208 
209 /* -    SPICELIB Version 1.2.0, 09-SEP-1993 (KRG) */
210 
211 /*        The list directed write was changed to a formatted write using */
212 /*        the specifier FMT='(A)'. This was done in order to prevent a */
213 /*        space from appearing as the first character on each line of the */
214 /*        file for certian computer platforms. */
215 
216 /* -    SPICELIB Version 1.1.0, 21-JUN-1993 (KRG) */
217 
218 /*        This routine was modified to avoid the creation of long output */
219 /*        lines on some of the supported systems, such as the NeXT with */
220 /*        Absoft Fortran 3.2. */
221 
222 /*        A disclaimer was added to the $ Examples section concerning */
223 /*        the output format used. The disclaimer simply states that the */
224 /*        output format used in the example is not necessarily the */
225 /*        output format actually used by the routine. */
226 
227 /* -    SPICELIB Version 1.0.0, 20-OCT-1992 (KRG) */
228 
229 /* -& */
230 /* $ Index_Entries */
231 
232 /*      encode and write d.p. numbers to a text file */
233 
234 /* -& */
235 /* $ Revisions */
236 
237 /* -    SPICELIB Version 1.2.0, 09-SEP-1993 (KRG) */
238 
239 /*        The list directed write was changed to a formatted write using */
240 /*        the  specifier FMT='(A)'. This was done in order to prevent a */
241 /*        space from appearing as the first character on each line of the */
242 /*        file for certian computer platforms. */
243 
244 /* -    SPICELIB Version 1.1.0, 21-JUN-1993 (KRG) */
245 
246 /*        This routine was modified to avoid the creation of long output */
247 /*        lines on some of the supported systems, such as the NeXT with */
248 /*        Absoft Fortran 3.2. */
249 
250 /*        On some of the supported computers this routine would produce */
251 /*        very long (greater than 1000 characters) output lines due to */
252 /*        the implicit DO loop used in the WRITE statment: */
253 
254 /*            WRITE (UNIT,IOSTAT=IOSTAT,FMT=*) */
255 /*           .   ( QUOTE//WORK(I)(1:LENGTH(I))//QUOTE//' ', I=1,NITMS ) */
256 
257 /*        This problem was fixed by removing the implicit DO loop from */
258 /*        the WRITE statement and placing an equivalent DO loop around */
259 /*        the WRITE statemtent: */
260 
261 /*            DO I = 1, NITMS */
262 /*               WRITE (UNIT,IOSTAT=IOSTAT,FMT=*) */
263 /*           .       QUOTE//WORK(I)(1:LENGTH(I))//QUOTE */
264 /*            END DO */
265 
266 /*        The net effect of this will be that only a single datum will */
267 /*        be written on each line of output. */
268 
269 /*        A disclaimer was added to the $ Examples section concerning */
270 /*        the output format used. The disclaimer simply states that the */
271 /*        output format used in the example is not necessarily the */
272 /*        output format actually used by the routine. */
273 
274 /* -    SPICELIB Version 1.0.0, 20-OCT-1992 (KRG) */
275 
276 /* -& */
277 
278 /*     SPICELIB functions */
279 
280 
281 /*     Local parameters */
282 
283 
284 /*     Local variables */
285 
286 
287 /*     Standard SPICE error handling. */
288 
289     if (return_()) {
290 	return 0;
291     } else {
292 	chkin_("WRENCD", (ftnlen)6);
293     }
294 
295 /*     Check to see if the number of data items is less than or equal */
296 /*     to zero. If it is, signal an error. */
297 
298     if (*n < 1) {
299 	setmsg_("The number of data items to be written was not positive: #.",
300 		 (ftnlen)59);
301 	errint_("#", n, (ftnlen)1);
302 	sigerr_("SPICE(INVALIDARGUMENT)", (ftnlen)22);
303 	chkout_("WRENCD", (ftnlen)6);
304 	return 0;
305     }
306 
307 /*     Initialize the beginning location for the data items to be */
308 /*     encoded. */
309 
310     itmbeg = 1;
311 
312 /*     Begin encoding the input data items in blocks of size NITMS. */
313 /*     Each time the number of data items NITMS is reached, write */
314 /*     out the encoded items in the workspace. */
315 
316     while(itmbeg <= *n) {
317 
318 /*        The number of items is either the size of the workspace, or */
319 /*        the number of data items which remain to be processed, which */
320 /*        should always be less than or equal to the size of the */
321 /*        workspace. */
322 
323 /* Computing MIN */
324 	i__1 = 64, i__2 = *n - itmbeg + 1;
325 	nitms = min(i__1,i__2);
326 
327 /*        Encode each of the numbers into an equivalent character string. */
328 
329 	i__1 = nitms;
330 	for (i__ = 1; i__ <= i__1; ++i__) {
331 	    dp2hx_(&data[itmbeg + i__ - 2], work + (((i__2 = i__ - 1) < 64 &&
332 		    0 <= i__2 ? i__2 : s_rnge("work", i__2, "wrencd_", (
333 		    ftnlen)324)) << 6), &length[(i__3 = i__ - 1) < 64 && 0 <=
334 		    i__3 ? i__3 : s_rnge("length", i__3, "wrencd_", (ftnlen)
335 		    324)], (ftnlen)64);
336 	}
337 
338 /*        Write out the current workspace, placing single quotes around */
339 /*        each of the character strings so that they may be read using */
340 /*        Fortran list directed read statements rather than the format */
341 /*        specifier FMT = '(A)'. */
342 
343 	i__1 = nitms;
344 	for (i__ = 1; i__ <= i__1; ++i__) {
345 	    ci__1.cierr = 1;
346 	    ci__1.ciunit = *unit;
347 	    ci__1.cifmt = "(A)";
348 	    iostat = s_wsfe(&ci__1);
349 	    if (iostat != 0) {
350 		goto L100001;
351 	    }
352 /* Writing concatenation */
353 	    i__4[0] = 1, a__1[0] = "'";
354 	    i__4[1] = length[(i__3 = i__ - 1) < 64 && 0 <= i__3 ? i__3 :
355 		    s_rnge("length", i__3, "wrencd_", (ftnlen)335)], a__1[1] =
356 		     work + (((i__2 = i__ - 1) < 64 && 0 <= i__2 ? i__2 :
357 		    s_rnge("work", i__2, "wrencd_", (ftnlen)335)) << 6);
358 	    i__4[2] = 1, a__1[2] = "'";
359 	    s_cat(ch__1, a__1, i__4, &c__3, (ftnlen)66);
360 	    iostat = do_fio(&c__1, ch__1, length[(i__3 = i__ - 1) < 64 && 0 <=
361 		     i__3 ? i__3 : s_rnge("length", i__3, "wrencd_", (ftnlen)
362 		    335)] + 2);
363 	    if (iostat != 0) {
364 		goto L100001;
365 	    }
366 	    iostat = e_wsfe();
367 L100001:
368 
369 /*           Check to see if we got a write error, IOSTAT .NE. 0. */
370 
371 	    if (iostat != 0) {
372 		setmsg_("Error writing to logical unit #, IOSTAT = #.", (
373 			ftnlen)44);
374 		errint_("#", unit, (ftnlen)1);
375 		errint_("#", &iostat, (ftnlen)1);
376 		sigerr_("SPICE(FILEWRITEFAILED)", (ftnlen)22);
377 		chkout_("WRENCD", (ftnlen)6);
378 		return 0;
379 	    }
380 	}
381 
382 /*        Position the data item pointer at the next location to begin */
383 /*        encoding the items in the array DATA, and continue processing */
384 /*        the data items until done. */
385 
386 	itmbeg += nitms;
387     }
388     chkout_("WRENCD", (ftnlen)6);
389     return 0;
390 } /* wrencd_ */
391 
392