1 /*
2 
3 -Procedure orderd_c ( Order of a double precision array )
4 
5 -Abstract
6 
7    Determine the order of elements in a double precision array.
8 
9 -Disclaimer
10 
11    THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE
12    CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.
13    GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE
14    ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE
15    PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS"
16    TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY
17    WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A
18    PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC
19    SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
20    SOFTWARE AND RELATED MATERIALS, HOWEVER USED.
21 
22    IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA
23    BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT
24    LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,
25    INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,
26    REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE
27    REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.
28 
29    RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF
30    THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY
31    CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE
32    ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.
33 
34 -Required_Reading
35 
36    None.
37 
38 -Keywords
39 
40     ARRAY,  SORT
41 
42 */
43 
44    #include "SpiceUsr.h"
45    #include "SpiceZfc.h"
46    #include "SpiceZim.h"
47    #undef    orderd_c
48 
49 
orderd_c(ConstSpiceDouble * array,SpiceInt ndim,SpiceInt * iorder)50    void orderd_c ( ConstSpiceDouble  * array,
51                    SpiceInt            ndim,
52                    SpiceInt          * iorder )
53 
54 /*
55 
56 -Brief_I/O
57 
58    VARIABLE  I/O  DESCRIPTION
59    --------  ---  --------------------------------------------------
60    array      I   Input array.
61    ndim       I   Dimension of array.
62    iorder     O   Order vector for array.
63 
64 -Detailed_Input
65 
66    array       is the input array.
67 
68    ndim        is the number of elements in the input array.
69 
70 -Detailed_Output
71 
72    iorder      is the order vector for the input array.
73                iorder[0] is the index of the smallest element
74                of array; iorder[1] is the index of the next
75                smallest; and so on.
76 
77                The elements of iorder range from zero to ndim-1.
78 -Parameters
79 
80    None.
81 
82 -Exceptions
83 
84    1) A negative input dimension causes this routine to
85       leave the output order vector unchanged.
86 
87    This routine is error free.
88 
89 -Files
90 
91    None.
92 
93 -Particulars
94 
95    orderd_c finds the index of the smallest element of the input
96    array. This becomes the first element of the order vector.
97    The process is repeated for the rest of the elements.
98 
99    The order vector returned by orderd_c may be used by any of
100    the reord* routines to sort sets of related arrays, as shown
101    in the example below.
102 
103 -Examples
104 
105    In the following example, the order* and reord* routines are
106    used to sort four related arrays (containing the names,
107    masses, integer ID codes, and visual magnitudes for a group
108    of satellites). This is representative of the typical use of
109    these routines.
110 
111       #include "SpiceUsr.h"
112            .
113            .
114            .
115       /.
116       Sort the object arrays by visual magnitude.
117       ./
118 
119       orderd_c ( vmags,  n,  iorder );
120 
121       reordc_c ( iorder, n, namlen, names  );
122       reordd_c ( iorder, n,         masses );
123       reordi_c ( iorder, n,         codes  );
124       reordd_c ( iorder, n,         vmags  );
125 
126 
127 -Restrictions
128 
129    None.
130 
131 -Literature_References
132 
133    None.
134 
135 -Author_and_Institution
136 
137    N.J. Bachman    (JPL)
138    I.M. Underwood  (JPL)
139 
140 -Version
141 
142    -CSPICE Version 1.0.1, 23-MAR-2010 (NJB)
143 
144       Header example was updated to show use of this routine.
145       Exceptions section was updated. Header sections were
146       re-ordered.
147 
148    -CSPICE Version 1.0.0, 08-JUL-2002 (NJB) (IMU)
149 
150 -Index_Entries
151 
152    order of a d.p. array
153 
154 -&
155 */
156 
157 { /* Begin orderd_c */
158 
159    /*
160    Local variables
161    */
162    SpiceInt                i;
163 
164 
165 
166    orderd_ ( ( doublereal * ) array,
167              ( integer    * ) &ndim,
168              ( integer    * ) iorder );
169 
170    /*
171    Map the order vector elements to the range 0 : ndim-1.
172    */
173    for ( i = 0;  i < ndim;  i++ )
174    {
175       --iorder[i];
176    }
177 
178 } /* End orderd_c */
179