[UP]


Manual Reference Pages  - read_all (3)

NAME

read_all(3f) - [M_io] read a line from specified LUN into allocatable string up to line length limit (LICENSE:PD)

CONTENTS

Syntax
Description
Options
Returns
Example
Author
License

SYNTAX

function read_all(line,lun) result(ier)

   character(len=:),allocatable,intent(out) :: line
   integer,intent(in),optional              :: lun
   integer,intent(out)                      :: ier

DESCRIPTION

Read a line of any length up to programming environment’s maximum line length. Requires Fortran 2003+.

It is primarily expected to be used when reading input which will then be parsed.

The input file must have a PAD attribute of YES for the function to work properly, which is typically true.

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.

OPTIONS

LINE line read
LUN optional LUN (Fortran logical I/O unit) number. Defaults to stdin.

RETURNS

IER zero unless an error occurred. If not zero, LINE returns the I/O error message.

EXAMPLE

Sample program:

   program demo_read_all
   use,intrinsic :: iso_fortran_env, only : stdin=>input_unit
   implicit none
   open(unit=stdin,pad=’yes’)
   ichars=0
   msg=’’
   do
      read(stdin,advance=’no’,size=isize,iostat=ios,fmt=’(*(a),t1)’,iomsg=msg)a
      if(ios.ne.0) exit
      ichars=ichars+1
      write(*,*)ichars,a
   enddo
   write(*,*)’END’,ichars,isize,trim(msg)
end program testit use M_io, only : read_all implicit none character(len=:),allocatable :: line INFINITE: do while (read_all(line)==0) write(*,’(a)’)’[’//line//’]’ enddo INFINITE end program demo_read_all

AUTHOR

John S. Urban

LICENSE

Public Domain


read_all (3) October 17, 2020
Generated by manServer 1.08 from faa81fa1-c609-4f7c-9030-9738f0439287 using man macros.