reads a line from unit into an allocatable character
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | unit | |||
| character(len=:), | intent(out), | allocatable | :: | line | ||
| integer, | intent(out), | optional | :: | iostat |
subroutine getline(unit,line,iostat) integer,intent(in) :: unit character(len=:),allocatable,intent(out) :: line integer,intent(out),optional :: iostat integer,parameter :: buffersize=256 character(len=buffersize) :: buffer integer :: size integer :: stat line = "" do read(unit,"(a)",advance="no",iostat=stat,size=size) & & buffer if (stat>0) then if (present(iostat)) iostat=stat return ! an error occurred end if line = line // buffer(:size) if (stat<0) then if (is_iostat_eor(stat)) stat = 0 if (present(iostat)) iostat=stat return end if end do end subroutine getline