Table of contents
CSPICE_SDIFF takes the symmetric difference of two sets of any data type
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_sdiff, a, b, c
returns:
c the SPICE set, distinct from sets `a' and `b' but with the same
type, containing the difference of `a' and `b' (that is, all of
the elements which are in `a' or `b' but NOT both).
help, c
STRUCT = cspice_celld(R) or STRUCT = cspice_celli(R)
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) Calculate the symmetric difference between two sets of integer
data values.
Example code begins here.
PRO sdiff_ex1
;;
;; Create three cells with the necessary size.
;; Set 'c' need not have a larger size than the
;; larger 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 symmetric difference between sets ,
;; 'a' and 'b' return that difference to set 'c'.
;;
cspice_sdiff, a, b, c
;;
;; Output the contents of set 'c'. Recall
;; set data begins at 'c.base[ c.data + 0 ]'.
;;
print, 'Symmetric difference between A and B sets:'
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:
Symmetric difference between A and B sets:
0
2
7
8
11
Note, the symmetric difference of the two sets contains the
members of `a' and `b' not in both `a' and `b'.
The symmetric difference of two sets contains every element which is
in the first set OR in the second set, but NOT in both sets.
{a,b} sym. difference {c,d} = {a,b,c,d}
{a,b,c} {b,c,d} {a,d}
{a,b,c,d} {} {a,b,c,d}
{} {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 symmetric difference 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 the set arguments have character type and the length of the
elements of the output set is less than the maximum of the
lengths of the elements of the input sets, the error
SPICE(ELEMENTSTOOSHORT) is signaled by a routine in the call
tree of this routine.
4) If either of the input arguments may be unordered or contain
duplicates, the error SPICE(NOTASET) is signaled by a routine
in the call tree of this routine.
5) If any of the input arguments, `a', `b' or `c', is undefined,
an error is signaled by the IDL error handling system.
6) 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_sdiff, current, new, current
cspice_sdiff, 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_sdiff, 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.2, 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.
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.1, 28-SEP-2006 (EDW)
Corrections to English.
Correct Required Reading citation cell.req to cells.req.
-Icy Version 1.0.0, 21-FEB-2005 (EDW)
symmetric difference of two sets
|