Table of contents
CSPICE_SUMAI returns the integer sum of elements of
an integer vector.
Given:
array the input array.
help, array
LONG = Array[n]
n the number of elements in the array, length or order.
help, n
LONG = Scalar
the call:
sumai = cspice_sumai( array, n)
returns:
sumai the summation of the `n' elements of the `array' 0 to n-1 where
`n' indicates the number of array elements to sum.
help, sumai
LONG = Scalar
That is,
cspice_sumai( array, n ) = array[0] + array[1] + ...
+ array[n-1]
Use of a value less than `n' sums only that subset of
array elements [0, M], M < n. If `n' is zero or negative,
cspice_sumai returns zero.
The user may also sum an arbitrary contiguous segment of
an array:
sumai = cspice_sumai( array[a,b], k)
which returns the sum of k element starting with
element array[a], assuming b-a =< k.
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) Output the integer sum of the elements (or a subset) of an
integer vector.
Example code begins here.
PRO sumai_ex1
vec = [ 34, -9, 18, 3 ]
print, FORMAT='("Input vector: ",4I6)', vec
print
;;
;; Sum of all elements of `vec'
;;
print, FORMAT='("Sum of all elements = ",I6)', $
cspice_sumai( vec, 4)
;;
;; Sum of all elements of `vec'. Note that the fourth
;; element will not be considered as the second argument
;; of cspice_sumai indicates that the vector `vec' has
;; only 3 elements.
;;
print, FORMAT='("Sum of first 3 elements = ",I6)', $
cspice_sumai( vec, 3)
;;
;; Sum of the first and second element of `vec'
;;
print, FORMAT='("Elements 0 + 1 = ",I6)', $
cspice_sumai( vec[0:1], 2)
;;
;; Sum of the second and third elements of `vec'. Note
;; that the fourth element will not be considered as
;; the second argument of cspice_sumai indicates that
;; the subset of vector `vec' has only 2 elements.
;;
print, FORMAT='("Elements 1 + 2 = ",I6)', $
cspice_sumai( vec[1:3], 2)
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Input vector: 34 -9 18 3
Sum of all elements = 46
Sum of first 3 elements = 43
Elements 0 + 1 = 25
Elements 1 + 2 = 9
The value of the function is initially set to zero. The elements
of the array are then added. If the number of elements is zero or
negative, cspice_sumai is zero.
1) If any of the input arguments, `array' or `n', is undefined,
an error is signaled by the IDL error handling system.
2) If any of the input arguments, `array' or `n', 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) cspice_sumai does not check for overflow.
ICY.REQ
None.
J. Diaz del Rio (ODC Space)
E.D. Wright (JPL)
-Icy Version 1.0.1, 10-AUG-2021 (JDR)
Edited the -Examples section 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.
Edited the -I/O section to comply with NAIF standard.
Removed reference to the routine's corresponding CSPICE header from
-Abstract section.
Added arguments' type and size information in the -I/O section.
-Icy Version 1.0.0, 16-JUN-2003 (EDW)
sum of an integer array
|