unique Interface

public interface unique

Module Procedures

private subroutine unique_integer_int8(array, ivals)

NAME

unique(3f) - [M_sort] return array with adjacent duplicate values
removed
(LICENSE:PD)

SYNOPSIS

subroutine unique(array,ivals)

 class(*),intent(inout)  :: array(:)
 integer,intent(out)     :: ivals

DESCRIPTION

 Assuming an array is sorted, return the array with adjacent duplicate
 values removed.

 If the input array is sorted, this will produce a list of unique
 values.

OPTIONS

array   may be of type INTEGER, REAL, CHARACTER, COMPLEX,
        DOUBLEPRECISION, or COMPLEX(KIND=KIND(0.0d0)).

ivals   returned number of unique values packed into beginning of array

EXAMPLE

Sample program

   program demo_unique
   use M_sort, only : unique
   implicit none
   character(len=:),allocatable :: strings(:)
   integer,allocatable :: ints(:)
   integer :: icount
   integer :: ilong

   strings=[character(len=20) :: 'orange','green','green', &
   & 'red','white','blue','yellow','blue','magenta','cyan','black']
   ints=[30,1,1,2,3,4,4,-10,20,20,30,3]
   ilong=maxval(len_trim(strings))

   write(*,'(a,*(a,1x))')'ORIGINAL:',strings(:)(:ilong)
   write(*,'("SIZE=",i0)')size(strings)
   call unique(strings,icount)
   write(*,*)
   write(*,'(a,*(a,1x))')'AFTER   :',strings(1:icount)(:ilong)
   write(*,'("SIZE=",i0)')size(strings)
   write(*,'("ICOUNT=",i0)')icount

   write(*,'(a,*(g0,1x))')'ORIGINAL:',ints
   write(*,'("SIZE=",i0)')size(ints)
   call unique(ints,icount)
   write(*,*)
   write(*,'(a,*(g0,1x))')'AFTER   :',ints(1:icount)
   write(*,'("SIZE=",i0)')size(ints)
   write(*,'("ICOUNT=",i0)')icount

   end program demo_unique

Expected output

ORIGINAL:orange  green   green   red     white   blue
yellow  blue    magenta cyan    black
SIZE=11

AFTER   :orange  green   red     white   blue    yellow
blue    magenta cyan    black
SIZE=11
ICOUNT=10

ORIGINAL:30 1 1 2 3 4 4 -10 20 20 30 3
SIZE=12

AFTER   :30 1 2 3 4 -10 20 30 3
SIZE=12
ICOUNT=8

Arguments

Type IntentOptional Attributes Name
integer(kind=int8), intent(inout) :: array(:)
integer, intent(out) :: ivals

private subroutine unique_integer_int16(array, ivals)

Arguments

Type IntentOptional Attributes Name
integer(kind=int16), intent(inout) :: array(:)
integer, intent(out) :: ivals

private subroutine unique_integer_int32(array, ivals)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(inout) :: array(:)
integer, intent(out) :: ivals

private subroutine unique_integer_int64(array, ivals)

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(inout) :: array(:)
integer, intent(out) :: ivals

private subroutine unique_real_real32(array, ivals)

Arguments

Type IntentOptional Attributes Name
real(kind=real32), intent(inout) :: array(:)
integer, intent(out) :: ivals

private subroutine unique_real_real64(array, ivals)

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(inout) :: array(:)
integer, intent(out) :: ivals

private subroutine unique_complex_real32(array, ivals)

Arguments

Type IntentOptional Attributes Name
complex(kind=real32), intent(inout) :: array(:)
integer, intent(out) :: ivals

private subroutine unique_complex_real64(array, ivals)

Arguments

Type IntentOptional Attributes Name
complex(kind=real64), intent(inout) :: array(:)
integer, intent(out) :: ivals

private subroutine unique_strings_allocatable_len(array, ivals)

Arguments

Type IntentOptional Attributes Name
character(len=:), intent(inout), allocatable :: array(:)
integer, intent(out) :: ivals

private subroutine unique_real_real128(array, ivals)

Arguments

Type IntentOptional Attributes Name
real(kind=real128), intent(inout) :: array(:)
integer, intent(out) :: ivals

private subroutine unique_complex_real128(array, ivals)

Arguments

Type IntentOptional Attributes Name
complex(kind=real128), intent(inout) :: array(:)
integer, intent(out) :: ivals