目的
マスクの値が真になるすべてのエレメントの最大値を持つ配列の最初のエレメント を、次元に沿って見つけます。 MAXLOC は、正の整数を用いているエレメントの位置を参照できる指標を戻します。
クラス
変換関数
引き数の型と属性
+---------------------------------Fortran 95---------------------------------+
+-----------------------------End of Fortran 95------------------------------+
結果の値と属性
DIM が存在しない場合、結果はランク 1 の整数配列 で、ARRAY のランクに等しいサイズを持ちます。 DIM が存在する場合、結果はランク rank(ARRAY)-1 の整数配列で、 その形状は (s1, ..., sDIM-1, sDIM+1, ..., sn) となります。 この場合 n は ARRAY のランクを表しています。
最大値が存在しない場合 (おそらく、配列がゼロにサイズ決定されているか、または、 マスク配列がすべて .FALSE. の値を持っているか、または、DIM 引き数 がないのが原因) は、戻り値はサイズがゼロで 1 次元のエンティティーです。 DIM が存在する場合、結果の形状は ARRAY の ランクによって決まります。
結果の値
結果は ARRAY の、マスクされた最大エレメントの位置の添え字を示します。 複数のエレメントがこの最大値に等しいと、この関数は (配列エレメント順に) 最初の位置を 検出します。 DIM が指定されると、結果は次元の各ベクトルに沿った 最大マスク・エレメントの位置を示します。
+---------------------------------Fortran 95---------------------------------+
DIM と MASK はどちらもオプションであるため、 引き数のさまざまな組み合わせが可能になります。 -qintlog オプションが 2 つの引き数を指定すると、2 番目の 引き数は次のうちの 1 つを参照します。
+-----------------------------End of Fortran 95------------------------------+
例
! A is the array | 4 9 8 -8 | ! | 2 1 -1 5 | ! | 9 4 -1 9 | ! | -7 5 7 -3 | ! Where is the largest element of A? RES = MAXLOC(A) ! The result is | 3 1 | because 9 is located at A(3,1). ! Although there are other 9s, A(3,1) is the first in ! column-major order. ! Where is the largest element in each column of A ! that is less than 7? RES = MAXLOC(A, DIM = 1, MASK = A .LT. 7) ! The result is | 1 4 2 2 | because these are the corresponding ! row locations of the largest value in each column ! that are less than 7 (the values being 4,5,-1,5).
Regardless of the defined upper and lower bounds of the array, MAXLOC will determine the lower bound index as '1'. Both MAXLOC and MINLOC index using positive integers. To find the actual index:
INTEGER B(-100:100) ! Maxloc views the bounds as (1:201) ! If the largest element is located at index '-49' I = MAXLOC(B) ! Will return the index '52' ! To return the exact index for the largest element, insert: INDEX = LBOUND(B) - 1 + I ! Which is: INDEX = (-100) - 1 + 52 = (-49) PRINT*, B(INDEX)