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 | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(parser_obj), | intent(inout) | :: | this |
Parser object |
||
| character(len=*), | intent(in), | optional | :: | optInput |
Optional input file name |
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