add(3f) - [M_list] insert entry into an allocatable sorted string array if it is not present
Synopsis
Description
Options
Examples
subroutine add(varname,dictionary)character(len=*),intent=(in) :: VARNAME character(len=*),allocatable :: DICTIONARY(:)
Find if a string is in a sorted array, and insert the string into the dictionary if it is not present.
VARNAME the string value to place in the array. DICTIONARY is the dictionary array. It must be sorted in descending order.
If string is not found in a sorted array, insert the string
program demo_add use M_sort, only : sort_shell use M_list, only : add implicit none character(len=20),allocatable :: arr(:) integer :: iResults:arr=[character(len=20) :: ZZZ, aaa, b, xxx ] ! make sure sorted in descending order call sort_shell(arr,order=d)
write(*,101)(trim(arr(i)),i=1,size(arr)) ! show array call add(b, arr); write(*,101)(trim(arr(i)),i=1,size(arr)) ! show array call add(^, arr); write(*,101)(trim(arr(i)),i=1,size(arr)) ! show array call add( , arr); write(*,101)(trim(arr(i)),i=1,size(arr)) ! show array call add(c, arr); write(*,101)(trim(arr(i)),i=1,size(arr)) ! show array call add(ZZ, arr); write(*,101)(trim(arr(i)),i=1,size(arr)) ! show array call add(ZZZZ, arr); write(*,101)(trim(arr(i)),i=1,size(arr)) ! show array call add(z, arr); write(*,101)(trim(arr(i)),i=1,size(arr)) ! show array 101 format (1x,*("[",a,"]",:,",")) end program demo_add
[xxx],[b],[aaa],[ZZZ] [xxx],[b],[aaa],[ZZZ] [xxx],[b],[aaa],[^],[ZZZ] [xxx],[b],[aaa],[^],[ZZZ],[] [xxx],[c],[b],[aaa],[^],[ZZZ],[] [xxx],[c],[b],[aaa],[^],[ZZZ],[ZZ],[] [xxx],[c],[b],[aaa],[^],[ZZZZ],[ZZZ],[ZZ],[] [z],[xxx],[c],[b],[aaa],[^],[ZZZZ],[ZZZ],[ZZ],[]
add (3) | June 16, 2019 |