1 /* rmdupi.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      RMDUPI ( Remove duplicates from an integer array ) */
rmdupi_(integer * nelt,integer * array)9 /* Subroutine */ int rmdupi_(integer *nelt, integer *array)
10 {
11     /* System generated locals */
12     integer i__1;
13 
14     /* Local variables */
15     integer i__, j;
16     extern /* Subroutine */ int shelli_(integer *, integer *);
17 
18 /* $ Abstract */
19 
20 /*      Remove duplicate elements from an integer array. */
21 
22 /* $ Disclaimer */
23 
24 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
25 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
26 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
27 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
28 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
29 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
30 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
31 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
32 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
33 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
34 
35 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
36 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
37 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
38 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
39 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
40 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
41 
42 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
43 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
44 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
45 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
46 
47 /* $ Required_Reading */
48 
49 /*     None. */
50 
51 /* $ Keywords */
52 
53 /*      ARRAY */
54 
55 /* $ Declarations */
56 /* $ Brief_I/O */
57 
58 /*      VARIABLE  I/O  DESCRIPTION */
59 /*      --------  ---  -------------------------------------------------- */
60 /*      NELT      I/O  Number of elements in the array. */
61 /*      ARRAY     I/O  Input/output array. */
62 
63 /* $ Detailed_Input */
64 
65 /*      NELT        on input is the number of elements in the input */
66 /*                  array. */
67 
68 /*      ARRAY       on input contains zero or more elements, from which */
69 /*                  all duplicate elements are to be removed. */
70 
71 /* $ Detailed_Output */
72 
73 /*      NELT        on output is the number of elements in the output */
74 /*                  array. */
75 
76 /*      ARRAY       on output contains the distinct elements of the */
77 /*                  input array, sorted in increasing order. (Character */
78 /*                  arrays are sorted according to the ASCII collating */
79 /*                  sequence). */
80 
81 /* $ Parameters */
82 
83 /*     None. */
84 
85 /* $ Particulars */
86 
87 /*      None. */
88 
89 /* $ Examples */
90 
91 /*      Let the arrays C and I contain the following elements. */
92 
93 /*            NC   = 7                NI   =   5 */
94 /*            C(1) = 'Miranda'        I(1) =  13 */
95 /*            C(2) = 'Ariel'          I(2) = -13 */
96 /*            C(3) = 'Umbriel'        I(3) =   0 */
97 /*            C(4) = 'Titania'        I(4) =   1 */
98 /*            C(5) = 'Miranda'        I(5) =   0 */
99 /*            C(6) = 'Oberon' */
100 /*            C(7) = 'Umbriel' */
101 
102 /*      Then following the calls */
103 
104 /*            CALL RMDUPC ( NC, C ) */
105 /*            CALL RMDUPI ( NI, I ) */
106 
107 /*      C and I contain the following. */
108 
109 /*            NC   = 5                NI   =   4 */
110 /*            C(1) = 'Ariel'          I(1) = -13 */
111 /*            C(2) = 'Miranda'        I(2) =   0 */
112 /*            C(3) = 'Oberon'         I(3) =   1 */
113 /*            C(4) = 'Titania'        I(4) =  13 */
114 /*            C(5) = 'Umbriel' */
115 
116 /* $ Restrictions */
117 
118 /*      None. */
119 
120 /* $ Exceptions */
121 
122 /*      Error free. */
123 
124 /* $ Files */
125 
126 /*      None. */
127 
128 /* $ Literature_References */
129 
130 /*      None. */
131 
132 /* $ Author_and_Institution */
133 
134 /*      I.M. Underwood  (JPL) */
135 
136 /* $ Version */
137 
138 /* -     SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
139 
140 /*         Comment section for permuted index source lines was added */
141 /*         following the header. */
142 
143 /* -     SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
144 
145 /* -& */
146 /* $ Index_Entries */
147 
148 /*     remove duplicates from an integer array */
149 
150 /* -& */
151 
152 /*     Local variables */
153 
154 
155 /*     Proceed only if the array actualy contains more than one element. */
156 
157     if (*nelt > 1) {
158 
159 /*        Sort the array in place. */
160 
161 	shelli_(nelt, array);
162 
163 /*        Drop duplicate entries. Compare adjacent entries, and move */
164 /*        duplicates forward. (Duplicates are now adjacent, because of */
165 /*        sorting.) */
166 
167 	j = 1;
168 	i__1 = *nelt;
169 	for (i__ = 2; i__ <= i__1; ++i__) {
170 	    if (array[i__ - 1] != array[i__ - 2]) {
171 		++j;
172 		array[j - 1] = array[i__ - 1];
173 	    }
174 	}
175 	*nelt = j;
176     }
177     return 0;
178 } /* rmdupi_ */
179 
180