On 9/6/2015 5:05 AM, Tim Prince wrote:
> On 9/5/2015 10:45 PM, nik@cabana wrote:
>
>>
>> I am beginner in Frotran. I am trying to check maxloc function on Arrays using following simple program:
>>
>> program Arrays
>> IMPLICIT NONE
>>
>> integer :: i
>> integer :: d(10)
>> d=(/5,6,8,9,4,6,7,9,10,3/)
It looks better if you write:
d = [5,6,8,9,4,6,7,9,10,3]
Using (/ and /) is only needed if your punch cards
cannot deal with the [ and ] characters.
>> i=maxloc(d)
>> write(*,*) i
>>
>> end program Arrays
>>
>> On compilation, it gives me an error that The shapes of the Array expressions do not conform. [I] Line 7
>>
>> My aim is to just determine location of maximum value in the vector d. Can somebody help me with this?
>>
>
>>
> You probably want the usual maxloc(d,dim=1). Without the (f95 and
> later) dim argument, the result is returned in an array:
> integer i(1)
And before f95 (and even later) we used this trick:
i = max(maxloc(d))
which looks puzzling, but is just the way to pick the
single element out of the array. Exactly the same can
be done like this: (but with even more confusion)
i = min(maxloc(d))
i = maxval(maxloc(d))
Fortran does not allow to write what is actually meant:
i = maxloc(d)(1)
(NB: I forgot why exactly this is disallowed, it must
have something to do with the possibility of ambiguous
syntax resulting.. If something is an array, why can't
we just subscript it?)
--
Jos