3 use iso_c_binding,
only : c_int, c_long_long, c_float, c_double, c_bool, &
11 procedure :: concatenate_char_char_fn
12 procedure :: concatenate_char_int_fn
13 procedure :: concatenate_char_float_fn
14 procedure :: concatenate_char_double_fn
15 end interface operator(+)
23 public ::
operator( .strequal. )
24 interface operator( .strequal. )
25 procedure :: is_char_equal_to_char_case_sensitive_fn
26 end interface operator( .strequal. )
28 public ::
operator( .strapprox. )
29 interface operator( .strapprox. )
30 procedure :: is_char_equal_to_char_case_insensitive_fn
31 end interface operator( .strapprox. )
33 public ::
operator( .contains. )
34 interface operator( .contains. )
35 procedure :: is_string2_present_in_string1_case_sensitive_fn
36 end interface operator( .contains. )
38 public ::
operator( .containssimilar. )
39 interface operator( .containssimilar. )
40 procedure :: is_string2_present_in_string1_case_insensitive_fn
41 end interface operator( .containssimilar. )
45 procedure :: short_to_char_fn
46 procedure :: int_to_char_fn
47 procedure :: long_long_to_char_fn
48 procedure :: float_to_char_fn
49 procedure :: double_to_char_fn
50 procedure :: bool_to_char_fn
56 procedure :: short_to_char_fn
57 procedure :: int_to_char_fn
58 procedure :: long_long_to_char_fn
59 procedure :: float_to_char_fn
60 procedure :: double_to_char_fn
61 procedure :: bool_to_char_fn
66 procedure :: string_to_integer_fn
71 procedure :: string_to_float_fn
76 procedure :: split_and_return_text_sub
81 procedure :: count_number_of_fields_fn
86 procedure :: remove_multiple_characters_fn
91 procedure :: squote_char_fn
96 procedure :: dquote_char_fn
101 procedure :: replace_character_sub
106 procedure :: char_to_uppercase_fn
111 procedure :: char_to_lowercase_fn
116 procedure :: char_to_uppercase_sub
121 procedure :: char_to_lowercase_sub
126 procedure :: char_to_uppercase_fn
131 procedure :: char_to_lowercase_fn
136 procedure :: char_to_uppercase_sub
141 procedure :: char_to_lowercase_sub
146 procedure :: return_right_part_of_string_fn
151 procedure :: return_left_part_of_string_fn
156 procedure :: f_to_c_string_fn
161 procedure :: c_to_f_string_fn
167 character (len=1),
parameter ::
tab = achar(9)
177 integer (c_int),
parameter ::
na_int = - (huge(1_c_int)-1_c_int)
178 real (c_float),
parameter ::
na_float = - (huge(1._c_float)-1._c_float)
179 real (c_double),
parameter ::
na_double = - (huge(1._c_double)-1._c_double)
186 character (len=*),
intent(in) :: text
187 integer (c_int) :: value
190 integer (c_int) :: op_status
191 character (len=:),
allocatable :: temp_str
192 real (c_float) :: float_value
195 read(unit=text, fmt=*, iostat=op_status)
value
196 if (op_status == 0)
return
203 if ( scan(temp_str,
".") /= 0 )
then
205 read(unit=temp_str, fmt=*, iostat=op_status) float_value
206 if (op_status == 0)
value = int(float_value, c_int)
210 read(unit=temp_str, fmt=*, iostat=op_status)
value
214 if (op_status /= 0)
value =
na_int
222 character (len=*),
intent(in) :: text
223 real (c_float) :: value
226 integer (c_int) :: op_status
227 character (len=:),
allocatable :: temp_str
230 read(unit=text, fmt=*, iostat=op_status)
value
231 if (op_status == 0)
return
235 read(unit=temp_str, fmt=*, iostat=op_status)
value
236 if (op_status /= 0)
value =
na_float
244 character (len=*),
intent(in) :: string
245 integer (c_int),
intent(in),
optional :: indx
246 character (len=*),
intent(in),
optional :: substring
247 character (len=:),
allocatable :: left_part
250 integer (c_int) :: position
252 if (
present( indx ) )
then
254 if ( ( indx > 0 ) .and. ( indx < len_trim( string ) ) )
then
256 left_part = string( 1:indx )
264 elseif (
present( substring ) )
then
266 position = index( string, substring )
268 if ( position > 0 )
then
270 left_part = string( 1:(position-1) )
291 character (len=*),
intent(in) :: string
292 integer (c_int),
intent(in),
optional :: indx
293 character (len=*),
intent(in),
optional :: substring
294 character (len=:),
allocatable :: right_part
297 integer (c_int) :: position
299 if (
present( indx ) )
then
301 if ( ( indx > 0 ) .and. ( indx < len_trim( string ) ) )
then
303 right_part = string( (indx+1):len_trim(string) )
311 elseif (
present( substring ) )
then
313 position = index( string, substring, back=.true._c_bool )
315 if ( position > 0 )
then
317 right_part = string( (position+1):len_trim(string) )
338 character (len=*),
intent(in) :: stext1
339 character (len=*),
intent(in) :: stext2
340 logical (c_bool) :: lbool
343 character (len=len_trim(sText1)) :: stemp1
344 character (len=len_trim(sText2)) :: stemp2
346 lbool = .false._c_bool
351 if ( index(stemp1, stemp2) /= 0 ) lbool = .true._c_bool
359 character (len=*),
intent(in) :: stext1
360 character (len=*),
intent(in) :: stext2
361 logical (c_bool) :: lbool
364 character (len=len_trim(sText1)) :: stemp1
365 character (len=len_trim(sText2)) :: stemp2
367 lbool = .false._c_bool
369 stemp1 = trim( stext1 )
370 stemp2 = trim( stext2 )
372 if ( index(stemp1, stemp2) /= 0 ) lbool = .true._c_bool
380 character (len=*),
intent(in) :: stext1
381 character (len=*),
intent(in) :: stext2
382 logical (c_bool) :: lbool
385 character (len=:),
allocatable :: stemp1
386 character (len=:),
allocatable :: stemp2
388 lbool = .false._c_bool
390 stemp1 = trim( stext1 )
391 stemp2 = trim( stext2 )
393 if (trim(adjustl( stemp1 ) ) .eq. trim(adjustl( stemp2) ) ) lbool = .true._c_bool
401 character (len=*),
intent(in) :: stext1
402 character (len=*),
intent(in) :: stext2
403 logical (c_bool) :: lbool
406 character (len=:),
allocatable :: stemp1
407 character (len=:),
allocatable :: stemp2
409 lbool = .false._c_bool
414 if (trim(adjustl( stemp1 ) ) .eq. trim(adjustl( stemp2) ) ) lbool = .true._c_bool
422 character (len=*),
intent(in) :: stext1
423 character (len=*),
intent(in) :: stext2
424 character (len=:),
allocatable :: stext
426 stext = stext1 // stext2
434 character (len=*),
intent(in) :: stext1
435 integer (c_int),
intent(in) :: ivalue1
436 character (len=:),
allocatable :: stext
446 character (len=*),
intent(in) :: stext1
447 real (c_float),
intent(in) :: fvalue1
448 character (len=:),
allocatable :: stext
458 character (len=*),
intent(in) :: stext1
459 real (c_double),
intent(in) :: dvalue1
460 character (len=:),
allocatable :: stext
468 integer (c_short),
intent(in) :: value
469 character (len=*),
intent(in),
optional :: fmt_string
470 character (len=:),
allocatable :: text
472 integer (c_int) :: status
473 character (len=32) :: sbuf
475 if (
present(fmt_string) )
then
476 write(sbuf, fmt=
"("//trim(fmt_string)//
")", iostat=status)
value
478 write(sbuf, fmt=*, iostat=status)
value
482 text = trim( adjustl(sbuf) )
492 integer (c_int),
intent(in) :: value
493 character (len=*),
intent(in),
optional :: fmt_string
494 character (len=:),
allocatable :: text
496 integer (c_int) :: status
497 character (len=32) :: sbuf
499 if (
present(fmt_string) )
then
500 write(sbuf, fmt=
"("//trim(fmt_string)//
")", iostat=status)
value
502 write(sbuf, fmt=*, iostat=status)
value
506 text = trim( adjustl(sbuf) )
516 integer (c_long_long),
intent(in) :: value
517 character (len=*),
intent(in),
optional :: fmt_string
518 character (len=:),
allocatable :: text
520 integer (c_int) :: status
521 character (len=32) :: sbuf
523 if (
present(fmt_string) )
then
524 write(sbuf, fmt=
"("//trim(fmt_string)//
")", iostat=status)
value
526 write(sbuf, fmt=*, iostat=status)
value
530 text = trim( adjustl(sbuf) )
540 real (c_float),
intent(in) :: value
541 character (len=*),
intent(in),
optional :: fmt_string
542 character (len=:),
allocatable :: text
544 integer (c_int) :: status
545 character (len=32) :: sbuf
547 if (
present(fmt_string) )
then
548 write(sbuf, fmt=
"("//trim(fmt_string)//
")", iostat=status)
value
550 write(sbuf, fmt=*, iostat=status)
value
554 text = trim( adjustl(sbuf) )
564 real (c_double),
intent(in) :: value
565 character (len=*),
intent(in),
optional :: fmt_string
566 character (len=:),
allocatable :: text
568 integer (c_int) :: status
569 character (len=32) :: sbuf
571 if (
present(fmt_string) )
then
572 write(sbuf, fmt=
"("//trim(fmt_string)//
")", iostat=status)
value
574 write(sbuf, fmt=*, iostat=status)
value
578 text = trim( adjustl(sbuf) )
588 logical (c_bool),
intent(in) :: value
589 character (len=:),
allocatable :: text
593 text =
".TRUE._c_bool"
604 character (len=*),
intent(in) :: stext1
605 character (len=:),
allocatable :: stext
607 stext =
"'"//trim(stext1)//
"'"
615 character (len=*),
intent(in) :: stext1
616 character (len=:),
allocatable :: stext
618 stext =
'"'//trim(stext1)//
'"'
627 character (len=*),
intent(in) :: s
628 character(len=len(s)) :: stext
634 integer (c_int),
parameter :: lower_to_upper = -32
635 integer (c_int),
parameter :: ascii_small_a = ichar(
"a")
636 integer (c_int),
parameter :: ascii_small_z = ichar(
"z")
640 do i=1,len_trim(stext)
641 if ( ichar(stext(i:i) ) >= ascii_small_a .and. ichar(stext(i:i)) <= ascii_small_z )
then
642 stext(i:i) = char( ichar( stext(i:i) ) + lower_to_upper )
653 character (len=*),
intent(in) :: s
654 character(len=len(s)) :: stext
659 integer (c_int),
parameter :: upper_to_lower = 32
660 integer (c_int),
parameter :: ascii_a = ichar(
"A")
661 integer (c_int),
parameter :: ascii_z = ichar(
"Z")
665 do i=1,len_trim(stext)
666 if ( ichar(stext(i:i) ) >= ascii_a .and. ichar(stext(i:i)) <= ascii_z )
then
667 stext(i:i) = char( ichar( stext(i:i) ) + upper_to_lower )
677 character (len=*),
intent(inout) :: s
681 integer (c_int),
parameter :: LOWER_TO_UPPER = -32
682 integer (c_int),
parameter :: ASCII_SMALL_A = ichar(
"a")
683 integer (c_int),
parameter :: ASCII_SMALL_Z = ichar(
"z")
686 if ( ichar(s(i:i) ) >= ascii_small_a .and. ichar(s(i:i)) <= ascii_small_z )
then
687 s(i:i) = char( ichar( s(i:i) ) + lower_to_upper )
697 character (len=*),
intent(inout) :: s
701 integer (c_int),
parameter :: UPPER_TO_LOWER = 32
702 integer (c_int),
parameter :: ASCII_A = ichar(
"A")
703 integer (c_int),
parameter :: ASCII_Z = ichar(
"Z")
708 if ( ichar(s(i:i) ) >= ascii_a .and. ichar(s(i:i)) <= ascii_z )
then
709 s(i:i) = char( ichar( s(i:i) ) + upper_to_lower )
729 character (len=*),
intent(inout) :: stext1
730 character (len=*),
intent(in),
optional :: stargetcharacters
731 character (len=:),
allocatable :: stext
734 character (len=512) :: sbuf
735 integer (c_int) :: ir
736 integer (c_int) :: iindex1, iindex2
737 character (len=:),
allocatable :: stargetcharacters_l
740 stext1 = adjustl(stext1)
744 if (
present(stargetcharacters) )
then
745 stargetcharacters_l = stargetcharacters
747 stargetcharacters_l =
":/;,"
750 do iindex1 = 1,len_trim(stext1)
752 ir = scan(stext1(iindex1:iindex1), stargetcharacters_l)
755 iindex2 = iindex2 + 1
756 sbuf(iindex2:iindex2) = stext1(iindex1:iindex1)
769 character (len=*),
intent(in) :: stext
770 character (len=*),
intent(in),
optional :: sdelimiters
771 integer (c_int) :: icount
774 character (len=len(sText)) :: str
775 character (len=len(sText)) :: substr
776 character (len=:),
allocatable :: delimiter_chr_
778 if (
present(sdelimiters) )
then
779 delimiter_chr_=sdelimiters
789 call chomp(str=str, substr=substr, delimiter_chr=delimiter_chr_ )
791 if ( len_trim( substr ) == 0 )
exit
803 character (len=*),
intent(inout) :: str
804 character (len=*),
intent(out) :: substr
805 character (len=*),
intent(in),
optional :: delimiter_chr
806 logical (c_bool),
intent(in),
optional :: remove_extra_delimiters
809 character (len=:),
allocatable :: delimiter_chr_
810 logical (c_bool) :: remove_extra_delimiters_
811 integer (kind=c_int) :: iIndex
814 if (
present(remove_extra_delimiters))
then
815 remove_extra_delimiters_ = remove_extra_delimiters
817 remove_extra_delimiters_ = .false._c_bool
820 if (
present(delimiter_chr) )
then
821 select case (delimiter_chr)
826 case (
"COMMA",
"CSV")
829 delimiter_chr_ = delimiter_chr
837 iindex = scan( string = str, set = delimiter_chr_ )
839 if (iindex == 0)
then
845 substr = trim( str(1:iindex-1) )
846 str = trim( str(iindex + 1: ) )
849 if (remove_extra_delimiters_)
then
854 if ( scan( string=str(1:1), set=delimiter_chr_) == 0)
exit
866 character (len=*),
intent(inout) :: sText1
867 character (len=1),
intent(in) :: sFind
868 character (len=1),
intent(in),
optional :: sReplace
871 integer (c_int) :: iIndex
872 integer (c_int) :: iCount
873 character (len=len_trim(sText1)) :: sText
877 if ( len(stext1) > 0 )
then
880 do iindex = 1, len_trim(stext1)
881 if ( stext1(iindex:iindex) .ne. sfind)
then
883 stext(icount:icount) = stext1(iindex:iindex)
885 if (
present(sreplace))
then
887 stext(icount:icount) = sreplace
903 character (len=*),
intent(in) :: text
904 character (len=len(text)) :: result_text
906 character (len=:),
allocatable :: temp_str
907 character (len=512) :: temp_result
910 integer (c_int) :: index1, index2
911 character (len=:),
allocatable :: target_characters
915 target_characters =
"qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM" &
918 temp_str = adjustl(text)
922 do index1 = 1,len_trim(text)
923 n = scan(text(index1:index1), target_characters)
926 temp_result(index2:index2) = text(index1:index1)
930 result_text = trim(temp_result)
938 character (len=*),
intent(in) :: c_character_str
939 character (len=:),
allocatable :: f_character_str
941 integer (c_int) :: indx
943 f_character_str = c_character_str
945 do indx=1,len(c_character_str)
946 if (c_character_str(indx:indx) == c_null_char)
then
947 f_character_str = c_character_str(1:indx-1)
958 character (len=*),
intent(in) :: f_character_str
959 character (len=:),
allocatable :: c_character_str
961 integer (c_int) :: str_len
963 str_len = len_trim(f_character_str)
965 if ( str_len == 0 )
then
966 c_character_str = c_null_char
967 elseif ( f_character_str(str_len:str_len) == c_null_char )
then
969 c_character_str = trim(f_character_str)
972 c_character_str = trim(f_character_str)//c_null_char
character(len=1), parameter, public forwardslash
impure elemental integer(c_int) function string_to_integer_fn(text)
character(len=:) function, allocatable int_to_char_fn(value, fmt_string)
character(len=:) function, allocatable dquote_char_fn(stext1)
pure logical(c_bool) function is_string2_present_in_string1_case_insensitive_fn(stext1, stext2)
impure character(len=:) function, allocatable remove_multiple_characters_fn(stext1, stargetcharacters)
Strip offending characters from a text string.
character(len=:) function, allocatable long_long_to_char_fn(value, fmt_string)
subroutine split_and_return_text_sub(str, substr, delimiter_chr, remove_extra_delimiters)
character(len=:) function, allocatable return_left_part_of_string_fn(string, indx, substring)
character(len=:) function, allocatable f_to_c_string_fn(f_character_str)
integer(c_int), parameter, private na_int
character(len=:) function, allocatable concatenate_char_double_fn(stext1, dvalue1)
real(c_double), parameter, private na_double
character(len=:) function, allocatable short_to_char_fn(value, fmt_string)
character(len=3), parameter, public punctuation
character(len=:) function, allocatable squote_char_fn(stext1)
impure elemental real(c_float) function string_to_float_fn(text)
character(len=1), parameter, public carriage_return
character(len=1), parameter, public tab
character(len=:) function, allocatable concatenate_char_float_fn(stext1, fvalue1)
pure character(len=len(s)) function char_to_uppercase_fn(s)
character(len=:) function, allocatable float_to_char_fn(value, fmt_string)
character(len=:) function, allocatable bool_to_char_fn(value)
character(len=:) function, allocatable double_to_char_fn(value, fmt_string)
subroutine char_to_lowercase_sub(s)
character(len=1), parameter, public backslash
subroutine replace_character_sub(stext1, sfind, sreplace)
integer(c_int) function count_number_of_fields_fn(stext, sdelimiters)
pure character(len=len(s)) function char_to_lowercase_fn(s)
impure elemental character(len=len(text)) function keepnumeric(text)
character(len=2), parameter, public whitespace
real(c_float), parameter, private na_float
pure logical(c_bool) function is_string2_present_in_string1_case_sensitive_fn(stext1, stext2)
pure logical(c_bool) function is_char_equal_to_char_case_sensitive_fn(stext1, stext2)
character(len=:) function, allocatable concatenate_char_int_fn(stext1, ivalue1)
subroutine char_to_uppercase_sub(s)
character(len=:) function, allocatable c_to_f_string_fn(c_character_str)
character(len=1), parameter, public double_quote
character(len=:) function, allocatable concatenate_char_char_fn(stext1, stext2)
pure logical(c_bool) function is_char_equal_to_char_case_insensitive_fn(stext1, stext2)
character(len=3), parameter, public comment_characters
character(len=:) function, allocatable return_right_part_of_string_fn(string, indx, substring)