Table of contents
CSPICE_INTER calculates the intersection of two sets to form
a third set
Given:
a,
b two SPICE sets, each of the same type, double precision, or
integer.
help, a
STRUCT = cspice_celld(N) or STRUCT = cspice_celli(N)
help, b
STRUCT = cspice_celld(M) or STRUCT = cspice_celli(M)
The user must create `a' and `b' using either cspice_celld
or cspice_celli.
the call:
cspice_inter, a, b, c
returns:
c the SPICE set, distinct from sets `a' and `b', which contains
the intersection of `a' and `b' (that is, all of the elements
which are in `a' AND `b').
help, c
STRUCT = cspice_celld(R) or STRUCT = cspice_celli(R)
`c' must have the same data type as `a' and `b'.
The user must create `c' using either cspice_celld or
cspice_celli.
None.
Any numerical results shown for this example may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
1) Compute the intersection of two integer sets and display the
output.
Example code begins here.
PRO inter_ex1
;;
;; Create three cells with the necessary size.
;; Set 'c' need not have a larger size than the
;; smaller of 'a' or 'b'.
;;
SIZE = 10
a = cspice_celli( SIZE )
b = cspice_celli( SIZE )
c = cspice_celli( SIZE )
;;
;; Create vectors of integers. It is more efficient to
;; load a set from a vector than looping over the
;; call, inserting one 'item' per iteration.
;;
ints1 = [ 0, 1, 1, 2, 3, 5, 8, 13 ]
ints2 = [ 1, 3, 5, 7, 11, 13]
;;
;; Insert the 'ints1' list into set 'a', 'ints2 '
;; into set 'b'.
;;
cspice_insrti, ints1, a
cspice_insrti, ints2, b
;;
;; Calculate the intersection between sets 'a' and 'b', return
;; that intersection to set 'c'.
;;
cspice_inter, a, b, c
;;
;; Output the contents of set 'c'. Recall
;; set data begins at 'c.base[ c.data + 0 ]'.
;;
print, 'Members of set A also in B: '
print, ''
for i=0, cspice_card(c)-1 do begin
print, c.base[ c.data + i]
endfor
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Members of set A also in B:
1
3
5
13
The intersection of two sets contains every element
which is in the first set and in the second set.
{a,b} intersect {c,d} = {}
{a,b,c} {b,c,d} {b,c}
{a,b,c,d} {} {}
{} {a,b,c,d} {}
The user must create any needed cell structures with cspice_celld,
cspice_celli prior to use regardless of whether the routine
uses the cell as input or returns it as output.
1) If the input set arguments don't have identical data types,
the error SPICE(TYPEMISMATCH) is signaled by a routine in the
call tree of this routine.
2) If the intersection of the two sets contains more elements
than can be contained in the output set, the error
SPICE(SETEXCESS) is signaled by a routine in the call tree of
this routine.
3) If any of the arguments may be unordered or contain
duplicates, the error SPICE(NOTASET) is signaled by a routine
in the call tree of this routine.
4) If any of the input arguments, `a', `b' or `c', is undefined,
an error is signaled by the IDL error handling system.
5) If any of the input arguments, `a', `b' or `c', is not of the
expected type, or it does not have the expected dimensions and
size, an error is signaled by the Icy interface.
None.
1) The output set must be distinct from both of the input sets.
For example, the following calls are invalid.
cspice_inter, current, new, current
cspice_inter, new, current, current
In each of the examples above, whether or not the subroutine
signals an error, the results will almost certainly be wrong.
Nearly the same effect can be achieved, however, by placing the
result into a temporary set, which is immediately copied back
into one of the input sets, as shown below.
cspice_inter, current, new, temp
new = temp
ICY.REQ
CELLS.REQ
SETS.REQ
None.
J. Diaz del Rio (ODC Space)
E.D. Wright (JPL)
-Icy Version 1.0.1, 24-AUG-2021 (JDR)
Added arguments' type and size information in the -I/O section.
Edited the header to comply with NAIF standard. Added example's
problem statement and reformatted example's output.
Added -Parameters, -Exceptions, -Files, -Restrictions,
-Literature_References and -Author_and_Institution sections.
Removed reference to the routine's corresponding CSPICE header from
-Abstract section.
-Icy Version 1.0.0, 18-OCT-2005 (EDW)
intersection of two sets
|