read_line Function

public function read_line(iunit, status_ok) result(line)

Reads the next line from a file.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: iunit
logical, intent(out), optional :: status_ok

true if no problems

Return Value character(len=:), allocatable


Called by

proc~~read_line~~CalledByGraph proc~read_line aoc_utilities::read_line proc~go~2 problem_18::go proc~go~2->proc~read_line proc~go~8 problem_12::go proc~go~8->proc~read_line proc~initialize problem_22::initialize proc~initialize->proc~read_line proc~read_file_to_char_array aoc_utilities::read_file_to_char_array proc~read_file_to_char_array->proc~read_line proc~read_file_to_int_array aoc_utilities::read_file_to_int_array proc~read_file_to_int_array->proc~read_line program~problem_1 problem_1 program~problem_1->proc~read_line program~problem_12b problem_12b program~problem_12b->proc~read_line program~problem_13 problem_13 program~problem_13->proc~read_line program~problem_15 problem_15 program~problem_15->proc~read_line program~problem_19 problem_19 program~problem_19->proc~read_line program~problem_19b problem_19b program~problem_19b->proc~read_line program~problem_2 problem_2 program~problem_2->proc~read_line program~problem_25 problem_25 program~problem_25->proc~read_line program~problem_4 problem_4 program~problem_4->proc~read_line program~problem_5 problem_5 program~problem_5->proc~read_line program~problem_7 problem_7 program~problem_7->proc~read_line program~problem_8 problem_8 program~problem_8->proc~read_line program~problem_9 problem_9 program~problem_9->proc~read_line proc~go~5 problem_23::go proc~go~5->proc~read_file_to_char_array proc~go~6 problem_11::go proc~go~6->proc~read_file_to_char_array program~problem_10 problem_10 program~problem_10->proc~read_file_to_char_array program~problem_12 problem_12 program~problem_12->proc~go~8 program~problem_16 problem_16 program~problem_16->proc~read_file_to_char_array program~problem_17 problem_17 program~problem_17->proc~read_file_to_int_array program~problem_17~2 problem_17 program~problem_17~2->proc~read_file_to_int_array program~problem_18 problem_18 program~problem_18->proc~go~2 program~problem_21 problem_21 program~problem_21->proc~read_file_to_char_array program~problem_22 problem_22 program~problem_22->proc~initialize program~problem_3 problem_3 program~problem_3->proc~read_file_to_char_array program~problem_11 problem_11 program~problem_11->proc~go~6 program~problem_23 problem_23 program~problem_23->proc~go~5

Source Code

    function read_line(iunit,status_ok) result(line)

    integer,intent(in) :: iunit
    character(len=:),allocatable :: line
    logical,intent(out),optional :: status_ok !! true if no problems

    integer :: nread  !! character count specifier for read statement
    integer :: istat  !! file read io status flag
    character(len=chunk_size) :: buffer !! the file read buffer

    nread  = 0
    buffer = ''
    line   = ''
    if (present(status_ok)) 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 (present(status_ok)) then
                status_ok = .false.
                exit
            else
                error stop 'Read error'
            end if
        end if
    end do

    end function read_line