ctoi_I2P Function

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

Convert string to integer.

 use penf
 print FI2P, cton(str='-1', knd=1_I2P)

Arguments

TypeIntentOptionalAttributesName
character, intent(in) :: str

String containing input number.

integer(kind=I2P), intent(in) :: knd

Number kind.

character, intent(in), optional :: pref

Prefixing string.

integer(kind=I4P), intent(out), optional :: error

Error trapping flag: 0 no errors, >0 error occurs.

Return Value integer(kind=I2P)

Number returned.


Called by

proc~~ctoi_i2p~~CalledByGraph proc~ctoi_i2p ctoi_I2P interface~cton cton interface~cton->proc~ctoi_i2p program~volatile_doctest~21 volatile_doctest program~volatile_doctest~21->interface~cton program~volatile_doctest~51 volatile_doctest program~volatile_doctest~51->interface~cton program~volatile_doctest~83 volatile_doctest program~volatile_doctest~83->interface~cton program~volatile_doctest~67 volatile_doctest program~volatile_doctest~67->interface~cton program~volatile_doctest~4 volatile_doctest program~volatile_doctest~4->interface~cton program~volatile_doctest~58 volatile_doctest program~volatile_doctest~58->interface~cton program~volatile_doctest~66 volatile_doctest program~volatile_doctest~66->interface~cton

Contents

Source Code


Source Code

   function ctoi_I2P(str, knd, pref, error) result(n)
   !< Convert string to integer.
   !<
   !<```fortran
   !< use penf
   !< print FI2P, cton(str='-1', knd=1_I2P)
   !<```
   !=> -1 <<<
   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
   endfunction ctoi_I2P