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.gt.0) then if (present(iostat)) iostat=stat return ! an error occurred endif line = line // buffer(:size) if (stat.lt.0) then if (is_iostat_eor(stat)) stat = 0 if (present(iostat)) iostat=stat return endif enddo end subroutine getline