Routine that extracts a variable name from a line of
the input file
author: P J Knight, CCFE, Culham Science Centre
varnam : output string : extracted variable name
varlen : output integer : length of variable name
isub1 : output integer : first subscript found
isub2 : output integer : second subscript found
This routine extracts a variable name from the current line of
the input file. It also extracts any subscripts present.
On exit, the counter iptr
points to the first
character of the value to be assigned to the variable.
If the routine finds an error a value of 0 is returned in
variable varlen
.
None
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(out) | :: | varnam | |||
integer, | intent(out) | :: | varlen | |||
integer, | intent(out) | :: | isub1 | |||
integer, | intent(out) | :: | isub2 |
subroutine get_variable_name(varnam,varlen,isub1,isub2)
!! Routine that extracts a variable name from a line of
!! the input file
!! author: P J Knight, CCFE, Culham Science Centre
!! varnam : output string : extracted variable name
!! varlen : output integer : length of variable name
!! isub1 : output integer : first subscript found
!! isub2 : output integer : second subscript found
!! This routine extracts a variable name from the current line of
!! the input file. It also extracts any subscripts present.
!! On exit, the counter <CODE>iptr</CODE> points to the first
!! character of the value to be assigned to the variable.
!! If the routine finds an error a value of 0 is returned in
!! variable <CODE>varlen</CODE>.
!! None
!
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
implicit none
! Arguments
integer, intent(out) :: varlen, isub1, isub2
character(len=*), intent(out) :: varnam
! Local variables
character(len=maxlen) :: line1
integer :: ifrom,ito,icode
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! *** Store LINE in local variable
line1 = line
! *** Convert string to lower case
call lower_case(line)
varlen = 0
ifrom = iptr
! *** First character must be alphabetic
if ((line(iptr:iptr) < 'a').or.(line(iptr:iptr) > 'z')) goto 1000
iptr = iptr + 1
if (iptr > linelen) goto 1000
! *** Now parse the rest of the letters (must be alphanumeric or _ )
10 continue
if ( ((line(iptr:iptr) >= 'a').and.(line(iptr:iptr) <= 'z')).or. &
((line(iptr:iptr) == '_')).or. &
((line(iptr:iptr) >= '0').and.(line(iptr:iptr) <= '9')) ) then
iptr = iptr + 1
if (iptr <= linelen) goto 10
end if
! *** Extract variable name
ito = iptr - 1
varlen = ito - ifrom + 1
if (varlen > 0) varnam = line(ifrom:ito)
! *** Ignore intervening spaces
20 continue
if (line(iptr:iptr) == ' ') then
iptr = iptr + 1
if (iptr <= linelen) goto 20
end if
! *** Now extract any subscript
call get_subscript(isub1,isub2,icode)
if (icode /= 0) then
varlen = 0
goto 1000
end if
! *** Ignore intervening spaces
30 continue
if (line(iptr:iptr) == ' ') then
iptr = iptr + 1
if (iptr <= linelen) goto 30
end if
! *** We now expect '='
if (line(iptr:iptr) == '=') then
iptr = iptr + 1
! *** Restore original string's upper/lower case after '=' sign
line(iptr:linelen) = line1(iptr:linelen)
else
varlen = 0
end if
1000 continue
end subroutine get_variable_name