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.
| Type | Intent | Optional | 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 |
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. implicit none class(parser_obj), intent(inout) :: this !! Parser object character(*), 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 ! Work variables integer :: entry_ID integer :: ierr ierr = 0 ! Get ID of label (or 0 if not found) entry_ID = this%FetchLabelID(label) if (entry_ID.eq.0.and..not.present(default)) then write(stdout,*) 'Error in Parser: '// trim(adjustl(label)) //' not found' stop else if (entry_ID.eq.0.and.present(default)) then ! Check default and value are of the same type call this%AssignDefault(value,default) else select type (value) type is (logical) select case (trim(adjustl(this%entries(entry_ID)%value))) case ('1', '.true.', '.True.', '.TRUE.') value = .true. case ('0', '.false.', '.False.', '.FALSE.') value = .false. case default write(stdout,*) 'Error in Parser: invalid value for '// trim(adjustl(label))//'.' end select type is (real(leapDP)) read(this%entries(entry_ID)%value,*,iostat=ierr) value type is (real(leapSP)) read(this%entries(entry_ID)%value,*,iostat=ierr) value type is (integer(leapI4)) read(this%entries(entry_ID)%value,*,iostat=ierr) value type is (integer(leapI8)) read(this%entries(entry_ID)%value,*,iostat=ierr) value type is (character(len=*)) value=trim(adjustl(this%entries(entry_ID)%value)) class default stop "Error in Parser: unknown variable type" end select end if if (ierr.ne.0) then write(stdout,*) 'Error in Parser: An error occured while reading the value of: '// trim(adjustl(label)) stop end if return end subroutine parser_obj_read0D