gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
Data Types | Functions/Subroutines
dc_string Module Reference

Handling character types. More...

Data Types

interface  concat
 
interface  cprintf
 
interface  cprintft
 
interface  get_array
 
interface  index_ofs
 
interface  lchar
 
interface  printf
 
interface  putline
 
interface  replace
 
interface  roundnum
 
interface  split
 
interface  stoa
 
interface  stod
 
interface  stoi
 
interface  str_to_logical
 
interface  strhead
 
interface  strieq
 
interface  strinclude
 
interface  tochar
 
interface  tolower
 
interface  toupper
 
interface  uchar
 

Functions/Subroutines

character(string) function, public joinchar (carray, expr)
 
integer function, public index_ofs (string, start, substr)
 
recursive character(string) function, public replace (str, from, to, recursive, start_pos)
 
character(string) function, public uchar (ch)
 
character(string) function, public lchar (ch)
 
character(string) function, public roundnum (num)
 

Detailed Description

Handling character types.

Author
Youhei SASAKI, Yasuhiro MORIKAWA, Eizi TOYODA

Important

This file is generated from ../../../../src/dc_utils/dc_string.erb by ERB included Ruby 3.3.8. Please do not edit this file directly.

Function/Subroutine Documentation

◆ index_ofs()

integer function, public dc_string::index_ofs ( character(len = *), intent(in)  string,
integer, intent(in)  start,
character(len = *), intent(in)  substr 
)

Find substring position with offset

Returns the starting position where substr is found in string, searching from position start. Returns 0 if not found. The returned position is counted from the beginning of string.

Parameters
[in]stringString to search in
[in]startStarting position for search
[in]substrSubstring to find
Returns
Position of substr, or 0 if not found

Definition at line 1611 of file dc_string.f90.

1612 character(len = *), intent(in):: string
1613 integer, intent(in):: start
1614 character(len = *), intent(in):: substr
1615 intrinsic index
1616 if (start < 1) then
1617 result = 0
1618 return
1619 endif
1620 result = index(string(start: ), substr)
1621 if (result == 0) return
1622 result = start + result - 1

◆ joinchar()

character(string) function, public dc_string::joinchar ( character(*), dimension(:), intent(in)  carray,
character(*), intent(in), optional  expr 
)

Join character array with delimiter

Joins elements of character array carray with ", " delimiter. If expr is given, uses that string as delimiter.

Parameters
[in]carrayCharacter array to join
[in]exprDelimiter string (optional, default: ", ")
Returns
Joined string

Definition at line 1120 of file dc_string.f90.

1121 implicit none
1122 character(*) , intent(in) :: carray(:)
1123 character(*) , intent(in), optional :: expr
1124 character(2) ,parameter :: default = ', '
1125 character(STRING) :: delimiter
1126 integer :: dellen, i
1127 continue
1128 if ( present(expr) ) then
1129 delimiter = expr
1130 dellen = len(expr)
1131 else
1132 delimiter = default
1133 dellen = len(default)
1134 endif
1135 if (size(carray) <= 0) then
1136 result = ""
1137 return
1138 endif
1139 result = trim(carray(1))
1140 do, i = 2, size(carray)
1141 result = trim(result) // delimiter(1:dellen) // trim(carray(i))
1142 enddo

◆ lchar()

character(string) function, public dc_string::lchar ( character(len = *), intent(in)  ch)

Return lowercase copy of string

Returns a copy of ch with all uppercase letters converted to lowercase. Non-alphabetic characters and already lowercase characters are unchanged.

Parameters
[in]chString to convert
Returns
Lowercase string

Definition at line 1808 of file dc_string.f90.

1809 character(len = *), intent(in):: ch
1810 continue
1811 result = ch
1812 call tolower(result)

◆ replace()

recursive character(string) function, public dc_string::replace ( character(*), intent(in)  str,
character(*), intent(in)  from,
character(*), intent(in)  to,
logical, intent(in), optional  recursive,
integer, intent(in), optional  start_pos 
)

Replace substring in string

If string from is included in str, replaces it with string to and returns. If from is not included, returns str without change. When multiple from are included, only the first one is replaced. To replace all from to to, give .true. to optional argument recursive. By default, the string is searched from the top. If optional argument start_pos is given, the search starts from start_pos.

Parameters
[in]strSource string
[in]fromString to find
[in]toReplacement string
[in]recursiveIf .true., replace all occurrences (optional)
[in]start_posStarting position for search (optional)
Returns
Replaced string

Definition at line 1658 of file dc_string.f90.

1660 use dc_types, only: string
1661 implicit none
1662 character(STRING):: result
1663 character(*), intent(in):: str, from, to
1664 logical, intent(in), optional:: recursive
1665 integer, intent(in), optional:: start_pos
1666 integer:: sp
1667 integer:: i, isa, isb, iea, ieb
1668 integer:: ir
1669 continue
1670 if ( present(start_pos) ) then
1671 sp = start_pos
1672 else
1673 sp = 1
1674 end if
1675 if ( sp < 1 ) then
1676 sp = 1
1677 end if
1678 result = str
1679 i = index(result(sp:), from)
1680 if (i == 0) return
1681 i = i + sp - 1
1682 isa = i + len(from)
1683 isb = i + len(to)
1684 if (len(to) < len(from)) then
1685 iea = len(result)
1686 ieb = len(result) + len(to) - len(from)
1687 else
1688 iea = len(result) + len(from) - len(to)
1689 ieb = len(result)
1690 endif
1691 if (len(to) /= len(from)) result(isb:ieb) = result(isa:iea)
1692 result(i:i+len(to)-1) = to
1693 !-----------------------------------
1694 ! 再帰的処理
1695 ! Recursive process
1696 ir = index(result(i+len(to):), from)
1697 if ( len_trim(from) == 0 ) then
1698 ir = index(trim(result(i+len(to):)), from)
1699 end if
1700 if (ir /= 0) then
1701 if ( present(recursive) ) then
1702 if ( recursive ) then
1703 result = replace( str = result, &
1704 & from = from, to = to, &
1705 & recursive = recursive, &
1706 & start_pos = i+len(to) )
1707 end if
1708 end if
1709 end if
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public sp
Single Precision Real number.
Definition dc_types.f90:82
integer, parameter, public string
Character length for string
Definition dc_types.f90:137

◆ roundnum()

character(string) function, public dc_string::roundnum ( character(*), intent(in)  num)

Round numeric string representation

Formats numeric strings like '0.30000001' or '12.999998' that have rounding errors to cleaner representations like '0.3' or '13.'.

Parameters
[in]numNumeric string to round
Returns
Rounded numeric string

Definition at line 1831 of file dc_string.f90.

1832 character(*), intent(in):: num
1833 character(STRING):: nrv, enrv
1834 integer:: i, moving_up, nrvi, dig, zero_stream
1835 continue
1836 !
1837 ! 実数でないものについてはそのまま返す.
1838 !
1839 if ( scan('.', trim(num) ) == 0 ) then
1840 result = num
1841 return
1842 end if
1843 nrv = num
1844 !
1845 ! 指数部を避けておく.
1846 !
1847 enrv = ''
1848 i = scan(nrv, "eE", back=.true.)
1849 if ( i > 1 ) then
1850 enrv = nrv(i:)
1851 nrv(i:) = " "
1852 elseif ( i == 1 ) then
1853 result = nrv
1854 return
1855 end if
1856 !
1857 ! 0.30000001 などの末尾の 1 のような, ゴミの桁の数値を掃除し,
1858 ! 0.3000000 などに整形.
1859 !
1860 if ( index( trim( nrv ), '.') - len_trim( nrv ) < -7 ) then
1861 do while ( index('567890.', nrv(len_trim(nrv):len_trim(nrv)) ) == 0 )
1862 if ( len_trim(nrv) < 2 ) exit
1863 nrv = nrv(1:len_trim(nrv)-1)
1864 end do
1865 end if
1866 !
1867 ! 0.30000001986 などの末尾の 1 以降のゴミの桁の数値を掃除し,
1868 ! 0.3000000 などに整形.
1869 !
1870 if ( index( trim( nrv ), '.') - len_trim( nrv ) < -7 ) then
1871 dig = index( trim( nrv ), '.') + 1
1872 zero_stream = 0
1873 do while ( dig < len_trim( nrv ) )
1874 if ( nrv(dig:dig) == "0" ) then
1875 zero_stream = zero_stream + 1
1876 else
1877 zero_stream = 0
1878 end if
1879 if ( zero_stream > 7 ) then
1880 nrv(dig:len_trim(nrv)) = '0'
1881 exit
1882 end if
1883 dig = dig + 1
1884 end do
1885 end if
1886 !
1887 ! 0.3000000 などの末尾の 0 を掃除し,
1888 ! 0.3 などに整形.
1889 !
1890 if ( index( trim( nrv ), '.') /= 0 ) then
1891 do while ( index('123456789.', nrv(len_trim(nrv):len_trim(nrv)) ) == 0 )
1892 if ( len_trim(nrv) < 2 ) exit
1893 nrv = nrv(1:len_trim(nrv)-1)
1894 end do
1895 end if
1896 !
1897 ! 0.89999998 などの末尾の 8 のような, ゴミの桁の数値を掃除し,
1898 ! 0.8999999 などに整形.
1899 !
1900 moving_up = 0
1901 if ( index( trim( nrv ), '.') - len_trim( nrv ) < -7 ) then
1902 do while ( index('12345690.', nrv(len_trim(nrv):len_trim(nrv)) ) == 0 )
1903 if ( len_trim(nrv) < 2 ) exit
1904 nrv = nrv(1:len_trim(nrv)-1)
1905 end do
1906 moving_up = 1
1907 end if
1908 !
1909 ! 0.8999999 などの末尾の 9 を掃除し, 繰り上げて
1910 ! 0.9 などに整形.
1911 !
1912 if ( moving_up > 0 ) then
1913 do while ( index('012345678.', nrv(len_trim(nrv):len_trim(nrv)) ) == 0 )
1914 if ( len_trim(nrv) < 2 ) exit
1915 nrv = nrv(1:len_trim(nrv)-1)
1916 end do
1917 end if
1918 i = len_trim(nrv)
1919 do while ( moving_up > 0 .and. i > 0 )
1920 if ( index('.', nrv(i:i)) /= 0 ) then
1921 i = i - 1
1922 cycle
1923 end if
1924 nrvi = stoi( nrv(i:i) ) + moving_up
1925 if ( nrvi < 10 ) then
1926 nrv(i:i) = trim( tochar( nrvi ) )
1927 exit
1928 else
1929 nrv(i:i) = '0'
1930 if ( i < 2 ) then
1931 nrv = '10'
1932 exit
1933 else
1934 i = i - 1
1935 cycle
1936 end if
1937 end if
1938 if ( len_trim(nrv) < 2 ) exit
1939 nrv = nrv(1:len_trim(nrv)-1)
1940 end do
1941 !
1942 ! 0.3000000 などの末尾の 0 を掃除し,
1943 ! 0.3 などに整形.
1944 !
1945 if ( index( trim( nrv ), '.') /= 0 ) then
1946 do while ( index('123456789.', nrv(len_trim(nrv):len_trim(nrv)) ) == 0 )
1947 if ( len_trim(nrv) < 2 ) exit
1948 nrv = nrv(1:len_trim(nrv)-1)
1949 end do
1950 end if
1951 !
1952 ! 指数部を復帰する
1953 !
1954 if ( len_trim(enrv) > 0 ) then
1955 nrv = trim(nrv) // enrv
1956 end if
1957 result = nrv

◆ uchar()

character(string) function, public dc_string::uchar ( character(len = *), intent(in)  ch)

Return uppercase copy of string

Returns a copy of ch with all lowercase letters converted to uppercase. Non-alphabetic characters and already uppercase characters are unchanged.

Parameters
[in]chString to convert
Returns
Uppercase string

Definition at line 1785 of file dc_string.f90.

1786 character(len = *), intent(in):: ch
1787 continue
1788 result = ch
1789 call toupper(result)