(git:08825b9)
Loading...
Searching...
No Matches
cp_files Module Reference

Utility routines to open and close files. More...

Functions/Subroutines

subroutine, public close_file (unit_number, file_status)
 Closes an open file given by its logical unit number.
subroutine, public open_file (file_name, unit_number, file_status, file_form, file_action, file_position, file_pad, file_access, debug)
 Opens a file and returns its logical unit number.
logical function, public file_exists (file_name)
 Checks if a file exists, considering also the file discovery mechanism.
character(len=default_path_length) function, public discover_file (file_name)
 Searches for a file in the current directory and then in the data directory.
character(len=default_path_length) function, public get_data_dir ()
 Returns path of data directory if set, otherwise an empty string.
character(len=default_path_length) function, public join_paths (path1, path2)
 Joins two file paths, inserting '/' as needed.

Detailed Description

Utility routines to open and close files.

History
  • Creation CP2K_WORKSHOP 1.0 TEAM
  • Revised (18.02.2011, MK)
  • Enhanced error checking (22.02.2011, MK)
  • Preconnected units removed (03.10.2026, MK)
Note
Positive unit numbers are used instead of OPEN(NEWUNIT=...), because NEWUNIT returns negative numbers and CP2K treats a unit number > 0 as "output enabled". open_file is thread-safe: finding a free unit and connecting the file are done within the OpenMP critical region cp_files_connect. Concurrent use of the same unit (I/O, REWIND, close_file) must be avoided by the caller.
Author
Matthias Krack (MK)

Function/Subroutine Documentation

◆ close_file()

subroutine, public cp_files::close_file ( integer, intent(in) unit_number,
character(len=*), intent(in), optional file_status )

Closes an open file given by its logical unit number.

Parameters
unit_numberLogical unit number of the file to be closed
file_statusFile status after closing: KEEP or DELETE (default: KEEP for named, DELETE for unnamed SCRATCH files)
Author
Matthias Krack (MK)
Note
The program is aborted, if the unit is one of the default units (stdin, stdout, stderr). A unit which is not open is ignored silently.

Definition at line 62 of file cp_files.F.

Here is the call graph for this function:

◆ open_file()

subroutine, public cp_files::open_file ( character(len=*), intent(in), optional file_name,
integer, intent(out) unit_number,
character(len=*), intent(in), optional file_status,
character(len=*), intent(in), optional file_form,
character(len=*), intent(in), optional file_action,
character(len=*), intent(in), optional file_position,
character(len=*), intent(in), optional file_pad,
character(len=*), intent(in), optional file_access,
logical, intent(in), optional debug )

Opens a file and returns its logical unit number.

Parameters
file_nameFile name; must be omitted for an anonymous SCRATCH file
unit_numberLogical unit number of the opened file
file_statusFortran file status OLD, NEW, REPLACE, UNKNOWN, or SCRATCH for an anonymous temporary file (default: OLD)
file_formFORMATTED or UNFORMATTED (default: FORMATTED)
file_actionREAD, WRITE, or READWRITE (default: WRITE for STATUS=NEW, REPLACE, and SCRATCH, otherwise READ)
file_positionASIS, REWIND, or APPEND (default: REWIND)
file_padYES or NO (default: YES); only allowed for FORMATTED files
file_accessSEQUENTIAL or STREAM (default: SEQUENTIAL); DIRECT is not supported
debugPrint the connection properties to the default output unit
Author
Matthias Krack (MK)
Note
- If the file is already open, its unit number is returned and no new connection is made. ACTION, FORM, and ACCESS must match the existing connection; with POSITION=REWIND the file is rewound.
  • For STATUS=OLD and ACTION=READ, the file is also looked up in the data directory (see discover_file). Files opened for writing are never taken from there.
  • Any error aborts the program; there is no IOSTAT return.

Definition at line 194 of file cp_files.F.

Here is the call graph for this function:

◆ file_exists()

logical function, public cp_files::file_exists ( character(len=*), intent(in) file_name)

Checks if a file exists, considering also the file discovery mechanism.

Parameters
file_nameName of the file
Returns
True, if the file exists in the current or the data directory
Author
Ole Schuett

Definition at line 516 of file cp_files.F.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ discover_file()

character(len=default_path_length) function, public cp_files::discover_file ( character(len=*), intent(in) file_name)

Searches for a file in the current directory and then in the data directory.

Parameters
file_nameName of the file
Returns
File name as given, if it exists, otherwise its path in the data directory, if it exists there, else the file name stripped of blanks
Author
Ole Schuett

Definition at line 536 of file cp_files.F.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_data_dir()

character(len=default_path_length) function, public cp_files::get_data_dir

Returns path of data directory if set, otherwise an empty string.

Returns
Path of the data directory or an empty string
Author
Ole Schuett

Definition at line 573 of file cp_files.F.

Here is the caller graph for this function:

◆ join_paths()

character(len=default_path_length) function, public cp_files::join_paths ( character(len=*), intent(in) path1,
character(len=*), intent(in) path2 )

Joins two file paths, inserting '/' as needed.

Parameters
path1Leading path, e.g. a directory
path2Trailing path; returned unchanged if it is an absolute path
Returns
Joined path; the program is aborted, if it exceeds default_path_length
Author
Ole Schuett

Definition at line 607 of file cp_files.F.

Here is the caller graph for this function: