Fortran-reduction

提供:Dev Guides
移動先:案内検索

Fortran-縮約関数

次の表に、縮約関数を示します。

Function Description
all(mask, dim) It returns a logical value that indicates whether all relations in mask are .true., along with only the desired dimension if the second argument is given.
any(mask, dim) It returns a logical value that indicates whether any relation in mask is .true., along with only the desired dimension if the second argument is given.
count(mask, dim) It returns a numerical value that is the number of relations in mask which are .true., along with only the desired dimension if the second argument is given.
maxval(array, dim, mask) It returns the largest value in the array array, of those that obey the relation in the third argument mask, if that one is given, along with only the desired dimension if the second argument dim is given.
minval(array, dim, mask) It returns the smallest value in the array array, of those that obey the relation in the third argument mask, if that one is given, along with only the desired dimension if the second argument DIM is given.
product(array, dim, mask) It returns the product of all the elements in the array array, of those that obey the relation in the third argument mask, if that one is given, along with only the desired dimension if the second argument dim is given.
sum (array, dim, mask) It returns the sum of all the elements in the array array, of those that obey the relation in the third argument mask, if that one is given, along with only the desired dimension if the second argument dim is given.
  • 例 *

次の例は、概念を示しています。

program arrayReduction

   real, dimension(3,2) :: a
   a = reshape( (/5,9,6,10,8,12/), (/3,2/) )

   Print* , all(a>5)
   Print *, any(a>5)
   Print *, count(a>5)
   Print *, all(a>=5 .and. a<10)

end program arrayReduction

上記のコードをコンパイルして実行すると、次の結果が生成されます。

F
T
5
F
  • 例 *

次の例は、概念を示しています。

program arrayReduction
implicit none

   real, dimension(1:6) :: a = (/21.0, 12.0,33.0, 24.0, 15.0, 16.0/)
   Print* , maxval(a)
   Print *, minval(a)
   Print *, sum(a)
   Print *, product(a)

end program arrayReduction

上記のコードをコンパイルして実行すると、次の結果が生成されます。

33.0000000
12.0000000
121.000000
47900160.0