C Library Functions  - unique (3)

NAME

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

CONTENTS

Synopsis
Description
Options
Example

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


Nemo Release 3.1 unique (3) July 22, 2023
Generated by manServer 1.08 from 8d307349-74eb-47bd-b3a7-6b534927b4f6 using man macros.