parser_obj_ParseFile Subroutine

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'.

Type Bound

parser_obj

Arguments

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

Parser object

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

Optional input file name


Calls

proc~~parser_obj_parsefile~~CallsGraph proc~parser_obj_parsefile parser_obj%parser_obj_ParseFile proc~cli_obj_get cli_obj%cli_obj_Get proc~parser_obj_parsefile->proc~cli_obj_get proc~parser_obj_parseline parser_obj%parser_obj_ParseLine proc~parser_obj_parsefile->proc~parser_obj_parseline proc~parser_obj_addentry parser_obj%parser_obj_AddEntry proc~parser_obj_parseline->proc~parser_obj_addentry proc~parser_obj_fetchlabelid parser_obj%parser_obj_FetchLabelID proc~parser_obj_parseline->proc~parser_obj_fetchlabelid proc~parser_obj_reformatline parser_obj%parser_obj_ReformatLine proc~parser_obj_parseline->proc~parser_obj_reformatline

Called by

proc~~parser_obj_parsefile~~CalledByGraph proc~parser_obj_parsefile parser_obj%parser_obj_ParseFile program~main main program~main->proc~parser_obj_parsefile

Source Code

  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'.
    implicit none
    class(parser_obj), intent(inout) :: this                                   !! Parser object
    character(len=*),  intent(in),    &
                            optional :: optInput                               !! Optional input file name
    ! Work variables
    character(len=str64)         :: input_file                                 !! Input file name to use
    integer                      :: fid                                        !! File ID
    type(cli_obj)                :: cli                                        !! A CLI tool
    character(len=MAX_LINE_SIZE) :: line                                       !! A line from the file
    integer :: ierr

    ! Define file name
    if (present(optInput)) then
      input_file=trim(adjustl(optInput))
    else
      call cli%Get('i',input_file,default="input")
    end if

    ! Open the file
    open (newunit=fid,file=input_file,form='formatted',status='old',iostat=ierr)
    if (ierr .ne. 0) stop 'Parser : unable to open the input file.'

    ! Read file line by line
    ierr = 0
    do while (ierr .eq. 0)
      ! Read new line
      read(fid,'(a)',iostat=ierr) line
      if (ierr.ne.0) cycle

      call this%ParseLine(line)
    end do

    ! Close file
    close(fid)

    return
  end subroutine parser_obj_ParseFile