read_line_from_file Subroutine

private subroutine read_line_from_file(me, iunit, line, status_ok)

Reads the next line from a file.

Type Bound

csv_file

Arguments

Type IntentOptional 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


Called by

proc~~read_line_from_file~~CalledByGraph proc~read_line_from_file csv_file%read_line_from_file proc~read_csv_file csv_file%read_csv_file proc~read_csv_file->proc~read_line_from_file

Source Code

    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