Commit 5094ddae authored by Henderson, Shane's avatar Henderson, Shane
Browse files

Merge branch 'int_real_sort' into 'master'

Implement another sorting subroutine

See merge request https://code.ornl.gov/futility/Futility/-/merge_requests/410
parents 8f6c02e3 fa30bc33
Loading
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -6388,23 +6388,28 @@ SUBROUTINE preRead(thisHDF5File,path,rank,dset_id,dspace_id,dims,error)
  ! Open the dataset
  CALL h5dopen_f(thisHDF5File%file_id, path, dset_id, error)
  IF(error /= 0) CALL thisHDF5File%e%raiseError(modName//'::'//myName// &
      ' - Failed to open dataset "'//path//'".')
      ' - Failed to open dataset "'//path//'" in file "'// &
      thishdf5file%getFilePath()//thishdf5file%getFileName()//thishdf5file%getFileExt()//'".')

  ! Get dataset dimensions for allocation
  CALL h5dget_space_f(dset_id,dspace_id,error)
  IF(error /= 0) CALL thisHDF5File%e%raiseError(modName//'::'//myName// &
      ' - Failed to obtain the dataspace for dataset "'//path//'".')
      ' - Failed to obtain the dataspace for dataset "'//path//'" in file "'// &
      thishdf5file%getFilePath()//thishdf5file%getFileName()//thishdf5file%getFileExt()//'".')

  ! Make sure the rank is right
  IF(rank > 0) THEN
    CALL h5sget_simple_extent_ndims_f(dspace_id,ndims,error)
    IF(error < 0) CALL thisHDF5File%e%raiseError(modName//'::'//myName// &
        ' - Failed to retrieve number of dataspace dimensions for dataset "'//path//'".')
        ' - Failed to retrieve number of dataspace dimensions for dataset "'//path//'" in file "'// &
      thishdf5file%getFilePath()//thishdf5file%getFileName()//thishdf5file%getFileExt()//'".')
    IF(ndims /= rank) CALL thisHDF5File%e%raiseError(modName//'::'//myName// &
        ' - Using wrong read function for rank for dataset "'//path//'".')
        ' - Using wrong read function for rank for dataset "'//path//'" in file "'// &
      thishdf5file%getFilePath()//thishdf5file%getFileName()//thishdf5file%getFileExt()//'".')
    CALL h5sget_simple_extent_dims_f(dspace_id,dims,maxdims,error)
    IF(error < 0) CALL thisHDF5File%e%raiseError(modName//'::'//myName// &
        ' - Failed to retrieve dataspace dimensions for dataset "'//path//'".')
        ' - Failed to retrieve dataspace dimensions for dataset "'//path//'" in file "'// &
      thishdf5file%getFilePath()//thishdf5file%getFileName()//thishdf5file%getFileExt()//'".')
  ELSE
    dims=1
  ENDIF
+49 −0
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@ INTERFACE sort
  !> @copybrief Sorting::bubble_sort_1DInt_1DInt
  !> @copydetails Sorting::bubble_sort_1DInt_1DInt
  MODULE PROCEDURE bubble_sort_1DInt_1DInt
  !> @copybrief Sorting::bubble_sort_1DInt_1DReal
  !> @copydetails Sorting::bubble_sort_1DInt_1DReal
  MODULE PROCEDURE bubble_sort_1DInt_1DReal
  !> @copybrief Sorting::bubble_sort_1DInt_1DStr
  !> @copydetails Sorting::bubble_sort_1DInt_1DStr
  MODULE PROCEDURE bubble_sort_1DInt_1DStr
@@ -414,6 +417,52 @@ ENDSUBROUTINE bubble_sort_1DInt_1DInt
!>        sorting.
!> @example
!>        int1=(/5,-1,10/)
!>        real2=(/-1.0,-2.0,-3.0/)
!>        CALL bubble_sort_1DInt_1DReal(int1,real2)
!>        int1=(/-1,5,10/)
!>        real2=(/-2.0,-1.0,-3.0/)
!> @param int1 A 1-D array of unsorted integers
!> @param real2 A 1-D array of unsorted reals
!>
PURE SUBROUTINE bubble_sort_1DInt_1DReal(int1,real2)
  INTEGER(SIK),INTENT(INOUT) :: int1(:)
  REAL(SRK),INTENT(INOUT) :: real2(:)
  !LOGICAL(SBK),INTENT(IN),OPTIONAL :: reverse
  LOGICAL(SBK) :: sorted
  INTEGER(SIK) :: i,ni,nr,ncomp
  INTEGER(SIK) :: tmpi
  REAL(SRK) :: tmpr

  sorted=.FALSE.
  ni=SIZE(int1,DIM=1)
  nr=SIZE(real2,DIM=1)
  ncomp=0
  IF(ni == nr) THEN
    DO WHILE(.NOT.sorted)
      sorted=.TRUE.
      ncomp=ncomp+1
      DO i=1,ni-ncomp
        IF(int1(i) > int1(i+1)) THEN
          tmpi=int1(i+1)
          int1(i+1)=int1(i)
          int1(i)=tmpi
          tmpr=real2(i+1)
          real2(i+1)=real2(i)
          real2(i)=tmpr
          sorted=.FALSE.
        ENDIF
      ENDDO
    ENDDO
  ENDIF
ENDSUBROUTINE bubble_sort_1DInt_1DReal
!
!-------------------------------------------------------------------------------
!> @brief A simple sorting algorithm for a 2 1-D array sorting.  The first array's
!>        data will be sorted in ascending/increasing order and returned.  The
!>        second array's data will be sorted positionally based on the first arrays
!>        sorting.
!> @example
!>        int1=(/5,-1,10/)
!>        str1=(/'g','a','d'/)
!>        CALL bubble_sort_1DInt_1DStr(int1,str1)
!>        int1=(/-1,5,10/)