目的
配列内の選択されたエレメントの合計を計算します。
クラス
変換関数
引き数の型と属性
結果の値
DIM が存在する場合は、結果は ARRAY と同じデータ型を持つ、ランク rank(ARRAY)-1 の配列になります。 DIM が脱落している場合、または MASK のランクが 1 の場合は、 結果はスカラーになります。
結果は、以下のいずれかの方式で計算されます。
+---------------------------------Fortran 95---------------------------------+
DIM と MASK はどちらもオプションであるため、 引き数のさまざまな組み合わせが可能になります。 -qintlog オプションが 2 つの引き数を指定すると、2 番目の 引き数は次のうちの 1 つを参照します。
+-----------------------------End of Fortran 95------------------------------+
例
方式 1:
! Sum all the elements in an array. RES = SUM( (/2, 3, 4 /) ) ! The result is 9 because (2+3+4) = 9
方式 2:
! A is the array (/ -3, -7, -5, 2, 3 /) ! Sum all elements that are greater than -5. RES = SUM( A, MASK = A .GT. -5 ) ! The result is 2 because (-3 + 2 + 3) = 2
方式 3:
! B is the array | 4 2 3 | ! | 7 8 5 | ! Sum the elements in each column. RES = SUM(B, DIM = 1) ! The result is | 11 10 8 | because (4 + 7) = 11 ! (2 + 8) = 10 ! (3 + 5) = 8 ! Sum the elements in each row. RES = SUM(B, DIM = 2) ! The result is | 9 20 | because (4 + 2 + 3) = 9 ! (7 + 8 + 5) = 20 ! Sum the elements in each row, considering only ! those elements greater than two. RES = SUM(B, DIM = 2, MASK = B .GT. 2) ! The result is | 7 20 | because (4 + 3) = 7 ! (7 + 8 + 5) = 20