1 /* packac.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      PACKAC ( Pack a character array ) */
packac_(char * in,integer * pack,integer * npack,integer * maxout,integer * nout,char * out,ftnlen in_len,ftnlen out_len)9 /* Subroutine */ int packac_(char *in, integer *pack, integer *npack, integer
10 	*maxout, integer *nout, char *out, ftnlen in_len, ftnlen out_len)
11 {
12     /* System generated locals */
13     integer i__1;
14 
15     /* Builtin functions */
16     /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen);
17 
18     /* Local variables */
19     integer i__;
20     extern /* Subroutine */ int chkin_(char *, ftnlen), sigerr_(char *,
21 	    ftnlen), chkout_(char *, ftnlen), setmsg_(char *, ftnlen),
22 	    errint_(char *, integer *, ftnlen);
23     extern logical return_(void);
24 
25 /* $ Abstract */
26 
27 /*     Pack the contents of a CHARACTER array. That is, take */
28 /*     a set of arbitrarily spaced elements from an input array, */
29 /*     and make them adjacent elements in an output array. */
30 
31 /* $ Disclaimer */
32 
33 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
34 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
35 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
36 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
37 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
38 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
39 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
40 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
41 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
42 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
43 
44 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
45 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
46 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
47 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
48 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
49 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
50 
51 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
52 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
53 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
54 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
55 
56 /* $ Required_Reading */
57 
58 /*     None. */
59 
60 /* $ Keywords */
61 
62 /*     ARRAY */
63 /*     ASSIGNMENT */
64 /*     UTILITY */
65 
66 /* $ Declarations */
67 /* $ Brief_I/O */
68 
69 /*     VARIABLE  I/O  DESCRIPTION */
70 /*     --------  ---  -------------------------------------------------- */
71 /*     IN         I   Input array. */
72 /*     PACK       I   Indices of elements to be packed. */
73 /*     NPACK      I   Number of indices. */
74 /*     MAXOUT     I   Maximum number of elements in the output array. */
75 /*     NOUT       O   Number of elements in the output array. */
76 /*     OUT        O   Output array. */
77 
78 /* $ Detailed_Input */
79 
80 /*     IN          is the input array. */
81 
82 /*     PACK        is the set of elements to be packed into the output */
83 /*                 array. PACK(i) is the index of the element in the */
84 /*                 input array that is to become the i'th element of */
85 /*                 the output array. */
86 
87 /*     NPACK       is the number of elements to be packed into the */
88 /*                 output array. */
89 
90 /*     MAXOUT      is the maximum number of elements to be packed */
91 /*                 into the output array. If NPACK is larger than */
92 /*                 MAXOUT, the extra items are ignored. */
93 
94 /* $ Detailed_Output */
95 
96 /*     NOUT        is the number of elements in the output array. */
97 
98 /*     OUT         is the output array. This array contains up to */
99 /*                 MAXOUT elements from the input array, located */
100 /*                 in the first NOUT elements of the array. */
101 
102 /* $ Parameters */
103 
104 /*     None. */
105 
106 /* $ Exceptions */
107 
108 /*     If an element in the PACK array is less than 1, the error */
109 /*     SPICE(INVALIDINDEX) is signalled. */
110 
111 /* $ Files */
112 
113 /*     None. */
114 
115 /* $ Particulars */
116 
117 /*     The indicated elements are moved from their current locations */
118 /*     in the input array to consecutive positions in the output array. */
119 
120 /*        OUT(   1) = IN(PACK(   1)) */
121 /*        OUT(   2) = IN(PACK(   2)) */
122 /*             . */
123 /*             . */
124 /*        OUT(NOUT) = IN(PACK(NOUT)) */
125 
126 /*     NOUT is either NPACK or MAXOUT, whichever is smaller. */
127 
128 /* $ Examples */
129 
130 /*     The most common use for this routine is to remove unwanted items */
131 /*     from an array or set of arrays. For example, suppose that the */
132 /*     arrays NAME, CODE, RADIUS and MASS contain the names, NAIF */
133 /*     integer ID codes, radii, and masses of a set of NSAT satellites. */
134 /*     Suppose further that the user selects a subset of the original */
135 /*     set of satellites from a menu of some sort. Let the indices of */
136 /*     these satellites be the NSEL elements of the array SEL. The */
137 /*     following sequence would remove the names, codes, etc., of the */
138 /*     unselected satellites from the arrays. */
139 
140 /*        CALL PACKAC ( NAME,   SEL, NSEL, NSAT, NOUT, NAME2   ) */
141 /*        CALL PACKAI ( CODE,   SEL, NSEL, NSAT, NOUT, CODE2   ) */
142 /*        CALL PACKAD ( RADIUS, SEL, NSEL, NSAT, NOUT, RADIUS2 ) */
143 /*        CALL PACKAD ( MASS,   SEL, NSEL, NSAT, NOUT, MASS2   ) */
144 
145 /*     In the example above, suppose that NAME and PACK contain */
146 /*     the following: */
147 
148 /*        NAME = 'MIMAS'          PACK = 2, 4, 6, 7 */
149 /*               'ENCELADUS' */
150 /*               'TETHYS' */
151 /*               'DIONE' */
152 /*               'RHEA' */
153 /*               'TITAN' */
154 /*               'HYPERION' */
155 /*               'IAPETUS' */
156 /*               'PHOEBE' */
157 
158 /*     Then, following the call to PACKAC, NOUT and NAME2 contain */
159 /*     the following: */
160 
161 /*        NOUT = 4                 NAME2 = 'ENCELADUS' */
162 /*                                         'DIONE' */
163 /*                                         'TITAN' */
164 /*                                         'HYPERION' */
165 
166 /* $ Restrictions */
167 
168 /*     None. */
169 
170 /* $ Literature_References */
171 
172 /*     None. */
173 
174 /* $ Author_and_Institution */
175 
176 /*     H.A. Neilan     (JPL) */
177 /*     W.L. Taber      (JPL) */
178 /*     I.M. Underwood  (JPL) */
179 
180 /* $ Version */
181 
182 /* -    SPICELIB Version 1.0.2, 23-APR-2010 (NJB) */
183 
184 /*        Header correction: assertions that the output */
185 /*        can overwrite the input have been removed. */
186 
187 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
188 
189 /*        Comment section for permuted index source lines was added */
190 /*        following the header. */
191 
192 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) (IMU) */
193 
194 /* -& */
195 /* $ Index_Entries */
196 
197 /*     pack a character array */
198 
199 /* -& */
200 /* $ Revisions */
201 
202 /* -     Beta Version 2.0.0, 4-JAN-1989 (HAN) */
203 
204 /*         Error handling was added to detect array indices that are */
205 /*         out of bound. If any element contained in the PACK array is */
206 /*         less than one, an error is signalled, and the output array is */
207 /*         not packed. */
208 
209 /* -& */
210 
211 /*     Spicelib functions */
212 
213 
214 
215 /*     Local variables */
216 
217 
218 /*     Standard SPICE error handling. */
219 
220     if (return_()) {
221 	return 0;
222     } else {
223 	chkin_("PACKAC", (ftnlen)6);
224     }
225 
226 /*     First, determine how many items to transfer. */
227 
228     *nout = min(*npack,*maxout);
229 
230 /*     Check to see if PACK contains valid array indices. */
231 
232     i__1 = *nout;
233     for (i__ = 1; i__ <= i__1; ++i__) {
234 	if (pack[i__ - 1] < 1) {
235 	    setmsg_("Element number * contains index *.", (ftnlen)34);
236 	    errint_("*", &i__, (ftnlen)1);
237 	    errint_("*", &pack[i__ - 1], (ftnlen)1);
238 	    sigerr_("SPICE(INVALIDINDEX)", (ftnlen)19);
239 	    chkout_("PACKAC", (ftnlen)6);
240 	    return 0;
241 	}
242     }
243 
244 /*     Transfer them. Just like it says in the header. */
245 
246     i__1 = *nout;
247     for (i__ = 1; i__ <= i__1; ++i__) {
248 	s_copy(out + (i__ - 1) * out_len, in + (pack[i__ - 1] - 1) * in_len,
249 		out_len, in_len);
250     }
251     chkout_("PACKAC", (ftnlen)6);
252     return 0;
253 } /* packac_ */
254 
255