16 public ::
assignment(=)
17 interface assignment(=)
19 end interface assignment(=)
23 character (len=:),
allocatable :: s
24 integer (c_int) :: count = 0
25 integer (c_int) :: missing_value_count = 0
104 integer (c_int),
parameter ::
na_int = - (huge(1_c_int)-1_c_int)
105 real (c_float),
parameter ::
na_float = - (huge(1._c_float)-1._c_float)
106 real (c_double),
parameter ::
na_double = - (huge(1._c_double)-1._c_double)
119 integer (c_int) :: order
120 character (len=:),
allocatable :: alpha_value
124 integer (c_int) :: order
125 integer (c_int) :: int_value
129 integer (c_int) :: order
130 real (c_float) :: float_value
140 character (len=*),
intent(in) :: character_str
153 character (len=:),
allocatable,
intent(out) :: character_str
154 type (FSTRING_LIST_T),
intent(in) :: string_list
156 character (len=:),
allocatable :: temp_str
158 temp_str = string_list%get(1)
159 character_str = trim(temp_str)
167 character (len=*),
intent(in) :: character_str
168 character (len=1),
intent(in),
optional :: delimiter_chr
171 character (len=len(character_str)) :: string
172 character (len=len(character_str)) :: substring
173 character (len=1) :: delimiter_chr_
174 integer (c_int) :: num_delimiters
177 if (
present(delimiter_chr) )
then
178 delimiter_chr_ = delimiter_chr
183 string = character_str
186 do i=1, len_trim(string)
187 if ( string(i:i) == delimiter_chr_ ) num_delimiters = num_delimiters + 1
190 if ( num_delimiters == 0 )
then
197 do i=1, num_delimiters
198 call chomp(string, substring, delimiter_chr_)
199 call new_fstring%append( substring )
202 call chomp(string, substring, delimiter_chr_)
203 call new_fstring%append( substring )
214 integer (c_int) :: count
220 do i=1, len_trim(this%s)
221 if( this%s(i:i) == c_null_char ) count = count + 1
231 character (len=*),
intent(in) :: character_str
233 if ( .not.
allocated( this%s ) ) this%s =
""
234 this%s = trim(this%s)//trim(adjustl(
f_to_c_str(character_str)))
235 if ( len_trim(character_str) == 0 ) &
236 this%missing_value_count = this%missing_value_count + 1
237 this%count = this%count + 1
246 character (len=*),
intent(in) :: character_str(:)
250 do i=1,
size(character_str,1)
252 this%s = trim(this%s)//trim(adjustl(
f_to_c_str(character_str(i))))
253 if ( len_trim(character_str(i)) == 0 ) &
254 this%missing_value_count = this%missing_value_count + 1
255 this%count = this%count + 1
266 type (FSTRING_LIST_T),
intent(inout) :: other_fstring
269 character (len=:),
allocatable :: temp_str
271 do i=1, other_fstring%count
273 temp_str = other_fstring%get(i)
274 call this%append( other_fstring%get(i) )
275 if ( len_trim(temp_str) == 0 ) &
276 this%missing_value_count = this%missing_value_count + 1
287 logical (c_bool) :: value
289 if ( this%missing_value_count > 0 )
then
290 value = .true._c_bool
292 value = .false._c_bool
303 character (len=:),
allocatable :: sbuf
304 integer (c_int) :: start_pos
305 integer (c_int) :: end_pos
306 integer (c_int) :: str_len
310 end_pos = index( this%s, c_null_char ) - 1
311 str_len = len_trim( this%s )
313 do i=1, this%count_entries()
315 write(*,fmt=
"(a)") this%s(start_pos:end_pos)
317 start_pos = end_pos + 2
318 end_pos = index( this%s(start_pos:str_len), c_null_char ) + start_pos - 2
328 type (FSTRING_LIST_T),
intent(inout) :: this
350 integer (c_int),
allocatable :: values(:)
353 integer (c_int) :: value
354 integer (c_int) :: op_status
355 character (len=64) :: sbuf
357 if (this%count <= 0)
then
358 allocate(values(1),stat=op_status)
362 allocate(values(this%count),stat=op_status)
367 if ( op_status==0 )
then
383 real (c_float),
allocatable :: values(:)
386 real (c_float) :: value
387 integer (c_int) :: op_status
388 character (len=64) :: sbuf
390 if (this%count <= 0)
then
391 allocate(values(1),stat=op_status)
394 allocate(values(this%count),stat=op_status)
398 read(unit=sbuf, fmt=*, iostat=op_status)
value
399 if ( op_status==0 )
then
415 real (c_double),
allocatable :: values(:)
418 real (c_double) :: value
419 integer (c_int) :: op_status
420 character (len=64) :: sbuf
422 if (this%count <=0)
then
424 allocate(values(1),stat=op_status)
429 allocate(values(this%count),stat=op_status)
433 read(unit=sbuf, fmt=*, iostat=op_status)
value
434 if ( op_status==0 )
then
450 logical (c_bool),
allocatable :: values(:)
453 logical (c_bool) :: value
454 integer (c_int) :: op_status
455 character (len=64) :: sbuf
457 allocate(values(this%count),stat=op_status)
464 case(
"true",
"T",
"True",
"TRUE",
"1",
"Y",
"Yes",
"yes",
"YES")
465 values(i) = .true._c_bool
467 values(i) = .false._c_bool
480 integer (c_int),
intent(in) :: index_val
481 character(len=:),
allocatable :: text
483 integer (c_int) :: start_pos
484 integer (c_int) :: end_pos
485 integer (c_int) :: str_len
491 if (
allocated(this%s) )
then
493 end_pos = index( this%s, c_null_char ) - 1
494 str_len = len_trim( this%s )
498 if ( index_val == i )
then
499 text = this%s(start_pos:end_pos)
505 start_pos = end_pos + 2
506 end_pos = index( this%s(start_pos:str_len), c_null_char ) + start_pos - 2
519 integer (c_int),
intent(in) :: index_val
520 character(len=*) :: character_str
523 type (FSTRING_LIST_T) :: temp_list
526 if (this%count > 0)
then
529 if ( index_val == i )
then
530 call temp_list%append(character_str)
532 call temp_list%append(this%get(i))
547 integer (c_int),
intent(in) :: start_indx
548 integer (c_int),
intent(in) :: end_indx
549 character (len=:),
allocatable :: text
553 if (this%count == 0)
then
557 if (i == start_indx)
then
558 text = trim(this%get(i))
559 elseif (i > start_indx .and. i <= end_indx )
then
560 text = trim(text)//
" "//trim(this%get(i))
572 character (len=1),
intent(in),
optional :: delimiter_chr
573 character (len=:),
allocatable :: text
577 if (this%count == 0)
then
579 elseif (
present(delimiter_chr) )
then
580 text = trim(this%get(1))
582 text = trim(text)//delimiter_chr//trim(this%get(i))
585 text =
"(1) "//trim(this%get(1))
587 text = trim(text)//
" ("//
as_character(i)//
") "//trim(this%get(i))
598 character (len=*),
intent(in),
optional :: sort_order
600 type (ALPHA_SORT_GROUP_T),
allocatable :: sort_group(:)
602 integer (c_int) :: count
603 logical (c_bool) :: decreasing_order
605 decreasing_order = .false._c_bool
607 if (
present(sort_order) )
then
608 select case (sort_order)
610 case (
"Decreasing",
"decreasing",
"DECREASING")
611 decreasing_order = .true._c_bool
617 allocate(sort_group(count))
621 sort_group(i)%order = i
622 sort_group(i)%alpha_value = this%get(i)
630 if ( decreasing_order )
then
633 call this%append(sort_group(i)%alpha_value)
638 call this%append(sort_group(i)%alpha_value)
648 character (len=*),
intent(in),
optional :: sort_order
650 type (INT_SORT_GROUP_T),
allocatable :: sort_group(:)
651 integer (c_int),
allocatable :: int_values(:)
653 integer (c_int) :: count
654 logical (c_bool) :: decreasing_order
656 decreasing_order = .false._c_bool
658 if (
present(sort_order) )
then
659 select case (sort_order)
660 case (
"Decreasing",
"decreasing",
"DECREASING")
661 decreasing_order = .true._c_bool
667 allocate(sort_group(count))
668 allocate(int_values(count))
670 int_values = this%get_integer()
674 sort_group(i)%order = i
675 sort_group(i)%int_value = int_values(i)
681 if ( decreasing_order )
then
684 call this%append(
as_character(sort_group(i)%int_value) )
689 call this%append(
as_character(sort_group(i)%int_value) )
699 character (len=*),
intent(in),
optional :: sort_order
701 type (FLOAT_SORT_GROUP_T),
allocatable :: sort_group(:)
702 real (c_float),
allocatable :: float_values(:)
704 integer (c_int) :: count
705 logical (c_bool) :: decreasing_order
707 decreasing_order = .false._c_bool
709 if (
present(sort_order) )
then
710 select case (sort_order)
712 case (
"Decreasing",
"decreasing",
"DECREASING")
713 decreasing_order = .true._c_bool
719 allocate(sort_group(count))
721 float_values = this%get_float()
725 sort_group(i)%order = i
726 sort_group(i)%float_value = float_values(i)
734 if ( decreasing_order )
then
737 call this%append(
as_character(sort_group(i)%float_value) )
742 call this%append(
as_character(sort_group(i)%float_value) )
757 integer (c_int),
intent(in) :: nrec
761 real (c_float) :: random
762 character (len=:),
allocatable :: pivot
764 integer (c_int) :: marker
768 call random_number(random)
769 pivot = sort_group(int(random*real(nrec-1))+1)%alpha_value
775 do while (sort_group(
right)%alpha_value > pivot)
779 do while (sort_group(
left)%alpha_value < pivot)
783 temp = sort_group(
left)
785 sort_group(
right) = temp
796 call qsort_alpha(sort_group(marker:),nrec-marker+1)
811 integer (c_int),
intent(in) :: nrec
815 real (c_float) :: random
816 integer (c_int) :: pivot
818 integer (c_int) :: marker
822 call random_number(random)
823 pivot = sort_group(int(random*real(nrec-1))+1)%int_value
829 do while (sort_group(
right)%int_value > pivot)
833 do while (sort_group(
left)%int_value < pivot)
837 temp = sort_group(
left)
839 sort_group(
right) = temp
849 call qsort_int(sort_group(:marker-1),marker-1)
850 call qsort_int(sort_group(marker:),nrec-marker+1)
865 integer (c_int),
intent(in) :: nrec
869 real (c_float) :: random
870 real (c_float) :: pivot
872 integer (c_int) :: marker
876 call random_number(random)
877 pivot = sort_group(int(random*real(nrec-1))+1)%float_value
883 do while (sort_group(
right)%float_value > pivot)
887 do while (sort_group(
left)%float_value < pivot)
891 temp = sort_group(
left)
893 sort_group(
right) = temp
904 call qsort_float(sort_group(marker:),nrec-marker+1)
915 character (len=*),
intent(in) :: substr
917 logical (c_bool),
intent(in),
optional :: match_case
918 integer (c_int) :: count
922 integer (c_int) :: status
923 logical (c_bool) :: match_case_
925 if (
present( match_case ) )
then
926 match_case_ = match_case
928 match_case_ = .false._c_bool
933 if ( match_case_ )
then
937 if ( this%get(i) .strequal. substr ) count = count + 1
945 if ( this%get(i) .strapprox. substr ) count = count + 1
958 character (len=*),
intent(in) :: substr
963 character (len=:),
allocatable :: temp_str
966 temp_str = this%get(i)
967 if ( temp_str .containssimilar. substr )
call new_fstring%append(temp_str)
970 if ( new_fstring%count == 0 ) new_fstring =
"<NA>"
979 character (len=*),
intent(in) :: character_str
980 integer (c_int),
allocatable :: index_values(:)
984 integer (c_int) :: match_index
985 logical (c_bool) :: string_present( this%count )
986 integer (c_int) :: number_of_matches
988 string_present = .false._c_bool
992 if ( this%get(i) .strapprox. character_str ) string_present(i) = .true._c_bool
995 number_of_matches = count(string_present)
996 if (number_of_matches > 0 )
then
997 allocate( index_values(number_of_matches) )
999 if (string_present(i))
then
1000 match_index = match_index + 1
1001 index_values(match_index) = i
1005 allocate( index_values(1) )
1006 index_values(1) = -9999
1018 integer (c_int) :: i
1019 character (len=:),
allocatable :: temp_str
1023 temp_str = this%get(i)
1024 if ( new_fstring%count_matching( temp_str ) == 0 )
call new_fstring%append(temp_str)
1028 if ( new_fstring%count == 0 ) new_fstring =
"<NA>"
1036 use iso_fortran_env,
only : output_unit
1039 integer (c_int),
optional :: lu
1042 integer (c_int) :: lu_
1043 integer (c_int) :: i
1045 if (
present(lu) )
then
1051 write(lu_, fmt=
"('|',a,t21,'|',a,t72,'|')")
"Index",
"Value"
1052 write(lu_, fmt=
"('|',a,t21,'|',a,t72,'|')") repeat(
"-",18)//
":", repeat(
"-",49)//
":"
1056 write(lu_, fmt=
"('|',i10,t21,'|',a,t72,'|')") i, this%get(i)
logical(c_bool) function, dimension(:), allocatable retrieve_values_as_logical_fn(this)
subroutine append_character_array_to_fstring_sub(this, character_str)
real(c_float) function, dimension(:), allocatable retrieve_values_as_float_fn(this)
subroutine list_finalize_sub(this)
subroutine quicksort_int_sub(this, sort_order)
character(len=:) function, allocatable retrieve_values_for_range_of_indices_fn(this, start_indx, end_indx)
subroutine append_character_to_fstring_sub(this, character_str)
subroutine append_fstring_to_fstring_sub(this, other_fstring)
type(fstring_list_t) function return_subset_of_partial_matches_fn(this, substr)
character(len=:) function, allocatable retrieve_value_from_list_at_index_fn(this, index_val)
logical(c_bool) function are_there_missing_list_values_fn(this)
integer(c_int) function, dimension(:), allocatable return_indices_of_matching_list_entries_fn(this, character_str)
subroutine assign_fstring_to_character_sub(character_str, string_list)
subroutine print_as_markdown_sub(this, lu)
integer(c_int) function, dimension(:), allocatable retrieve_values_as_integer_fn(this)
integer(c_int) function return_count_of_matching_strings_fn(this, substr, match_case)
subroutine quicksort_float_sub(this, sort_order)
subroutine assign_character_to_fstring_sub(this, character_str)
character(len=:) function, allocatable list_all_fn(this, delimiter_chr)
subroutine clear_list_sub(this)
real(c_double) function, dimension(:), allocatable retrieve_values_as_double_fn(this)
recursive subroutine qsort_alpha(sort_group, nrec)
recursive subroutine qsort_float(sort_group, nrec)
integer(c_int) function count_strings_in_list_fn(this)
subroutine replace_value_at_index_sub(this, index_val, character_str)
subroutine print_all_entries_sub(this)
subroutine quicksort_alpha_sub(this, sort_order)
type(fstring_list_t) function split_character_into_fstring_list_fn(character_str, delimiter_chr)
type(fstring_list_t) function return_list_of_unique_values_fn(this)
recursive subroutine qsort_int(sort_group, nrec)
integer(c_int), parameter, private na_int
real(c_double), parameter, private na_double
real(c_float), parameter, private na_float