Skip to content

Commit

Permalink
Merge pull request #57 from hphratchian/master
Browse files Browse the repository at this point in the history
Sort added to general and updated version number.
  • Loading branch information
hphratchian authored May 27, 2023
2 parents 9161046 + d9d317e commit fd96ff9
Showing 1 changed file with 93 additions and 16 deletions.
109 changes: 93 additions & 16 deletions src/mqc_general.F03
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ Module MQC_General
module procedure real2character
module procedure complex2character
end interface
!
interface sort
module procedure mqc_bubbleSort_integer
module procedure mqc_bubbleSort_real
end interface
!
interface flatten
module procedure mqc_flattenR4Real
Expand Down Expand Up @@ -159,10 +164,10 @@ subroutine mqc_version(major,minor,revision,versionString)
integer,OPTIONAL,intent(out)::major,minor,revision
character(len=*),OPTIONAL,intent(out)::versionString
!
if(PRESENT(major)) major = 22
if(PRESENT(minor)) minor = 12
if(PRESENT(major)) major = 23
if(PRESENT(minor)) minor = 5
if(PRESENT(revision)) revision = 1
if(PRESENT(versionString)) versionString = '22.12.1'
if(PRESENT(versionString)) versionString = '23.05.1'
!
return
end subroutine mqc_version
Expand Down Expand Up @@ -2049,29 +2054,100 @@ end subroutine mqc_matrixInverse_symmFull
! |
!----------------------------------------------------------------
!
!PROCEDURE mqc_bubbleSort
subroutine mqc_bubbleSort(listIn,listOut,listMap)
!PROCEDURE mqc_bubbleSort_integer
subroutine mqc_bubbleSort_integer(listIn,listOut,map,sortListIn)
!
! This subroutine carries out a simple bubble sort algorithm to order the
! values in the array <listIn>. The sorted list is returned in the optional
! argument <listOut> if it is sent. The mapping of the unsorted list to the
! sorted list is returned in the optional argument <map>. If neither
! <listOut> or <map> is sent, then the sorted list will overwrite the input
! data in listIn. If <listOut> and/or <map> are sent, it should already be
! appropriately allocated. If <sortListIn> is sent and is TRUE, then listIn
! is always returned with the sorted values.
!
! H. P. Hratchian, 2023.
!
!
! Variabile Declarations
implicit none
integer(kind=int64),dimension(:)::listIn
integer(kind=int64),dimension(:),optional::listOut,map
logical,optional::sortListIn
integer(kind=int64)::i,j,nDim,nSwaps,valueTemp
integer(kind=int64),dimension(:),allocatable::listTemp,listMapTemp
logical::overwriteListIn
!
! Allocate listTemp and copy listIn into it.
!
overwriteListIn = .false.
if(PRESENT(sortListIn)) overwriteListIn = sortListIn
nDim = Size(listIn)
Allocate(listTemp(nDim),listMapTemp(nDim))
listTemp = listIn
call mqc_seq(listMapTemp)
!
! Carry out the bubble sort algorithm on listTemp.
!
do i = 1,nDim
nSwaps = 0
do j = 1,nDim-i
if(listTemp(j).gt.listTemp(j+1)) then
nSwaps = nSwaps + 1
valueTemp = listTemp(j)
listTemp(j) = listTemp(j+1)
listTemp(j+1) = valueTemp
valueTemp = listMapTemp(j)
listMapTemp(j) = listMapTemp(j+1)
listMapTemp(j+1) = valueTemp
endIf
endDo
if(nSwaps.eq.0) exit
endDo
!
! Put the sorted list into listOut or back into listIn.
!
if(PRESENT(listOut)) listOut = listTemp
if(PRESENT(map)) map = listMapTemp
if(overwriteListIn.or.(.not.(PRESENT(listOut).or.PRESENT(map)))) &
listIn = listTemp
!
return
end subroutine mqc_bubbleSort_integer


!
!PROCEDURE mqc_bubbleSort_real
subroutine mqc_bubbleSort_real(listIn,listOut,map,sortListIn)
!
! This subroutine carries out a simple bubble sort algorithm to order the
! values in the array <listIn>. The sorted list is returned in the optional
! argument <listOut> if it is sent. The mapping of the unsorted list to the
! sorted list is returned in the optional argument <listMap>. If neither
! <listOut> or <listMap> is sent, then the sorted list will overwrite the
! input data in listIn. If <listOut> and/or <listMap> are sent, it should
! already be appropriately allocated.
! sorted list is returned in the optional argument <map>. If neither
! <listOut> or <map> is sent, then the sorted list will overwrite the input
! data in listIn. If <listOut> and/or <map> are sent, it should already be
! appropriately allocated. If <sortListIn> is sent and is TRUE, then listIn
! is always returned with the sorted values.
!
! H. P. Hratchian, 2023.
!
!
! Variabile Declarations
implicit none
integer,dimension(:)::listIn
integer,dimension(:),optional::listOut,listMap
integer::i,j,nDim,nSwaps,valueTemp
integer,dimension(:),allocatable::listTemp,listMapTemp
real(kind=real64),dimension(:)::listIn
real(kind=real64),dimension(:),optional::listOut
integer(kind=int64),dimension(:),optional::map
logical,optional::sortListIn
integer(kind=int64)::i,j,nDim,nSwaps
integer(kind=int64),dimension(:),allocatable::listMapTemp
real(kind=real64)::valueTemp
real(kind=real64),dimension(:),allocatable::listTemp
logical::overwriteListIn
!
! Allocate listTemp and copy listIn into it.
!
overwriteListIn = .false.
if(PRESENT(sortListIn)) overwriteListIn = sortListIn
nDim = Size(listIn)
Allocate(listTemp(nDim),listMapTemp(nDim))
listTemp = listIn
Expand All @@ -2098,11 +2174,12 @@ subroutine mqc_bubbleSort(listIn,listOut,listMap)
! Put the sorted list into listOut or back into listIn.
!
if(PRESENT(listOut)) listOut = listTemp
if(PRESENT(listMap)) listMap = listMapTemp
if(.not.(PRESENT(listOut).or.PRESENT(listMap))) listIn = listTemp
if(PRESENT(map)) map = listMapTemp
if(overwriteListIn.or.(.not.(PRESENT(listOut).or.PRESENT(map)))) &
listIn = listTemp
!
return
end
end subroutine mqc_bubbleSort_real


!
Expand Down

0 comments on commit fd96ff9

Please sign in to comment.