read_file_to_integer_array Function

public function read_file_to_integer_array(filename) result(iarray)

Read a file into an integer array (one element per line)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename

Return Value integer, dimension(:), allocatable


Calls

proc~~read_file_to_integer_array~~CallsGraph proc~read_file_to_integer_array aoc_utilities::read_file_to_integer_array proc~number_of_lines_in_file aoc_utilities::number_of_lines_in_file proc~read_file_to_integer_array->proc~number_of_lines_in_file

Source Code

    function read_file_to_integer_array(filename) result(iarray)

    character(len=*),intent(in) :: filename
    integer,dimension(:),allocatable :: iarray

    integer :: i, iunit, n_lines, istat

    open(newunit=iunit, file=filename, iostat=istat)
    if (istat /= 0) error stop ' error reading file'

    n_lines = number_of_lines_in_file(iunit)
    allocate(iarray(n_lines))
    do i = 1, n_lines
        read(iunit, '(I10)') iarray(i)
    end do

    close(iunit)

    end function read_file_to_integer_array