Table of contents
CSPICE_SUMAD returns the double precision sum of elements of
a double precision vector.
Given:
array the input array.
help, array
DOUBLE = Array[n]
n the number of elements in the array, length or order.
help, n
LONG = Scalar
the call:
sumad = cspice_sumad( array, n)
returns:
sumad the summation of the `n' elements of the `array' 0 to n-1 where
`n' indicates the number of array elements to sum.
help, sumad
DOUBLE = Scalar
That is,
cspice_sumad( 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_sumad returns zero.
The user may also sum an arbitrary contiguous segment of
an array:
sumad = cspice_sumad( 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 double precision sum of the elements (or a subset)
of a double precision vector.
Example code begins here.
PRO sumad_ex1
vec1 = [ 12.3d, -4.32d, 76.d, 1.87d]
print, FORMAT='("Input vector: ",4F8.2)', vec1
print
;;
;; Sum of the third and fourth element of `vec1'
;;
print, FORMAT='("Elements 2 + 3 = ",F6.2)', $
cspice_sumad( vec1[2:3], 2 )
;;
;; Sum of the second and third element of `vec1'.
;; Note that the fourth element will not be considered
;; as the second argument of cspice_sumad indicates that
;; the vector `vec1' has only 2 elements.
;;
print, FORMAT='("Elements 1 + 2 = ",F6.2)', $
cspice_sumad( vec1[1:3], 2 )
;;
;; Sum of all elements of `vec1'
;;
print, FORMAT='("Sum of all elements = ",F6.2)', $
cspice_sumad( vec1[0:3], 4 )
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Input vector: 12.30 -4.32 76.00 1.87
Elements 2 + 3 = 77.87
Elements 1 + 2 = 71.68
Sum of all elements = 85.85
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_sumad 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_sumad 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 a d.p. array
|