number_of_lines_in_file Function

private function number_of_lines_in_file(iunit) result(n_lines)

Returns the number of lines in a text file.

Note

It rewinds the file back to the beginning when finished.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: iunit

the file unit number (assumed to be open)

Return Value integer

the number of lines in the file


Called by

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

Source Code

    function number_of_lines_in_file(iunit) result(n_lines)

    implicit none

    integer,intent(in)  :: iunit   !! the file unit number
                                     !! (assumed to be open)
    integer :: n_lines   !! the number of lines in the file

    character(len=1) :: tmp
    integer :: istat

    rewind(iunit)
    n_lines = 0
    do
        read(iunit,fmt='(A1)',iostat=istat) tmp
        if (is_iostat_end(istat)) exit
        n_lines = n_lines + 1
    end do
    rewind(iunit)

    end function number_of_lines_in_file