Clicky

Fortran Wiki
sum (Rev #2, changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #1 to #2: (追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)

Description

Adds the elements of array along dimension dim if the corresponding element in mask is true.

Standard

(削除) Fortran 95 and later (削除ここまで)(追記) Fortran 95 (追記ここまで)(追記) and later (追記ここまで)

Class

Transformational function

Syntax

result = sum(array[, mask]) result = sum(array, dim[, mask])

Arguments

  • array - Shall be an array of type integer, real or complex.
  • dim - (Optional) shall be a scalar of type integer with a value in the range from 1 to n, where n equals the rank of array.
  • mask - (Optional) shall be of type logical and either be a scalar or an array of the same shape as array.

Return value

The result is of the same type as array.

If dim is absent, a scalar with the sum of all elements in array is returned. Otherwise, an array of rank n-1, where n equals the rank of array,and a shape similar to that of array with dimension dim dropped is returned.

Example

program test_sum
 integer :: x(5) = (/ 1, 2, 3, 4 ,5 /)
 print *, sum(x) ! all elements, sum = 15
 print *, sum(x, mask=mod(x, 2)==1) ! odd elements, sum = 9
end program

See also

product

category: (削除) Intrinsics (削除ここまで)(追記) intrinsics (追記ここまで)

Revision from April 30, 2009 17:34:14 by Jason Blevins
Forward in time (to current) | Back in time (1 more) | See current | Hide changes | History | Rollback | View: Source | Linked from: Intrinsic procedures, product, norm2

AltStyle によって変換されたページ (->オリジナル) /