Skip to content

Commit

Permalink
GitHub Issue NOAA-EMC#13. Continuing to clear through coding standard…
Browse files Browse the repository at this point in the history
… issues in the master. Finished through src/gsi/m_sstnode.F90.
  • Loading branch information
MichaelLueken committed Aug 14, 2020
1 parent 0b01a67 commit 856d5f8
Show file tree
Hide file tree
Showing 5 changed files with 548 additions and 543 deletions.
87 changes: 46 additions & 41 deletions src/gsi/m_sortind.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module m_sortind
! assimilation
!
! program history log:
! 1996-10-01 Joiner/Karki - initial coding from NASA/GMAO
! 2012-02-15 eliu - reformat to use in GSI
! 1996-10-01 Joiner/Karki - initial coding from nasa/gmao
! 2012-02-15 eliu - reformat to use in gsi
!
! subroutines included:
!
Expand All @@ -24,8 +24,8 @@ module m_sortind

use kinds,only : i_kind, r_kind
interface sortind
module procedure r_sortind
module procedure i_sortind
module procedure r_sortind
module procedure i_sortind
end interface

contains
Expand Down Expand Up @@ -53,34 +53,36 @@ function i_sortind(arr) result(arr2)

end function i_sortind

SUBROUTINE indexx(n,arr,indx)
subroutine indexx(n,arr,indx)

INTEGER(i_kind):: n,indx(n),M,NSTACK
REAL(r_kind) :: arr(n)
PARAMETER (M=7,NSTACK=50)
INTEGER(i_kind):: i,indxt,ir,itemp,j,jstack,k,l,istack(NSTACK)
REAL(r_kind) :: a
implicit none

integer(i_kind):: n,indx(n),m,nstack
real(r_kind) :: arr(n)
parameter (m=7,nstack=50)
integer(i_kind):: i,indxt,ir,itemp,j,jstack,k,l,istack(nstack)
real(r_kind) :: a
do 11 j=1,n
indx(j)=j
11 continue
jstack=0
l=1
ir=n
loop2: do
if(ir-l.lt.M)then
if(ir-l<m)then
loop: do j=l+1,ir
indxt=indx(j)
a=arr(indxt)
do 12 i=j-1,1,-1
if(arr(indx(i)).le.a)then
if(arr(indx(i))<=a)then
indx(i+1)=indxt
cycle loop
end if
indx(i+1)=indx(i)
12 continue
indx(1)=indxt
end do loop
if(jstack.eq.0)return
if(jstack==0)return
ir=istack(jstack)
l=istack(jstack-1)
jstack=jstack-2
Expand Down Expand Up @@ -110,22 +112,22 @@ SUBROUTINE indexx(n,arr,indx)
a=arr(indxt)
loop1: do
i=i+1
if(arr(indx(i)).lt.a)cycle loop1
if(arr(indx(i))<a)cycle loop1
do
4 continue
4 continue
j=j-1
if(arr(indx(j))<=a)exit
end do
if(j.lt.i)exit loop1
if(j<i)exit loop1
itemp=indx(i)
indx(i)=indx(j)
indx(j)=itemp
end do loop1
5 indx(l)=indx(j)
indx(j)=indxt
jstack=jstack+2
if(jstack.gt.NSTACK)pause 'NSTACK too small in indexx'
if(ir-i+1.ge.j-l)then
if(jstack>nstack)pause 'NSTACK too small in indexx'
if(ir-i+1>=j-l)then
istack(jstack)=ir
istack(jstack-1)=i
ir=j-1
Expand All @@ -136,35 +138,38 @@ SUBROUTINE indexx(n,arr,indx)
endif
endif
end do loop2
END subroutine indexx

SUBROUTINE iindexx(n,arr,indx)
INTEGER(i_kind):: n,indx(n),M,NSTACK
INTEGER(i_kind):: arr(n)
PARAMETER (M=7,NSTACK=50)
INTEGER(i_kind):: i,indxt,ir,itemp,j,jstack,k,l,istack(NSTACK)
INTEGER(i_kind):: a
end subroutine indexx

subroutine iindexx(n,arr,indx)

implicit none

integer(i_kind):: n,indx(n),m,nstack
integer(i_kind):: arr(n)
parameter (m=7,nstack=50)
integer(i_kind):: i,indxt,ir,itemp,j,jstack,k,l,istack(nstack)
integer(i_kind):: a
do 11 j=1,n
indx(j)=j
11 continue
jstack=0
l=1
ir=n
loop2: do
if(ir-l.lt.M)then
if(ir-l<m)then
loop: do j=l+1,ir
indxt=indx(j)
a=arr(indxt)
do 12 i=j-1,1,-1
if(arr(indx(i)).le.a)then
indx(i+1)=indxt
cycle loop
if(arr(indx(i))<=a)then
indx(i+1)=indxt
cycle loop
end if
indx(i+1)=indx(i)
12 continue
indx(1)=indxt
end do loop
if(jstack.eq.0)return
if(jstack==0)return
ir=istack(jstack)
l=istack(jstack-1)
jstack=jstack-2
Expand All @@ -173,17 +178,17 @@ SUBROUTINE iindexx(n,arr,indx)
itemp=indx(k)
indx(k)=indx(l+1)
indx(l+1)=itemp
if(arr(indx(l+1)).gt.arr(indx(ir)))then
if(arr(indx(l+1))>arr(indx(ir)))then
itemp=indx(l+1)
indx(l+1)=indx(ir)
indx(ir)=itemp
endif
if(arr(indx(l)).gt.arr(indx(ir)))then
if(arr(indx(l))>arr(indx(ir)))then
itemp=indx(l)
indx(l)=indx(ir)
indx(ir)=itemp
endif
if(arr(indx(l+1)).gt.arr(indx(l)))then
if(arr(indx(l+1))>arr(indx(l)))then
itemp=indx(l+1)
indx(l+1)=indx(l)
indx(l)=itemp
Expand All @@ -201,16 +206,16 @@ SUBROUTINE iindexx(n,arr,indx)
j=j-1
if(arr(indx(j))<=a)exit
end do
if(j.lt.i)exit loop1
itemp=indx(i)
indx(i)=indx(j)
indx(j)=itemp
if(j<i)exit loop1
itemp=indx(i)
indx(i)=indx(j)
indx(j)=itemp
end do loop1
indx(l)=indx(j)
indx(j)=indxt
jstack=jstack+2
if(jstack.gt.NSTACK)pause 'NSTACK too small in indexx'
if(ir-i+1.ge.j-l)then
if(jstack>nstack)pause 'NSTACK too small in indexx'
if(ir-i+1>=j-l)then
istack(jstack)=ir
istack(jstack-1)=i
ir=j-1
Expand All @@ -221,6 +226,6 @@ SUBROUTINE iindexx(n,arr,indx)
endif
endif
end do loop2
END subroutine iindexx
end subroutine iindexx

end module m_sortind
Loading

0 comments on commit 856d5f8

Please sign in to comment.