If I print maxloc(datinlns(n,:,3)), I get the integer location of the maximum value of the second dimension. n has an assigned value in the code. If I write imax= maxloc(datinlns(n,:,3)), the compiler complains that there is an " error #6366: The shapes of the array expressions do not conform."
If I write maxval(datinlns(n,:,3)), I get the expected result: the maximum value of the second dimension. What is up with maxloc? I'm using the 2017 beta.
The result is an array of type integer.
So you can't assign an array to an integer variable.
[edited ... I thought this would work, but it doesn't]
imax = maxloc(datainlns(n,:,3))(1)
What I have used in the past is this method:
imax = sum(maxloc(datainlns(n,:,3)))
Alternatively, you could define imax as an array of size (1), but then you may need to replace references to imax with imax(1) where scalars are needed.
The dim argument for maxloc and minloc was added in f95. I see very little attempt to restrict usage to f90 in the last decade.
By the way, 16.0.3 seems to treat noold_maxminloc the way 16.0.1 did, no simd.
I suggest that both of you take another look at the documentation. What is wanted here is the optional DIM argument. By default, MAXLOC indeed returns an array of results, one for each dimension, giving you the subscript of the maximum value location. In the case of a dimension-1 array argument, specifying DIM=1 will get you the first value from that array which is what you want. Like this:
It gets a bit more complicated if the first argument is an array with more than one dimension, but the standard specifies the behavior.
I read the documentation and Metcalf w/o much help. Your solution seems to work. Since the syntax is the same as that of Maxval (i.e., work on the dimension denoted by the ':', I still don't understand why one needs the DIM=1. Just an inconsistency in definitions or am I missing something subtle? Where do you think I can find the best description for the (X,:,Y) syntax?
The definitions of MAXVAL and MAXLOC, with a single array argument, are different. MAXVAL(array) returns a single value whereas MAXLOC returns an array of indexes telling you WHERE in the array that maximum value is.
(X,:,Y) is an array section where the second dimension is all the indexes in that dimension so the result is a rank-1 array. (I am assuming X and Y are scalars.) You can look up "array section" in the documentation.