parser_obj Derived Type

type, public :: parser_obj

A utility to parse information in an ASCII file.


Inherits

type~~parser_obj~~InheritsGraph type~parser_obj parser_obj type~entry_obj entry_obj type~parser_obj->type~entry_obj entries

Inherited by

type~~parser_obj~~InheritedByGraph type~parser_obj parser_obj type~collision_obj collision_obj type~collision_obj->type~parser_obj parser type~marker_set marker_set type~collision_obj->type~marker_set IB type~particle_set particle_set type~collision_obj->type~particle_set PP type~respart_set ResPart_set type~collision_obj->type~respart_set RP type~timer_obj timer_obj type~collision_obj->type~timer_obj timer type~marker_set->type~parser_obj parser type~marker_set->type~timer_obj timer type~particle_set->type~parser_obj parser type~particle_set->type~timer_obj timer type~respart_set->type~parser_obj parser type~respart_set->type~marker_set ib type~respart_set->type~timer_obj timer type~solver_obj solver_obj type~solver_obj->type~parser_obj parser type~solver_obj->type~timer_obj timer type~timer_obj->type~parser_obj parser type~cdifs_obj cdifs_obj type~cdifs_obj->type~collision_obj collisions type~cdifs_obj->type~marker_set IB type~cdifs_obj->type~respart_set RP type~cdifs_obj->type~solver_obj type~grans_obj grans_obj type~grans_obj->type~collision_obj collisions type~grans_obj->type~marker_set IB type~grans_obj->type~particle_set PP type~grans_obj->type~respart_set RP type~grans_obj->type~solver_obj type~solid_obj solid_obj type~solid_obj->type~marker_set type~solid_set solid_set type~solid_set->type~solid_obj p

Components

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

Entries in file


Type-Bound Procedures

procedure, public :: Finalize => parser_obj_final

  • 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

generic, public :: Get => parser_obj_read0D, parser_obj_read1D

  • 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

procedure, public :: Initialize => parser_obj_init

  • private pure subroutine parser_obj_init(this)

    Initializes the parser object.

    Arguments

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

    Parser object

procedure, public :: IsDefined => parser_obj_IsDefined

  • 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

procedure, public :: ParseFile => parser_obj_ParseFile

  • 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

procedure, public :: Print => parser_obj_print

  • 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

procedure, private :: AddEntry => parser_obj_AddEntry

  • 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

generic, private :: AssignDefault => parser_obj_AssignDefault0D, parser_obj_AssignDefault1D

  • 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

procedure, private :: FetchLabelID => parser_obj_FetchLabelID

  • 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

procedure, private :: ParseLine => parser_obj_ParseLine

  • 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

procedure, private, nopass :: parser_obj_AssignDefault0D

  • 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

procedure, private, nopass :: parser_obj_AssignDefault1D

  • 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

procedure, private, nopass :: parser_obj_ReformatLine

  • 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

procedure, private :: parser_obj_read0D

  • 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

procedure, private :: parser_obj_read1D

  • 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

Source Code

  type :: parser_obj
    !> A utility to parse information in an ASCII file.
    type(entry_obj), allocatable :: entries(:)                                 !! Entries in file
    contains
      procedure :: Initialize               => parser_obj_Init
      procedure :: Finalize                 => parser_obj_Final
      procedure :: ParseFile                => parser_obj_ParseFile
      generic   :: Get                      => parser_obj_read0D,parser_obj_read1D
      procedure :: IsDefined                => parser_obj_IsDefined
      procedure :: Print                    => parser_obj_Print
      ! Internal/private procedures
      procedure, private :: ParseLine       => parser_obj_ParseLine
      procedure, private :: AddEntry        => parser_obj_AddEntry
      procedure, private :: FetchLabelID    => parser_obj_FetchLabelID
      generic  , private :: AssignDefault   => parser_obj_AssignDefault0D,parser_obj_AssignDefault1D
      procedure, private,nopass :: parser_obj_ReformatLine
      procedure, private        :: parser_obj_read0D
      procedure, private        :: parser_obj_read1D
      procedure, private,nopass :: parser_obj_AssignDefault0D
      procedure, private,nopass :: parser_obj_AssignDefault1D
  end type parser_obj