fpm_filesystem Module

This module contains general routines for interacting with the file system



Contents


Functions

public function basename(path, suffix) result(base)

Extract filename from path with/without suffix

Arguments

Type IntentOptional AttributesName
character, intent(in) :: path
logical, intent(in), optional :: suffix

Return Value character, allocatable

public function canon_path(path)

Canonicalize path for comparison * Handles path string redundancies * Does not test existence of path

Read more…

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: path

Return Value character(len=:), allocatable

public function dirname(path) result(dir)

Extract dirname from path

Arguments

Type IntentOptional AttributesName
character, intent(in) :: path

Return Value character, allocatable

public function exists(filename) result(r)

test if pathname already exists

Arguments

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

Return Value logical

public function get_temp_filename() result(tempfile)

Get a unused temporary filename Calls posix ‘tempnam’ - not recommended, but we have no security concerns for this application and use here is temporary. Works with MinGW

Arguments

None

Return Value character, allocatable

public function is_dir(dir)

test if a name matches an existing directory path

Arguments

Type IntentOptional AttributesName
character, intent(in) :: dir

Return Value logical

public function join_path(a1, a2, a3, a4, a5) result(path)

Construct path by joining strings with os file separator

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: a1
character(len=*), intent(in) :: a2
character(len=*), intent(in), optional :: a3
character(len=*), intent(in), optional :: a4
character(len=*), intent(in), optional :: a5

Return Value character(len=:), allocatable

public function number_of_rows(s) result(nrows)

Determine number or rows in a file given a LUN

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: s

Return Value integer

public function parent_dir(path) result(dir)

Extract dirname from path

Arguments

Type IntentOptional AttributesName
character, intent(in) :: path

Return Value character, allocatable

public function read_lines(fh) result(lines)

read lines into an array of TYPE(STRING_T) variables

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: fh

Return Value type(string_t), allocatable, (:)

public function read_lines_expanded(fh) result(lines)

read lines into an array of TYPE(STRING_T) variables expanding tabs

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: fh

Return Value type(string_t), allocatable, (:)

public function unix_path(path) result(nixpath)

Replace file system separators for 1

Arguments

Type IntentOptional AttributesName
character, intent(in) :: path

Return Value character, allocatable

public function which(command) result(pathname)

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: command

NAME

 which(3f) - [M_io:ENVIRONMENT] given a command name find the pathname by searching
             the directories in the environment variable $PATH
 (LICENSE:PD)

SYNTAX

function which(command) result(pathname)

character(len=*),intent(in)  :: command
character(len=:),allocatable :: pathname

DESCRIPTION

Given a command name find the first file with that name in the directories
specified by the environment variable $PATH.

OPTIONS

COMMAND   the command to search for

RETURNS

PATHNAME  the first pathname found in the current user path. Returns blank
          if the command is not found.

EXAMPLE

Sample program:

Checking the error message and counting lines:

 program demo_which
 use M_io, only : which
 implicit none
    write(*,*)'ls is ',which('ls')
    write(*,*)'dir is ',which('dir')
    write(*,*)'install is ',which('install')
 end program demo_which

AUTHOR

John S. Urban

LICENSE

Public Domain

Return Value character(len=:), allocatable

public function windows_path(path) result(winpath)

Replace file system separators for windows

Arguments

Type IntentOptional AttributesName
character, intent(in) :: path

Return Value character, allocatable


Subroutines

public subroutine delete_file(file)

delete a file by filename

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: file

public subroutine env_variable(var, name)

return value of environment variable

Arguments

Type IntentOptional AttributesName
character(len=:), intent(out), allocatable:: var
character(len=*), intent(in) :: name

public subroutine fileclose(lun, ier)

simple close of a LUN. On error show message and stop (by default)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: lun
integer, intent(out), optional :: ier

public subroutine fileopen(filename, lun, ier)

procedure to open filename as a sequential “text” file

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: filename
integer, intent(out) :: lun
integer, intent(out), optional :: ier

public subroutine filewrite(filename, filedata)

procedure to write filedata to file filename

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: filedata(:)

public subroutine getline(unit, line, iostat, iomsg)

read a line of arbitrary length into a CHARACTER variable from the specified LUN

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: unit

Formatted IO unit

character(len=:), intent(out), allocatable:: line

Line to read

integer, intent(out) :: iostat

Status of operation

character(len=:), optional allocatable:: iomsg

Error message

public recursive subroutine list_files(dir, files, recurse)

Get file & directory names in directory dir using iso_c_binding.

Read more…

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: dir
type(string_t), intent(out), allocatable:: files(:)
logical, intent(in), optional :: recurse

public subroutine mkdir(dir)

Create a directory. Create subdirectories as needed

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: dir

public subroutine warnwrite(fname, data)

write trimmed character data to a file if it does not exist

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: fname
character(len=*), intent(in) :: data(:)