[UP]


Manual Reference Pages  - getline (3)

NAME

getline(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 getline(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 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_getline
   use,intrinsic :: iso_fortran_env, only : stdin=>input_unit
   use M_io, only : getline
   implicit none
   character(len=:),allocatable :: line
      open(unit=stdin,pad=’yes’)
      INFINITE: do while (getline(line)==0)
         write(*,’(a)’)’[’//line//’]’
      enddo INFINITE
   end program demo_getline

AUTHOR

John S. Urban

LICENSE

Public Domain


getline (3) March 11, 2021
Generated by manServer 1.08 from 3cfcec84-e88a-4150-bda8-406c5cd3be5d using man macros.