read_file_to_int_vec Function

public function read_file_to_int_vec(filename) result(array)

read a file that is single string of ints into a vector

Arguments

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

Return Value integer, dimension(:), allocatable


Calls

proc~~read_file_to_int_vec~~CallsGraph proc~read_file_to_int_vec read_file_to_int_vec proc~read_line read_line proc~read_file_to_int_vec->proc~read_line

Source Code

    function read_file_to_int_vec(filename) result(array)
        !! read a file that is single string of ints into a vector
        character(len=*),intent(in) :: filename
        integer,dimension(:),allocatable :: array

        integer :: i, iunit, n_lines, n_cols
        character(len=:),allocatable :: line

        open(newunit=iunit, file=filename, status='OLD')
        line = read_line(iunit)
        allocate(array(len(line)))
        do i = 1, size(array)
            read(line(i:i),'(*(I1))') array(i)
        end do
        close(iunit)

    end function read_file_to_int_vec