View previous topic :: View next topic |
Author |
Message |
AKS
Joined: 19 Mar 2008 Posts: 29
|
Posted: Mon Jun 08, 2020 9:33 pm Post subject: Overriding Intrinsic Functions in Fortran 95 |
|
|
I am converting a set of old Fortran (77?) files to Fortran 95. In the old Fortran, there are 2 variables TRIM and RANGE which are Intrinsic functions n Fortran 95. Is there any way to suppress the use of the TRIM and RANGE functions in Fortran 95 in order to use TRIM and RANGE as variables in the new Fortran 95 code? Thank you. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1888
|
Posted: Tue Jun 09, 2020 2:23 am Post subject: |
|
|
Why is a "conversion" needed for variables with the same name as F95 intrinsic functions? Fortran has no reserved names, and user-created names supplant intrinsic names (and even keywords). In the following example, trim and range are variables, whereas nint, int, log10 and abs remain intrinsic functions:
Code: | subroutine sub(x, trim, range)
trim = nint(x*10.0)*0.1
range = int(log10(abs(x)))
return
end |
Last edited by mecej4 on Tue Jun 09, 2020 2:52 pm; edited 1 time in total |
|
Back to top |
|
|
AKS
Joined: 19 Mar 2008 Posts: 29
|
Posted: Tue Jun 09, 2020 2:40 pm Post subject: Reserved words |
|
|
Perhaps I jumped to conclusions, but Fortran 95 definitely did not like me using TRIM and RANGE as variables from the previous code.Thanks for your quick response. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1888
|
Posted: Tue Jun 09, 2020 2:54 pm Post subject: |
|
|
It will be necessary to see the statements in question that the compiler "did not like", and the actual error messages issued.
Better yet, provide the complete source code of the program unit that the compiler rejected.
For an independent discussion of this issue by a member of the Fortran Standard J3/WG5 committee, please see https://stevelionel.com/drfortran/2020/06/07/doctor-fortran-in-no-reserve/ . |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Tue Jun 09, 2020 8:44 pm Post subject: |
|
|
mecej4 shind some lights upon my poor soul here !
Quote: | Fortran has no reserved names,
|
you learn something new everyday ! ..... was this an F90 or F95 'innovation' ? I thought F77 it was forbidden to use 'reserved' names.
Quote: | and user-created names supplant intrinsic names |
I'd personally call that a dangerously devilish(take note Dan !) development !
Quote: | (and even keywords) |
you mean one could use a variable, for example, called 'subroutine' !!! ???
Presumeably, in such cases, IMPLICIT NONE is a very big no-no ? _________________ ''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... " |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1888
|
Posted: Wed Jun 10, 2020 12:33 am Post subject: |
|
|
That no keywords are reserved is an attribute for which Fortran is notorious.
Just for laughs, this is a valid but deplorable program in free form:
Code: | program program
real real
integer integer
character character
!
do integer = 1, 5
real = integer
character = achar (integer + 64)
print *,integer, real, character
end do
end program |
So is the following version, now in fixed form:
Code: | programprogram;realreal;integerinteger;charactercharacter
dointeger=1,5;real=integer;character=achar(integer+64)
print*,integer,real,character;enddo;endprogram |
If you take the additional step of replacing semicolons by newlines+6 blanks, the old Salford/Silverfrost FTN77 compiler will also compile this program. |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Fri Jun 12, 2020 10:17 am Post subject: |
|
|
good grief ! that's A-mazing !
But whatif you had something like
Do DoVariable = 1,10
and wrote it as:
DoDoVariable=1,10
would the DoDo confuse it (would it detect x2 Do statements I wanda and a variable called Variable ? _________________ ''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... " |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2556 Location: Sydney
|
Posted: Mon Jun 15, 2020 2:37 pm Post subject: |
|
|
John,
perhaps more confusing ?
Code: | complex a, dodovariable
integer dovariable
dodovariable = (1,10)
dodovariable = 1,10
a = dovariable + dodovariable
end do
end |
|
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1888
|
Posted: Tue Jun 23, 2020 9:42 am Post subject: |
|
|
And then, for extra credit, find a Fortran-aware editor that correctly indents the DO loop in John C's example code! |
|
Back to top |
|
|
|