replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - minloc function
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

minloc function

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Mon Sep 29, 2014 8:18 am    Post subject: minloc function Reply with quote

I'd like to find the position of the smallest element in a vector, and I tried this:

Code:
      winapp
      program test
      implicit none
      include <windows.ins>

      integer*4      i
      real*8         r(4)

      r(1) = 0.D0
      r(2) = 7.2D0
      r(3) = -.8D0
      r(4) = 0.D0

      i = minloc(r)
      print*,i,r(i)   ! should give 3, -.8D0

      end


It failes with the message "Result has insufficient elements". Can anyone please help?

Thanks & regards
Wilfried
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 814
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Mon Sep 29, 2014 11:00 am    Post subject: Reply with quote

I've seen this one before, i must be dimensioned as a vector with one element.

Code:
       winapp
       program test
       implicit none
       include <windows.ins>

       integer*4      i(1)    !NOTE:: must be dimensioned.
       real*8         r(4)

       r(1) = 0.D0
       r(2) = 7.2D0
       r(3) = -.8D0
       r(4) = 0.D0

       i = minloc(r)
       print*,i,r(i)   ! should give 3, -.8D0

       end


Cheers
Ken
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Mon Sep 29, 2014 11:24 am    Post subject: Reply with quote

Ken, thanks a lot, now it works!

Wilfried
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Mon Sep 29, 2014 5:57 pm    Post subject: Reply with quote

Yes. In the original code, the result is an array of rank 1.

Alternatively, you can use the DIM argument to get a scalar result. So the original code becomes.

Code:

      winapp
      program test
      implicit none
      include <windows.ins>

      integer*4      i
      real*8         r(4)

      r(1) = 0.D0
      r(2) = 7.2D0
      r(3) = -.8D0
      r(4) = 0.D0

      i = minloc(r, dim=1)
      print*,i,r(i)   ! should give 3, -.8D0

      end

_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Tue Sep 30, 2014 8:21 am    Post subject: Reply with quote

Thanks again!

I was a bit confused because the related functions minval and maxval don't need such constructions but simply run with j = minval(r) or j = maxval(r).

Have a nice day
Wilfried
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Tue Sep 30, 2014 8:53 am    Post subject: Reply with quote

It puzzles me also, although if the array being scanned is of rank > 1 then the result is an array of the same rank and of size = rank.
Extrapolating this for a scanned array of rank 1 is a bit of an anomaly.

You'd think it would have been easier in this case to allow either
I = minloc(array) or I(1) = minloc(array)
to be acceptable.

this might be explained as
array = scalar ! is acceptable but
scalar = array ! is not ok

Just another tick in the box of avoiding this intrinsic function, which looks inefficient, especially for large arrays.

John
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group