@@ -1301,7 +1301,7 @@ recursive subroutine check_syntax (me,func,funcstr,var,ipos)
1301
1301
end if
1302
1302
1303
1303
end_of_function = .false.
1304
- n = mathfunction_index (func(j:))
1304
+ n = mathfunction_index (func(j:), var )
1305
1305
if (n > 0 ) then ! Check for math function
1306
1306
j = j+ len_trim (functions(n))
1307
1307
if (j > lFunc) then
@@ -1310,9 +1310,9 @@ recursive subroutine check_syntax (me,func,funcstr,var,ipos)
1310
1310
end if
1311
1311
c = func(j:j)
1312
1312
if (c /= ' (' ) then
1313
- write (* ,* ) ' here' , funcstr
1314
- write (* ,* ) ' j = ' , j
1315
- write (* ,* ) ' c = ' , c
1313
+ ! write(*,*) 'here', funcstr
1314
+ ! write(*,*) 'j = ', j
1315
+ ! write(*,*) 'c = ', c
1316
1316
call me% add_error(j, ipos, funcstr, ' Missing opening parenthesis' )
1317
1317
return
1318
1318
end if
@@ -1336,8 +1336,8 @@ recursive subroutine check_syntax (me,func,funcstr,var,ipos)
1336
1336
call me% add_error(j, ipos, funcstr, ' Missing required function argument' )
1337
1337
return
1338
1338
elseif (num_args > required_args(n) + optional_args(n)) then
1339
- call me% add_error(j, ipos, funcstr, ' Too many function arguments' )
1340
- return
1339
+ call me% add_error(j, ipos, funcstr, ' Too many function arguments' )
1340
+ return
1341
1341
end if
1342
1342
1343
1343
! Recursively check each argument substring.
@@ -1516,11 +1516,12 @@ end function operator_index
1516
1516
! >
1517
1517
! Return index of math function beginning at 1st position of string `str`
1518
1518
1519
- function mathfunction_index (str ) result (n)
1519
+ function mathfunction_index (str , var ) result (n)
1520
1520
1521
1521
implicit none
1522
1522
1523
1523
character (len=* ), intent (in ) :: str
1524
+ character (len=* ), dimension (:),intent (in ) :: var ! ! array with variable names
1524
1525
integer :: n
1525
1526
1526
1527
integer :: j
@@ -1537,6 +1538,19 @@ function mathfunction_index (str) result (n)
1537
1538
end if
1538
1539
end do
1539
1540
1541
+ if (n> 0 ) then
1542
+ if (any (functions(n) == var)) then
1543
+ ! in this case, there is a variable with the same
1544
+ ! name as this function. So, check to make sure this
1545
+ ! is really the function.
1546
+ if (k+1 <= len (str)) then
1547
+ if (str(k+1 :k+1 ) /= ' (' ) then ! this assumes that spaces have been removed
1548
+ n = 0 ! assume it is the variable
1549
+ end if
1550
+ end if
1551
+ end if
1552
+ end if
1553
+
1540
1554
end function mathfunction_index
1541
1555
! *******************************************************************************
1542
1556
@@ -1785,8 +1799,8 @@ function completely_enclosed (f, b, e) result (res)
1785
1799
1786
1800
character (len=* ), intent (in ) :: f ! ! function substring
1787
1801
integer , intent (in ) :: b,e ! ! first and last pos. of substring
1788
-
1789
1802
logical :: res
1803
+
1790
1804
integer :: j,k
1791
1805
1792
1806
res= .false.
@@ -1836,7 +1850,7 @@ recursive subroutine compile_substr (me, f, b, e, var)
1836
1850
call compile_substr (me, f, b+1 , e-1 , var)
1837
1851
return
1838
1852
elseif (scan (f(b:b),calpha) > 0 ) then
1839
- n = mathfunction_index (f(b:e))
1853
+ n = mathfunction_index (f(b:e), var )
1840
1854
if (n > 0 ) then
1841
1855
b2 = b+ index (f(b:e),' (' )- 1
1842
1856
if (completely_enclosed(f, b2, e)) then ! case 3: f(b:e) = 'fcn(...)'
@@ -1868,7 +1882,7 @@ recursive subroutine compile_substr (me, f, b, e, var)
1868
1882
call add_compiled_byte (me, cneg)
1869
1883
return
1870
1884
elseif (scan (f(b+1 :b+1 ),calpha) > 0 ) then
1871
- n = mathfunction_index (f(b+1 :e))
1885
+ n = mathfunction_index (f(b+1 :e), var )
1872
1886
if (n > 0 ) then
1873
1887
b2 = b+ index (f(b+1 :e),' (' )
1874
1888
if (completely_enclosed(f, b2, e)) then ! case 5: f(b:e) = '-fcn(...)'
0 commit comments