1 /* inslai.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      INSLAI (Insert at location in an integer array) */
inslai_(integer * elts,integer * ne,integer * loc,integer * array,integer * na)9 /* Subroutine */ int inslai_(integer *elts, integer *ne, integer *loc,
10 	integer *array, integer *na)
11 {
12     /* System generated locals */
13     integer i__1;
14 
15     /* Local variables */
16     integer size, i__;
17     extern /* Subroutine */ int chkin_(char *, ftnlen), sigerr_(char *,
18 	    ftnlen), chkout_(char *, ftnlen), setmsg_(char *, ftnlen),
19 	    errint_(char *, integer *, ftnlen);
20     extern logical return_(void);
21 
22 /* $ Abstract */
23 
24 /*      Insert one or more elements into an integer array at */
25 /*      the indicated location. */
26 
27 /* $ Disclaimer */
28 
29 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
30 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
31 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
32 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
33 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
34 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
35 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
36 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
37 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
38 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
39 
40 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
41 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
42 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
43 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
44 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
45 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
46 
47 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
48 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
49 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
50 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
51 
52 /* $ Required_Reading */
53 
54 /*     None. */
55 
56 /* $ Keywords */
57 
58 /*      ARRAY,  ASSIGNMENT */
59 
60 /* $ Declarations */
61 /* $ Brief_I/O */
62 
63 /*      VARIABLE  I/O  DESCRIPTION */
64 /*      --------  ---  -------------------------------------------------- */
65 /*      ELTS       I   Elements to be inserted. */
66 /*      NE         I   Number of elements to be inserted. */
67 /*      LOC        I   Location of the first inserted element. */
68 /*      ARRAY     I/O  Input/output array. */
69 /*      NA        I/O  Number of elements in the input/output array. */
70 
71 /* $ Detailed_Input */
72 
73 /*      ELTS        contains one or more elements which are to be */
74 /*                  inserted into the input array. */
75 
76 /*      NE          is the number of elements to be inserted. */
77 
78 /*      LOC         is the location in the array at which the first */
79 /*                  element of ELTS is to be inserted. LOC must be */
80 /*                  within the interval [1, NA+1]. To append to */
81 /*                  ARRAY, set LOC equal to NA+1. */
82 
83 /*      ARRAY       on input, is the original array. */
84 
85 /*      NA          on input, is the number of elements in ARRAY. */
86 
87 /* $ Detailed_Output */
88 
89 /*      ARRAY       on output, is the original array with the elements */
90 /*                  of ELT inserted into positions LOC through LOC+NE-1. */
91 /*                  The original elements in these positions are moved */
92 /*                  back to make room for the inserted elements. */
93 
94 /*      NA          on output, is the number of elements in ARRAY. */
95 
96 /* $ Parameters */
97 
98 /*     None. */
99 
100 /* $ Particulars */
101 
102 /*      The elements in positions LOC through LOC+NE-1 are moved back */
103 /*      by NE spaces to make room for the new elements, which are then */
104 /*      inserted into the vacated spaces. */
105 
106 /* $ Examples */
107 
108 /*      Let */
109 
110 /*            ELTS(1) = 5        NA = 4      ARRAY(1) =  1 */
111 /*            ELTS(2) = 6                    ARRAY(2) =  2 */
112 /*            ELTS(3) = 7                    ARRAY(3) =  3 */
113 /*                                           ARRAY(4) =  4 */
114 
115 /*      Then the call */
116 
117 /*            CALL INSLAI ( ELTS, 3, 3, ARRAY, NA ) */
118 
119 /*      yields the following result: */
120 
121 /*            NA = 7      ARRAY(1) = 1 */
122 /*                        ARRAY(2) = 2 */
123 /*                        ARRAY(3) = 5 */
124 /*                        ARRAY(4) = 6 */
125 /*                        ARRAY(5) = 7 */
126 /*                        ARRAY(6) = 3 */
127 /*                        ARRAY(7) = 4 */
128 
129 
130 /*      The following calls to INSLAI signal errors. */
131 
132 /*      CALL INSLAI ( ELTS, 3, -1, ARRAY, NA ) */
133 /*      CALL INSLAI ( ELTS, 3,  6, ARRAY, NA ) */
134 /*      CALL INSLAI ( ELTS, 3,  2, ARRAY, -1 ) */
135 /*      CALL INSLAI ( ELTS, 3, -1, ARRAY, -1 ) */
136 
137 /* $ Restrictions */
138 
139 /*      The array must be large enough to contain both the original */
140 /*      and the inserted elements. */
141 
142 /* $ Exceptions */
143 
144 /*     1) The dimension of the array is set equal to zero if its */
145 /*        input value is less than one. */
146 
147 /*     2) If LOC is not in the interval [1, NA+1], the error */
148 /*        SPICE(INVALIDINDEX) is signalled. */
149 
150 /*     3) If the number of elements to be inserted is less than one, */
151 /*        the array is not modified. */
152 
153 /* $ Files */
154 
155 /*      None. */
156 
157 /* $ Author_and_Institution */
158 
159 /*      H.A. Neilan     (JPL) */
160 /*      I.M. Underwood  (JPL) */
161 
162 /* $ Literature_References */
163 
164 /*      None. */
165 
166 /* $ Version */
167 
168 /* -     SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
169 
170 /*         Comment section for permuted index source lines was added */
171 /*         following the header. */
172 
173 /* -     SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
174 
175 /* -& */
176 /* $ Index_Entries */
177 
178 /*     insert at location in an integer array */
179 
180 /* -& */
181 /* $ Revisions */
182 
183 /* -     Beta Version 2.0.0, 30-DEC-1988 (HAN) */
184 
185 /*         If the location at which the elements are to be inserted is */
186 /*         not in the interval [1, NA+1], an error is signalled. */
187 /*         Locations not within that interval refer to non-exixtent */
188 /*         array elements. (To append to the array, the location */
189 /*         should be equal to NA+1.) */
190 
191 /*         A negative dimension bug was fixed. The results of the */
192 /*         old version were unpredictable if the input array dimension */
193 /*         was negative. To avoid this problem the maximum of zero and */
194 /*         the input dimension becomes the dimension used by the */
195 /*         the routine. In this case, the only valid location at which */
196 /*         to insert is 1. If it is not 1, an error is signalled */
197 /*         when the location is checked. */
198 
199 /* -& */
200 
201 /*     SPICELIB functions */
202 
203 
204 /*     Other functions */
205 
206 
207 /*     Local variables */
208 
209 
210 /*     Standard SPICE error handling. */
211 
212     if (return_()) {
213 	return 0;
214     } else {
215 	chkin_("INSLAI", (ftnlen)6);
216     }
217 
218 /*     Check the dimension of the array. */
219 
220     size = max(0,*na);
221 
222 /*     Make sure the location at which the elements are to be inserted */
223 /*     is not out of range. If it is, signal an error and bail out. */
224 
225     if (*loc < 1 || *loc > size + 1) {
226 	setmsg_("Location was *.", (ftnlen)15);
227 	errint_("*", loc, (ftnlen)1);
228 	sigerr_("SPICE(INVALIDINDEX)", (ftnlen)19);
229 	chkout_("INSLAI", (ftnlen)6);
230 	return 0;
231     }
232 
233 /*     If the number of elements to be inserted is greater than zero, */
234 /*     insert them. If not, do not modify the array. */
235 
236     if (*ne > 0) {
237 
238 /*        Move the trailing elements back to make room for the new ones. */
239 
240 	i__1 = *loc;
241 	for (i__ = size; i__ >= i__1; --i__) {
242 	    array[i__ + *ne - 1] = array[i__ - 1];
243 	}
244 
245 /*        Now put the new elements in the vacated spaces. */
246 
247 	i__1 = *ne;
248 	for (i__ = 1; i__ <= i__1; ++i__) {
249 	    array[*loc + i__ - 2] = elts[i__ - 1];
250 	}
251 
252 /*        Update the number of elements in the array. */
253 
254 	*na = size + *ne;
255     }
256     chkout_("INSLAI", (ftnlen)6);
257     return 0;
258 } /* inslai_ */
259 
260