ctoi_I4P Function

private function ctoi_I4P(str, knd, pref, error) result(n)

Arguments

TypeIntentOptionalAttributesName
character, intent(in) :: str
integer(kind=I4P), intent(in) :: knd
character, intent(in), optional :: pref
integer(kind=I4P), intent(out), optional :: error

Return Value integer(kind=I4P)


Called by

proc~~ctoi_i4p~4~~CalledByGraph proc~ctoi_i4p~4 ctoi_I4P interface~cton~4 cton interface~cton~4->proc~ctoi_i4p~4

Contents

Source Code


Source Code

   function ctoi_I4P(str, knd, pref, error) result(n)
   !< Convert string to integer.
   !<
   !<```fortran
   !< use penf
   !< print FI4P, cton(str='-1', knd=1_I4P)
   !<```
   !=> -1 <<<
   character(*),           intent(in)  :: str   !< String containing input number.
   integer(I4P),           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(I4P)                        :: 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
   endfunction ctoi_I4P