Routine that extracts an integer value from a line of the input file author: P J Knight, CCFE, Culham Science Centre ival : output integer : extracted integer value icode : output integer : diagnostic flag This routine extracts an integer value from the current line of the input file, i.e. the value of an integer variable as specified by the user. None
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(out) | :: | ival | |||
integer, | intent(out) | :: | icode |
subroutine get_value_int(ival,icode)
!! Routine that extracts an integer value from a line of the
!! input file
!! author: P J Knight, CCFE, Culham Science Centre
!! ival : output integer : extracted integer value
!! icode : output integer : diagnostic flag
!! This routine extracts an integer value from the current line of
!! the input file, i.e. the value of an integer variable as
!! specified by the user.
!! None
!
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
implicit none
! Arguments
integer, intent(out) :: ival, icode
! Local variables
character(len=maxlen) :: varval
integer :: varlen
integer :: foundComma, foundAst, foundPoint
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! *** Ignore leading spaces
10 continue
if (iptr <= linelen) then
if (line(iptr:iptr) == ' ') then
iptr = iptr + 1
goto 10
end if
end if
if (iptr > linelen) goto 60
! 40 continue !KE I guess I can remove this too
! *** Put rest of line into varval (makes it easier to parse)
varval = line(iptr:)
! *** Exclude any input after * or , - these denote an input comment
varlen = len_trim(varval)
foundComma = varlen
foundAst = varlen
foundPoint = 0
if (index(varval,',') > 0) then
foundComma = index(varval,',') - 1
end if
if (index(varval,'*') > 0) then
foundAst = index(varval,'*') - 1
end if
varlen = min(varlen, foundComma, foundAst)
if (varlen <= 0) varlen = index(varval,' ') - 1
if (varlen <= 0) varlen = iptr
varval = varval(:varlen)
varlen = len_trim(varval)
foundPoint = index(varval,'.') - 1
if (foundPoint > 0) then
varlen = foundPoint
write(*,*) 'Integer value expected in following input line...'
write(*,*) ' ',line(1:50),'...'
error = .True.
end if
! *** Update pointer
iptr = iptr + varlen
! *** Ignore trailing spaces
50 continue
if (line(iptr:iptr) == ' ') then
iptr = iptr + 1
if (iptr <= linelen) goto 50
end if
! *** Ignore comma, if present
if (iptr <= linelen) then
if (line(iptr:iptr) == ',') iptr = iptr + 1
end if
! *** Convert the ASCII text into an integer value
call string_to_int(varval,varlen,ival,icode)
goto 1000
60 continue
icode = 1
1000 continue
end subroutine get_value_int