leapParser Module

Simple parser to read inputs from ASCII files. These files should be organized like this: Label 1 : 0.1 # A scalar value Label 2 : 0.1 0.2 0.3 # A vector value Label 3 : Test # A string Label 4 : Test1 Test2 # An array of strings Label 5 : .true. # A logical !Label 6 : .false. # This line is ignored because of '!' Label 7 : 0.1 ! 0.2 0.3 # A scalar value

In this example, the symbol ':' separates labels and values. All characters that appear after a comment symbol (!, #, or %) are ignored.



Uses

  • module~~leapparser~~UsesGraph module~leapparser leapParser iso_fortran_env iso_fortran_env module~leapparser->iso_fortran_env module~leapcli leapCli module~leapparser->module~leapcli module~leapkinds leapKinds module~leapparser->module~leapkinds module~leapcli->module~leapkinds module~leapkinds->iso_fortran_env

Used by

  • module~~leapparser~~UsedByGraph module~leapparser leapParser module~cdifs cdifs module~cdifs->module~leapparser module~collisions collisions module~cdifs->module~collisions module~leapsolver leapSolver module~cdifs->module~leapsolver module~leaptimer leapTimer module~cdifs->module~leaptimer module~particles_resolved particles_resolved module~cdifs->module~particles_resolved module~immersed_boundaries immersed_boundaries module~cdifs->module~immersed_boundaries module~collisions->module~leapparser module~collisions->module~leaptimer module~particles_point particles_point module~collisions->module~particles_point module~collisions->module~particles_resolved module~collisions->module~immersed_boundaries module~grans grans module~grans->module~leapparser module~grans->module~collisions module~grans->module~leapsolver module~grans->module~leaptimer module~grans->module~particles_point module~grans->module~particles_resolved module~grans->module~immersed_boundaries module~immersed_boundaries_markers immersed_boundaries_markers module~immersed_boundaries_markers->module~leapparser module~immersed_boundaries_markers->module~leaptimer module~leapsolver->module~leapparser module~leapsolver->module~leaptimer module~leaptimer->module~leapparser module~particles_point->module~leapparser module~particles_point->module~leaptimer module~particles_point->module~immersed_boundaries module~particles_resolved->module~leapparser module~particles_resolved->module~leaptimer module~particles_resolved->module~immersed_boundaries program~main main program~main->module~leapparser program~main->module~cdifs program~main->module~grans program~main->module~leapsolver program~main->module~leaptimer module~cdifs_advancesolution_smod cdifs_AdvanceSolution_smod module~cdifs_advancesolution_smod->module~cdifs module~cdifs_monitor_smod cdifs_Monitor_smod module~cdifs_monitor_smod->module~cdifs module~cdifs_preparesolver_smod cdifs_PrepareSolver_smod module~cdifs_preparesolver_smod->module~cdifs module~cdifs_writeoutputdata_smod cdifs_WriteOutputData_smod module~cdifs_writeoutputdata_smod->module~cdifs module~cdifs_writerestartdata_smod cdifs_WriteRestartData_smod module~cdifs_writerestartdata_smod->module~cdifs module~grans_advancesolution_smod grans_AdvanceSolution_smod module~grans_advancesolution_smod->module~grans module~grans_module_smod grans_module_smod module~grans_module_smod->module~grans module~grans_preparesolver_smod grans_PrepareSolver_smod module~grans_preparesolver_smod->module~grans module~grans_writeoutputdata_smod grans_WriteOutputData_smod module~grans_writeoutputdata_smod->module~grans module~grans_writerestartdata_smod grans_WriteRestartData_smod module~grans_writerestartdata_smod->module~grans module~immersed_boundaries->module~immersed_boundaries_markers module~immersed_boundaries_solids immersed_boundaries_solids module~immersed_boundaries->module~immersed_boundaries_solids module~immersed_boundaries_solids->module~immersed_boundaries_markers

Variables

Type Visibility Attributes Name Initial
character(len=3), private, parameter :: COMMENT_SYMBOLS = '!#%'

Allowed comment symbols

integer, private, parameter :: MAX_LABEL_SIZE = 128

Maximum number of characters in a label

integer, private, parameter :: MAX_LINE_SIZE = 4096

Maximum number of characters in a line

character(len=1), private, parameter :: SEPARATOR = ':'

Character used to seperate label form value

integer, private, parameter :: TAB_ICHAR = 9

ichar of a tab character


Derived Types

type, public ::  parser_obj

A utility to parse information in an ASCII file.

Components

Type Visibility Attributes Name Initial
type(entry_obj), public, allocatable :: entries(:)

Entries in file

Type-Bound Procedures

procedure, public :: Finalize => parser_obj_final
generic, public :: Get => parser_obj_read0D, parser_obj_read1D
procedure, public :: Initialize => parser_obj_init
procedure, public :: IsDefined => parser_obj_IsDefined
procedure, public :: ParseFile => parser_obj_ParseFile
procedure, public :: Print => parser_obj_print
procedure, private :: AddEntry => parser_obj_AddEntry
generic, private :: AssignDefault => parser_obj_AssignDefault0D, parser_obj_AssignDefault1D
procedure, private :: FetchLabelID => parser_obj_FetchLabelID
procedure, private :: ParseLine => parser_obj_ParseLine
procedure, private, nopass :: parser_obj_AssignDefault0D
procedure, private, nopass :: parser_obj_AssignDefault1D
procedure, private, nopass :: parser_obj_ReformatLine
procedure, private :: parser_obj_read0D
procedure, private :: parser_obj_read1D

type, private ::  entry_obj

Object representing an entry in the input file.

Components

Type Visibility Attributes Name Initial
character(len=:), public, allocatable :: label

Column label

character(len=:), public, allocatable :: value

Value


Functions

private pure function parser_obj_FetchLabelID(this, label) result(id)

Returns ID of label in entries array. Returns 0 if label not found.

Arguments

Type IntentOptional Attributes Name
class(parser_obj), intent(in) :: this

Parser object

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

label to look for

Return Value integer

private pure function parser_obj_IsDefined(this, label) result(found)

Checks whether a label was found when parsing the file.

Arguments

Type IntentOptional Attributes Name
class(parser_obj), intent(in) :: this

Parser object

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

label to look for

Return Value logical

Result


Subroutines

private pure subroutine parser_obj_AddEntry(this, entry)

Resizes entries array to add a new entry.

Arguments

Type IntentOptional Attributes Name
class(parser_obj), intent(inout) :: this

Parser object

type(entry_obj), intent(in) :: entry

New entrysize

private impure subroutine parser_obj_AssignDefault0D(value, default)

Sets 0D (scalar) value equal to 0D (scalar) default.

Arguments

Type IntentOptional Attributes Name
class(*), intent(out) :: value

Value to return

class(*), intent(in) :: default

Default value to return in case label is not found

private impure subroutine parser_obj_AssignDefault1D(value, default)

Sets 1D (array) values equal to 1D (array) defaults.

Arguments

Type IntentOptional Attributes Name
class(*), intent(out) :: value(:)

Value to return

class(*), intent(in) :: default(:)

Default value to return in case label is not found

private impure subroutine parser_obj_ParseFile(this, optInput)

Parses an ASCII file. This subroutine will identify all entries in the file (label-value pairs) and store them internally. Users can specify the filename using the optional optInput variable. Otherwise, the default filename is 'input'.

Arguments

Type IntentOptional Attributes Name
class(parser_obj), intent(inout) :: this

Parser object

character(len=*), intent(in), optional :: optInput

Optional input file name

private pure subroutine parser_obj_ParseLine(this, line)

Parses a line by finding the label-value pair and storing it as a new entry.

Arguments

Type IntentOptional Attributes Name
class(parser_obj), intent(inout) :: this

Parser object

character(len=MAX_LINE_SIZE), intent(inout) :: line

A line from the input file

private pure subroutine parser_obj_ReformatLine(line)

Fomats a line by removing comments and replacing tabs with spaces.

Arguments

Type IntentOptional Attributes Name
character(len=MAX_LINE_SIZE), intent(inout) :: line

A line from the input file

private pure subroutine parser_obj_final(this)

Finalizes object and frees allocated memory.

Arguments

Type IntentOptional Attributes Name
class(parser_obj), intent(inout) :: this

Parser object

private pure subroutine parser_obj_init(this)

Initializes the parser object.

Arguments

Type IntentOptional Attributes Name
class(parser_obj), intent(inout) :: this

Parser object

private impure subroutine parser_obj_print(this)

Prints all variables found in the parsed file.

Arguments

Type IntentOptional Attributes Name
class(parser_obj), intent(inout) :: this

Parser object

private impure subroutine parser_obj_read0D(this, label, value, default)

Reads 0D (scalar) values of kind real, integer, logical, or character string. If label is not found and the optional default is provided, the value will be set to the default value. If the label is not found and there is no optional default, this subroutine will return an error.

Arguments

Type IntentOptional Attributes Name
class(parser_obj), intent(inout) :: this

Parser object

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

Label

class(*), intent(out) :: value

Value to return

class(*), intent(in), optional :: default

Default value to return in case label is not found

private impure subroutine parser_obj_read1D(this, label, value, default)

Reads 1D (array) values of kind real, integer, logical, or character string. If label is not found and the optional default is provided, the value will be set to the default value. If the label is not found and there is no optional default, this subroutine will return an error.

Arguments

Type IntentOptional Attributes Name
class(parser_obj), intent(inout) :: this

Parser object

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

Label

class(*), intent(out) :: value(:)

Value to return

class(*), intent(in), optional :: default(:)

Default value to return in case label is not found