indexx.f90

Path: src/indexx.f90
Last Update: Tue Feb 22 17:07:20 JST 2005

    Copyright (c) 2002 Shin-ichi Takehiro. All rights reserved.

表題 INDEXX :" 小さい順番号付け

履歴 1992/12/17 竹広真一 Numerical Recipies より移植

     2002/07/06   竹広真一 Fortran90 版

備考 大きさで並び変えるには次のようにすればよい

       index = indexx(array)
       array = array(index)                      ! 小さい順
       array = array(index(size(index):1:-1)     ! 大きい順

Methods

indexx  

Public Instance methods

indexx :integer, dimension(size(arrin))
arrin :real(8), dimension(:), intent(in)

[Source]

  function indexx(arrin)
    implicit none
    real(8), dimension(:), intent(in)  :: arrin
    integer, dimension(size(arrin))    :: indexx

    integer :: ir, l, i, j, indxt
    real(8) :: Q

    integer :: n

    n = size(arrin)

    indexx = (/(j, j=1,n)/)

    l  = n/2 + 1
    ir = n

10  continue

    if( l .gt. 1 )then
       l     = l - 1
       indxt = indexx(l)
       q     = arrin(indxt)
    else
       indxt = indexx(ir)
       q     = arrin(indxt)
       indexx(ir) = indexx(1)
       ir = ir - 1
       if( ir .eq. 1 )then
          indexx(1) = indxt
          return
       endif
    endif
    i = l
    j = l + l

20  if( j .le. ir )then
       if( j .lt. ir )then
          if( arrin( indexx(j) ) .lt. arrin( indexx(j+1) )  ) j = j + 1
       endif
       if(  q .lt. arrin( indexx(j) )  )then
          indexx( i ) = indexx( j )
          i = J
          j = j + j
       else
          j = ir + 1
       endif
       go to 20
    endif
    indexx( i ) = indxt
    go to 10

  end function indexx

[Validate]