! This automatically generated Fortran wrapper file allows codes
! written in Fortran to be called directly from C and translates all
! C-style arguments into expected Fortran-style arguments (with
! assumed size, local type declarations, etc.).


MODULE C_FAST_SORT
USE ISO_FORTRAN_ENV , ONLY : REAL32 , INT64
USE SWAP , ONLY : SWAP_I64 , SWAP_R32
  IMPLICIT NONE


CONTAINS


  
  SUBROUTINE C_ARGSORT(VALUES_DIM_1, VALUES, INDICES_DIM_1, INDICES, MIN_SIZE_PRESENT, MIN_SIZE) BIND(C)
    USE ISO_C_BINDING, ONLY: C_BOOL
    USE FAST_SORT, ONLY: ARGSORT
    IMPLICIT NONE
    INTEGER(KIND=SELECTED_INT_KIND(18)), INTENT(IN) :: VALUES_DIM_1
    REAL(KIND=REAL32), INTENT(INOUT), DIMENSION(VALUES_DIM_1) :: VALUES
    INTEGER(KIND=SELECTED_INT_KIND(18)), INTENT(IN) :: INDICES_DIM_1
    INTEGER(KIND=INT64), INTENT(INOUT), DIMENSION(INDICES_DIM_1) :: INDICES
    LOGICAL(KIND=C_BOOL), INTENT(IN) :: MIN_SIZE_PRESENT
    INTEGER(KIND=INT64), INTENT(IN) :: MIN_SIZE
  
    IF (MIN_SIZE_PRESENT) THEN
      CALL ARGSORT(VALUES=VALUES, INDICES=INDICES, MIN_SIZE=MIN_SIZE)
    ELSE
      CALL ARGSORT(VALUES=VALUES, INDICES=INDICES)
    END IF
  END SUBROUTINE C_ARGSORT
  

  
  SUBROUTINE C_INSERTION_ARGSORT(VALUES_DIM_1, VALUES, INDICES_DIM_1, INDICES) BIND(C)
    USE FAST_SORT, ONLY: INSERTION_ARGSORT
    IMPLICIT NONE
    INTEGER(KIND=SELECTED_INT_KIND(18)), INTENT(IN) :: VALUES_DIM_1
    REAL(KIND=REAL32), INTENT(INOUT), DIMENSION(VALUES_DIM_1) :: VALUES
    INTEGER(KIND=SELECTED_INT_KIND(18)), INTENT(IN) :: INDICES_DIM_1
    INTEGER(KIND=INT64), INTENT(INOUT), DIMENSION(INDICES_DIM_1) :: INDICES
  
    CALL INSERTION_ARGSORT(VALUES, INDICES)
  END SUBROUTINE C_INSERTION_ARGSORT
  

  
  SUBROUTINE C_ARGPARTITION(VALUES_DIM_1, VALUES, INDICES_DIM_1, INDICES, LEFT) BIND(C)
    USE FAST_SORT, ONLY: ARGPARTITION
    IMPLICIT NONE
    INTEGER(KIND=SELECTED_INT_KIND(18)), INTENT(IN) :: VALUES_DIM_1
    REAL(KIND=REAL32), INTENT(INOUT), DIMENSION(VALUES_DIM_1) :: VALUES
    INTEGER(KIND=SELECTED_INT_KIND(18)), INTENT(IN) :: INDICES_DIM_1
    INTEGER(KIND=INT64), INTENT(INOUT), DIMENSION(INDICES_DIM_1) :: INDICES
    INTEGER(KIND=INT64) :: LEFT
  
    LEFT = ARGPARTITION(VALUES, INDICES)
  END SUBROUTINE C_ARGPARTITION
  
END MODULE C_FAST_SORT

