read_line(3f) - [M_io] read a line from specified LUN into allocatable string up to line length limit cleaning up input line (LICENSE:MIT)
Syntax
Description
Example
Author
License
function read_line(line,lun) result(ier)
character(len=:),allocatable,intent(out) :: line integer,intent(in) :: lun integer,intent(out) :: ier
Read a line of any length up to programming environments maximum line length. Requires Fortran 2003+.
It is primarily expected to be used when reading input which will then be parsed.
The simple use of a loop that repeatedly re-allocates a character variable in addition to reading the input file one buffer at a time could (depending on the programming environment used) be inefficient, as it could reallocate and allocate memory used for the output string with each buffer read.
o Append lines that end in a backslash with next line o Expand tabs o Replace unprintable characters with spaces o Remove trailing carriage return characters and white space
Sample program:
program demo_read_line use M_io, only : read_line implicit none character(len=:),allocatable :: line INFINITE: do while (read_line(line)==0) write(*,(a))[//line//] enddo INFINITE end program demo_read_line
John S. Urban
MIT License
read_line (3) | November 13, 2019 |