rsspice/generated/spicelib/
sumai.rs

1//
2// GENERATED FILE
3//
4
5use super::*;
6use crate::SpiceContext;
7use f2rust_std::*;
8
9/// Sum of an integer array
10///
11/// Return the sum of the elements of an integer array.
12///
13/// # Brief I/O
14///
15/// ```text
16///  VARIABLE  I/O  DESCRIPTION
17///  --------  ---  --------------------------------------------------
18///  ARRAY      I   Input array.
19///  N          I   Number of elements in ARRAY.
20///
21///  The function returns the sum of the elements of ARRAY.
22/// ```
23///
24/// # Detailed Input
25///
26/// ```text
27///  ARRAY    is the input integer array.
28///
29///  N        is the number of elements in the array.
30/// ```
31///
32/// # Detailed Output
33///
34/// ```text
35///  The function returns the sum of the elements of the input array.
36///  That is,
37///
38///     SUMAI( ARRAY, N ) = ARRAY(1) + ARRAY(2) + ... + ARRAY(N)
39///
40///  If N is zero or negative, SUMAI is zero.
41/// ```
42///
43/// # Exceptions
44///
45/// ```text
46///  Error free.
47/// ```
48///
49/// # Particulars
50///
51/// ```text
52///  The value of the function is initially set to zero. The elements
53///  of the array are then added. If the number of elements is zero or
54///  negative, SUMAI is zero.
55/// ```
56///
57/// # Examples
58///
59/// ```text
60///  Let ARRAY contain the following elements.
61///
62///        ARRAY(1) = 12
63///        ARRAY(2) =  1
64///        ARRAY(3) =  4
65///        ARRAY(4) = 75
66///        ARRAY(5) = 18
67///
68///  Then
69///
70///        SUMAI ( ARRAY,   -3 )       =   0
71///        SUMAI ( ARRAY,    0 )       =   0
72///        SUMAI ( ARRAY,    1 )       =  12
73///        SUMAI ( ARRAY,    2 )       =  13
74///        SUMAI ( ARRAY,    5 )       = 110
75///        SUMAI ( ARRAY(3), 3 )       =  97
76/// ```
77///
78/// # Restrictions
79///
80/// ```text
81///  1)  SUMAI does not check for overflow.
82/// ```
83///
84/// # Author and Institution
85///
86/// ```text
87///  J. Diaz del Rio    (ODC Space)
88///  W.L. Taber         (JPL)
89///  I.M. Underwood     (JPL)
90/// ```
91///
92/// # Version
93///
94/// ```text
95/// -    SPICELIB Version 1.1.0, 09-APR-2021 (JDR)
96///
97///         Added IMPLICIT NONE statement.
98///
99///         Edited the header to comply with NAIF standard.
100///
101/// -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)
102///
103///         Comment section for permuted index source lines was added
104///         following the header.
105///
106/// -    SPICELIB Version 1.0.0, 31-JAN-1990 (IMU)
107/// ```
108pub fn sumai(array: &[i32], n: i32) -> i32 {
109    let ret = SUMAI(array, n);
110    ret
111}
112
113//$Procedure SUMAI ( Sum of an integer array )
114pub fn SUMAI(ARRAY: &[i32], N: i32) -> i32 {
115    let ARRAY = DummyArray::new(ARRAY, 1..);
116    let mut SUMAI: i32 = 0;
117    let mut SUM: i32 = 0;
118
119    //
120    // Local variables
121    //
122
123    //
124    // Begin at zero.
125    //
126    SUM = 0;
127
128    //
129    // Sum the elements. If N is zero or negative, nothing happens.
130    //
131    for I in 1..=N {
132        SUM = (SUM + ARRAY[I]);
133    }
134
135    //
136    // Return the sum.
137    //
138    SUMAI = SUM;
139
140    SUMAI
141}