dm_file Module

File access utility routines.


Uses

  • module~~dm_file~~UsesGraph module~dm_file dm_file module~dm_error dm_error module~dm_file->module~dm_error module~dm_kind dm_kind module~dm_file->module~dm_kind module~dm_error->module~dm_kind module~dm_ascii dm_ascii module~dm_error->module~dm_ascii iso_fortran_env iso_fortran_env module~dm_kind->iso_fortran_env

Used by

  • module~~dm_file~~UsedByGraph module~dm_file dm_file module~dm_arg dm_arg module~dm_arg->module~dm_file module~dm_camera dm_camera module~dm_camera->module~dm_file module~dm_fifo dm_fifo module~dm_fifo->module~dm_file module~dm_gm dm_gm module~dm_gm->module~dm_file module~dm_im dm_im module~dm_im->module~dm_file module~dm_lua dm_lua module~dm_lua->module~dm_file module~dm_plot dm_plot module~dm_plot->module~dm_file module~dm_report dm_report module~dm_report->module~dm_file module~dm_report->module~dm_plot module~dm_tty dm_tty module~dm_tty->module~dm_file module~dmpack dmpack module~dmpack->module~dm_file module~dmpack->module~dm_arg module~dmpack->module~dm_camera module~dmpack->module~dm_fifo module~dmpack->module~dm_gm module~dmpack->module~dm_im module~dmpack->module~dm_lua module~dmpack->module~dm_plot module~dmpack->module~dm_report module~dmpack->module~dm_tty module~dm_config dm_config module~dmpack->module~dm_config module~dm_geocom dm_geocom module~dmpack->module~dm_geocom module~dm_lua_api dm_lua_api module~dmpack->module~dm_lua_api module~dm_lua_geocom dm_lua_geocom module~dmpack->module~dm_lua_geocom proc~dm_config_open dm_config_open proc~dm_config_open->module~dm_file proc~dm_config_open->module~dm_lua_api proc~dm_config_open->module~dm_lua_geocom proc~dm_db_attach dm_db_attach proc~dm_db_attach->module~dm_file proc~dm_db_backup dm_db_backup proc~dm_db_backup->module~dm_file proc~dm_db_open dm_db_open proc~dm_db_open->module~dm_file proc~dm_db_vacuum dm_db_vacuum proc~dm_db_vacuum->module~dm_file proc~dm_hdf5_file_is_valid dm_hdf5_file_is_valid proc~dm_hdf5_file_is_valid->module~dm_file module~dm_config->module~dm_lua module~dm_geocom->module~dm_tty module~dm_lua_api->module~dm_lua module~dm_lua_geocom->module~dm_lua proc~dm_modbus_create_rtu dm_modbus_create_rtu proc~dm_modbus_create_rtu->module~dm_tty proc~luaopen_libdmpack luaopen_libdmpack proc~luaopen_libdmpack->module~dm_lua proc~luaopen_libdmpack->module~dm_lua_api proc~luaopen_libdmpack->module~dm_lua_geocom

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: FILE_PATH_LEN = 2048

Maximum file path length.

integer, public, parameter :: FILE_TYPE_NONE = 0

Unknown type.

integer, public, parameter :: FILE_TYPE_BLOCK = 1

Block device.

integer, public, parameter :: FILE_TYPE_CHAR = 2

Character device.

integer, public, parameter :: FILE_TYPE_DIR = 3

Directory.

integer, public, parameter :: FILE_TYPE_FIFO = 4

FIFO or pipe.

integer, public, parameter :: FILE_TYPE_FILE = 5

Regular file.

integer, public, parameter :: FILE_TYPE_LINK = 6

Symbolic link.

integer, public, parameter :: FILE_TYPE_SOCKET = 7

Socket.


Derived Types

type, public ::  file_status_type

Abstraction of C struct stat(2) that stores parts of a file status. The file mode is usually an unsigned type (uint32_t on Linux, uint16_t on FreeBSD), and is therefore converted to signed integer after the syscall.

Components

Type Visibility Attributes Name Initial
integer, public :: type = FILE_TYPE_NONE

File type.

integer(kind=i8), public :: mode = 0

File mode as signed integer.

integer(kind=i8), public :: size = 0_i8

File size in bytes.

integer(kind=i8), public :: a_time = 0_i8

Time of last access (Unix epoch).

integer(kind=i8), public :: m_time = 0_i8

Time of last modification (Unix epoch).

integer(kind=i8), public :: c_time = 0_i8

Time of last status change (Unix epoch).


Functions

public function dm_file_exists(path) result(file_exists)

Returns .true. if file at given file path exists.

Arguments

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

File path.

Return Value logical

public function dm_file_line_count(path, error) result(n)

Returns number of lines in given file by counting new lines. Sets error to E_IO if opening the file failed, and to E_EMPTY if the file has no lines.

Arguments

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

File path.

integer, intent(out), optional :: error

Error code.

Return Value integer(kind=i8)

public function dm_file_size(path, error) result(sz)

Returns file size in file storage units (usually, bytes). On error, size is 0 and the error code E_NOT_FOUND is returned in dummy argument error.

Arguments

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

File path.

integer, intent(out), optional :: error

Error code.

Return Value integer(kind=i8)

public function dm_file_status(path, status) result(rc)

Returns status of file at given path in status. The function returns E_SYSTEM on error.

Arguments

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

File path.

type(file_status_type), intent(out) :: status

File status type.

Return Value integer


Subroutines

public subroutine dm_file_delete(path, error)

Deletes file at given file path. Returns E_IO on error.

Arguments

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

File to delete.

integer, intent(out), optional :: error

Error code.

public subroutine dm_file_touch(path, error)

Creates empty file at given file path. Returns E_IO on error.

Arguments

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

File to create.

integer, intent(out), optional :: error

Error code.

public subroutine dm_file_read(path, content, size, error)

Reads file contents as byte stream into allocatable character string.

Read more…

Arguments

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

File path.

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

Byte string.

integer(kind=i8), intent(out), optional :: size

Content size.

integer, intent(out), optional :: error

Error code.

public subroutine dm_file_write(path, content, raw, error)

Writes content to given file (ASCII or binary).

Read more…

Arguments

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

Output file path.

character(len=*), intent(in) :: content

Bytes to write.

logical, intent(in), optional :: raw

Unformatted output if true.

integer, intent(out), optional :: error

Error code.