unique(3f) - [M_sort] return array with adjacent duplicate values removed (LICENSE:PD)
Synopsis
Description
Options
Examples
subroutine unique(array,ivals)
class(*),intent(inout) :: array(:) integer,intent(out) :: ivals
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.
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
Sample program
program demo_unique use M_sort, only : unique implicit none character(len=:),allocatable :: strings(:) integer,allocatable :: ints(:) integer :: icount integer :: ilongExpected outputstrings=[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
ORIGINAL:orange green green red white blue yellow blue magenta cyan black SIZE=11AFTER :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
Nemo Release 3.1 | unique (3) | February 23, 2025 |