Other useful subroutines/functions

file_exists

How to use

subroutine file_exists(path)
Parameters:path :: file path [1]
Call :file_exists(path)

numRows

How to use

subroutine numRows(unit)
Parameters:unit :: file unit [1]
Call :numRows(unit)
[1](1, 2) Defined by user

[Code example] Reads a file, checks to see if it exists, and counts the number of rows.

!:==================== File utilities =========================================
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
#RedHat based systems
gfortran -o fileutils.out fileutils.f90 -I/usr/lib64/gfortran/modules/ -lFPL

#Debian based systems
gfortran -o fileutils.out fileutils.f90 -I/usr/include/ -lFPL

Important

-I<dir> This option specifies where to put .mod files for compiled modules. It is also added to the list of directories to Influencing the linking step. See the GNU Fortran Compiler Documentation .

<dir> is defined in Makefile as $(FPL_moddir). See Build Library.

After compilation run the program ./fileutils.out

Attention

Change the file paths according to your system!