Takes a string in the form 0.0,1.0,0.5 and returns an array of the real num
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=maxlen), | intent(in) | :: | string_tmp | |||
real(kind=dp), | intent(out) | :: | outvec(3) |
subroutine utility_string_to_coord(string_tmp, outvec)!
!====================================================!
! !
!! Takes a string in the form 0.0,1.0,0.5
!! and returns an array of the real num
! !
!====================================================!
use w90_io, only: io_error, maxlen
implicit none
character(len=maxlen), intent(in) :: string_tmp
real(kind=dp), intent(out) :: outvec(3)
integer :: pos
character(len=maxlen) :: ctemp
character(len=maxlen) :: ctemp2
ctemp = string_tmp
pos = index(ctemp, ',')
if (pos <= 0) call io_error('utility_string_to_coord: Problem reading string into real number '//trim(string_tmp))
ctemp2 = ctemp(1:pos - 1)
read (ctemp2, *, err=100, end=100) outvec(1)
ctemp = ctemp(pos + 1:)
pos = index(ctemp, ',')
ctemp2 = ctemp(1:pos - 1)
read (ctemp2, *, err=100, end=100) outvec(2)
ctemp = ctemp(pos + 1:)
read (ctemp, *, err=100, end=100) outvec(3)
return
100 call io_error('utility_string_to_coord: Problem reading string into real number '//trim(string_tmp))
end subroutine utility_string_to_coord