Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | str | String containing input number. |
||
integer(kind=I2P), | intent(in) | :: | knd | Number kind. |
||
character(len=*), | intent(in), | optional | :: | pref | Prefixing string. |
|
integer(kind=I4P), | intent(out), | optional | :: | error | Error trapping flag: 0 no errors, >0 error occurs. |
Number returned.
Convert string to integer.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer(kind=I4P), | public | :: | err | Error trapping flag: 0 no errors, >0 error occurs. |
|||
character(len=:), | public, | allocatable | :: | prefd | Prefixing string. |
function ctoi_I2P(str, knd, pref, error) result(n)
!---------------------------------------------------------------------------------------------------------------------------------
!< Convert string to integer.
!---------------------------------------------------------------------------------------------------------------------------------
character(*), intent(in) :: str !< String containing input number.
integer(I2P), intent(in) :: knd !< Number kind.
character(*), optional, intent(in) :: pref !< Prefixing string.
integer(I4P), optional, intent(out) :: error !< Error trapping flag: 0 no errors, >0 error occurs.
integer(I2P) :: n !< Number returned.
integer(I4P) :: err !< Error trapping flag: 0 no errors, >0 error occurs.
character(len=:), allocatable :: prefd !< Prefixing string.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
read(str, *, iostat=err) n ! Casting of str to n.
if (err/=0) then
prefd = '' ; if (present(pref)) prefd = pref
write(stderr, '(A,I1,A)') prefd//' Error: conversion of string "'//str//'" to integer failed! integer(', kind(knd), ')'
endif
if (present(error)) error = err
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction ctoi_I2P