rd(3f) - [M_io] ask for string from standard input with user-definable prompt (LICENSE:PD)
function rd(prompt,default) result(strout)character(len=*),intent(in) :: prompt
character(len=*),intent(in) :: default or integer,intent(in) :: default or real,intent(in) :: default or doubleprecision,intent(in) :: default
character(len=:),allocatable,intent(out) :: strout
Description
Options
Returns
Example
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.
strout returned string or value. If an end-of-file or system error is encountered the string "EOF" is returned, or a "Nan" numeric value.
Sample program:
program demo_rd use M_io, only : rd implicit none character(len=:),allocatable :: mystring doubleprecision :: d real :: r integer :: iINFINITE: do mystring=rd(Enter string or "STOP":,default=Today) if(mystring.eq.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))
write(*,*)I=, i, R=, r, D=,d, MYSTRING=, mystring enddo INFINITE
end program demo_rd
John S. Urban, 1993
Public Domain
rd (3) | March 11, 2021 |