Example 05 — File Utilities
Checks if a file exists and counts the number of rows.
Source Code
program utils
use fpl
implicit none
integer(kind=4) :: nrows
write(*,*) "Count line number"
write(*,*) "============================"
if (file_exists("database/data.txt")) then
write(*,*) "File OK!"
open(100, file="database/data.txt", status="old")
end if
nrows = numRows(100)
write(*,*) nrows, file_exists("database/data.txt")
end program utils
Compile & Run
gfortran -o ex5.out ex5_utils.f90 -I/usr/lib64/gfortran/modules/ -lFPL
./ex5.out
Output
