Convert real array to string.
use penf
print "(A)", str(n=[1._R4P, -2._R4P])
use penf
print "(A)", str(n=[1._R4P, 2._R4P], no_sign=.true.)
use penf
print "(A)", str(n=[1._R4P, -2._R4P], separator='|')
use penf
print "(A)", str(n=[1._R4P, -2._R4P], delimiters=['(', ')'])
use penf
print "(A)", str(n=[1._R4P, -2._R4P], compact=.true.)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=R4P), | intent(in) | :: | n(:) |
Real array to be converted. |
||
logical, | intent(in), | optional | :: | no_sign |
Flag for leaving out the sign. |
|
character(len=1), | intent(in), | optional | :: | separator |
Eventual separator of array values. |
|
character(len=*), | intent(in), | optional | :: | delimiters(1:2) |
Eventual delimiters of array values. |
|
logical, | intent(in), | optional | :: | compact |
Flag for compacting string encoding. |
Returned string containing input number.
pure function str_a_R4P(n, no_sign, separator, delimiters, compact) result(str) !< Convert real array to string. !< !<```fortran !< use penf !< print "(A)", str(n=[1._R4P, -2._R4P]) !<``` !=> +0.100000E+01,-0.200000E+01 <<< !< !<```fortran !< use penf !< print "(A)", str(n=[1._R4P, 2._R4P], no_sign=.true.) !<``` !=> 0.100000E+01,0.200000E+01 <<< !< !<```fortran !< use penf !< print "(A)", str(n=[1._R4P, -2._R4P], separator='|') !<``` !=> +0.100000E+01|-0.200000E+01 <<< !< !<```fortran !< use penf !< print "(A)", str(n=[1._R4P, -2._R4P], delimiters=['(', ')']) !<``` !=> (+0.100000E+01,-0.200000E+01) <<< !< !<```fortran !< use penf !< print "(A)", str(n=[1._R4P, -2._R4P], compact=.true.) !<``` !=> +0.1E+1,-0.2E+1 <<< real(R4P), intent(in) :: n(:) !< Real array to be converted. logical, intent(in), optional :: no_sign !< Flag for leaving out the sign. character(1), intent(in), optional :: separator !< Eventual separator of array values. character(*), intent(in), optional :: delimiters(1:2) !< Eventual delimiters of array values. logical, intent(in), optional :: compact !< Flag for *compacting* string encoding. character(len=:), allocatable :: str !< Returned string containing input number. character(DR4P) :: strn !< String containing of element of input array number. character(len=1) :: sep !< Array values separator integer :: i !< Counter. str = '' sep = ',' if(present(separator)) sep = separator do i=1,size(n) strn = str_R4P(no_sign=no_sign, compact=compact, n=n(i)) str = str//sep//trim(strn) enddo str = trim(str(2:)) if (present(delimiters)) str = delimiters(1)//str//delimiters(2) endfunction str_a_R4P