C Library Functions  - rd (3)

NAME

rd(3f) - [M_io:READ] ask for string from standard input with user-definable prompt (LICENSE:PD)

  function rd(prompt,default) result(out)

character(len=*),intent(in) :: prompt

One of

character(len=*),intent(in) :: default character(len=:),allocatable,intent(out) :: out

integer,intent(in) :: default integer,intent(out) :: out

real,intent(in) :: default real,intent(out) :: out

doubleprecision,intent(in) :: default doubleprecision,intent(out) :: out

logical,intent(in) :: default logical,intent(out) :: out

CONTENTS

Description
Options
Returns
Example
Author
License

DESCRIPTION

Ask for string or value from standard input with user-definable prompt up to 20 times.

Do not use the function in an I/O statement as not all versions of Fortran support this form of recursion. Numeric values may be input in standard INTEGER, REAL, and DOUBLEPRECISION formats or as whole numbers in base 2 to 36 in the format BASE#VALUE.

OPTIONS

prompt Prompt string; displayed on same line as input is read from
default
  default answer on carriage-return. The type of the default determines the type of the output.

RETURNS

out returned string or value. If an end-of-file or system error is encountered the string "EOF" is returned, or a "Nan" REAL numeric value, or huge(0), or .false. .

EXAMPLE

Sample program:

   program demo_rd
   use M_io, only : rd
   implicit none
   character(len=:),allocatable :: mystring
   doubleprecision              :: d
   real                         :: r
   integer                      :: i
   logical                      :: l

INFINITE: do mystring=rd(’Enter string or "STOP":’,default=’Today’) if(mystring == ’STOP’)stop i=rd(’Enter integer:’,default=huge(0)) r=rd(’Enter real:’,default=huge(0.0)) d=rd(’Enter double:’,default=huge(0.0d0)) l=rd(’Enter logical:’,default=.false.)

write(*,*)’I=’, i, ’R=’, r, ’D=’,d, ’MYSTRING=’, mystring write(*,*)’L=’, l enddo INFINITE

end program demo_rd

AUTHOR

John S. Urban, 1993

LICENSE

Public Domain


Nemo Release 3.1 rd (3) July 22, 2023
Generated by manServer 1.08 from 7667a690-5d64-4d56-9eb1-7e8631df19a3 using man macros.