The AHA Model  Revision: 12809
Reference implementation 04 (HEDG02_04)
file_io::file_handle Type Reference

FILE_HANDLE is the basic file handle object. It provides an unitary object oriented interface for operations with any supported file types. More...

Collaboration diagram for file_io::file_handle:

Public Member Functions

procedure, public is_success => file_operation_last_is_success
 Obtain the success (TRUE) or failure (FALSE) status of the latest file operation. See example code. More...
 
procedure, public get_name => file_hangle_get_name_string
 Get the file name associated with the file handle. See example code. More...
 
procedure, public get_unit => file_object_get_associated_unit
 Get the Fortran unit number associated with the file handle object. See example code. More...
 
procedure, public is_csv => file_object_format_is_csv
 Check if the file format is CSV. See example code. More...
 
procedure, public is_txt => file_object_format_is_txt
 Check if the file format is TXT. See example code. More...
 
procedure, public open_write => csv_open_write_this
 Open file for physical writing on the disk. See example code. More...
 
procedure, public header_write => csv_header_line_write_this
 Physically write an information header (metadata) about the file. See example code. More...
 
procedure, public close => csv_close_this
 Closes the file for reading or writing. See example code. More...
 
procedure, public record_write => csv_record_string_write_this
 Physically write a single string CSV data record (row) to the file. See example code. More...
 

Private Attributes

integer, private format
 The format of the file, i.e. the file type. The following file types are implemented: More...
 
type(csv_file), private file_object_csv
 file_object_csv is the standard CSV_FILE type from CSV_IO module HEDTOOLS. For details on this component type see CSV_FILE CSV_FILE has the following sub-components: More...
 

Detailed Description

FILE_HANDLE is the basic file handle object. It provides an unitary object oriented interface for operations with any supported file types.

Example:

type(FILE_HANDLE) :: data_file

Only CSV format is supported so far.

Note
It would be even more useful to add the CSV file record into the type as an allocatable component and implement simple record_clean record_append functions. However, allocatable components are not supported in GNU gfortran 4.8, issues error: ‘Error: Deferred-length character component 'record_string’ at (1) is not yet supported`. Therefore, raw operations with the CSV file record are left here as in the non-OO versions. See extended example in HEDTOOLS and the code of this procedure: the_population::population_save_data_all_agents_csv(). But note that these codes use standard non-object-oriented procedures from HEDTOOLS, not these object oriented wrappers.

Definition at line 148 of file m_fileio.f90.

Member Function/Subroutine Documentation

◆ is_success()

procedure, public file_io::file_handle::is_success

Obtain the success (TRUE) or failure (FALSE) status of the latest file operation. See example code.

Example:

if ( data_file%is_success() ) then

Definition at line 177 of file m_fileio.f90.

◆ get_name()

procedure, public file_io::file_handle::get_name

Get the file name associated with the file handle. See example code.

Example:

print *, data_file%get_name()

Definition at line 185 of file m_fileio.f90.

◆ get_unit()

procedure, public file_io::file_handle::get_unit

Get the Fortran unit number associated with the file handle object. See example code.

Example:

print *, data_file%get_unit()

Definition at line 194 of file m_fileio.f90.

◆ is_csv()

procedure, public file_io::file_handle::is_csv

Check if the file format is CSV. See example code.

Definition at line 197 of file m_fileio.f90.

◆ is_txt()

procedure, public file_io::file_handle::is_txt

Check if the file format is TXT. See example code.

Definition at line 200 of file m_fileio.f90.

◆ open_write()

procedure, public file_io::file_handle::open_write

Open file for physical writing on the disk. See example code.

Example:

call data_file%open_write( "file_001.csv" )

Definition at line 208 of file m_fileio.f90.

◆ header_write()

procedure, public file_io::file_handle::header_write

Physically write an information header (metadata) about the file. See example code.

Example:

call data_file%header_write("Agent data at start of the simulation")

Definition at line 216 of file m_fileio.f90.

◆ close()

procedure, public file_io::file_handle::close

Closes the file for reading or writing. See example code.

Example:

call data_file%close()

Definition at line 224 of file m_fileio.f90.

◆ record_write()

procedure, public file_io::file_handle::record_write

Physically write a single string CSV data record (row) to the file. See example code.

Example:

call data_file%record_write( record_string )

Definition at line 232 of file m_fileio.f90.

Member Data Documentation

◆ format

integer, private file_io::file_handle::format
private

The format of the file, i.e. the file type. The following file types are implemented:

  • FORMAT_CSV – Comma Separated Values is a plain text;
  • FORMAT_TXT – Plain text file.

Definition at line 154 of file m_fileio.f90.

◆ file_object_csv

type (csv_file), private file_io::file_handle::file_object_csv
private

file_object_csv is the standard CSV_FILE type from CSV_IO module HEDTOOLS. For details on this component type see CSV_FILE CSV_FILE has the following sub-components:

  • character (len=MAX_FILENAME) :: name – file name;
  • integer :: unit – Fortran file unit;
  • logical :: status – Logical status of the last operation.
Note
In the wrapper implementation routines, just substitute the original CSV file handle object with thisfile_object_csv.

Definition at line 165 of file m_fileio.f90.


The documentation for this type was generated from the following file: