Reads the next line from a file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(csv_file), | intent(in) | :: | me | |||
integer, | intent(in) | :: | iunit | |||
character(len=:), | intent(out), | allocatable | :: | line | ||
logical, | intent(out) | :: | status_ok |
true if no problems |
subroutine read_line_from_file(me,iunit,line,status_ok) implicit none class(csv_file),intent(in) :: me integer,intent(in) :: iunit character(len=:),allocatable,intent(out) :: line logical,intent(out) :: status_ok !! true if no problems integer :: nread !! character count specifier for read statement integer :: istat !! file read io status flag character(len=me%chunk_size) :: buffer !! the file read buffer nread = 0 buffer = '' line = '' status_ok = .true. do ! read in the next block of text from the line: read(iunit,fmt='(A)',advance='NO',size=nread,iostat=istat) buffer if (IS_IOSTAT_END(istat) .or. IS_IOSTAT_EOR(istat)) then ! add the last block of text before the end of record if (nread>0) line = line//buffer(1:nread) exit else if (istat==0) then ! all the characters were read line = line//buffer ! add this block of text to the string else ! some kind of error if (me%verbose) write(error_unit,'(A,1X,I5)') 'Read error for file unit: ',iunit status_ok = .false. exit end if end do end subroutine read_line_from_file