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
Description
Options
Returns
Examples
Author
License
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.
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.
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. .
Sample program:
program demo_rd use M_io, only : rd implicit none character(len=:),allocatable :: mystring doubleprecision :: d real :: r integer :: i logical :: lINFINITE: 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
John S. Urban, 1993
Public Domain
Nemo Release 3.1 | rd (3) | February 23, 2025 |