Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Using MaxLoc

sabalan
New Contributor I
924 Views
I have a one-dimensional Real(8):: array(dim) which beginsat 0.D0, goes up to a calculated value, say 51.5787511797424, stays constant there a while and then goes back to 0.D0. I am trying to find the location of the maximum value in this array.
MaxLoc should find the first occurrence of the maximum value, but it finds sometimes the first occurrence of the maximum constant value and sometimes the last one depending on the input values to the program. I can see that the hex valuesare different -
sometimes #4049CA1484C6C1E8,
sometimes #4049CA1484C6C1EC, and
sometimes #4049CA1484C6C1F0.
My question is: how can I always find the first occurrence of that "constant" decimal value which is "seen", the first "top" point, regardless of those tiny fluctuations which follow the first top point?I can not think of aMASK which canbe usedthere.
I am talking about CVF.
Thanks for any help.
Sabalan.
0 Kudos
4 Replies
TimP
Honored Contributor III
924 Views
If I understand you correctly, you want maxloc() to work as if you first converted the values to decimal, e.g. with a g15 format. This would be fairly complicated, depending on your exact requirements.If you displayed the values you quoted with 17 decimal significant digits, no doubt you would see the differences.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
924 Views
Isn't a simple solution to roll your own DO loop with custom rounding within?

Jugoslav
0 Kudos
sabalan
New Contributor I
924 Views

Thanks Yugoslav. I had own DO loop there and changed it to MaxLoc because the curve happens not to beascendant all the way to the top.

Thanks Tim. That is all decimals which the debugger shows me and I don't know if I can change this setting. But my problem was the opposit: I wanted to make MaxLoc NOT to see those last decimals, and I found, for my case, a very simple solution:

M_Loc = MaxLoc(SNGL(array))

This cuts away last decimals and makes MaxLoc stop at the first occurrence of the "constant" maximum.

Sabalan.
0 Kudos
jim_dempsey
Beginner
924 Views
MaxLoc is returning the correct value
sometimes #4049CA1484C6C1E8,
sometimes #4049CA1484C6C1EC, and
sometimes #4049CA1484C6C1F0.
The last in the list is the highest value. The solutionj you found may be too aggressive (i.e. discarding more precision than you want). Also the you must be sure your exponent doesn't max out.
If you want to reduce the precision fast then make a union of your real(8) with an integer(8) and make a prepass (filter) using bitwise AND to truncate (or round)the least significant bits that you deem are insignificant. If you want to keep the original data then copy with bitwise AND and get the max from the copy.
Jim Dempsey
0 Kudos
Reply