The AHA Model
Revision: 12809
Reference implementation 04 (HEDG02_04)
|
Definition of high level file objects. More...
Data Types | |
type | file_handle |
FILE_HANDLE is the basic file handle object. It provides an unitary object oriented interface for operations with any supported file types. More... | |
Functions/Subroutines | |
logical function | file_operation_last_is_success (this) |
Get the success or error status of the latest file operation. Example: More... | |
character(len=:) function, allocatable | file_hangle_get_name_string (this) |
Get the file name associated with the file handle. If the file name is (yet) undefined, the latest operation success flag (see file_io::is_success()) is FALSE. Example: More... | |
integer function | file_object_get_associated_unit (this) |
A Low level function to get the Fortran unit number associated with the file handle object. More... | |
logical function | file_object_format_is_csv (this) |
Check if the file format is CSV. More... | |
logical function | file_object_format_is_txt (this) |
Check if the file format is CSV. More... | |
subroutine | csv_open_write_this (this, name, format) |
This is an object oriented wrapper for CSV_OPEN_WRITE() . For details see CSV_OPEN_WRITE. More... | |
subroutine | csv_close_this (this) |
This is an object oriented wrapper for CSV_CLOSE() . For details see CSV_CLOSE. More... | |
subroutine | csv_header_line_write_this (this, header) |
This is an object oriented wrapper for CSV_HEADER_WRITE() . See CSV_HEADER_WRITE for details. More... | |
subroutine | csv_record_string_write_this (this, csv_record) |
Physically write a single string CSV data record to the file. See CSV_RECORD_WRITE Example: More... | |
Public enumeration constants defining supported file types | |
enum | |
@, public | undefined |
@, public | format_csv |
@, public | format_txt |
Definition of high level file objects.
This module defines input and output to external files in various formats. The main format for output files for numerical data is CSV. It is useful for one-dimensional vectors and two-dimensional matrices. More complex data structures can be output in other formats (to be implemented) such as binary, XML or HDF. This module provides an unitary object-oriented interface to all file types and objects.
Current status: Only CSV and plain text (TXT) files are implemented so far. And even here, only the file object is implemented in the object oriented style, record (string) is used exactly as in the CSV_IO in HEDTOOLS.
Notably, standard HEDTOOLS whole array procedure CSV_MATRIX_WRITE can save a single vector or 2D matrix into a separate CSV file.
See code of the the_population::population_save_data_all_agents_csv() for another example of writing data to CSV file. But note that these codes use the standard non-object-oriented procedures from HEDTOOLS, not these wrappers.
The file handler object file_io::file_handle defined in this module can be easily used to write arbitrary plain text files. Here is an example.
Example:
Thus, the wrappers implemented in this unit allow to use unitary file handler object to work with specific files, even though they are not fully object oriented. Using a single file handle is simpler and more understandable than different Fortran file identifiers (file name, unit).
The logger commondata::logger_init() is the standard normal method to report everything in the model during the runtime. Therefore, using separate plain text file(s) to output any reports should be very rare if needed at all.
By default, all objects in FILE_IO
are private.
|
private |
Definition at line 120 of file m_fileio.f90.
logical function file_io::file_operation_last_is_success | ( | class(file_handle), intent(inout) | this | ) |
Get the success or error status of the latest file operation. Example:
Definition at line 244 of file m_fileio.f90.
|
private |
Get the file name associated with the file handle. If the file name is (yet) undefined, the latest operation success flag (see file_io::is_success()) is FALSE. Example:
Definition at line 260 of file m_fileio.f90.
|
private |
A Low level function to get the Fortran unit number associated with the file handle object.
Definition at line 278 of file m_fileio.f90.
|
private |
Check if the file format is CSV.
Definition at line 288 of file m_fileio.f90.
|
private |
Check if the file format is CSV.
Definition at line 301 of file m_fileio.f90.
|
private |
This is an object oriented wrapper for CSV_OPEN_WRITE()
. For details see CSV_OPEN_WRITE.
[in] | name | name the name of the file. |
[in] | format | format optional data format type of the file:
|
Set name from the mandatory name
argument.
Default format is FORMAT_CSV
.
Providing a non-supported format results in FALSE status flag.
Open the file for writing physically.
Definition at line 321 of file m_fileio.f90.
|
private |
This is an object oriented wrapper for CSV_CLOSE()
. For details see CSV_CLOSE.
Definition at line 373 of file m_fileio.f90.
|
private |
This is an object oriented wrapper for CSV_HEADER_WRITE()
. See CSV_HEADER_WRITE for details.
[in] | header | header is the optional header line for the CSV file. If header is absent, it is automatically generated from the file name. |
Definition at line 387 of file m_fileio.f90.
|
private |
Physically write a single string CSV data record to the file. See CSV_RECORD_WRITE Example:
[in] | csv_record | csv_record character string that keeps the whole record (row) of the CSV data spreadsheet. |
Definition at line 408 of file m_fileio.f90.
@, public file_io::undefined |
Definition at line 121 of file m_fileio.f90.
@, public file_io::format_csv |
Definition at line 121 of file m_fileio.f90.
@, public file_io::format_txt |
Definition at line 121 of file m_fileio.f90.