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.
| 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_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. 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 character(len=str8), & allocatable :: outputs(:) character(len=:), & allocatable :: str integer :: count integer :: n 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) ! Count number of entries str = trim(adjustl(this%entries(entry_ID)%value)) count = 0 n = 1 do while (n.ne.0) count = count + 1 str = adjustl(str(n:len_trim(str))) n = scan(trim(str),' ') end do allocate (outputs(count)) read(this%entries(entry_ID)%value,*,iostat=ierr) outputs do n = 1, count select case (trim(adjustl(outputs(n)))) case ('1', '.true.', '.True.', '.TRUE.') value(n) = .true. case ('0', '.false.', '.False.', '.FALSE.') value(n) = .false. case default write(stdout,*) 'Error in Parser: invalid value for '// trim(adjustl(label))//'.' end select end do 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=*)) read(this%entries(entry_ID)%value,*,iostat=ierr) 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_read1D